Пример #1
0
 private HLLocation ProcessTargetExpression(ITargetExpression pExpression)
 {
     if (pExpression.Definition is ILocalDefinition)
     {
         return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition)));
     }
     else if (pExpression.Definition is IParameterDefinition)
     {
         HLParameter parameter = HLDomain.GetParameter(pExpression.Definition as IParameterDefinition);
         parameter.RequiresAddressing = true;
         return(HLParameterLocation.Create(parameter));
     }
     else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference)
     {
         IFieldDefinition definition         = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField;
         HLType           typeFieldContainer = HLDomain.GetOrCreateType(definition.Container);
         HLField          field = HLDomain.GetField(definition);
         if (field.IsStatic)
         {
             return(HLStaticFieldLocation.Create(field));
         }
         HLLocation instance = ProcessExpression(pExpression.Instance);
         return(HLFieldLocation.Create(instance, field));
     }
     else if (pExpression.Definition is IAddressDereference)
     {
         IAddressDereference definition      = pExpression.Definition as IAddressDereference;
         HLLocation          locationAddress = ProcessExpression(definition.Address);
         return(HLIndirectAddressLocation.Create(locationAddress, HLDomain.GetOrCreateType(pExpression.Type)));
     }
     throw new NotSupportedException();
 }
 public override void Visit(ITargetExpression targetExpression)
 {
     if (Process(targetExpression))
     {
         visitor.Visit(targetExpression);
     }
     base.Visit(targetExpression);
 }
Пример #3
0
        public override void TraverseChildren(ITargetExpression targetExpression)
        {
            base.TraverseChildren(targetExpression);
            ITypeReference         type  = Dummy.TypeReference;
            ILocalDefinition /*?*/ local = targetExpression.Definition as ILocalDefinition;

            if (local != null)
            {
                if (local.IsReference)
                {
                    if (local.IsPinned)
                    {
                        type = Immutable.PointerType.GetPointerType(local.Type, this.host.InternFactory);
                    }
                    else
                    {
                        type = Immutable.ManagedPointerType.GetManagedPointerType(local.Type, this.host.InternFactory);
                    }
                }
                else
                {
                    type = local.Type;
                }
            }
            else
            {
                IParameterDefinition /*?*/ parameter = targetExpression.Definition as IParameterDefinition;
                if (parameter != null)
                {
                    type = parameter.Type;
                }
                else
                {
                    IFieldReference /*?*/ field = targetExpression.Definition as IFieldReference;
                    if (field != null)
                    {
                        type = field.Type;
                    }
                    else
                    {
                        IPropertyDefinition /*?*/ property = targetExpression.Definition as IPropertyDefinition;
                        if (property != null)
                        {
                            type = property.Type;
                        }
                        else
                        {
                            IExpression /*?*/ expression = targetExpression.Definition as IExpression;
                            if (expression != null)
                            {
                                type = expression.Type;
                            }
                        }
                    }
                }
            }
            ((TargetExpression)targetExpression).Type = type;
        }
Пример #4
0
        public override void TraverseChildren(ITargetExpression targetExpression)
        {
            base.TraverseChildren(targetExpression);
            var local = targetExpression.Definition as ILocalDefinition;

            if (local != null && this.firstReferenceToLocal[local] == null)
            {
                this.firstReferenceToLocal[local] = targetExpression;
            }
        }
        public override void TraverseChildren(ITargetExpression targetExpression)
        {
            base.TraverseChildren(targetExpression);
            var local = targetExpression.Definition as ILocalDefinition;

            if (local == null)
            {
                return;
            }
            this.numberOfAssignmentsToLocal[local]++;
        }
Пример #6
0
        public override ITargetExpression Rewrite(ITargetExpression targetExpression)
        {
            var result = base.Rewrite(targetExpression);
            var field  = targetExpression.Definition as IFieldReference;

            if (field == null)
            {
                var capturedLocal = targetExpression.Definition as CapturedLocalDefinition;
                if (capturedLocal != null)
                {
                    field = capturedLocal.capturingField;
                }
            }
            if (field != null)
            {
                var locOrPar = this.closureFieldToLocalOrParameterMap.Find(field.InternedKey);
                if (locOrPar != null)
                {
                    object definition      = locOrPar;
                    var    boundExpression = locOrPar as IBoundExpression;
                    if (boundExpression != null)
                    {
                        definition = boundExpression.Definition;
                    }
                    Contract.Assume(definition is ILocalDefinition || definition is IParameterDefinition ||
                                    definition is IFieldReference || definition is IArrayIndexer ||
                                    definition is IAddressDereference || definition is IPropertyDefinition);
                    if (definition is LocalDefinition)
                    {
                        this.numberOfAssignmentsToLocal[definition]++;
                    }
                    return(new TargetExpression()
                    {
                        Definition = definition, Type = field.Type
                    });
                }
            }
            return(result);
        }
