/// <summary>
        /// checks if argument is locally created URI with static URI target
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static bool isArgumentURILocallyCreatedStatic(IExpression arg, IMetadataHost host, out string uri)
        {
            uri = null;
            ICreateObjectInstance creationSite = arg as ICreateObjectInstance;

            if (creationSite == null)
            {
                return(false);
            }

            if (!arg.Type.isURIClass(host))
            {
                return(false);
            }

            IExpression uriTargetArg = creationSite.Arguments.First();

            if (!uriTargetArg.Type.isStringClass(host))
            {
                return(false);
            }

            ICompileTimeConstant staticURITarget = uriTargetArg as ICompileTimeConstant;

            if (staticURITarget == null)
            {
                return(false);
            }

            uri = staticURITarget.Value as string;
            return(true);
        }
        /// <summary>
        /// checks if argument is locally created URI where target has statically created URI root
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static bool isArgumentURILocallyCreatedStaticRoot(IExpression arg, IMetadataHost host, out string uri)
        {
            // Pre: !isArgumentURILocallyCreatedStatic
            uri = null;
            ICreateObjectInstance creationSite = arg as ICreateObjectInstance;

            if (creationSite == null)
            {
                return(false);
            }

            if (!arg.Type.isURIClass(host))
            {
                return(false);
            }

            IExpression uriTargetArg = creationSite.Arguments.First();

            if (!uriTargetArg.Type.isStringClass(host))
            {
                return(false);
            }

            if (!uriTargetArg.IsStaticURIRootExtractable(out uri))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
        {
            base.TraverseChildren(createObjectInstance);
            var ps = new List <IParameterTypeInformation>(createObjectInstance.MethodToCall.Parameters);
            int i  = 0;

            foreach (var a in createObjectInstance.Arguments)
            {
                Contract.Assume(i < ps.Count); //assume that argument count matches the parameter count. I.e. assume the IL being decompiled is valid.
                var p = ps[i++];
                Contract.Assume(p != null);
                var ctc = a as CompileTimeConstant;
                if (ctc == null)
                {
                    continue;
                }
                if (p.Type.TypeCode == PrimitiveTypeCode.Boolean && ctc.Type.TypeCode == PrimitiveTypeCode.Int32)
                {
                    Contract.Assume(ctc.Value != null && ctc.Value is int);
                    ctc.Value = ((int)ctc.Value) == 0 ? false : true;
                    ctc.Type  = this.host.PlatformType.SystemBoolean;
                }
            }
            ((CreateObjectInstance)createObjectInstance).Type = createObjectInstance.MethodToCall.ContainingType;
        }
 public override void Visit(ICreateObjectInstance createObjectInstance)
 {
     if (Process(createObjectInstance))
     {
         visitor.Visit(createObjectInstance);
     }
     base.Visit(createObjectInstance);
 }
Exemple #5
0
        private static IMethodBody /*?*/ FirstStatementIsIteratorCreation(IMetadataHost host, ISourceMethodBody possibleIterator, INameTable nameTable, IStatement statement)
        {
            ICreateObjectInstance createObjectInstance = GetICreateObjectInstance(statement);

            if (createObjectInstance == null)
            {
                // If the first statement in the method body is not the creation of iterator closure, return a dummy.
                // Possible corner case not handled: a local is used to hold the constant value for the initial state of the closure.
                return(null);
            }
            ITypeReference closureType /*?*/        = createObjectInstance.MethodToCall.ContainingType;
            ITypeReference unspecializedClosureType = ContractHelper.Unspecialized(closureType);

            if (!AttributeHelper.Contains(unspecializedClosureType.Attributes, host.PlatformType.SystemRuntimeCompilerServicesCompilerGeneratedAttribute))
            {
                return(null);
            }
            INestedTypeReference closureTypeAsNestedTypeReference = unspecializedClosureType as INestedTypeReference;

            if (closureTypeAsNestedTypeReference == null)
            {
                return(null);
            }
            ITypeReference unspecializedClosureContainingType = ContractHelper.Unspecialized(closureTypeAsNestedTypeReference.ContainingType);

            if (closureType != null && TypeHelper.TypesAreEquivalent(possibleIterator.MethodDefinition.ContainingTypeDefinition, unspecializedClosureContainingType))
            {
                IName MoveNextName = nameTable.GetNameFor("MoveNext");
                foreach (ITypeDefinitionMember member in closureType.ResolvedType.GetMembersNamed(MoveNextName, false))
                {
                    IMethodDefinition moveNext = member as IMethodDefinition;
                    if (moveNext != null)
                    {
                        ISpecializedMethodDefinition moveNextGeneric = moveNext as ISpecializedMethodDefinition;
                        if (moveNextGeneric != null)
                        {
                            moveNext = moveNextGeneric.UnspecializedVersion.ResolvedMethod;
                        }
                        return(moveNext.Body);
                    }
                }
            }
            return(null);
        }
Exemple #6
0
        public override IExpression Rewrite(ICreateObjectInstance createObjectInstance)
        {
            var mutableCreateObjectInstance = createObjectInstance as CreateObjectInstance;

            if (mutableCreateObjectInstance != null && mutableCreateObjectInstance.Arguments.Count == 2)
            {
                AddressOf /*?*/ aexpr = mutableCreateObjectInstance.Arguments[1] as AddressOf;
                if (aexpr != null && aexpr.Expression.Definition is IMethodReference)
                {
                    CreateDelegateInstance createDel = new CreateDelegateInstance();
                    createDel.Instance                = mutableCreateObjectInstance.Arguments[0];
                    createDel.IsVirtualDelegate       = aexpr.Expression.Instance != null;
                    createDel.MethodToCallViaDelegate = (IMethodReference)aexpr.Expression.Definition;
                    createDel.Locations               = mutableCreateObjectInstance.Locations;
                    createDel.Type = createObjectInstance.Type;
                    return(this.Rewrite(createDel));
                }
            }
            return(base.Rewrite(createObjectInstance));
        }
Exemple #7
0
        public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
        {
            base.TraverseChildren(createObjectInstance);
            var ps = new List <IParameterTypeInformation>(createObjectInstance.MethodToCall.Parameters);
            int i  = 0;

            foreach (var a in createObjectInstance.Arguments)
            {
                var p   = ps[i++];
                var ctc = a as ICompileTimeConstant;
                if (ctc == null)
                {
                    continue;
                }
                if (p.Type.TypeCode == PrimitiveTypeCode.Boolean && ctc.Type.TypeCode == PrimitiveTypeCode.Int32)
                {
                    ((CompileTimeConstant)ctc).Value = ((int)ctc.Value) == 0 ? false : true;
                    ((CompileTimeConstant)ctc).Type  = this.host.PlatformType.SystemBoolean;
                }
            }
            ((CreateObjectInstance)createObjectInstance).Type = createObjectInstance.MethodToCall.ContainingType;
        }
Exemple #8
0
        private static ICreateObjectInstance /*?*/ GetICreateObjectInstance(IStatement statement)
        {
            IExpressionStatement expressionStatement = statement as IExpressionStatement;

            if (expressionStatement != null)
            {
                IAssignment assignment = expressionStatement.Expression as IAssignment;
                if (assignment == null)
                {
                    return(null);
                }
                ICreateObjectInstance createObjectInstance = assignment.Source as ICreateObjectInstance;
                return(createObjectInstance);
            }
            ILocalDeclarationStatement localDeclaration = statement as ILocalDeclarationStatement;

            if (localDeclaration != null)
            {
                ICreateObjectInstance createObjectInstance = localDeclaration.InitialValue as ICreateObjectInstance;
                return(createObjectInstance);
            }
            return(null);
        }
Exemple #9
0
        private HLLocation ProcessCreateObjectInstanceExpression(ICreateObjectInstance pExpression)
        {
            HLMethod          methodCalled        = HLDomain.GetOrCreateMethod(pExpression.MethodToCall);
            HLLocation        locationThis        = HLTemporaryLocation.Create(CreateTemporary(methodCalled.Container));
            List <HLLocation> locationsParameters = new List <HLLocation>();

            if (methodCalled.Container == HLDomain.SystemString)
            {
                locationsParameters.Add(locationThis.AddressOf());
            }
            else
            {
                mCurrentBlock.EmitNewObject(methodCalled.Container, locationThis.AddressOf());
                locationsParameters.Add(locationThis);
            }

            foreach (IExpression argument in pExpression.Arguments)
            {
                locationsParameters.Add(ProcessExpression(argument));
            }

            mCurrentBlock.EmitCall(methodCalled, false, null, locationsParameters);
            return(locationThis);
        }
Exemple #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="createObjectInstance"></param>
 internal ConstructorOrMethodCall(ICreateObjectInstance createObjectInstance)
     : base(createObjectInstance)
 {
     Contract.Requires(createObjectInstance != null);
       this.arguments = new List<IExpression>(createObjectInstance.Arguments);
       this.methodToCall = createObjectInstance.MethodToCall;
 }
Exemple #11
0
 public void Visit(ICreateObjectInstance createObjectInstance)
 {
     throw new NotImplementedException();
 }
Exemple #12
0
 /// <summary>
 /// Performs some computation with the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public virtual void Visit(ICreateObjectInstance createObjectInstance)
 {
     this.Visit((IExpression)createObjectInstance);
 }
Exemple #13
0
 /// <summary>
 /// Traverses the children of the create object instance expression.
 /// </summary>
 public virtual void TraverseChildren(ICreateObjectInstance createObjectInstance)
 {
     Contract.Requires(createObjectInstance != null);
       this.TraverseChildren((IExpression)createObjectInstance);
       if (this.StopTraversal) return;
       this.Traverse(createObjectInstance.MethodToCall);
       if (this.StopTraversal) return;
       this.Traverse(createObjectInstance.Arguments);
 }
Exemple #14
0
 /// <summary>
 /// Performs some computation with the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public virtual void Visit(ICreateObjectInstance createObjectInstance)
 {
 }
        public override void Visit(ICreateObjectInstance createObjectInstance)
        {
            VisitMethodCall(createObjectInstance.MethodToCall, createObjectInstance.Arguments);

            base.Visit(createObjectInstance);
        }
    /// <summary>
    /// For "new A(...)" generate "{ A a = Alloc(); A..ctor(a); return a; }" where
    /// "a" is a fresh local.
    /// </summary>
    public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
    {
      var ctor = createObjectInstance.MethodToCall;
      var resolvedMethod = ResolveUnspecializedMethodOrThrow(ctor);

      Bpl.IToken token = createObjectInstance.Token();

      var a = this.sink.CreateFreshLocal(createObjectInstance.Type);

      if (createObjectInstance.Type.TypeCode == PrimitiveTypeCode.IntPtr ||
          createObjectInstance.Type.TypeCode == PrimitiveTypeCode.UIntPtr) {
        List<Bpl.Expr> args = new List<Bpl.Expr>();
        foreach (IExpression e in createObjectInstance.Arguments) {
          this.Traverse(e);
          args.Add(TranslatedExpressions.Pop());
        }
        System.Diagnostics.Debug.Assert(args.Count == 1);
        this.StmtTraverser.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(a), args[0]));
      }
      else {
        // First generate an Alloc() call
        this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(token, this.sink.AllocationMethodName, new List<Bpl.Expr>(), new List<Bpl.IdentifierExpr>(new Bpl.IdentifierExpr[] {Bpl.Expr.Ident(a)})));

        // Second, generate the call to the appropriate ctor

        List<Bpl.Expr> inexpr;
        List<Bpl.IdentifierExpr> outvars;
        Bpl.IdentifierExpr thisExpr;
        Dictionary<Bpl.IdentifierExpr, Tuple<Bpl.IdentifierExpr,bool>> toBoxed;
        var proc = TranslateArgumentsAndReturnProcedure(token, ctor, resolvedMethod, null, createObjectInstance.Arguments, out inexpr, out outvars, out thisExpr, out toBoxed);
        inexpr.Insert(0, Bpl.Expr.Ident(a));

        EmitLineDirective(token);

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

        // Generate an assumption about the dynamic type of the just allocated object
        sink.GenerateDynamicTypeAssume(this.StmtTraverser.StmtBuilder, token, Bpl.Expr.Ident(a), createObjectInstance.Type);
      }
      TranslatedExpressions.Push(Bpl.Expr.Ident(a));
    }
