Ejemplo n.º 1
0
 @Override
 public void visit(InvokeInstruction insn) {
   Expr[] exprArgs = new Expr[insn.getMethod().getParameterTypes().length];
   for (int i = 0; i < insn.getArguments().size(); ++i) {
     exprArgs[i] = Expr.var(insn.getArguments().get(i).getIndex());
   }
   InvocationExpr invocationExpr;
   if (insn.getInstance() != null) {
     if (insn.getType() == InvocationType.VIRTUAL) {
       invocationExpr =
           Expr.invoke(insn.getMethod(), Expr.var(insn.getInstance().getIndex()), exprArgs);
     } else {
       invocationExpr =
           Expr.invokeSpecial(insn.getMethod(), Expr.var(insn.getInstance().getIndex()), exprArgs);
     }
   } else {
     invocationExpr = Expr.invokeStatic(insn.getMethod(), exprArgs);
   }
   AssignmentStatement stmt;
   if (insn.getReceiver() != null) {
     stmt = Statement.assign(Expr.var(insn.getReceiver().getIndex()), invocationExpr);
     stmt.getDebugNames().addAll(insn.getReceiver().getDebugNames());
   } else {
     stmt = Statement.assign(null, invocationExpr);
   }
   stmt.setLocation(currentLocation);
   stmt.setAsync(async);
   async = false;
   statements.add(stmt);
 }
Ejemplo n.º 2
0
 @Override
 public void visit(GetFieldInstruction insn) {
   if (insn.getInstance() != null) {
     AssignmentStatement stmt =
         Statement.assign(
             Expr.var(insn.getReceiver().getIndex()),
             Expr.qualify(Expr.var(insn.getInstance().getIndex()), insn.getField()));
     stmt.setLocation(currentLocation);
     statements.add(stmt);
   } else {
     Expr fieldExpr = Expr.qualify(null, insn.getField());
     AssignmentStatement stmt =
         Statement.assign(Expr.var(insn.getReceiver().getIndex()), fieldExpr);
     stmt.setLocation(currentLocation);
     statements.add(stmt);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void visit(ExitInstruction insn) {
   ReturnStatement stmt =
       Statement.exitFunction(
           insn.getValueToReturn() != null ? Expr.var(insn.getValueToReturn().getIndex()) : null);
   stmt.setLocation(currentLocation);
   statements.add(stmt);
 }
Ejemplo n.º 4
0
 private void branch(Expr condition, BasicBlock consequentBlock, BasicBlock alternativeBlock) {
   Statement consequent = generateJumpStatement(consequentBlock);
   Statement alternative = generateJumpStatement(alternativeBlock);
   statements.add(
       Statement.cond(
           condition,
           consequent != null ? Arrays.asList(consequent) : Collections.emptyList(),
           alternative != null ? Arrays.asList(alternative) : Collections.emptyList()));
 }
Ejemplo n.º 5
0
 @Override
 public void visit(AssignInstruction insn) {
   AssignmentStatement stmt =
       Statement.assign(
           Expr.var(insn.getReceiver().getIndex()), Expr.var(insn.getAssignee().getIndex()));
   stmt.getDebugNames().addAll(insn.getReceiver().getDebugNames());
   stmt.setLocation(currentLocation);
   statements.add(stmt);
 }
Ejemplo n.º 6
0
 @Override
 public void visit(PutElementInstruction insn) {
   AssignmentStatement stmt =
       Statement.assign(
           Expr.subscript(
               Expr.var(insn.getArray().getIndex()), Expr.var(insn.getIndex().getIndex())),
           Expr.var(insn.getValue().getIndex()));
   stmt.setLocation(currentLocation);
   statements.add(stmt);
 }
Ejemplo n.º 7
0
 @Override
 public void visit(PutFieldInstruction insn) {
   Expr right = Expr.var(insn.getValue().getIndex());
   Expr left;
   if (insn.getInstance() != null) {
     left = Expr.qualify(Expr.var(insn.getInstance().getIndex()), insn.getField());
   } else {
     left = Expr.qualify(null, insn.getField());
   }
   AssignmentStatement stmt = Statement.assign(left, right);
   stmt.setLocation(currentLocation);
   statements.add(stmt);
 }
Ejemplo n.º 8
0
 private boolean processSequenceImpl(List<Statement> statements) {
   for (Statement part : statements) {
     if (part instanceof SequentialStatement) {
       if (!processSequenceImpl(((SequentialStatement) part).getSequence())) {
         return false;
       }
       continue;
     }
     part.acceptVisitor(this);
     part = resultStmt;
     if (part instanceof SequentialStatement) {
       if (!processSequenceImpl(((SequentialStatement) part).getSequence())) {
         return false;
       }
       continue;
     }
     resultSequence.add(part);
     if (part instanceof BreakStatement) {
       return false;
     }
   }
   return true;
 }
Ejemplo n.º 9
0
 @Override
 public void visit(ConditionalStatement statement) {
   statement.getCondition().acceptVisitor(this);
   statement.setCondition(resultExpr);
   List<Statement> consequent = processSequence(statement.getConsequent());
   List<Statement> alternative = processSequence(statement.getAlternative());
   if (consequent.isEmpty()) {
     consequent.addAll(alternative);
     alternative.clear();
     statement.setCondition(ExprOptimizer.invert(statement.getCondition()));
   }
   if (consequent.isEmpty()) {
     resultStmt = Statement.empty();
     return;
   }
   statement.getConsequent().clear();
   statement.getConsequent().addAll(consequent);
   statement.getAlternative().clear();
   statement.getAlternative().addAll(alternative);
   resultStmt = statement;
 }
Ejemplo n.º 10
0
 @Override
 public void visit(InitClassInstruction insn) {
   InitClassStatement stmt = Statement.initClass(insn.getClassName());
   stmt.setLocation(currentLocation);
   statements.add(stmt);
 }
Ejemplo n.º 11
0
 private void assign(Expr source, Variable target) {
   AssignmentStatement stmt = Statement.assign(Expr.var(target.getIndex()), source);
   stmt.setLocation(currentLocation);
   stmt.getDebugNames().addAll(target.getDebugNames());
   statements.add(stmt);
 }