Beispiel #1
0
  private void writeIfStatement(IASTIfStatement ifStatement) {
    scribe.print(IF);
    scribe.noNewLines();
    if (ifStatement instanceof ICPPASTIfStatement) {
      ICPPASTIfStatement cppIfStatment = (ICPPASTIfStatement) ifStatement;

      if (cppIfStatment.getConditionDeclaration() == null) {
        cppIfStatment.getConditionExpression().accept(visitor);
      } else {
        writeDeclarationWithoutSemicolon(cppIfStatment.getConditionDeclaration());
      }
    } else {
      ifStatement.getConditionExpression().accept(visitor);
    }

    scribe.print(')');
    scribe.newLines();
    nextCompoundNoNewLine();
    IASTStatement elseClause = ifStatement.getElseClause();
    writeBodyStatement(ifStatement.getThenClause(), elseClause != null);

    if (elseClause != null) {
      scribe.print(ELSE);
      nextCompoundNoNewLine();
      writeBodyStatement(elseClause, false);
    }
  }
  @Override
  public boolean accept(ASTVisitor action) {
    N stack = null;
    ICPPASTIfStatement stmt = this;
    loop:
    for (; ; ) {
      if (action.shouldVisitStatements) {
        switch (action.visit(stmt)) {
          case ASTVisitor.PROCESS_ABORT:
            return false;
          case ASTVisitor.PROCESS_SKIP:
            stmt = null;
            break loop;
          default:
            break;
        }
      }

      if (!((CPPASTIfStatement) stmt).acceptByAttributeSpecifiers(action)) return false;

      IASTNode child = stmt.getConditionExpression();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getConditionDeclaration();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getThenClause();
      if (child != null && !child.accept(action)) return false;
      child = stmt.getElseClause();
      if (child instanceof ICPPASTIfStatement) {
        if (action.shouldVisitStatements) {
          N n = new N(stmt);
          n.fNext = stack;
          stack = n;
        }
        stmt = (ICPPASTIfStatement) child;
      } else {
        if (child != null && !child.accept(action)) return false;
        break loop;
      }
    }

    if (action.shouldVisitStatements) {
      if (stmt != null && action.leave(stmt) == ASTVisitor.PROCESS_ABORT) return false;
      while (stack != null) {
        if (action.leave(stack.fIfStatement) == ASTVisitor.PROCESS_ABORT) return false;
        stack = stack.fNext;
      }
    }
    return true;
  }