public override void VisitExpressionStatement <TExpression>(IExpressionStatement <TExpression> expressionStatement)
 {
     Value = new Statement()
     {
         ExpressionStatement = new ExpressionStatementFactory(expressionStatement).Value
     };
 }
Example #2
0
        protected override IStatement ConvertExpressionStatement(IExpressionStatement ies)
        {
            var imie = ies.Expression as IMethodInvokeExpression;

            if (imie == null)
            {
                return(base.ConvertExpressionStatement(ies));
            }

            if (CodeRecognizer.Instance.IsStaticGenericMethod(imie, new Action <object, object>(Csoft.Observe)))
            {
                var memberRef = ExtractMemberRef(imie.Arguments[0]);
                if (memberRef == null)
                {
                    throw new InvalidOperationException("First argument must be a field or property");
                }

                var observedExpr = imie.Arguments[1];

                var observeMethod = GetMethodInfo <IGeneratedAlgorithm>(algo => algo.SetObservedValue(null, null));
                var call          = Builder.Method(Builder.VarRefExpr(algorithmVar), observeMethod, Builder.LiteralExpr(memberRef.Name), observedExpr);
                return(Builder.ExprStatement(call));
            }

            if (Attribute.GetCustomAttribute(imie.Method.Method.MethodInfo, typeof(ModelMethodAttribute)) != null)
            {
                return(ConvertModelMethodCall(imie));
            }

            return(base.ConvertExpressionStatement(ies));
        }
 private bool ContainsStatement(IStatement dependencySt, IStatement ist)
 {
     if (ReferenceEquals(dependencySt, ist))
     {
         return(true);
     }
     if (dependencySt is AnyStatement)
     {
         AnyStatement anySt = (AnyStatement)dependencySt;
         bool         found = false;
         ForEachStatement(anySt, st =>
         {
             if (ContainsStatement(st, ist))
             {
                 found = true;
             }
         });
         return(found);
     }
     if (dependencySt is IExpressionStatement && ist is IExpressionStatement)
     {
         IExpressionStatement es  = (IExpressionStatement)dependencySt;
         IExpressionStatement ies = (IExpressionStatement)ist;
         return(CodeBuilder.Instance.ContainsExpression(es.Expression, ies.Expression));
     }
     return(false);
 }
        public override void VisitExpressionStatement(IExpressionStatement operation)
        {
            LogString(nameof(IExpressionStatement));
            LogCommonPropertiesAndNewLine(operation);

            base.VisitExpressionStatement(operation);
        }
            private bool ValidateExpression(IExpressionStatement expressionStatement)
            {
                if (expressionStatement.Expression == null || expressionStatement.Expression.Kind != OperationKind.InvocationExpression)
                {
                    return(false);
                }

                var invocationExpression = (IInvocationExpression)expressionStatement.Expression;

                if (!_callsDisposeBool)
                {
                    bool result = IsDisposeBoolCall(invocationExpression);
                    if (result)
                    {
                        _callsDisposeBool = true;
                    }

                    return(result);
                }
                else if (!_callsSuppressFinalize)
                {
                    bool result = IsSuppressFinalizeCall(invocationExpression);
                    if (result)
                    {
                        _callsSuppressFinalize = true;
                    }

                    return(result);
                }

                return(false);
            }