Пример #7
0
 public virtual void onASTElement(ITargetExpression targetExpression) { }
 public override void TraverseChildren(ITargetExpression targetExpression) {
   IArrayIndexer/*?*/ indexer = targetExpression.Definition as IArrayIndexer;
   if (indexer != null) {
     this.Traverse(indexer);
     return;
   }
   IAddressDereference/*?*/ deref = targetExpression.Definition as IAddressDereference;
   if (deref != null) {
     IAddressOf/*?*/ addressOf = deref.Address as IAddressOf;
     if (addressOf != null) {
       this.Traverse(addressOf.Expression);
       return;
     }
     if (targetExpression.Instance != null) {
       this.Traverse(targetExpression.Instance);
       this.sourceEmitterOutput.Write("->");
     } else if (deref.Address.Type is IPointerTypeReference || deref.Address.Type.TypeCode == PrimitiveTypeCode.IntPtr)
       this.sourceEmitterOutput.Write("*");
     this.Traverse(deref.Address);
     return;
   } else {
     if (targetExpression.Instance != null) {
       IAddressOf/*?*/ addressOf = targetExpression.Instance as IAddressOf;
       if (addressOf != null)
         this.Traverse(addressOf.Expression);
       else
         this.Traverse(targetExpression.Instance);
       this.sourceEmitterOutput.Write(".");
     }
   }
   ILocalDefinition/*?*/ local = targetExpression.Definition as ILocalDefinition;
   if (local != null)
     this.PrintLocalName(local);
   else {
     IFieldReference/*?*/ field = targetExpression.Definition as IFieldReference;
     if (field != null) {
       if (field.IsStatic) {
         this.PrintTypeReference(field.ContainingType);
         this.sourceEmitterOutput.Write(".");
       }
       this.sourceEmitterOutput.Write(field.Name.Value);
     } else {
       INamedEntity/*?*/ ne = targetExpression.Definition as INamedEntity;
       if (ne != null)
         this.sourceEmitterOutput.Write(ne.Name.Value);
     }
   }
 }
Пример #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="assignment"></param>
 public Assignment(IAssignment assignment)
     : base(assignment)
 {
     this.source = assignment.Source;
       this.target = assignment.Target;
 }
Пример #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="targetExpression"></param>
 public TargetExpression(ITargetExpression targetExpression)
     : base(targetExpression)
 {
     this.definition = targetExpression.Definition;
       this.instance = targetExpression.Instance;
       if (targetExpression.IsUnaligned)
     this.alignment = targetExpression.Alignment;
       else
     this.alignment = 0;
       this.isVolatile = targetExpression.IsVolatile;
 }
Пример #11
0
 public override void Visit(ITargetExpression targetExpression)
 {
     allElements.Add(new InvokInfo(Traverser, "ITargetExpression", targetExpression));
 }
Пример #12
0
 /// <summary>
 /// Performs some computation with the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public virtual void Visit(ITargetExpression targetExpression)
 {
 }
Пример #13
0
 public override void Visit(ITargetExpression target)
 {
     HandleComposite(target, target.Instance);
 }
Пример #14
0
 /// <summary>
 /// Traverses the children of the target expression.
 /// </summary>
 public virtual void TraverseChildren(ITargetExpression targetExpression)
 {
     Contract.Requires(targetExpression != null);
       this.TraverseChildren((IExpression)targetExpression);
       if (this.StopTraversal) return;
       var local = targetExpression.Definition as ILocalDefinition;
       if (local != null)
     this.Traverse(local);
       else {
     var parameter = targetExpression.Definition as IParameterDefinition;
     if (parameter != null)
       this.Traverse(parameter);
     else {
       var fieldReference = targetExpression.Definition as IFieldReference;
       if (fieldReference != null)
     this.Traverse(fieldReference);
       else {
     var arrayIndexer = targetExpression.Definition as IArrayIndexer;
     if (arrayIndexer != null) {
       this.Traverse(arrayIndexer);
       return; //do not visit the instance again
     } else {
       var addressDereference = targetExpression.Definition as IAddressDereference;
       if (addressDereference != null)
         this.Traverse(addressDereference);
       else {
         var propertyDefinition = targetExpression.Definition as IPropertyDefinition;
         if (propertyDefinition != null)
           this.Traverse(propertyDefinition);
         else
           this.Traverse((IThisReference)targetExpression.Definition);
       }
     }
       }
     }
       }
       if (this.StopTraversal) return;
       if (targetExpression.Instance != null)
     this.Traverse(targetExpression.Instance);
 }
 /// <summary>
 /// Performs some computation with the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public virtual void Visit(ITargetExpression targetExpression)
 {
 }
