private bool _AreAllAccessesTheSame(IEnumerable <ArrayAccess> accesses)
        {
            // TODO maybe merge with the other iterations?
            // Accessor does not have to be tracked as no more than one
            // definition per instruction is possible.
            Expression expectedExpression = null;
            FlowNode   expectedNode       = null;
            int        expectedPosition   = -1;

            foreach (var access in accesses)
            {
                var accessor   = _GetAccessor(access);
                var expression = _GetAliasTarget(accessor.Variable, access.Node);

                if (expectedExpression == null)
                {
                    expectedExpression = expression;
                    expectedNode       = access.Node;
                    expectedPosition   = accessor.Position;
                    continue;
                }

                var equality = new ExpressionEquality(expectedNode, access.Node, _aliasAnalysis);
                if (expectedPosition != accessor.Position || !equality.AreEqual(expectedExpression, expression))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool _IsSingleStepIncrement()
        {
            try {
                // TODO maybe change this to use symbols, but this would require more checks.
                var indexName   = _loopIndex.Name;
                var incrementor = _forStatement.Incrementors.Single();

                var code = CodeFactory.Create(_forStatement.Incrementors.Single(), _semanticModel);
                if (code.Root.Count != 1)
                {
                    Debug.WriteLine($"the incrementor is not a single instruction: {incrementor}");
                    return(false);
                }

                var assignment = CodeFactory.Create(_forStatement.Incrementors.Single(), _semanticModel).Root.Single() as Assignment;
                if (assignment == null)
                {
                    Debug.WriteLine($"the incrementor is not an assignment as expected");
                    return(false);
                }

                if (!(assignment.Left is VariableExpression assigned) || !Equals(assigned?.Name, indexName))
                {
                    Debug.WriteLine($"no incrementation of loop index");
                    return(false);
                }

                var equality = new ExpressionEquality();
                return(equality.AreEqual(assignment.Right, new AddExpression(new VariableExpression(indexName), new IntegerExpression(1))));
            } catch (UnsupportedSyntaxException e) {
                Debug.WriteLine($"cannot check incrementor: {e.Message}");
                return(false);
            }
        }
 public void Initialize()
 {
     _instance = new ExpressionEquality();
 }