示例#1
0
  private Ref<CConstraint> setRealClauseWithThis() {
    final LazyRef<CConstraint> ref =
        new LazyRef_c<CConstraint>(ConstraintManager.getConstraintSystem().makeCConstraint());
    final Runnable runnable =
        new Runnable() {
          public void run() {
            CConstraint c = X10ClassDef_c.this.realClause.get();
            c = c.instantiateSelf(thisVar());
            ref.update(c);
          }

          public String toString() {
            return "realClauseWithThis for " + X10ClassDef_c.this;
          }
        };
    ref.setResolver(runnable);
    return ref;
  }
示例#2
0
 public XVar thisVar() {
   if (this.thisDef != null) return this.thisDef.thisVar();
   return ConstraintManager.getConstraintSystem().makeThis(); // Why #this instead of this?
 }
示例#3
0
  /**
   * Set the realClause for this type. The realClause is the conjunction of the depClause and the
   * baseClause for the type -- it represents all the constraints that are satisfied by an instance
   * of this type. The baseClause is the invariant for the base type. If the base type C has defined
   * properties P1 p1, ..., Pk pk, and inherits from type B, then the baseClause for C is the
   * baseClause for B conjoined with r1[self.p1/self, self/this] && ... && rk[self.pk/self,
   * self/this] where ri is the realClause for Pi.
   */
  private Ref<CConstraint> setRealClause() {
    final LazyRef<CConstraint> ref =
        new LazyRef_c<CConstraint>(ConstraintManager.getConstraintSystem().makeCConstraint());
    Runnable runnable =
        new Runnable() {
          boolean computing = false;

          public void run() {
            if (computing) {
              return;
            }
            computing = true;
            CConstraint result = ConstraintManager.getConstraintSystem().makeCConstraint();
            try {
              List<X10FieldDef> properties = properties();
              XVar oldThis =
                  thisVar(); // xts.xtypeTranslator().translateThisWithoutTypeConstraint();

              try {
                // Add in constraints from the supertypes.  This is
                // no need to change self, and no occurrence of this is possible in
                // a type's base constraint.
                // vj: 08/12/09. Incorrect. this can occur in a type's base constraint.
                {
                  Type type = Types.get(superType());
                  if (type != null) {
                    CConstraint rs = Types.realX(type);
                    if (rs != null && !rs.valid()) {
                      if (rs.thisVar() != null) rs = rs.substitute(oldThis, (XVar) rs.thisVar());
                      result.addIn(rs);
                    }
                  }
                }

                // Add in constraints from the interfaces.
                for (Iterator<Ref<? extends Type>> i = interfaces().iterator(); i.hasNext(); ) {
                  Ref<? extends Type> it = (Ref<? extends Type>) i.next();
                  CConstraint rs = Types.realX(it.get());
                  // no need to change self, and no occurrence of this is possible in
                  // a type's base constraint.
                  if (rs != null && !rs.valid()) {
                    //    						    rs = rs.substitute(rs.self(), oldThis);
                    result.addIn(rs);
                  }
                }

                // add in the bindings from the property declarations.
                for (X10FieldDef fi : properties) {
                  Type type = fi.asInstance().type(); // ### check for recursive call here
                  XVar fiThis = fi.thisVar();
                  CConstraint rs = Types.realX(type);
                  if (rs != null) {
                    // Given: f:C{c}
                    // Add in: c[self.f/self,self/this]
                    XTerm newSelf = ts.xtypeTranslator().translate(result.self(), fi.asInstance());
                    CConstraint rs1 = rs.instantiateSelf(newSelf);
                    CConstraint rs2;
                    if (fiThis != null) rs2 = rs1.substitute(result.self(), fiThis);
                    else rs2 = rs1;
                    result.addIn(rs2);
                  }
                }

                // Finally, add in the class invariant.
                // It is important to do this last since we need avoid type-checking constraints
                // until after the base type of the supertypes are resolved.
                XVar thisVar = thisVar();
                CConstraint ci = Types.get(classInvariant);
                if (ci != null && !ci.valid()) {
                  ci = ci.substitute(ci.self(), oldThis);
                  result.addIn(ci);
                }

              } catch (XFailure f) {
                result.setInconsistent();
                X10ClassDef_c.this.realClauseInvalid =
                    new SemanticException(
                        "The real clause for " + this + " is inconsistent.", position());
              }

              // Now verify that the root clause entails the assertions of the properties.
              // We need to set the root clause first, to avoid a spurious report of a cyclic
              // dependency.
              // This can happen when one of the properties is subtype of this type:
              // class Ref(home: Place) { }
              // class Place extends Ref { ... }

              // Disable this for now since it can cause an infinite loop.
              // TODO: vj 08/12/09 Revisit this.
              /*if (false && result.consistent()) {
               // Verify that the realclause, as it stands, entails the assertions of the
               // property.
               for (X10FieldDef fi : properties) {
                Type ftype = fi.asInstance().type();

                CConstraint c = X10TypeMixin.realX(ftype);
                XTerm newSelf = xts.xtypeTranslator().trans(c, c.self(), fi.asInstance());
                c = c.substitute(newSelf, c.self());

                if (! result.entails(c, ((X10Context) ts.emptyContext()).constraintProjection(result, c))) {
                 this.rootClause = Types.ref(result);
                 this.rootClauseInvalid =
                  new SemanticException("The real clause, " + result + ", does not satisfy constraints from " + fi + ".", position());
                }
               }
              }*/
            }
            /*  catch (XFailure e) {
            	CConstraint result = ConstraintManager.getConstraintSystem().makeCConstraint();
             result.setInconsistent();
             this.rootClause = Types.ref(result);
             this.rootClauseInvalid = new SemanticException(e.getMessage(), position());
            }*/
            finally {
              ref.update(result);
              this.computing = false;
            }
          }

          public String toString() {
            return "realClause for " + X10ClassDef_c.this;
          }
        };
    ref.setResolver(runnable);
    return ref;
  }