Exemple #17
0
    /// <summary>
    /// Returns a deep copy of the given constructor call expression.
    /// </summary>
    /// <param name="createObjectInstance"></param>
    public CreateObjectInstance Copy(ICreateObjectInstance createObjectInstance) {
      Contract.Requires(createObjectInstance != null);
      Contract.Ensures(Contract.Result<CreateObjectInstance>() != null);

      var mutableCopy = this.shallowCopier.Copy(createObjectInstance);
      this.CopyChildren((Expression)mutableCopy);
      mutableCopy.MethodToCall = this.Copy(mutableCopy.MethodToCall);
      mutableCopy.Arguments = this.Copy(mutableCopy.Arguments);
      return mutableCopy;
    }
 public override void TraverseChildren(ICreateObjectInstance createObjectInstance) {
   base.TraverseChildren(createObjectInstance);
   var ps = new List<IParameterTypeInformation>(createObjectInstance.MethodToCall.Parameters);
   int i = 0;
   foreach (var a in createObjectInstance.Arguments) {
     Contract.Assume(i < ps.Count); //assume that argument count matches the parameter count. I.e. assume the IL being decompiled is valid.
     var p = ps[i++];
     Contract.Assume(p != null);
     var ctc = a as CompileTimeConstant;
     if (ctc == null) continue;
     if (p.Type.TypeCode == PrimitiveTypeCode.Boolean && ctc.Type.TypeCode == PrimitiveTypeCode.Int32) {
       Contract.Assume(ctc.Value != null && ctc.Value is int);
       ctc.Value = ((int)ctc.Value) == 0 ? false : true;
       ctc.Type = this.host.PlatformType.SystemBoolean;
     }
   }
   ((CreateObjectInstance)createObjectInstance).Type = createObjectInstance.MethodToCall.ContainingType;
 }
 public override void Visit(ICreateObjectInstance createObjectInstance)
 {
     if(Process(createObjectInstance)){visitor.Visit(createObjectInstance);}
     base.Visit(createObjectInstance);
 }
 /// <summary>
 /// Rewrites the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public virtual IExpression Rewrite(ICreateObjectInstance createObjectInstance)
 {
     return createObjectInstance;
 }