Example #6
0
        public override IEnumerable <IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            IExpressionStatement parentExpression = GetParentExpressionStatemenmt(registrationRootElement);

            if (parentExpression == null)
            {
                yield break;
            }

            IStructuralMatchResult match = Match(registrationRootElement);

            if (match.Matched)
            {
                var arguments = match.GetMatchedElementList("assemblies").Cast <ICSharpArgument>();

                IEnumerable <IModule> modules = arguments.SelectNotNull(argument => ModuleExtractor.GetTargetModule(argument.Value));

                IEnumerable <FilteredRegistrationBase> basedOnRegistrations = basedOnPatterns.SelectMany(
                    basedOnPattern => basedOnPattern.GetBasedOnRegistrations(parentExpression.Expression)).ToList();

                foreach (IModule module in modules)
                {
                    // todo blech, fix this
                    yield return(new CompositeRegistration(registrationRootElement, basedOnRegistrations.Union(
                                                               new ComponentRegistrationBase[]
                    {
                        new DefaultScanAssemblyRegistration(registrationRootElement),
                        new ModuleBasedOnRegistration(registrationRootElement, module)
                    })));
                }
            }
        }
        private static bool IsNullDeclaration(IStatement state)
        {
            IExpressionStatement state_exp = state as IExpressionStatement;

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

            IVariableDeclarationExpression exp_var;

            IAssignExpression exp_assign = state_exp.Expression as IAssignExpression;

            if (exp_assign != null)
            {
                // T value=nullptr; の場合
                ILiteralExpression exp_lit = exp_assign.Expression as ILiteralExpression;
                if (exp_lit == null || exp_lit.Value != null)
                {
                    return(false);
                }
                exp_var = exp_assign.Target as IVariableDeclarationExpression;
            }
            else
            {
                // T value; の場合
                exp_var = state_exp.Expression as IVariableDeclarationExpression;
            }

            return(exp_var != null);
        }
Example #8
0
        /// <summary>
        /// Given expression statement determines if it defines a function
        /// and if so, returns the function definition and the variable
        /// it is assigned to.
        /// </summary>
        public static IFunctionDefinition GetVariableOrFunctionDefinition(this IExpressionStatement es, out Variable v)
        {
            v = null;
            if (es == null || es.Expression == null)
            {
                return(null);
            }

            // Tree:
            //       <-
            //    x      function(a)
            //
            //
            var c = es.Expression.Children;

            if (c.Count == 1)
            {
                var op = c[0] as IOperator;
                if (op != null)
                {
                    if (op.OperatorType == OperatorType.LeftAssign)
                    {
                        v = op.LeftOperand as Variable;
                        if (v != null)
                        {
                            return(op.RightOperand as IFunctionDefinition);
                        }
                    }
                }
            }
            return(null);
        }
Example #9
0
        /// <summary>
        /// Given expression statement determines if it defines a function
        /// and if so, returns the function definition and the variable
        /// it is assigned to.
        /// </summary>
        public static IFunctionDefinition GetVariableOrFunctionDefinition(this IExpressionStatement es, out IVariable v)
        {
            v = null;

            // Tree:
            //       <-
            //    x      function(a)
            //
            //
            var c = es?.Expression?.Children;

            if (c?.Count == 1)
            {
                if (c[0] is IOperator op)
                {
                    if (op.OperatorType == OperatorType.LeftAssign || op.OperatorType == OperatorType.Equals)
                    {
                        v = op.LeftOperand as Variable;
                        if (v != null)
                        {
                            return(op.RightOperand as IFunctionDefinition);
                        }
                    }
                    else if (op.OperatorType == OperatorType.RightAssign)
                    {
                        v = op.RightOperand as Variable;
                    }
                }
            }
            return(null);
        }
Example #10
0
 public override IStatement Visit(IExpressionStatement stmt, int context)
 {
     return(new ExpressionStatement
     {
         Expression = Anonymize(stmt.Expression)
     });
 }
