예제 #1
0
        void ProcessBlock(BlockStatement node)
        {
            for (int i = 0; i < node.Statements.Count - 1; i++)
            {
                ForeachArrayMatcher matcher = new ForeachArrayMatcher(node.Statements[i], node.Statements[i + 1], this.context.MethodContext);
                if (!matcher.Match())
                {
                    continue;
                }

                if (CheckForIndexUsages(matcher))
                {
                    continue;
                }

                context.MethodContext.RemoveVariable(matcher.Incrementor);
                if (matcher.CurrentVariable != null)
                {
                    context.MethodContext.RemoveVariable(matcher.CurrentVariable);
                }

                node.Statements.RemoveAt(i);
                node.Statements.RemoveAt(i);
                node.AddStatementAt(i, matcher.Foreach);
                ProcessBlock(matcher.Foreach.Body);
            }
        }
		void ProcessBlock (BlockStatement node)
		{
			for (int i = 0; i < node.Statements.Count - 1; i++)
			{
				ForeachArrayMatcher matcher = new ForeachArrayMatcher(node.Statements[i], node.Statements[i + 1], this.context.MethodContext);
				if (!matcher.Match())
				{
					continue;
				}

				if (CheckForIndexUsages(matcher))
				{
					continue;
				}

				context.MethodContext.RemoveVariable(matcher.Incrementor);
				if (matcher.CurrentVariable != null)
				{
					context.MethodContext.RemoveVariable(matcher.CurrentVariable);
				}

				node.Statements.RemoveAt(i);
				node.Statements.RemoveAt(i);
				node.AddStatementAt(i, matcher.Foreach);
				ProcessBlock(matcher.Foreach.Body);
			}
		}
예제 #3
0
 private bool CheckForIndexUsages(ForeachArrayMatcher matcher)
 {
     currentForIndeces.Push(matcher.Incrementor);
     currentForIndecesUsed.Push(false);
     foreach (var childStatement in matcher.Foreach.Body.Statements)
     {
         Visit(childStatement);
     }
     currentForIndeces.Pop();
     return(currentForIndecesUsed.Pop());
 }
		private bool CheckForIndexUsages(ForeachArrayMatcher matcher)
		{
			currentForIndeces.Push(matcher.Incrementor);
			currentForIndecesUsed.Push(false);
			foreach (var childStatement in matcher.Foreach.Body.Statements)
			{
				Visit(childStatement);
			}
			currentForIndeces.Pop();
			return currentForIndecesUsed.Pop();
		}