Пример #16
0
    /// <summary>
    /// Returns a shallow copy of the given target expression.
    /// </summary>
    /// <param name="targetExpression"></param>
    public TargetExpression Copy(ITargetExpression targetExpression) {
      Contract.Requires(targetExpression != null);
      Contract.Ensures(Contract.Result<TargetExpression>() != null);

      return new TargetExpression(targetExpression);
    }
Пример #17
0
 public override void TraverseChildren(ITargetExpression targetExpression) {
   base.TraverseChildren(targetExpression);
   ITypeReference type = Dummy.TypeReference;
   ILocalDefinition/*?*/ local = targetExpression.Definition as ILocalDefinition;
   if (local != null) {
     if (local.IsReference) {
       if (local.IsPinned)
         type = Immutable.PointerType.GetPointerType(local.Type, this.host.InternFactory);
       else
         type = Immutable.ManagedPointerType.GetManagedPointerType(local.Type, this.host.InternFactory);
     } else
       type = local.Type;
   } else {
     IParameterDefinition/*?*/ parameter = targetExpression.Definition as IParameterDefinition;
     if (parameter != null)
       type = parameter.Type;
     else {
       IFieldReference/*?*/ field = targetExpression.Definition as IFieldReference;
       if (field != null)
         type = field.Type;
       else {
         IPropertyDefinition/*?*/ property = targetExpression.Definition as IPropertyDefinition;
         if (property != null)
           type = property.Type;
         else {
           IExpression/*?*/ expression = targetExpression.Definition as IExpression;
           if (expression != null)
             type = expression.Type;
         }
       }
     }
   }
   ((TargetExpression)targetExpression).Type = type;
 }
Пример #18
0
 public override void TraverseChildren(ITargetExpression targetExpression) {
   if (targetExpression.Definition == this.local) {
     this.localCanBeReplaced = false;
     this.StopTraversal = true;
     return;
   }
   base.TraverseChildren(targetExpression);
 }
 /// <summary>
 /// Rewrites the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public virtual ITargetExpression Rewrite(ITargetExpression targetExpression)
 {
     return targetExpression;
 }
Пример #20
0
 /*?*/
 private ILocalDefinition TargetExpressionAsLocal(ITargetExpression targetExpression)
 {
     if (targetExpression.Instance != null) return null;
     return targetExpression.Definition as ILocalDefinition;
 }
Пример #21
0
 public override void TraverseChildren(ITargetExpression targetExpression)
 {
     base.TraverseChildren(targetExpression);
     this.UpdateDeclaringBlock(targetExpression.Definition as IFieldReference);
 }
Пример #22
0
        public override void TraverseChildren(ITargetExpression targetExpression)
{ MethodEnter(targetExpression);
            base.TraverseChildren(targetExpression);
     MethodExit();   }
Пример #23
0
 /// <summary>
 /// Performs some computation with the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public virtual void Visit(ITargetExpression targetExpression)
 {
     this.Visit((IExpression)targetExpression);
 }
Пример #24
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public virtual void Visit(ITargetExpression targetExpression)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       object def = targetExpression.Definition;
       var loc = def as ILocalDefinition;
       if (loc != null)
     this.VisitReference(loc);
       else {
     var par = def as IParameterDefinition;
     if (par != null)
       this.VisitReference(par);
     else {
       var fieldReference = def as IFieldReference;
       if (fieldReference != null)
     this.Visit(fieldReference);
       else {
     var indexer = def as IArrayIndexer;
     if (indexer != null) {
       this.Visit(indexer);
       return; //do not visit the instance again
     } else {
       var adr = def as IAddressDereference;
       if (adr != null)
         this.Visit(adr);
       else {
         var meth = def as IMethodReference;
         if (meth != null)
           this.Visit(meth);
         else {
           var propertyReference = (IPropertyDefinition)def;
           this.VisitReference(propertyReference);
         }
       }
     }
       }
     }
       }
       if (targetExpression.Instance != null)
     this.Visit(targetExpression.Instance);
       //^ assume this.path.Count == oldCount; //True because all of the virtual methods of this class promise not decrease this.path.Count.
 }