Exemple #21
0
 public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
 {
     base.TraverseChildren(createObjectInstance);
       var ps = new List<IParameterTypeInformation>(createObjectInstance.MethodToCall.Parameters);
       int i = 0;
       foreach (var a in createObjectInstance.Arguments) {
     var p = ps[i++];
     var ctc = a as ICompileTimeConstant;
     if (ctc == null) continue;
     if (p.Type.TypeCode == PrimitiveTypeCode.Boolean && ctc.Type.TypeCode == PrimitiveTypeCode.Int32) {
       ((CompileTimeConstant)ctc).Value = ((int)ctc.Value) == 0 ? false : true;
       ((CompileTimeConstant)ctc).Type = this.host.PlatformType.SystemBoolean;
     }
       }
       ((CreateObjectInstance)createObjectInstance).Type = createObjectInstance.MethodToCall.ContainingType;
 }
        /// <summary>
        /// Stores information for the instrumentation of counters increments after "new" calls and
        /// passes along the call info to VisitMethodCall
        /// </summary>
        public override void Visit(ICreateObjectInstance createObjectInstance)
        {
            if (_currentInstrInfo.StoreNextTmp)
            {
                var type = createObjectInstance.Type;
                var tmpField = GetTmpField(_currentMethod, type);
                if (_currentInstrInfo.TmpFieldsToInstrument.ContainsKey(tmpField))
                {
                    if (!_currentInstrInfo.GlobalPolyInfoTmp.ContainsKey(type.ToString()))
                    {
                        _currentInstrInfo.GlobalPolyInfoTmp.Add(type.ToString(), new GlobalPolyInfo());
                    }
                    if (_currentInstrInfo.Instrument)
                    {
                        if (_loopNestLevel > 0)
                        {
                            _currentInstrInfo.GlobalPolyInfoTmp[type.ToString()].AllContractsRequiredAvailable = false;
                        }
                        else
                        {
                            _currentInstrInfo.GlobalPolyInfoTmp[type.ToString()].DirectQuantity++;
                        }
                        //register the counter to be instrumented
                       _currentInstrInfo.TmpFieldsToInstrument[tmpField].Add(_currentStatement);
                    }
                    else
                    {
                        //register the poly to be added to the tmp field after the loop
                        _afterLoopAssignments.Add(new Tuple<FieldDefinition, PolyCond>(tmpField, _currentInstrInfo.NextStmtPoly));
                        //store in the global poly info
                        _currentInstrInfo.GlobalPolyInfoTmp[type.ToString()].DirectQuantityLoops.Add(_currentInstrInfo.NextStmtPoly);
                    }
                }

                //verify that the object doesn't escape
                if (!_currentInstrInfo.TrustNextAnnotation &&
                    _pointsToInformation.Escapes(_currentMethod.ContainingType.ToString(), _currentMethod.Name.Value, _currentStatement) &&
                    _previousStatement != null)
                {
                    string location = LocationsToString(_previousStatement.Locations);
                    if (location != null)
                    {
                        _errorReportItems.Add(new ErrorReportItem()
                            {
                                Message = string.Format("The object created escapes from the method."),
                                Location = location
                            });
                    }
                }

                _currentInstrInfo.StoreNextTmp = false;
            }

            if (_currentInstrInfo.StoreNextRsd)
            {
                var type = createObjectInstance.Type;
                var rsdField = GetRsdField(_currentMethod, _currentInstrInfo.NextStoreRsdName, type);
                if (_currentInstrInfo.RsdFieldsToInstrument.ContainsKey(rsdField))
                {
                    var typeAndName = new Tuple<string, string>(type.ToString(), _currentInstrInfo.NextStoreRsdName);
                    if (!_currentInstrInfo.GlobalPolyInfoRsd.ContainsKey(typeAndName))
                    {
                        _currentInstrInfo.GlobalPolyInfoRsd.Add(typeAndName, new GlobalPolyInfo());
                    }
                    if (_currentInstrInfo.Instrument)
                    {
                        if (_loopNestLevel > 0)
                        {
                            _currentInstrInfo.GlobalPolyInfoRsd[typeAndName].AllContractsRequiredAvailable = false;
                        }
                        else
                        {
                            _currentInstrInfo.GlobalPolyInfoRsd[typeAndName].DirectQuantity++;
                        }
                        //register the counter to be instrumented
                        _currentInstrInfo.RsdFieldsToInstrument[rsdField].Add(_currentStatement);
                    }
                    else
                    {
                        //register the poly to be added to the rsd field after the loop
                        _afterLoopAssignments.Add(new Tuple<FieldDefinition, PolyCond>(rsdField, _currentInstrInfo.NextStmtPoly));
                        //store in the global poly info
                        _currentInstrInfo.GlobalPolyInfoRsd[typeAndName].DirectQuantityLoops.Add(_currentInstrInfo.NextStmtPoly);
                    }
                }

                //verify that the object escapes
                if (!_currentInstrInfo.TrustNextAnnotation && _previousStatement != null)
                {
                    if (!_pointsToInformation.Escapes(_currentMethod.ContainingType.ToString(), _currentMethod.Name.Value, _currentStatement))
                    {
                        string location = LocationsToString(_previousStatement.Locations);
                        if (location != null)
                        {
                            _errorReportItems.Add(new ErrorReportItem()
                            {
                                Message = "The object created doesn't escape from the method.",
                                Location = location
                            });
                        }
                    }
                    //if it does escape, verify that escape expression is correct
                    else
                    {
                        var rsdName = _currentInstrInfo.NextStoreRsdName;
                        var expr = "";
                        if (rsdName == "Contracts.Contract.Memory.Return")
                        {
                            expr = "vRet";
                        }
                        else if (rsdName == "Contracts.Contract.Memory.This")
                        {
                            expr = "this";
                        }
                        else if (_memoryContractsInformation.MethodsRsdExprs.ContainsKey(_currentMethod.ToString()) &&
                                 _memoryContractsInformation.MethodsRsdExprs[_currentMethod.ToString()].ContainsKey(rsdName))
                        {
                            expr = _memoryContractsInformation.MethodsRsdExprs[_currentMethod.ToString()][rsdName];
                        }
                        if (expr != "" && !_pointsToInformation.Escapes(_currentMethod.ContainingType.ToString(), _currentMethod.Name.Value, _currentStatement, expr))
                        {
                            string location = LocationsToString(_previousStatement.Locations);
                            if (location != null)
                            {
                                _errorReportItems.Add(new ErrorReportItem()
                                {
                                    Message = string.Format("The object created escapes but not through the expression '{0}'.", expr),
                                    Location = location
                                });
                            }
                        }
                    }
                }

                _currentInstrInfo.StoreNextRsd = false;
            }

            VisitMethodCall(createObjectInstance.MethodToCall, createObjectInstance.Arguments);

            base.Visit(createObjectInstance);
        }
