Exemple #1
0
 public override void addStatement(Statement statement)
 {
     if(!finalize && statement is Assignment)
     {
       this.assign = (Assignment) statement;
     }
     else if(statement is BooleanIndicator)
     {
       finalize = true;
     }
 }
Exemple #2
0
 public virtual void useAssignment(Assignment assign)
 {
     this.assign = assign;
     branch.useExpression(assign.getFirstValue());
 }
 public IfThenEndBlockOperation(int line, Assignment _assign, Expression _expr)
     : base(line)
 {
     assign = _assign;
     expr = _expr;
 }
Exemple #4
0
 public override void print(Output @out)
 {
     if(assign != null && assign.getFirstTarget() != null)
     {
       Assignment assignOut = new Assignment(assign.getFirstTarget(), Value);
       assignOut.print(@out);
     }
     else
     {
       @out.print("-- unhandled set block");
       @out.println();
     }
 }
Exemple #5
0
        private void processSequence(int begin, int end)
        {
            int blockIndex = 1;
            Stack<Block> blockStack = new Stack<Block>();
            blockStack.Push(blocks[0]);
            skip = new bool[end + 1];
            for(int line = begin; line <= end; line++)
            {
            //
            //      System.out.print("-- line " + line + "; R[0] = ");
            //      r.getValue(0, line).print(new Output());
            //      System.out.println();
            //      System.out.print("-- line " + line + "; R[1] = ");
            //      r.getValue(1, line).print(new Output());
            //      System.out.println();
            //      System.out.print("-- line " + line + "; R[2] = ");
            //      r.getValue(2, line).print(new Output());
            //      System.out.println();
            //
              Operation blockHandler = null;
              while(blockStack.Peek().end <= line)
              {
            Block block1 = blockStack.Pop();
            blockHandler = block1.process(this);
            if(blockHandler != null)
            {
              break;
            }
              }
              if(blockHandler == null)
              {
            while(blockIndex < blocks.Count && blocks[blockIndex].begin <= line)
            {
              blockStack.Push(blocks[blockIndex++]);
            }
              }
              Block block = blockStack.Peek();
              r.startLine(line); //Must occur AFTER block.rewrite
              if(skip[line])
              {
            List<Declaration> newLocals1 = r.getNewLocals(line);
            if(newLocals1.Count != 0)
            {
              Assignment assign1 = new Assignment();
              assign1.declare(newLocals1[0].begin);
              foreach(Declaration decl in newLocals1)
              {
                assign1.addLast(new VariableTarget(decl), r.getValue(decl.register, line));
              }
              blockStack.Peek().addStatement(assign1);
            }
            continue;
              }
              List<Operation> operations = processLine(line);
              List<Declaration> newLocals = r.getNewLocals(blockHandler == null ? line : line - 1);
              //List<Declaration> newLocals = r.getNewLocals(line);
              Assignment assign = null;
              if(blockHandler == null)
              {
            if(code.op(line) == Op.LOADNIL)
            {
              assign = new Assignment();
              int count = 0;
              foreach(Operation operation in operations)
              {
                RegisterSet @set = (RegisterSet) operation;
                operation.process(r, block);
                if(r.isAssignable(@set.register, @set.line))
                {
                  assign.addLast(r.getTarget(@set.register, @set.line), @set.value);
                  count++;
                }
              }
              if(count > 0)
              {
                block.addStatement(assign);
              }
              }
            else
            {
              //System.out.println("-- Process iterating ... ");
              foreach(Operation operation in operations)
              {
            //System.out.println("-- iter");
                Assignment temp = processOperation(operation, line, line + 1, block);
                if(temp != null)
                {
                  assign = temp;
              //System.out.print("-- top assign -> "); temp.getFirstTarget().print(new Output()); System.out.println();
                }
              }
              if(assign != null && assign.getFirstValue().isMultiple())
              {
                block.addStatement(assign);
              }
            }
              }
              else
              {
            assign = processOperation(blockHandler, line, line, block);
              }
              if(assign != null)
              {
            if(newLocals.Count != 0)
            {
              assign.declare(newLocals[0].begin);
              foreach(Declaration decl in newLocals)
              {
            //System.out.println("-- adding decl @" + line);
                assign.addLast(new VariableTarget(decl), r.getValue(decl.register, line + 1));
              }
              //blockStack.peek().addStatement(assign);
            }
              }
              if(blockHandler == null)
              {
            if(assign != null)
            {

            }
            else if(newLocals.Count != 0 && code.op(line) != Op.FORPREP)
            {
              if(code.op(line) != Op.JMP || code.op(line + 1 + code.sBx(line)) != tforTarget)
              {
                assign = new Assignment();
                assign.declare(newLocals[0].begin);
                foreach(Declaration decl in newLocals)
                {
                  assign.addLast(new VariableTarget(decl), r.getValue(decl.register, line));
                }
                blockStack.Peek().addStatement(assign);
              }
            }
              }
              if(blockHandler != null)
              {
            //System.out.println("-- repeat @" + line);
            line--;
            continue;
              }
            }
        }