Exemplo n.º 1
0
 public bool VisitNode(BreakStatement node)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
 public bool VisitNode(BreakStatement node)
 {
     // break;
     Write("break");
     return true;
 }
Exemplo n.º 3
0
        // TODO: guess for loop, probably requires a large restructure
        public Statement DecompileConditionalJump(bool isOpt = false)
        {
            PopByte();
            var scopeStartOffset = StartPositions.Pop();
            Statement statement = null;
            bool hasElse = false;
            var scopeStatements = new List<Statement>();

            UInt16 scopeEndJmpOffset = 0;
            UInt16 afterScopeOffset = 0;
            Expression conditional = null;

            if (isOpt)
            {
                var obj = ReadObject();
                var optCheck = Convert.ToBoolean(ReadByte());
                afterScopeOffset = ReadUInt16();

                String special = (optCheck ? "" : "!") + obj.ObjectName;
                conditional = new SymbolReference(null, null, null, special);
            }
            else
            {
                afterScopeOffset = ReadUInt16();
                conditional = DecompileExpression();
            }

            if (conditional == null)
                return null;

            if (afterScopeOffset < scopeStartOffset) // end of do_until detection
            {
                scopeStartOffset = afterScopeOffset;
                var outerScope = Scopes[CurrentScope.Peek()];
                var startStatement = StatementLocations[afterScopeOffset];
                StatementLocations.Remove(afterScopeOffset);
                var index = outerScope.IndexOf(startStatement);
                scopeStatements = new List<Statement>(outerScope.Skip(index));
                outerScope.RemoveRange(index, outerScope.Count - index);
                statement = new DoUntilLoop(conditional, new CodeBody(scopeStatements, null, null), null, null);
            }

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < afterScopeOffset)
            {
                if (CurrentIs(StandardByteCodes.Jump))
                {
                    var contPos = (UInt16)Position;
                    PopByte();
                    scopeEndJmpOffset = ReadUInt16();
                    if (scopeEndJmpOffset == scopeStartOffset)
                    {
                        statement = new WhileLoop(conditional, new CodeBody(scopeStatements, null, null), null, null);
                        break;
                    }
                    else if (Position < afterScopeOffset) // if we are not at the end of the scope, this is a continue statement in a loop rather than an else statement
                    {
                        var cont = new ContinueStatement(null, null);
                        StatementLocations.Add(contPos, cont);
                        scopeStatements.Add(cont);
                    }
                    else if (ForEachScopes.Count != 0 && scopeEndJmpOffset == ForEachScopes.Peek())
                    {
                        var breakStatement = new BreakStatement(null, null);
                        StatementLocations.Add(contPos, breakStatement);
                        scopeStatements.Add(breakStatement);
                    }
                    else
                    {
                        hasElse = true;
                    }

                    continue;
                }

                var current = DecompileStatement();
                if (current == null)
                    return null; // ERROR ?

                scopeStatements.Add(current);
            }
            CurrentScope.Pop();

            List<Statement> elseStatements = new List<Statement>();
            if (hasElse)
            {
                var endElseOffset = scopeEndJmpOffset;
                Scopes.Add(elseStatements);
                CurrentScope.Push(Scopes.Count - 1);
                while (Position < endElseOffset)
                {
                    var current = DecompileStatement();
                    if (current == null)
                        return null; // ERROR ?

                    elseStatements.Add(current);
                }
                CurrentScope.Pop();
            }

            statement = statement ?? new IfStatement(conditional, new CodeBody(scopeStatements, null, null),
                        null, null, elseStatements.Count != 0 ? new CodeBody(elseStatements, null, null) : null);
            StatementLocations.Add(scopeStartOffset, statement);
            return statement;
        }
Exemplo n.º 4
0
        public SwitchStatement DecompileSwitch()
        {
            PopByte();
            var objIndex = ReadObject();
            var unknByte = ReadByte();
            var expr = DecompileExpression();
            var scopeStatements = new List<Statement>();
            UInt16 endOffset = 0xFFFF; // set it at max to begin with, so we can begin looping

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < endOffset && Position < Size)
            {
                if (CurrentIs(StandardByteCodes.Jump)) // break detected, save the endOffset
                {                                    // executes for all occurences, to handle them all.
                    StartPositions.Push((UInt16)Position);
                    PopByte();
                    endOffset = ReadUInt16();
                    var breakStatement = new BreakStatement(null, null);
                    StatementLocations.Add(StartPositions.Pop(), breakStatement);
                    scopeStatements.Add(breakStatement);
                    continue;
                }

                var current = DecompileStatement();
                if (current == null)
                    return null; // ERROR ?

                scopeStatements.Add(current);
                if (current is DefaultStatement && endOffset == 0xFFFF)
                    break; // If no break was detected, we end the switch rather than include the rest of ALL code in the default.
            }
            CurrentScope.Pop();

            var statement = new SwitchStatement(expr, new CodeBody(scopeStatements, null, null), null, null);
            StatementLocations.Add(StartPositions.Pop(), statement);
            return statement;
        }
Exemplo n.º 5
0
        public Statement DecompileJump()
        {
            PopByte();
            var jumpOffs = ReadUInt16(); // discard jump destination
            Statement statement = null;

            if (ForEachScopes.Count != 0 && jumpOffs == ForEachScopes.Peek()) // A jump to the IteratorPop of a ForEach means break afaik.
                statement = new BreakStatement(null, null);
            else
                statement = new ContinueStatement(null, null);

            StatementLocations.Add(StartPositions.Pop(), statement);
            return statement;
        }
Exemplo n.º 6
0
 public Statement DecompileIteratorPop()
 {
     PopByte();
     if (CurrentIs(StandardByteCodes.Return)) // Any return inside a ForEach seems to call IteratorPop before the return, maybe breaks the loop?
     {
         return DecompileReturn();
     }
     else
     {
         var statement = new BreakStatement(null, null);
         StatementLocations.Add(StartPositions.Pop(), statement);
         return statement;
     }
 }