Пример #25
0
 public void Visit(ITargetExpression targetExpression)
 {
     throw new NotImplementedException();
 }
Пример #26
0
 /// <summary>
 /// Traverses the target expression.
 /// </summary>
 public void Traverse(ITargetExpression targetExpression)
 {
     Contract.Requires(targetExpression != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(targetExpression);
       if (this.StopTraversal) return;
       this.TraverseChildren(targetExpression);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(targetExpression);
 }
Пример #27
0
 /// <summary>
 /// 
 /// </summary>
 public OutArgument()
 {
     this.expression = CodeDummy.TargetExpression;
 }
Пример #28
0
 public void Visit(ITargetExpression targetExpression)
 {
     this.traverser.Traverse(targetExpression);
 }
Пример #29
0
 /// <summary>
 /// Visits the specified target expression.
 /// </summary>
 /// <param name="targetExpression">The target expression.</param>
 public override void Visit(ITargetExpression targetExpression)
 {
     TargetExpression mutableTargetExpression = new TargetExpression(targetExpression);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableTargetExpression);
 }
Пример #30
0
 public void Visit(ITargetExpression targetExpression)
 {
     Contract.Requires(targetExpression != null);
       throw new NotImplementedException();
 }
Пример #31
0
 /// <summary>
 /// Returns a deep copy of the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public TargetExpression Copy(ITargetExpression targetExpression)
 {
     var mutableCopy = this.shallowCopier.Copy(targetExpression);
       this.CopyChildren((Expression)mutableCopy);
       if (mutableCopy.Instance != null) {
     mutableCopy.Instance = this.Copy(mutableCopy.Instance);
       }
       var local = mutableCopy.Definition as ILocalDefinition;
       if (local != null)
     mutableCopy.Definition = this.GetExistingCopyIfInsideCone(local);
       else {
     var parameter = mutableCopy.Definition as IParameterDefinition;
     if (parameter != null)
       mutableCopy.Definition = this.GetExistingCopyIfInsideCone(parameter);
     else {
       var fieldReference = mutableCopy.Definition as IFieldReference;
       if (fieldReference != null)
     mutableCopy.Definition = this.Copy(fieldReference);
       else {
     var arrayIndexer = mutableCopy.Definition as IArrayIndexer;
     if (arrayIndexer != null)
       mutableCopy.Definition = this.Copy(arrayIndexer);
     else {
       var addressDereference = mutableCopy.Definition as IAddressDereference;
       if (addressDereference != null)
         mutableCopy.Definition = this.Copy(addressDereference);
       else {
         var propertyDefinition = (IPropertyDefinition)mutableCopy.Definition;
         mutableCopy.Definition = this.GetExistingCopyIfInsideCone(propertyDefinition);
       }
     }
       }
     }
       }
       return mutableCopy;
 }
Пример #32
0
    public override void Visit(ITargetExpression targetExpression) {
      #region ArrayIndexer
      IArrayIndexer/*?*/ indexer = targetExpression.Definition as IArrayIndexer;
      if (indexer != null) {
        this.Visit(indexer);
        return;
      }
      #endregion

      #region AddressDereference
      IAddressDereference/*?*/ deref = targetExpression.Definition as IAddressDereference;
      if (deref != null) {
        IAddressOf/*?*/ addressOf = deref.Address as IAddressOf;
        if (addressOf != null) {
          this.Visit(addressOf.Expression);
          return;
        }
        IConversion/*?*/ conversion = deref.Address as IConversion;
        if (conversion != null) {
          IBoundExpression be = conversion.ValueToConvert as IBoundExpression;
          if (be != null) {
            IParameterDefinition pd = be.Definition as IParameterDefinition;
            if (pd != null) {
              var pv = this.sink.FindParameterVariable(pd);
              TranslatedExpressions.Push(Bpl.Expr.Ident(pv));
              return;
            }
          }
        }
        if (targetExpression.Instance != null) {
          // TODO
          throw new NotImplementedException("targetExpr->AddrDeRef->InstanceNull");
        } else if (deref.Address.Type is IPointerTypeReference)
          throw new NotImplementedException("targetExpr->AddrDeRef->Pointertype");
        this.Visit(deref.Address);
        return;
      }
      #endregion

      #region LocalDefinition
      ILocalDefinition/*?*/ local = targetExpression.Definition as ILocalDefinition;
      if (local != null) {
        TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.FindOrCreateLocalVariable(local)));
        return;
      }
      #endregion

      #region ParameterDefenition
      IParameterDefinition param = targetExpression.Definition as IParameterDefinition;
      if (param != null) {
        TranslatedExpressions.Push(Bpl.Expr.Ident(this.sink.FindParameterVariable(param)));
        return;
      }
      #endregion

      #region FieldReference
      IFieldReference field = targetExpression.Definition as IFieldReference;
      if (field != null) {
        ProcessFieldVariable(field, targetExpression.Instance, false);
        return;
      }
      #endregion

      #region PropertyDefiniton
      IPropertyDefinition prop = targetExpression.Definition as IPropertyDefinition;
      if (prop != null) {
        throw new NotImplementedException("targetExpr->Property");
      }
      #endregion
    }