Example #11
0
        public override IEnumerable <IComponentRegistration> GetComponentRegistrations(ITreeNode registrationRootElement)
        {
            // This entire thing is one big hack. Need to come back to it one day :)
            // There is (currently) no way to create a pattern that would match the Bind() call with implicit this in ReSharper SSR.
            // Therefore I'm only matching by the method name only, and later verifying that the method invocation's qualifier
            // is indeed derived from global::Ninject.Syntax.IBindingRoot

            if (!IsNinjectBindCall(registrationRootElement))
            {
                yield break;
            }

            IExpressionStatement statement = GetParentExpressionStatemenmt(registrationRootElement);

            if (statement == null)
            {
                yield break;
            }
            foreach (var toPattern in toPatterns)
            {
                var implementedByRegistration = toPattern.GetComponentRegistrations(statement.Expression)
                                                .Cast <ComponentRegistration>()
                                                .FirstOrDefault();

                if (implementedByRegistration != null)
                {
                    foreach (var registration in DoCreateRegistrations(statement.Expression).OfType <ComponentRegistration>())
                    {
                        registration.Implementation = implementedByRegistration.ServiceType;
                        yield return(registration);
                    }
                }
            }
        }
        private UnitTestElementLocation GetUnitTestElementLocation(IExpressionStatement statement)
        {
            var projectFile = statement.GetSourceFile().AssertNotNull().ToProjectFile();
            var textRange   = statement.GetDocumentRange().TextRange;

            return(new UnitTestElementLocation(projectFile, textRange, textRange));
        }
 public override void Visit(IExpressionStatement statement)
 {
    var assignment = statement.Expression as IAssignment;
    if (assignment != null && !Parent.CurrentMethod.IsConstructor)
    {
         MarkMutationTarget(statement);
    }
 }
 public override void Visit(IExpressionStatement expressionStatement)
 {
     if (Process(expressionStatement))
     {
         visitor.Visit(expressionStatement);
     }
     base.Visit(expressionStatement);
 }
        protected override IStatement ConvertExpressionStatement(IExpressionStatement ies)
        {
            if (parent == null)
            {
                return(ies);
            }
            bool keepIfStatement = false;
            // Only keep the surrounding if statement when a factor or constraint is being added.
            IExpression expr = ies.Expression;

            if (expr is IMethodInvokeExpression)
            {
                keepIfStatement = true;
                if (CodeRecognizer.IsInfer(expr))
                {
                    keepIfStatement = false;
                }
            }
            else if (expr is IAssignExpression)
            {
                keepIfStatement = false;
                IAssignExpression       iae  = (IAssignExpression)expr;
                IMethodInvokeExpression imie = iae.Expression as IMethodInvokeExpression;
                if (imie != null)
                {
                    keepIfStatement = true;
                    if (imie.Arguments.Count > 0)
                    {
                        // Statements that copy evidence variables should not send evidence messages.
                        IVariableDeclaration ivd    = Recognizer.GetVariableDeclaration(iae.Target);
                        IVariableDeclaration ivdArg = Recognizer.GetVariableDeclaration(imie.Arguments[0]);
                        if (ivd != null && context.InputAttributes.Has <DoNotSendEvidence>(ivd) &&
                            ivdArg != null && context.InputAttributes.Has <DoNotSendEvidence>(ivdArg))
                        {
                            keepIfStatement = false;
                        }
                    }
                }
                else
                {
                    expr = iae.Target;
                }
            }
            if (expr is IVariableDeclarationExpression)
            {
                IVariableDeclarationExpression ivde = (IVariableDeclarationExpression)expr;
                IVariableDeclaration           ivd  = ivde.Variable;
                keepIfStatement = CodeRecognizer.IsStochastic(context, ivd) && !context.InputAttributes.Has <DoNotSendEvidence>(ivd);
            }
            if (!keepIfStatement)
            {
                return(ies);
            }
            IConditionStatement cs = Builder.CondStmt(parent.Condition, Builder.BlockStmt());

            cs.Then.Statements.Add(ies);
            return(cs);
        }
Example #16
0
        private void ProcessExpressionStatement(IExpressionStatement pStatement)
        {
            if (mCurrentBlock.Terminated)
            {
                mCurrentBlock = CreateBlock(CreateLabel());
            }

            ProcessExpression(pStatement.Expression);
        }
