public bool VisitNode(ForEachLoop node) { // foreach IteratorFunction(parameters) { /n contents /n } Write("foreach "); node.IteratorCall.AcceptVisitor(this); Append("{0}", "{"); NestingLevel++; node.Body.AcceptVisitor(this); NestingLevel--; Write("{0}", "}"); return true; }
public bool VisitNode(ForEachLoop node) { throw new NotImplementedException(); }
// TODO: guess for loop, probably requires a large restructure public Statement DecompileForEach(bool isDynArray = false) { PopByte(); var scopeStatements = new List<Statement>(); var iteratorFunc = DecompileExpression(); if (iteratorFunc == null) return null; Expression dynArrVar = null; Expression dynArrIndex = null; bool unknByte = false; if (isDynArray) { dynArrVar = DecompileExpression(); unknByte = Convert.ToBoolean(ReadByte()); dynArrIndex = DecompileExpression(); } var scopeEnd = ReadUInt16(); // MemOff ForEachScopes.Push(scopeEnd); Scopes.Add(scopeStatements); CurrentScope.Push(Scopes.Count - 1); while (Position < Size) { if (CurrentIs(StandardByteCodes.IteratorNext) && PeekByte == (byte)StandardByteCodes.IteratorPop) { PopByte(); // IteratorNext PopByte(); // IteratorPop break; } var current = DecompileStatement(); if (current == null) return null; // ERROR ? scopeStatements.Add(current); } CurrentScope.Pop(); ForEachScopes.Pop(); if (isDynArray) { var builder = new CodeBuilderVisitor(); // what a wonderful hack, TODO. iteratorFunc.AcceptVisitor(builder); var arrayName = new SymbolReference(null, null, null, builder.GetCodeString()); var parameters = new List<Expression>() { dynArrVar, dynArrIndex }; iteratorFunc = new FunctionCall(arrayName, parameters, null, null); } var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements, null, null), null, null); StatementLocations.Add(StartPositions.Pop(), statement); return statement; }