Пример #33
0
 /// <summary>
 /// Returns a shallow copy of the given target expression.
 /// </summary>
 /// <param name="targetExpression"></param>
 public TargetExpression Copy(ITargetExpression targetExpression)
 {
     return new TargetExpression(targetExpression);
 }
Пример #34
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="outArgument"></param>
 public OutArgument(IOutArgument outArgument)
     : base(outArgument)
 {
     this.expression = outArgument.Expression;
 }
Пример #35
0
 public void Visit(ITargetExpression targetExpression)
 {
     this.result = this.copier.Copy(targetExpression);
 }
Пример #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Assignment"/> class.
 /// </summary>
 public Assignment()
 {
     this.source = CodeDummy.Expression;
       this.target = CodeDummy.TargetExpression;
 }
    private void VisitAssignment(ITargetExpression target, IExpression source, SourceTraverser sourceTraverser,
      bool treatAsStatement, bool pushTargetRValue, bool resultIsInitialTargetRValue) {
      Contract.Requires(target != null);
      Contract.Requires(source != null);
      Contract.Requires(sourceTraverser != null);
      Contract.Requires(!resultIsInitialTargetRValue || pushTargetRValue);
      Contract.Requires(!pushTargetRValue || source is IBinaryOperation);

      var tok = source.Token();
      var typ = source.Type;
      var structCopy = TranslationHelper.IsStruct(typ) && !(source is IDefaultValue);
      // then a struct value of type S is being assigned: "lhs := s"
      // model this as the statement "call lhs := S..#copy_ctor(s)" that does the bit-wise copying
      Bpl.DeclWithFormals proc = null;
      if (structCopy) {
        proc = this.sink.FindOrCreateProcedureForStructCopy(typ);
      }

      object container = target.Definition;

      Top:

      ILocalDefinition/*?*/ local = container as ILocalDefinition;
      if (local != null) {
        if (source is IDefaultValue && !local.Type.ResolvedType.IsReferenceType) {
        //  this.LoadAddressOf(local, null);
        //  this.generator.Emit(OperationCode.Initobj, local.Type);
        //  if (!treatAsStatement) this.LoadLocal(local);
        } else {
          Bpl.IdentifierExpr temp = null;
          var bplLocal = Bpl.Expr.Ident(this.sink.FindOrCreateLocalVariable(local));
          if (pushTargetRValue) {
            this.TranslatedExpressions.Push(bplLocal);
            if (!treatAsStatement && resultIsInitialTargetRValue) {
              var loc = this.sink.CreateFreshLocal(source.Type);
              temp = Bpl.Expr.Ident(loc);
              var e3 = this.TranslatedExpressions.Pop();
              var cmd3 = Bpl.Cmd.SimpleAssign(tok, temp, e3);
              this.StmtTraverser.StmtBuilder.Add(cmd3);
              this.TranslatedExpressions.Push(temp);
            }
          }
          sourceTraverser(source);
          var e = this.TranslatedExpressions.Pop();
          if (temp != null) this.TranslatedExpressions.Push(temp);

          Bpl.Cmd cmd;
          if (structCopy) {
            cmd = new Bpl.CallCmd(tok, proc.Name, new List<Bpl.Expr> { e, }, new List<Bpl.IdentifierExpr> { bplLocal, });
          } else {
            cmd = Bpl.Cmd.SimpleAssign(tok, bplLocal, e);
          }
          StmtTraverser.StmtBuilder.Add(cmd);

          if (!treatAsStatement && !resultIsInitialTargetRValue) {
            this.TranslatedExpressions.Push(bplLocal);
          }
        }
        return;
      }
      IParameterDefinition/*?*/ parameter = container as IParameterDefinition;
      if (parameter != null) {
        if (source is IDefaultValue && !parameter.Type.ResolvedType.IsReferenceType) {
          //this.LoadAddressOf(parameter, null);
          //this.generator.Emit(OperationCode.Initobj, parameter.Type);
          //if (!treatAsStatement) this.LoadParameter(parameter);
        } else {
          Bpl.IdentifierExpr temp = null;
          if (pushTargetRValue) {
            this.LoadParameter(parameter);
            if (!treatAsStatement && resultIsInitialTargetRValue) {
              var loc = this.sink.CreateFreshLocal(source.Type);
              temp = Bpl.Expr.Ident(loc);
              var e3 = this.TranslatedExpressions.Pop();
              var cmd3 = Bpl.Cmd.SimpleAssign(tok, temp, e3);
              this.StmtTraverser.StmtBuilder.Add(cmd3);
              this.TranslatedExpressions.Push(temp);
            }
          }
          sourceTraverser(source);
          var e = this.TranslatedExpressions.Pop();
          if (temp != null) this.TranslatedExpressions.Push(temp);
          var bplParam = Bpl.Expr.Ident(this.sink.FindParameterVariable(parameter, this.contractContext));

          Bpl.Cmd cmd;
          if (structCopy) {
            cmd = new Bpl.CallCmd(tok, proc.Name, new List<Bpl.Expr> { e, bplParam, }, new List<Bpl.IdentifierExpr>());
          } else {
            cmd = Bpl.Cmd.SimpleAssign(tok, bplParam, e);
          }
          StmtTraverser.StmtBuilder.Add(cmd);

          if (!treatAsStatement && !resultIsInitialTargetRValue) {
            this.LoadParameter(parameter);
          }
        }
        return;
      }
      IFieldReference/*?*/ field = container as IFieldReference;
      if (field != null) {

        var f = Bpl.Expr.Ident(this.sink.FindOrCreateFieldVariable(field));
        var boogieTypeOfField = sink.CciTypeToBoogie(field.Type);

        if (source is IDefaultValue && !field.Type.ResolvedType.IsReferenceType) {
          //this.LoadAddressOf(field, target.Instance);
          //if (!treatAsStatement) {
          //  this.generator.Emit(OperationCode.Dup);
          //  this.StackSize++;
          //}
          //this.generator.Emit(OperationCode.Initobj, field.Type);
          //if (!treatAsStatement)
          //  this.generator.Emit(OperationCode.Ldobj, field.Type);
          //else
          //  this.StackSize--;
        } else {
          Bpl.Expr x = null;
          Bpl.IdentifierExpr temp = null;
          if (pushTargetRValue) {
            if (target.Instance != null) {
              this.Traverse(target.Instance);
              x = this.TranslatedExpressions.Pop();
              AssertOrAssumeNonNull(tok, x);
              var e2 = this.sink.Heap.ReadHeap(x, f, TranslationHelper.IsStruct(field.ContainingType) ? AccessType.Struct : AccessType.Heap, boogieTypeOfField);
              this.TranslatedExpressions.Push(e2);
            } else {
              TranslatedExpressions.Push(f);
            }
            
            if (!treatAsStatement && resultIsInitialTargetRValue) {
              var loc = this.sink.CreateFreshLocal(source.Type);
              temp = Bpl.Expr.Ident(loc);
              var e3 = this.TranslatedExpressions.Pop();
              var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
              this.StmtTraverser.StmtBuilder.Add(cmd);
              this.TranslatedExpressions.Push(temp);
            }
          }
          sourceTraverser(source);
          if (!treatAsStatement && !resultIsInitialTargetRValue) {
            var loc = this.sink.CreateFreshLocal(source.Type);
            temp = Bpl.Expr.Ident(loc);
            var e3 = this.TranslatedExpressions.Pop();
            var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
            this.StmtTraverser.StmtBuilder.Add(cmd);
            this.TranslatedExpressions.Push(temp);
          }

          var e = this.TranslatedExpressions.Pop();
          if (temp != null) this.TranslatedExpressions.Push(temp);

          if (target.Instance == null) {
            // static fields are not kept in the heap
            StmtTraverser.StmtBuilder.Add(Bpl.Cmd.SimpleAssign(tok, f, e));
          } else {
            this.sink.Heap.WriteHeap(tok, x, f, e,
              field.ResolvedField.ContainingType.ResolvedType.IsStruct ? AccessType.Struct : AccessType.Heap,
              boogieTypeOfField, StmtTraverser.StmtBuilder);
          }

        }
        return;
      }

      VisitArrayIndexer:

      IArrayIndexer/*?*/ arrayIndexer = container as IArrayIndexer;
      if (arrayIndexer != null) {
        Contract.Assume(arrayIndexer.Indices.Count() == 1); // BUG: deal with multi-dimensional arrays
        if (source is IDefaultValue && !arrayIndexer.Type.ResolvedType.IsReferenceType) {
        //  this.LoadAddressOf(arrayIndexer, target.Instance);
        //  if (!treatAsStatement) {
        //    this.generator.Emit(OperationCode.Dup);
        //    this.StackSize++;
        //  }
        //  this.generator.Emit(OperationCode.Initobj, arrayIndexer.Type);
        //  if (!treatAsStatement)
        //    this.generator.Emit(OperationCode.Ldobj, arrayIndexer.Type);
        //  else
        //    this.StackSize--;
        } else {
          Bpl.IdentifierExpr/*?*/ temp = null;
          this.Traverse(arrayIndexer.IndexedObject);
          var arrayExpr = this.TranslatedExpressions.Peek();
          this.Traverse(arrayIndexer.Indices);
          var indexExpr = this.TranslatedExpressions.Peek();
          if (pushTargetRValue) {
            AssertOrAssumeNonNull(tok, arrayExpr);
            var e2 = this.sink.Heap.ReadHeap(arrayExpr, indexExpr, AccessType.Array, this.sink.CciTypeToBoogie(arrayIndexer.Type));
            this.TranslatedExpressions.Push(e2);

            if (!treatAsStatement && resultIsInitialTargetRValue) {
                var loc = this.sink.CreateFreshLocal(source.Type);
                temp = Bpl.Expr.Ident(loc);
                var e3 = this.TranslatedExpressions.Pop();
                var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
                this.StmtTraverser.StmtBuilder.Add(cmd);
                this.TranslatedExpressions.Push(temp);
            }
          }
          sourceTraverser(source);

          var e = this.TranslatedExpressions.Pop();
          var indices_prime = this.TranslatedExpressions.Pop();
          var x = this.TranslatedExpressions.Pop();
          sink.Heap.WriteHeap(Bpl.Token.NoToken, x, indices_prime, e, AccessType.Array, sink.CciTypeToBoogie(arrayIndexer.Type), StmtTraverser.StmtBuilder);

          if (!treatAsStatement && !resultIsInitialTargetRValue) {
            AssertOrAssumeNonNull(tok, arrayExpr);
            var e2 = this.sink.Heap.ReadHeap(arrayExpr, indexExpr, AccessType.Array, this.sink.CciTypeToBoogie(arrayIndexer.Type));
            this.TranslatedExpressions.Push(e2);
          } else {
            if (temp != null) this.TranslatedExpressions.Push(temp);
          }
        }
        return;
      }
      IAddressDereference/*?*/ addressDereference = container as IAddressDereference;
      if (addressDereference != null) {
        var addrOf = addressDereference.Address as IAddressOf;
        if (addrOf != null) {
          var arrayIndexer2 = addrOf.Expression.Definition as IArrayIndexer;
          if (arrayIndexer2 != null) {
            container = arrayIndexer2;
            goto VisitArrayIndexer;
          }
        }
        var be = addressDereference.Address as IBoundExpression;
        if (be != null) {
          container = be.Definition;
          goto Top;
        }
        this.Traverse(addressDereference.Address);
        if (source is IDefaultValue && !addressDereference.Type.ResolvedType.IsReferenceType) {
          //if (!treatAsStatement) {
          //  this.generator.Emit(OperationCode.Dup);
          //  this.StackSize++;
          //}
          //this.generator.Emit(OperationCode.Initobj, addressDereference.Type);
          //if (!treatAsStatement)
          //  this.generator.Emit(OperationCode.Ldobj, addressDereference.Type);
          //else
          //  this.StackSize--;
        } else if (source is IAddressDereference) {
          //if (!treatAsStatement) {
          //  this.generator.Emit(OperationCode.Dup);
          //  this.StackSize++;
          //}
          //this.Traverse(((IAddressDereference)source).Address);
          //this.generator.Emit(OperationCode.Cpobj, addressDereference.Type);
          //this.StackSize -= 2;
          //if (!treatAsStatement)
          //  this.generator.Emit(OperationCode.Ldobj, addressDereference.Type);
        } else {
          Bpl.IdentifierExpr/*?*/ temp = null;
          if (pushTargetRValue) {
            this.TranslatedExpressions.Push(this.TranslatedExpressions.Peek());
            if (!treatAsStatement && resultIsInitialTargetRValue) {
              this.TranslatedExpressions.Push(this.TranslatedExpressions.Peek());
              var loc = this.sink.CreateFreshLocal(source.Type);
              temp = Bpl.Expr.Ident(loc);
              var e3 = this.TranslatedExpressions.Pop();
              var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
              this.StmtTraverser.StmtBuilder.Add(cmd);
              this.TranslatedExpressions.Push(temp);
            }
          }
          sourceTraverser(source);
          if (!treatAsStatement && !resultIsInitialTargetRValue) {
            this.TranslatedExpressions.Push(this.TranslatedExpressions.Peek());
            var loc = this.sink.CreateFreshLocal(source.Type);
            temp = Bpl.Expr.Ident(loc);
            var e3 = this.TranslatedExpressions.Pop();
            var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
            this.StmtTraverser.StmtBuilder.Add(cmd);
            this.TranslatedExpressions.Push(temp);
          }
          //this.VisitAssignmentTo(addressDereference);
          if (temp != null) this.TranslatedExpressions.Push(temp);
        }
        return;
      }
      IPropertyDefinition/*?*/ propertyDefinition = container as IPropertyDefinition;
      if (propertyDefinition != null) {
        Contract.Assume(propertyDefinition.Getter != null && propertyDefinition.Setter != null);
        if (!propertyDefinition.IsStatic) {
          this.Traverse(target.Instance);
        }
        Bpl.IdentifierExpr temp = null;
        var token = Bpl.Token.NoToken;
        if (pushTargetRValue) {

          List<Bpl.Expr> inexpr;
          List<Bpl.IdentifierExpr> outvars;
          Bpl.IdentifierExpr thisExpr;
          Dictionary<Bpl.IdentifierExpr, Tuple<Bpl.IdentifierExpr, bool>> toBoxed;
          var proc2 = TranslateArgumentsAndReturnProcedure(token, propertyDefinition.Getter, propertyDefinition.Getter.ResolvedMethod, target.Instance, Enumerable<IExpression>.Empty, out inexpr, out outvars, out thisExpr, out toBoxed);

          EmitLineDirective(token);

          this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(token, proc2.Name, inexpr, outvars));

          if (!treatAsStatement && resultIsInitialTargetRValue) {
            //var 
            //this.generator.Emit(OperationCode.Dup);
            //this.StackSize++;
            //temp = new TemporaryVariable(source.Type, this.method);
            //this.VisitAssignmentTo(temp);
          }
        }
        sourceTraverser(source);
        if (!treatAsStatement && !resultIsInitialTargetRValue) {
          var e3 = this.TranslatedExpressions.Pop();
          var loc = this.sink.CreateFreshLocal(source.Type);
          temp = Bpl.Expr.Ident(loc);
          var cmd = Bpl.Cmd.SimpleAssign(tok, temp, e3);
          this.StmtTraverser.StmtBuilder.Add(cmd);
          this.TranslatedExpressions.Push(temp);
        }

        var setterArgs = new List<Bpl.Expr>();
        var setterArg = this.TranslatedExpressions.Pop();
        if (!propertyDefinition.IsStatic)
          setterArgs.Add(this.TranslatedExpressions.Pop());
        setterArgs.Add(setterArg);

        var setterProc = this.sink.FindOrCreateProcedure(propertyDefinition.Setter.ResolvedMethod);
        EmitLineDirective(token);
        this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(token, setterProc.Decl.Name, setterArgs, new List<Bpl.IdentifierExpr>()));

        if (temp != null) this.TranslatedExpressions.Push(temp);
        return;
      }
      Contract.Assume(false);
    }
 public override void TraverseChildren(ITargetExpression targetExpression) {
   this.LookForCapturedDefinition(targetExpression.Definition);
   base.TraverseChildren(targetExpression);
 }
 public override void TraverseChildren(ITargetExpression targetExpression)
 {
   Contract.Assume(false, "The expression containing this as a subexpression should never allow a call to this routine.");
 }
 public override ITargetExpression Rewrite(ITargetExpression targetExpression) {
   Contract.Assume(false, "The expression containing this as a subexpression should never allow a call to this routine.");
   return null;
 }
Пример #41
0
 public virtual void onASTElement(ITargetExpression targetExpression)
 {
 }
Пример #42
0
 public override void TraverseChildren(ITargetExpression targetExpression)
 {
     MethodEnter(targetExpression);
     base.TraverseChildren(targetExpression);
     MethodExit();
 }
 public override void Visit(ITargetExpression bounded)
 {
     HandleBundle(bounded, bounded.Definition, bounded.Instance);
 }