Exemple #23
0
 public override void Visit(ICreateObjectInstance createObjectInstance)
 {
     allElements.Add(new InvokInfo(Traverser, "ICreateObjectInstance", createObjectInstance));
 }
Exemple #24
0
 public void Visit(ICreateObjectInstance createObjectInstance)
 {
     this.result = this.copier.Copy(createObjectInstance);
 }
Exemple #25
0
    /// <summary>
    /// Returns a shallow copy of the given constructor call expression.
    /// </summary>
    /// <param name="createObjectInstance"></param>
    public CreateObjectInstance Copy(ICreateObjectInstance createObjectInstance) {
      Contract.Requires(createObjectInstance != null);
      Contract.Ensures(Contract.Result<CreateObjectInstance>() != null);

      return new CreateObjectInstance(createObjectInstance);
    }
Exemple #26
0
 public virtual void onASTElement(ICreateObjectInstance createObjectInstance)
 {
 }
 /// <summary>
 /// Performs some computation with the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public virtual void Visit(ICreateObjectInstance createObjectInstance)
 {
 }
        public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
{ MethodEnter(createObjectInstance);
            base.TraverseChildren(createObjectInstance);
     MethodExit();   }
 public override IExpression Rewrite(ICreateObjectInstance createObjectInstance) {
   var mutableCreateObjectInstance = createObjectInstance as CreateObjectInstance;
   if (mutableCreateObjectInstance != null && mutableCreateObjectInstance.Arguments.Count == 2) {
     AddressOf/*?*/ aexpr = mutableCreateObjectInstance.Arguments[1] as AddressOf;
     if (aexpr != null && aexpr.Expression.Definition is IMethodReference) {
       CreateDelegateInstance createDel = new CreateDelegateInstance();
       createDel.Instance = mutableCreateObjectInstance.Arguments[0];
       createDel.IsVirtualDelegate = aexpr.Expression.Instance != null;
       createDel.MethodToCallViaDelegate = (IMethodReference)aexpr.Expression.Definition;
       createDel.Locations = mutableCreateObjectInstance.Locations;
       createDel.Type = createObjectInstance.Type;
       return this.Rewrite(createDel);
     }
   }
   return base.Rewrite(createObjectInstance);
 }
