Beispiel #1
0
  @Override
  public boolean visit(org.eclipse.edt.compiler.core.ast.WhenClause whenClause) {
    IfStatement clause = factory.createIfStatement();

    Expression prevCond = null;
    for (Node node : whenClause.getExpr_plus()) {
      node.accept(this);

      Expression expr = (Expression) stack.pop();
      if (prevCond != null) {
        BinaryExpression binExp = factory.createBinaryExpression();
        binExp.setLHS(prevCond);
        binExp.setRHS(expr);
        binExp.setOperator(Operation.OR);
        expr = binExp;
      }
      prevCond = expr;
      clause.setCondition(expr);
    }
    StatementBlock block = factory.createStatementBlock();
    for (Node node : (List<Node>) whenClause.getStmts()) {
      node.accept(this);
      Statement stmt = (Statement) stack.pop();
      if (stmt != null) {
        block.getStatements().add(stmt);
      }
    }
    clause.setTrueBranch(block);
    stack.push(clause);
    setElementInformation(whenClause, clause);
    setElementInformation(whenClause, block);
    return false;
  }
Beispiel #2
0
 @Override
 public boolean visit(org.eclipse.edt.compiler.core.ast.IfStatement ifStatement) {
   IfStatement stmt = factory.createIfStatement();
   stack.push(stmt);
   setElementInformation(ifStatement, stmt);
   ifStatement.getCondition().accept(this);
   stmt.setCondition((Expression) stack.pop());
   StatementBlock block = factory.createStatementBlock();
   setElementInformation(ifStatement, block);
   stmt.setTrueBranch(block);
   for (Node node : (List<Node>) ifStatement.getStmts()) {
     node.accept(this);
     Statement currStmt = (Statement) stack.pop();
     if (currStmt != null) {
       block.getStatements().add(currStmt);
     }
   }
   if (ifStatement.hasElse()) {
     block = factory.createStatementBlock();
     setElementInformation(ifStatement, block);
     stmt.setFalseBranch(block);
     for (Node node : (List<Node>) ifStatement.getElse().getStmts()) {
       node.accept(this);
       Statement currStmt = (Statement) stack.pop();
       if (currStmt != null) {
         block.getStatements().add(currStmt);
       }
     }
   }
   return false;
 }
Beispiel #3
0
  @Override
  public boolean visit(org.eclipse.edt.compiler.core.ast.CaseStatement caseStatement) {
    IfStatement stmt = null;
    Expression criterion = null;

    // need to create a statement block to hold the label statement and if statement
    StatementBlock block = factory.createStatementBlock();
    LabelStatement label = factory.createLabelStatement();
    label.setLabel("eze_CaseLabel_" + caseLabelCounter);
    caseLabelCounter = caseLabelCounter + 1;
    caseLabelStack.push(label);
    setElementInformation(caseStatement, label);
    block.getStatements().add(label);

    if (caseStatement.hasCriterion()) {
      caseStatement.getCriterion().accept(this);
      criterion = (Expression) stack.pop();
    }
    IfStatement current = null;
    for (Node node : caseStatement.getWhenClauses()) {
      node.accept(this);
      IfStatement when = (IfStatement) stack.pop();
      if (criterion != null) {
        when.setCondition(addWhenCriterion(criterion, when.getCondition()));
      }
      if (stmt == null) {
        current = when;
        stmt = current;
      } else {
        current.setFalseBranch(when);
        current = when;
      }
    }

    if (caseStatement.getDefaultClause() != null) {
      caseStatement.getDefaultClause().accept(this);
      current.setFalseBranch((Statement) stack.pop());
    }
    block.getStatements().add(stmt);
    stack.push(block);
    setElementInformation(caseStatement, stmt);
    return false;
  }