Example #17
0
            public override void VisitExpressionStatementNode(IExpressionStatement expressionStatementParam, IHighlightingConsumer context)
            {
                if (expressionStatementParam.FirstChild is IIdentifier identifier)
                {
                    context.AddHighlighting(new CgHighlighting(CgHighlightingAttributeIds.VARIABLE_IDENTIFIER, identifier.GetDocumentRange()));
                }

                base.VisitExpressionStatementNode(expressionStatementParam, context);
            }
Example #18
0
            public override void Visit(IExpressionStatement statement)
            {
                var assignment = statement.Expression as IAssignment;

                if (assignment != null && !Parent.CurrentMethod.IsConstructor)
                {
                    MarkMutationTarget(statement);
                }
            }
 public override IStatement Rewrite(IExpressionStatement expressionStatement) {
   var assignment = expressionStatement.Expression as Assignment;
   if (assignment != null) {
     var local = assignment.Target.Definition as LocalDefinition;
     if (local != null && this.delegatesCachedInLocals != null && this.delegatesCachedInLocals.ContainsKey(local))
       return CodeDummy.Block;
   }
   return base.Rewrite(expressionStatement);
 }
Example #20
0
        private static IAssignExpression GetAssignExpression(IStatement statement)
        {
            IExpressionStatement state_exp = statement as IExpressionStatement;

            if (state_exp == null)
            {
                return(null);
            }

            return(state_exp.Expression as IAssignExpression);
        }
Example #21
0
        public override IStatement Rewrite(IExpressionStatement expressionStatement)
        {
            var assignment = expressionStatement.Expression as Assignment;

            if (assignment != null)
            {
                var field = assignment.Target.Definition as IFieldReference;
                if (field != null)
                {
                    if (this.closures.Find(field.Type.InternedKey) != null)
                    {
                        //Assigning the closure instance to a field of an outer closure or an interator state class.
                        return(CodeDummy.Block);
                    }
                    //in this case we may be initializing a closure field with the parameter that it captures.
                    var closureInstance = assignment.Target.Instance;
                    if (closureInstance != null && this.closures.Find(closureInstance.Type.InternedKey) != null)
                    {
                        var locOrPar = this.closureFieldToLocalOrParameterMap.Find(field.InternedKey) as IBoundExpression;
                        if (locOrPar != null)
                        {
                            var binding = assignment.Source as IBoundExpression;
                            if (binding != null)
                            {
                                if (binding.Definition == locOrPar.Definition)
                                {
                                    return(CodeDummy.Block);
                                }
                            }
                        }
                        else
                        {
                            var thisRef = assignment.Source as IThisReference;
                            if (thisRef != null)
                            {
                                return(CodeDummy.Block);
                            }
                        }
                    }
                    //If we get here, we just have a normal assignment to a closure field. We need to replace the field with the local or parameter.
                    //The base call will do that by calling Rewrite(ITargetExpression).
                }
                else
                {
                    var local = assignment.Target.Definition as ILocalDefinition;
                    if (local != null && this.closures.Find(local.Type.InternedKey) != null)
                    {
                        Contract.Assume(assignment.Source is ICreateObjectInstance);
                        return(CodeDummy.Block);
                    }
                }
            }
            return(base.Rewrite(expressionStatement));
        }
Example #22
0
        private static IMethodInvokeExpression GetInvokeExpression(IStatement statement)
        {
            IExpressionStatement state_exp = statement as IExpressionStatement;

            if (state_exp == null)
            {
                return(null);
            }

            return(state_exp.Expression as IMethodInvokeExpression);
        }
            public override Node VisitExpressionStatement(IExpressionStatement operation, Graph graph)
            {
                var node = graph.AddNode(GetId(operation));

                node.LabelText = "ExpressionStatement";

                var child = this.Visit(operation.Expression, graph);

                graph.AddEdge(node.Id, child.Id);

                return(node);
            }
 public override void Visit(IExpressionStatement statement)
 {
     var assignment = statement.Expression as IAssignment;
     if (assignment != null && Parent.CurrentMethod.IsConstructor)
     {
         if (assignment.Target.Definition is IFieldReference
             && assignment.Target.Instance is ThisReference)
         {
             MarkMutationTarget(statement);
         }
     }
 }
 public override bool Visit(IExpressionStatement statement, IStatement context)
 {
     _stack.Push(statement);
     try
     {
         return(base.Visit(statement, context));
     }
     finally
     {
         _stack.Pop();
     }
 }