Exemple #30
0
 /// <summary>
 /// Traverses the create object instance expression.
 /// </summary>
 public void Traverse(ICreateObjectInstance createObjectInstance)
 {
     Contract.Requires(createObjectInstance != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(createObjectInstance);
       if (this.StopTraversal) return;
       this.TraverseChildren(createObjectInstance);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(createObjectInstance);
 }
 public virtual void onASTElement(ICreateObjectInstance createObjectInstance) { }
Exemple #32
0
 public void Visit(ICreateObjectInstance createObjectInstance)
 {
     this.traverser.Traverse(createObjectInstance);
 }
Exemple #33
0
        private HLLocation ProcessCreateObjectInstanceExpression(ICreateObjectInstance pExpression)
        {
            HLMethod methodCalled = HLDomain.GetOrCreateMethod(pExpression.MethodToCall);
            HLLocation locationThis = HLTemporaryLocation.Create(CreateTemporary(methodCalled.Container));
            List<HLLocation> locationsParameters = new List<HLLocation>();
            if (methodCalled.Container == HLDomain.SystemString) locationsParameters.Add(locationThis.AddressOf());
            else
            {
                mCurrentBlock.EmitNewObject(methodCalled.Container, locationThis.AddressOf());
                locationsParameters.Add(locationThis);
            }

            foreach (IExpression argument in pExpression.Arguments)
                locationsParameters.Add(ProcessExpression(argument));

            mCurrentBlock.EmitCall(methodCalled, false, null, locationsParameters);
            return locationThis;
        }
Exemple #34
0
 public void Visit(ICreateObjectInstance createObjectInstance)
 {
     Contract.Requires(createObjectInstance != null);
       throw new NotImplementedException();
 }
Exemple #35
0
 /// <summary>
 /// Returns a deep copy of the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public CreateObjectInstance Copy(ICreateObjectInstance createObjectInstance)
 {
     var mutableCopy = this.shallowCopier.Copy(createObjectInstance);
       this.CopyChildren((Expression)mutableCopy);
       mutableCopy.MethodToCall = this.Copy(mutableCopy.MethodToCall);
       mutableCopy.Arguments = this.Copy(mutableCopy.Arguments);
       return mutableCopy;
 }
Exemple #36
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public virtual void Visit(ICreateObjectInstance createObjectInstance)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(createObjectInstance);
       this.Visit(createObjectInstance.Arguments);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count.
       this.path.Pop();
 }
