Ejemplo n.º 1
0
 public virtual Expression VisitCoerceTuple(CoerceTuple coerceTuple, CoerceTuple changes, CoerceTuple deletions, CoerceTuple insertions){
   this.UpdateSourceContext(coerceTuple, changes);
   if (coerceTuple == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
       coerceTuple.Fields = this.VisitFieldList(coerceTuple.Fields, changes.Fields, deletions.Fields, insertions.Fields);
       coerceTuple.OriginalTuple = this.VisitExpression(coerceTuple.OriginalTuple, changes.OriginalTuple, deletions.OriginalTuple, insertions.OriginalTuple);
     }
   }else if (deletions != null)
     return null;
   return coerceTuple;
 }
Ejemplo n.º 2
0
 public virtual Expression VisitCoerceTuple(CoerceTuple coerceTuple){
   if (coerceTuple == null) return null;
   coerceTuple.OriginalTuple = this.VisitExpression(coerceTuple.OriginalTuple);
   return this.VisitConstructTuple(coerceTuple);
 }
Ejemplo n.º 3
0
    public virtual Differences VisitCoerceTuple(CoerceTuple coerceTuple1, CoerceTuple coerceTuple2){
      Differences differences = new Differences(coerceTuple1, coerceTuple2);
      if (coerceTuple1 == null || coerceTuple2 == null){
        if (coerceTuple1 != coerceTuple2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      CoerceTuple changes = (CoerceTuple)coerceTuple2.Clone();
      CoerceTuple deletions = (CoerceTuple)coerceTuple2.Clone();
      CoerceTuple insertions = (CoerceTuple)coerceTuple2.Clone();

      FieldList fieldChanges, fieldDeletions, fieldInsertions;
      Differences diff = this.VisitFieldList(coerceTuple1.Fields, coerceTuple2.Fields, out fieldChanges, out fieldDeletions, out fieldInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Fields = fieldChanges;
      deletions.Fields = fieldDeletions;
      insertions.Fields = fieldInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(coerceTuple1.OriginalTuple, coerceTuple2.OriginalTuple);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.OriginalTuple = diff.Changes as Expression;
      deletions.OriginalTuple = diff.Deletions as Expression;
      insertions.OriginalTuple = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.OriginalTuple && diff.Deletions == deletions.OriginalTuple && diff.Insertions == insertions.OriginalTuple);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Ejemplo n.º 4
0
 public virtual void VisitCoerceTuple(CoerceTuple coerceTuple)
 {
   if (coerceTuple == null) return;
   this.VisitExpression(coerceTuple.OriginalTuple);
   this.VisitConstructTuple(coerceTuple);
 }
Ejemplo n.º 5
0
 public virtual Expression TupleCoercion(Expression source, TypeNode sourceType, TypeNode targetType, bool explicitCoercion, TypeViewer typeViewer){
   TupleType sTuple = sourceType as TupleType;
   TupleType tTuple = targetType as TupleType; 
   if (sTuple == null){
     if (!explicitCoercion) return null;
     if (tTuple == null) return null;
     MemberList tMems = tTuple.Members;
     if (tMems == null || tMems.Count != 3) return null;
     ConstructTuple consTuple = new ConstructTuple();
     consTuple.Type = tTuple;
     Field f = (Field)tMems[0].Clone();
     consTuple.Fields = new FieldList(f);
     if (f.Type is TypeAlias)
       f.Initializer = this.ExplicitCoercion(source, f.Type, typeViewer);
     else
       f.Initializer = this.StandardExplicitCoercion(source, this.IsNonNullType(sourceType), sourceType, this.IsNonNullType(f.Type), f.Type, f.Type, typeViewer);
     if (f.Initializer == null) return null;
     return consTuple;
   }
   MemberList sMembers = sTuple.Members;
   if (sMembers == null) return null;
   int n = sMembers.Count;
   if (tTuple == null){
     if (n == 3){
       TypeUnion tUnion = targetType as TypeUnion;
       if (tUnion != null){
         Method coercion = this.UserDefinedImplicitCoercionMethod(source, sourceType, targetType, true, typeViewer);
         if (coercion != null) 
           return new MethodCall(new MemberBinding(null, coercion), new ExpressionList(this.ImplicitCoercion(source, coercion.Parameters[0].Type, typeViewer)), 
             NodeType.Call, coercion.ReturnType, source.SourceContext);
       }
       Field sField = sMembers[0] as Field;
       if (sField == null || (!explicitCoercion && !this.ImplicitCoercionFromTo(sField.Type, targetType, typeViewer))) return null;
       if (!sField.IsAnonymous && targetType == SystemTypes.Object)
         return new BinaryExpression(source, new MemberBinding(null, sTuple), NodeType.Box, SystemTypes.Object);
       ConstructTuple cTuple = source as ConstructTuple;
       if (cTuple != null){
         //TODO: give a warning
         source = cTuple.Fields[0].Initializer;
       }else{
         MemberBinding mb = new MemberBinding(new UnaryExpression(source, NodeType.AddressOf), sField);
         mb.Type = sField.Type;
         source = mb;
       }
       if (explicitCoercion)
         return this.ExplicitCoercion(source, targetType, typeViewer);
       else
         return this.ImplicitCoercion(source, targetType, typeViewer);
     }
     if (targetType == SystemTypes.Object)
       return new BinaryExpression(source, new MemberBinding(null, sTuple), NodeType.Box, SystemTypes.Object);
     return null;
   }
   MemberList tMembers = tTuple.Members;
   if (sMembers == tMembers) return source;
   if (tMembers == null) return null;
   if (n != tMembers.Count) return null;
   n-=2;
   ConstructTuple consTup = source as ConstructTuple;
   if (consTup != null){
     FieldList consFields = consTup.Fields;
     for (int i = 0; i < n; i++){
       Field cField = consFields[i];
       if (cField == null) continue;
       Field tField = tMembers[i] as Field;
       if (tField == null) return null;
       if (explicitCoercion)
         cField.Initializer = this.ExplicitCoercion(cField.Initializer, tField.Type, typeViewer);
       else{
         if (!tField.IsAnonymous && tField.Name != null && 
           (cField.IsAnonymous || cField.Name == null || cField.Name.UniqueIdKey != tField.Name.UniqueIdKey)) return null;
         cField.Initializer = this.ImplicitCoercion(cField.Initializer, tField.Type, typeViewer);
       }
       if (cField.Initializer == null) return null;
       cField.Type = tField.Type;
     }
     consTup.Type = tTuple;
     return consTup;
   }
   Local loc = new Local(sTuple);
   CoerceTuple cTup = new CoerceTuple();
   cTup.OriginalTuple = source;
   cTup.Temp = loc;
   cTup.Type = tTuple;
   FieldList cFields = cTup.Fields = new FieldList(n);
   for (int i = 0; i < n; i++){
     Field sField = sMembers[i] as Field;
     if (sField == null) return null;
     Field tField = tMembers[i] as Field;
     if (tField == null) return null;
     Field cField = new Field();
     cField.Type = tField.Type;
     MemberBinding mb = new MemberBinding(loc, sField);
     if (explicitCoercion)
       cField.Initializer = this.ExplicitCoercion(mb, tField.Type, typeViewer);
     else{
       if (!tField.IsAnonymous && tField.Name != null && 
         (sField.IsAnonymous || sField.Name == null || sField.Name.UniqueIdKey != tField.Name.UniqueIdKey)) return null;
       cField.Initializer = this.ImplicitCoercion(mb, tField.Type, typeViewer);
     }
     if (cField.Initializer == null) return null;
     cFields.Add(cField);
   }
   return cTup;
 }
Ejemplo n.º 6
0
 public override Expression VisitCoerceTuple(CoerceTuple coerceTuple)
 {
     if (coerceTuple == null) return null;
     return base.VisitCoerceTuple((CoerceTuple)coerceTuple.Clone());
 }
Ejemplo n.º 7
0
 public virtual Expression VisitCoerceTuple(CoerceTuple coerceTuple1, CoerceTuple coerceTuple2)
 {
     if (coerceTuple1 == null) return null;
     if (coerceTuple2 == null)
         coerceTuple1.OriginalTuple = this.VisitExpression(coerceTuple1.OriginalTuple, null);
     else
         coerceTuple1.OriginalTuple = this.VisitExpression(coerceTuple1.OriginalTuple, coerceTuple2.OriginalTuple);
     return this.VisitConstructTuple(coerceTuple1, coerceTuple2);
 }
Ejemplo n.º 8
0
 public override Expression VisitCoerceTuple(CoerceTuple coerceTuple){
   if (coerceTuple == null) return null;
   StatementList statements = new StatementList(2);
   statements.Add(new AssignmentStatement(coerceTuple.Temp, this.VisitExpression(coerceTuple.OriginalTuple)));
   statements.Add(new ExpressionStatement(this.VisitConstructTuple(coerceTuple)));
   return new BlockExpression(new Block(statements));
 }