Example #26
0
        private static void WriteExpression(LanguageWriter w, IExpressionStatement state)
        {
            w.WriteExpression(state.Expression);

            if (w.SkipWriteLine)
            {
                return;
            }

            w.Write(";");
            w.WriteLine();
        }
            public override void Visit(IExpressionStatement statement)
            {
                var assignment = statement.Expression as IAssignment;

                if (assignment != null && Parent.CurrentMethod.IsConstructor)
                {
                    if (assignment.Target.Definition is IFieldReference &&
                        assignment.Target.Instance is ThisReference)
                    {
                        MarkMutationTarget(statement);
                    }
                }
            }
Example #28
0
 public StatementTestDeclaration(
     IIdentity identity,
     IProject project,
     string text,
     IEnumerable <ITestDeclaration> testDeclarations,
     IExpressionStatement statement)
     : base(statement)
 {
     _identity         = identity;
     _project          = project;
     _text             = text;
     _testDeclarations = testDeclarations;
 }
 public StatementTestDeclaration(
 IIdentity identity,
 IProject project,
 string text,
 IEnumerable<ITestDeclaration> testDeclarations,
 IExpressionStatement statement)
     : base(statement)
 {
     _identity = identity;
       _project = project;
       _text = text;
       _testDeclarations = testDeclarations;
 }
Example #30
0
        public override IStatement Rewrite(IExpressionStatement expressionStatement)
        {
            var assignment = expressionStatement.Expression as Assignment;

            if (assignment != null)
            {
                var local = assignment.Target.Definition as LocalDefinition;
                if (local != null && this.delegatesCachedInLocals != null && this.delegatesCachedInLocals.ContainsKey(local))
                {
                    return(CodeDummy.Block);
                }
            }
            return(base.Rewrite(expressionStatement));
        }
