Exemplo n.º 1
0
    public virtual Differences VisitLRExpression(LRExpression expr1, LRExpression expr2){
      Differences differences = new Differences(expr1, expr2);
      if (expr1 == null || expr2 == null){
        if (expr1 != expr2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      LRExpression changes = (LRExpression)expr2.Clone();
      LRExpression deletions = (LRExpression)expr2.Clone();
      LRExpression insertions = (LRExpression)expr2.Clone();

      Differences diff = this.VisitExpression(expr1.Expression, expr2.Expression);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Expression = diff.Changes as Expression;
      deletions.Expression = diff.Deletions as Expression;
      insertions.Expression = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Expression && diff.Deletions == deletions.Expression && diff.Insertions == insertions.Expression);
      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;
    }
Exemplo n.º 2
0
 public virtual Expression VisitLRExpression(LRExpression expr, LRExpression changes, LRExpression deletions, LRExpression insertions){
   this.UpdateSourceContext(expr, changes);
   if (expr == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return expr;
 }
Exemplo n.º 3
0
 public override Expression VisitUnaryExpression(UnaryExpression unaryExpression) {
   if (unaryExpression == null) return null;
   Expression opnd = null;
   switch (unaryExpression.NodeType) {
     case NodeType.AddressOf:
       opnd = unaryExpression.Operand = this.VisitExpression(unaryExpression.Operand);
       if (opnd != null && this.CheckFixed(opnd) && opnd.Type != null && !opnd.Type.IsUnmanaged) {
         this.HandleError(unaryExpression, Error.ManagedAddr, this.GetTypeName(opnd.Type));
         return null;
       }
       break;
     case NodeType.OutAddress:
     case NodeType.RefAddress: {
         bool savedRefout = this.refOrOutAddress;
         this.refOrOutAddress = true;
         Expression e = unaryExpression.Operand = this.VisitTargetExpression(unaryExpression.Operand);
         this.refOrOutAddress = savedRefout;
         if (e == null) return null;
         else if (!this.AllowPropertiesIndexersAsRef) {
           Indexer eAsIndexer = e as Indexer;
           if (eAsIndexer != null && eAsIndexer.CorrespondingDefaultIndexedProperty != null) {
             this.HandleError(e, Error.NotAssignable);
             return null;
           }
           MemberBinding eAsMB = e as MemberBinding;
           if (eAsMB != null && eAsMB.BoundMember is Property) {
             this.HandleError(e, Error.NotAssignable);
             return null;
           }
         }
         if (unaryExpression.NodeType != NodeType.OutAddress)
           e = this.VisitExpression(e);
         if (e == null) return null;
         MemberBinding mb = e as MemberBinding;
         if (mb != null) {
           Field f = mb.BoundMember as Field;
           if (f != null) {
             if (f.IsVolatile)
               this.HandleError(unaryExpression.Operand, Error.VolatileByRef, this.GetMemberSignature(f));
           } else if (mb.BoundMember is Property)
             e = new LRExpression(e);
         } else {
           Indexer indxr = e as Indexer;
           if (indxr != null && indxr.CorrespondingDefaultIndexedProperty != null)
             e = new LRExpression(e);
         }
         opnd = unaryExpression.Operand = e;
         break;
       }
     default:
       opnd = unaryExpression.Operand = this.VisitExpression(unaryExpression.Operand);
       break;
   }
   if (opnd == null) return null;
   switch (unaryExpression.NodeType) {
     //TODO: deal with SkipCheck and EnforceCheck
     case NodeType.DefaultValue:
     case NodeType.Sizeof:
     case NodeType.Typeof:
       if (opnd == null) return null;
       Literal lit = opnd as Literal;
       if (lit == null || !(lit.Value is TypeNode)) {
         Debug.Assert(false);
         return null;
       }
       if (unaryExpression.NodeType == NodeType.Sizeof) {
         TypeNode t = (TypeNode)lit.Value;
         if (!t.IsUnmanaged) {
           this.HandleError(unaryExpression.Operand, Error.ManagedAddr, this.GetTypeName(t));
           if (!this.typeSystem.insideUnsafeCode) {
             this.HandleError(unaryExpression, Error.SizeofUnsafe, this.GetTypeName(t));
           }
           return null;
         }
       }
       return unaryExpression;
     case NodeType.LogicalNot: {
         TypeNode t = unaryExpression.Type;
         if (t == null) return null;
         if (this.typeSystem.IsNullableType(t)) t = this.typeSystem.RemoveNullableWrapper(t);
         if (t != SystemTypes.Boolean) {
           this.HandleError(unaryExpression, Error.BadUnaryOp, "!", this.GetTypeName(t));
           return null;
         }
         Expression e = this.typeSystem.ImplicitCoercion(unaryExpression.Operand, SystemTypes.Boolean, this.TypeViewer);
         if (e != null)
           unaryExpression.Operand = e;
         return unaryExpression;
       }
     case NodeType.Neg: {
         TypeNode t =  this.typeSystem.Unwrap(opnd.Type);
         if (t == null) return null;
         if (this.typeSystem.IsNullableType(t)) t = this.typeSystem.RemoveNullableWrapper(t);
         if ((!t.IsPrimitiveNumeric && t != SystemTypes.Char && t != SystemTypes.Decimal) || t.TypeCode == TypeCode.UInt64) {
           this.HandleError(unaryExpression, Error.BadUnaryOp, "-", this.GetTypeName(t));
           return null;
         }
         t = unaryExpression.Type;
         if (t == null) return null;
         opnd = this.typeSystem.TryImplicitCoercion(unaryExpression.Operand, t, this.TypeViewer);
         if (opnd != null)
           unaryExpression.Operand = opnd;
         if (this.typeSystem.checkOverflow && opnd != null && t.IsPrimitiveInteger) {
           BinaryExpression be = new BinaryExpression(Literal.Int32Zero, opnd, NodeType.Sub_Ovf);
           if (t.IsUnsignedPrimitiveNumeric)
             be.NodeType = NodeType.Sub_Ovf_Un;
           if (t.TypeCode == TypeCode.Int64 || t.TypeCode == TypeCode.UInt64)
             be.Operand1 = Literal.Int64Zero;
           be.Type = unaryExpression.Type;
           be.SourceContext = unaryExpression.SourceContext;
           return be;
         }
         goto default;
       }
     default:
       return unaryExpression;
   }
 }
Exemplo n.º 4
0
 public virtual Expression VisitLRExpression(LRExpression expr){
   if (expr == null) return null;
   expr.Expression = this.VisitExpression(expr.Expression);
   return expr;
 }
Exemplo n.º 5
0
 public virtual void VisitLRExpression(LRExpression expr)
 {
   if (expr == null) return;
   this.VisitExpression(expr.Expression);
 }
Exemplo n.º 6
0
 public override Statement VisitAssignmentStatement(AssignmentStatement assignment) {
   if (assignment == null) return null;
   if (this.TypeInVariableContext(assignment.Source as Literal))
     return null;
   if (this.insideMethodContract || this.insideAssertOrAssume || this.insideInvariant) {
     this.HandleError(assignment, Error.SideEffectsNotAllowedInContracts);
     return null;
   }
   Composition comp = assignment.Target as Composition;
   if (comp != null) {
     comp.Expression = this.VisitTargetExpression(comp.Expression);
     if (comp.Expression == null) return null;
   } else {
     bool savedMayReferenceThisAndBase = this.MayReferenceThisAndBase;
     MemberBinding mb = assignment.Target as MemberBinding;
     if (assignment.Operator == NodeType.Nop
       && mb != null
       && (mb.TargetObject is ImplicitThis || mb.TargetObject is This)) {
       this.MayReferenceThisAndBase = true;
     }
     assignment.Target = this.VisitTargetExpression(assignment.Target);
     this.MayReferenceThisAndBase = savedMayReferenceThisAndBase;
     if (assignment.Target == null) return null;
   }
   TypeNode t = assignment.Target.Type;
   if (t == null) assignment.Target.Type = t = SystemTypes.Object;
   Expression source = this.VisitExpression(assignment.Source);
   if (source == null) return null;
   Reference rt = t as Reference;
   NodeType oper = assignment.Operator;
   if (rt != null && oper != NodeType.CopyReference) t = rt.ElementType;
   if (oper != NodeType.Nop && oper != NodeType.CopyReference) {
     this.CheckForGetAccessor(assignment.Target);
     LRExpression e = new LRExpression(assignment.Target);
     assignment.Target = e;
     if (assignment.OperatorOverload == null) {
       BinaryExpression be = new BinaryExpression(e, source, assignment.Operator, t, assignment.SourceContext);
       if (assignment.UnifiedType != t && assignment.UnifiedType != null) be.Type = assignment.UnifiedType;
       Expression pop = new Expression(NodeType.Pop, be.Type);
       Pointer pt = t as Pointer;
       if (pt != null && (assignment.Operator == NodeType.Add || assignment.Operator == NodeType.Sub)) {
         if (pt.ElementType != SystemTypes.Int8 && pt.ElementType != SystemTypes.UInt8) {
           UnaryExpression sizeOf = new UnaryExpression(new Literal(pt.ElementType, SystemTypes.Type), NodeType.Sizeof, SystemTypes.UInt32);
           Expression elemSize = PureEvaluator.EvalUnaryExpression((Literal)sizeOf.Operand, sizeOf);
           if (elemSize == null) elemSize = sizeOf;
           TypeNode offsetType = SystemTypes.Int32;
           if (source.Type != null && source.Type.IsPrimitiveInteger) offsetType = source.Type;
           BinaryExpression offset = new BinaryExpression(source, elemSize, NodeType.Mul, offsetType, source.SourceContext);
           Literal offsetLit = PureEvaluator.TryEvalBinaryExpression(source as Literal, elemSize as Literal, offset, this.typeSystem);
           if (offsetLit == null) {
             if (offsetType == SystemTypes.Int32)
               offset.Operand1 = new UnaryExpression(source, NodeType.Conv_I);
             else
               offset.Operand2 = this.typeSystem.ExplicitCoercion(elemSize, offsetType, this.TypeViewer);
             source = offset;
           } else
             source = offsetLit;
         }
         source = this.typeSystem.ExplicitCoercion(source, pt, this.TypeViewer);
         be.Operand2 = source;
         assignment.Source = be;
         return assignment;
       }
       source = this.CoerceBinaryExpressionOperands(be, pop, source);
       if (source == null) return null;
       if (source == pop)
         source = e;
       else if (!(source is Literal)) {
         be.Operand1 = e;
       }
     }
     assignment.Operator = NodeType.Nop;
     if (!t.IsPrimitiveNumeric && t != SystemTypes.Char && t != SystemTypes.Boolean && assignment.OperatorOverload == null &&
       (assignment.UnifiedType == null || !assignment.UnifiedType.IsPrimitiveNumeric) &&
       oper != NodeType.AddEventHandler && oper != NodeType.RemoveEventHandler && 
       !(t is DelegateNode && (source.NodeType == NodeType.Add || source.NodeType == NodeType.Sub)) && !(t is EnumNode)) {
       this.HandleError(assignment, Error.BadBinaryOps,
         this.GetOperatorSymbol(oper), this.GetTypeName(t), this.GetTypeName(assignment.Source.Type));
       return null;
     }
     if (assignment.OperatorOverload != null) {
       if (assignment.OperatorOverload.Parameters == null || assignment.OperatorOverload.Parameters.Count < 2) {
         Debug.Assert(false); return null;
       }
       source = this.typeSystem.ImplicitCoercion(source, assignment.OperatorOverload.Parameters[1].Type, this.TypeViewer);
       ExpressionList arguments = new ExpressionList(e, source);
       source = new MethodCall(new MemberBinding(null, assignment.OperatorOverload), arguments, NodeType.Call, assignment.OperatorOverload.ReturnType);
       assignment.OperatorOverload = null;
     }
   }
   assignment.Source = this.typeSystem.ImplicitCoercion(source, t, this.TypeViewer);
   return assignment;
 }
 public override Expression VisitLRExpression(LRExpression expr)
 {
   throw new ApplicationException("unimplemented");
 }
Exemplo n.º 8
0
 public override Expression VisitLRExpression(LRExpression expr)
 {
     if (expr == null) return null;
     return base.VisitLRExpression((LRExpression)expr.Clone());
 }
Exemplo n.º 9
0
 public virtual Expression VisitLRExpression(LRExpression expr1, LRExpression expr2)
 {
     if (expr1 == null) return null;
     if (expr2 == null)
         expr1.Expression = this.VisitExpression(expr1.Expression, null);
     else
         expr1.Expression = this.VisitExpression(expr1.Expression, expr2.Expression);
     return expr1;
 }
Exemplo n.º 10
0
 public override Expression VisitLRExpression(LRExpression expr){
   if (expr == null) return null;
   Expression e = this.VisitExpression(expr.Expression);
   Reference eRef = e == null ? null : e.Type as Reference;
   if (eRef != null)
     return new AddressDereference(e, eRef.ElementType);
   return e;
 }
Exemplo n.º 11
0
 public override Expression VisitLRExpression(LRExpression expr)
 {
     throw new ApplicationException("unimplemented");
 }