Exemple #37
0
 /// <summary>
 /// Returns a shallow copy of the given constructor call expression.
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public CreateObjectInstance Copy(ICreateObjectInstance createObjectInstance)
 {
     return new CreateObjectInstance(createObjectInstance);
 }
Exemple #38
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="createObjectInstance"></param>
 public CreateObjectInstance(ICreateObjectInstance createObjectInstance)
     : base(createObjectInstance)
 {
 }
Exemple #39
0
 /// <summary>
 /// Generates IL for the specified create object instance.
 /// </summary>
 /// <param name="createObjectInstance">The create object instance.</param>
 public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
 {
     this.Traverse(createObjectInstance.Arguments);
       this.generator.Emit(OperationCode.Newobj, createObjectInstance.MethodToCall);
       this.StackSize -= (ushort)IteratorHelper.EnumerableCount(createObjectInstance.Arguments);
       this.StackSize++;
 }
 public override void TraverseChildren(ICreateObjectInstance createObjectInstance) {
   this.PrintToken(CSharpToken.New);
   this.PrintTypeReferenceName(createObjectInstance.MethodToCall.ContainingType);
   this.PrintArgumentList(createObjectInstance.Arguments, createObjectInstance.MethodToCall.Parameters);
 }
Exemple #41
0
 /// <summary>
 /// Visits the specified create object instance.
 /// </summary>
 /// <param name="createObjectInstance">The create object instance.</param>
 public override void Visit(ICreateObjectInstance createObjectInstance)
 {
     CreateObjectInstance mutableCreateObjectInstance = new CreateObjectInstance(createObjectInstance);
     this.resultExpression = this.myCodeCopier.DeepCopy(mutableCreateObjectInstance);
 }
Exemple #42
0
 public override void TraverseChildren(ICreateObjectInstance createObjectInstance)
 {
     MethodEnter(createObjectInstance);
     base.TraverseChildren(createObjectInstance);
     MethodExit();
 }
Exemple #43
0
 public void Visit(ICreateObjectInstance createObjectInstance)
 {
     this.result = this.rewriter.Rewrite(createObjectInstance);
 }