Example #31
0
 protected string StatementLabel(IStatement ist)
 {
     if (ist is IExpressionStatement)
     {
         IExpressionStatement ies = (IExpressionStatement)ist;
         string s;
         if (ies.Expression is IAssignExpression)
         {
             s = ExpressionToString(((IAssignExpression)ies.Expression).Target);
         }
         else
         {
             s = ExpressionToString(ies.Expression);
         }
         if (s.StartsWith("this."))
         {
             s = s.Substring(5);
         }
         //if (s.EndsWith("[0]")) s = s.Substring(0, s.Length - 3);
         return(s);
     }
     if (ist is IForStatement)
     {
         return(StatementLabel(((IForStatement)ist).Body.Statements[0]));
     }
     if (ist is IConditionStatement)
     {
         return(String.Format("if ({0}) {1}", ((IConditionStatement)ist).Condition.ToString(),
                              StatementLabel(((IConditionStatement)ist).Then)));
     }
     if (ist is IBlockStatement)
     {
         int    blockSize = ((IBlockStatement)ist).Statements.Count;
         string s;
         if (blockSize > 0)
         {
             s = StatementLabel(((IBlockStatement)ist).Statements[0]);
         }
         else
         {
             s = "EmptyBlock";
         }
         if (blockSize > 1)
         {
             s += " ...";
         }
         return(s);
     }
     return(ist.GetType().Name);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="expressionStatement"></param>
        /// <remarks> TODO: might be wrong for the general case</remarks>
        public override void TraverseChildren(IExpressionStatement expressionStatement)
        {
            var expressionIsOpAssignStatement = false;
            var binOp = expressionStatement.Expression as IBinaryOperation;

            if (binOp != null && binOp.LeftOperand is ITargetExpression)
            {
                expressionIsOpAssignStatement = true;
            }

            ExpressionTraverser etrav = this.factory.MakeExpressionTraverser(this.sink, this, this.contractContext, expressionIsOpAssignStatement);

            etrav.Traverse(expressionStatement.Expression);
        }
 private void ForEachAttributeOfCodeElementAndContents(object codeElement, Action <ICompilerAttribute> action)
 {
     if ((attributes == null) || (codeElement == null))
     {
         return;
     }
     foreach (var attr in attributes.GetAll <ICompilerAttribute>(codeElement))
     {
         action(attr);
     }
     if (codeElement is IStatement)
     {
         if (codeElement is IExpressionStatement)
         {
             IExpressionStatement ies = (IExpressionStatement)codeElement;
             ForEachAttributeOfCodeElement(ies.Expression, action);
             if (ies.Expression is IVariableDeclarationExpression)
             {
                 ForEachAttributeOfCodeElement(((IVariableDeclarationExpression)ies.Expression).Variable, action);
             }
             else if (ies.Expression is IAssignExpression)
             {
                 IAssignExpression iae = (IAssignExpression)ies.Expression;
                 if (iae.Target is IVariableDeclarationExpression)
                 {
                     ForEachAttributeOfCodeElement(((IVariableDeclarationExpression)iae.Target).Variable, action);
                 }
                 if (iae.Expression is IMethodInvokeExpression)
                 {
                     ForEachAttributeOfCodeElement(iae.Expression, action);
                 }
             }
         }
         else if (codeElement is IForStatement)
         {
             IForStatement ifs = (IForStatement)codeElement;
             ForEachAttributeOfCodeElementAndContents(ifs.Initializer, action);
             IBinaryExpression ibe = (IBinaryExpression)ifs.Condition;
             ForEachAttributeOfCodeElementAndContents(ibe.Right, action);
         }
     }
     if (codeElement is IMethodDeclaration)
     {
         IMethodDeclaration imd = (IMethodDeclaration)codeElement;
         foreach (IParameterDeclaration ipd in imd.Parameters)
         {
             ForEachAttributeOfCodeElement(ipd, action);
         }
     }
 }
 internal RedundantAwaitSuggestion(
     [NotNull] string message,
     [NotNull] Action removeAsync,
     [NotNull] IAwaitExpression awaitExpression,
     [CanBeNull] IExpressionStatement statementToBeReplacedWithReturnStatement,
     [NotNull] ICSharpExpression expressionToReturn,
     [CanBeNull] IAttributesOwnerDeclaration attributesOwnerDeclaration) : base(message)
 {
     RemoveAsync     = removeAsync;
     AwaitExpression = awaitExpression;
     StatementToBeReplacedWithReturnStatement = statementToBeReplacedWithReturnStatement;
     ExpressionToReturn         = expressionToReturn;
     AttributesOwnerDeclaration = attributesOwnerDeclaration;
 }
 public override void Visit(IExpressionStatement statement)
 {
     var call = statement.Expression as MethodCall;
     if (call != null)
     {
         var method = call.MethodToCall.ResolvedMethod;
         if (method.IsVirtual && !Parent.CurrentMethod.IsNewSlot
          && method.Name.Value == Parent.CurrentMethod.Name.Value )
         {//
       //  && Parent.CurrentMethod.ContainingTypeDefinition.BaseClasses
       //      .Any(c => c.ResolvedType == method.ContainingTypeDefinition)
             MarkMutationTarget(statement);
         }
     }
     
 }
            public override void Visit(IExpressionStatement statement)
            {
                var call = statement.Expression as MethodCall;
                if (call != null && (call.MethodToCall.Name.Value.StartsWith("remove_")
                    || call.MethodToCall.Name.Value.StartsWith("add_")))
                {
                    if(call.MethodToCall.ResolvedMethod.IsCil
                    && call.MethodToCall.ResolvedMethod.Parameters.Count() == 1
                    && call.MethodToCall.ResolvedMethod.Parameters.Single()
                        .Type.ResolvedType.BaseClasses.OfType<NamespaceTypeReference>()
                        .Any(type => type.Name.Value == ("MulticastDelegate")) )
                    {
                        MarkMutationTarget(statement);
                    }

                }
            }
Example #37
0
 public virtual void VisitExpressionStatement(IExpressionStatement operation)
 {
     DefaultVisit(operation);
 }
Example #38
0
    /// <summary>
    /// Returns a shallow copy of the given expression statement.
    /// </summary>
    /// <param name="expressionStatement"></param>
    public ExpressionStatement Copy(IExpressionStatement expressionStatement) {
      Contract.Requires(expressionStatement != null);
      Contract.Ensures(Contract.Result<ExpressionStatement>() != null);

      return new ExpressionStatement(expressionStatement);
    }
Example #39
0
 public override void TraverseChildren(IExpressionStatement expressionStatement) {
   this.PrintToken(CSharpToken.Indent);
   this.Traverse(expressionStatement.Expression);
   this.PrintToken(CSharpToken.Semicolon);
 }
Example #40
0
 /// <summary>
 /// Returns a shallow copy of the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public ExpressionStatement Copy(IExpressionStatement expressionStatement)
 {
     return new ExpressionStatement(expressionStatement);
 }
 /// <summary>
 /// Rewrites the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public virtual IStatement Rewrite(IExpressionStatement expressionStatement)
 {
     return expressionStatement;
 }
Example #42
0
 /// <summary>
 /// Traverses the children of the expression statement.
 /// </summary>
 public virtual void TraverseChildren(IExpressionStatement expressionStatement)
 {
     Contract.Requires(expressionStatement != null);
       this.TraverseChildren((IStatement)expressionStatement);
       if (this.StopTraversal) return;
       this.Traverse(expressionStatement.Expression);
 }
Example #43
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="expressionStatement"></param>
 public ExpressionStatement(IExpressionStatement expressionStatement)
   : base(expressionStatement) {
   this.expression = expressionStatement.Expression;
 }
Example #44
0
 /// <summary>
 /// Performs some computation with the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public virtual void Visit(IExpressionStatement expressionStatement)
 {
 }
Example #45
0
 /// <summary>
 /// Traverses the expression statement.
 /// </summary>
 public void Traverse(IExpressionStatement expressionStatement)
 {
     Contract.Requires(expressionStatement != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(expressionStatement);
       if (this.StopTraversal) return;
       this.TraverseChildren(expressionStatement);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(expressionStatement);
 }
Example #46
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public virtual void Visit(IExpressionStatement expressionStatement)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(expressionStatement);
       this.Visit(expressionStatement.Expression);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
            private bool ValidateExpression(IExpressionStatement expressionStatement)
            {
                if (expressionStatement.Expression == null || expressionStatement.Expression.Kind != OperationKind.InvocationExpression)
                {
                    return false;
                }

                var invocationExpression = (IInvocationExpression)expressionStatement.Expression;
                if (!_callsDisposeBool)
                {
                    bool result = IsDisposeBoolCall(invocationExpression);
                    if (result)
                    {
                        _callsDisposeBool = true;
                    }

                    return result;
                }
                else if (!_callsSuppressFinalize)
                {
                    bool result = IsSuppressFinalizeCall(invocationExpression);
                    if (result)
                    {
                        _callsSuppressFinalize = true;
                    }

                    return result;
                }

                return false;
            }
        public override void TraverseChildren(IExpressionStatement expressionStatement)
{ MethodEnter(expressionStatement);
            base.TraverseChildren(expressionStatement);
     MethodExit();   }
Example #49
0
    /// <summary>
    /// Returns a deep copy of the given expression statement.
    /// </summary>
    /// <param name="expressionStatement"></param>
    public ExpressionStatement Copy(IExpressionStatement expressionStatement) {
      Contract.Requires(expressionStatement != null);
      Contract.Ensures(Contract.Result<ExpressionStatement>() != null);

      var mutableCopy = this.shallowCopier.Copy(expressionStatement);
      mutableCopy.Expression = this.Copy(mutableCopy.Expression);
      return mutableCopy;
    }
Example #50
0
 public void Visit(IExpressionStatement expressionStatement)
 {
     this.traverser.Traverse(expressionStatement);
 }
        private bool TryFindAssignmentExpression(
            IBlockStatement containingBlock, IIfStatement ifOperation, ISymbol localOrParameter,
            out IExpressionStatement expressionStatement, out IAssignmentExpression assignmentExpression)
        {
            var ifOperationIndex = containingBlock.Statements.IndexOf(ifOperation);

            // walk forward until we find an assignment of this local/parameter into
            // something else.
            for (var i = ifOperationIndex + 1; i < containingBlock.Statements.Length; i++)
            {
                expressionStatement = containingBlock.Statements[i] as IExpressionStatement;
                if (expressionStatement == null)
                {
                    continue;
                }

                assignmentExpression = expressionStatement.Expression as IAssignmentExpression;
                if (assignmentExpression == null)
                {
                    continue;
                }

                if (!TryGetLocalOrParameterSymbol(assignmentExpression.Value, out var assignmentValue))
                {
                    continue;
                }

                if (!Equals(localOrParameter, assignmentValue))
                {
                    continue;
                }

                return true;
            }

            expressionStatement = null;
            assignmentExpression = null;
            return false;
        }
Example #52
0
 /// <summary>
 /// Performs some computation with the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public virtual void Visit(IExpressionStatement expressionStatement)
 {
     this.Visit((IStatement)expressionStatement);
 }
Example #53
0
 public override void VisitExpressionStatement(IExpressionStatement operation)
 {
     base.VisitExpressionStatement(operation);
 }
Example #54
0
 public void Visit(IExpressionStatement expressionStatement)
 {
     Contract.Requires(expressionStatement != null);
       throw new NotImplementedException();
 }
 public override IStatement Rewrite(IExpressionStatement expressionStatement) {
   this.currentSingleUseSingleReferenceLocal = null;
   var result = base.Rewrite(expressionStatement);
   if (this.currentSingleUseSingleReferenceLocal != null) {
     var exprStat = result as IExpressionStatement;
     if (exprStat != null) {
       var assign = exprStat.Expression as IAssignment;
       if (assign != null && assign.Target.Definition == this.currentSingleUseSingleReferenceLocal)
         this.expressionToSubstituteForSingleUseSingleReferenceLocal = assign.Source;
     }
   }
   return result;
 }
Example #56
0
 public void Visit(IExpressionStatement expressionStatement)
 {
     throw new NotImplementedException();
 }
Example #57
0
 /// <summary>
 /// Visits the specified expression statement.
 /// </summary>
 /// <param name="expressionStatement">The expression statement.</param>
 public override void Visit(IExpressionStatement expressionStatement)
 {
     ExpressionStatement mutableExpressionStatement = new ExpressionStatement(expressionStatement);
     this.resultStatement = this.myCodeCopier.DeepCopy(mutableExpressionStatement);
 }
Example #58
0
 public void Visit(IExpressionStatement expressionStatement)
 {
     this.result = this.copier.Copy(expressionStatement);
 }
 public virtual void onASTElement(IExpressionStatement expressionStatement) { }
Example #60
0
 /// <summary>
 /// Returns a deep copy of the given expression statement.
 /// </summary>
 /// <param name="expressionStatement"></param>
 public ExpressionStatement Copy(IExpressionStatement expressionStatement)
 {
     var mutableCopy = this.shallowCopier.Copy(expressionStatement);
       mutableCopy.Expression = this.Copy(mutableCopy.Expression);
       return mutableCopy;
 }