public Statement DecompileForEach(bool isDynArray = false) { PopByte(); var scopeStatements = new List <Statement>(); var iteratorFunc = DecompileExpression(); if (iteratorFunc == null) { return(null); } if (isDynArray) { Expression dynArrVar = DecompileExpression(); bool hasIndex = Convert.ToBoolean(ReadByte()); Expression dynArrIndex = DecompileExpression(); iteratorFunc = new DynArrayIterator(iteratorFunc, dynArrVar, dynArrIndex); } var scopeEnd = ReadUInt16(); // MemOff ForEachScopes.Push(scopeEnd); Scopes.Add(scopeStatements); CurrentScope.Push(Scopes.Count - 1); while (Position < Size) { if (CurrentIs(OpCodes.IteratorNext)) { PopByte(); // IteratorNext if (PeekByte == (byte)OpCodes.IteratorPop) { StatementLocations[(ushort)(Position - 1)] = new IteratorNext(); StatementLocations[(ushort)Position] = new IteratorPop(); PopByte(); // IteratorPop break; } Position--; } var current = DecompileStatement(); if (current == null) { return(null); // ERROR ? } scopeStatements.Add(current); } CurrentScope.Pop(); ForEachScopes.Pop(); var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements)) { iteratorPopPos = Position - 1 }; StatementLocations.Add(StartPositions.Pop(), statement); return(statement); }
public Statement DecompileForEach(bool isDynArray = false) // TODO: guess for loop, probably requires a large restructure { 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); }