Program: 50103
Project: 50103
Buggy source:
/** 
 * Attempts to convert the given C++ statement to one or more Java statements.
 */
private List<Statement> evalStmt(IASTStatement statement) throws DOMException {
  List<Statement> ret=new ArrayList<Statement>();
  if (statement instanceof IASTBreakStatement) {
    print("String_Node_Str");
    int temp=findLastLoopId();
    if (m_localVariableId != -1) {
      Block blk=ast.newBlock();
      blk.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
      blk.statements().add(ast.newBreakStatement());
      ret.add(blk);
    }
 else     ret.add(ast.newBreakStatement());
  }
 else   if (statement instanceof IASTCaseStatement) {
    IASTCaseStatement caseStatement=(IASTCaseStatement)statement;
    print("String_Node_Str");
    SwitchCase cs=ast.newSwitchCase();
    cs.setExpression(eval1Expr(caseStatement.getExpression()));
    ret.add(cs);
  }
 else   if (statement instanceof IASTContinueStatement) {
    print("String_Node_Str");
    int temp=findLastLoopId();
    if (m_localVariableId != -1) {
      Block blk=ast.newBlock();
      blk.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
      blk.statements().add(ast.newContinueStatement());
      ret.add(blk);
    }
 else     ret.add(ast.newContinueStatement());
  }
 else   if (statement instanceof IASTDefaultStatement) {
    print("String_Node_Str");
    SwitchCase cs=ast.newSwitchCase();
    cs.setExpression(null);
    ret.add(cs);
  }
 else   if (statement instanceof IASTGotoStatement) {
    IASTGotoStatement gotoStatement=(IASTGotoStatement)statement;
    print("String_Node_Str");
    getSimpleName(gotoStatement.getName());
  }
 else   if (statement instanceof IASTNullStatement) {
    print("String_Node_Str");
    ret.add(ast.newEmptyStatement());
  }
 else   if (statement instanceof IASTProblemStatement) {
    IASTProblemStatement probStatement=(IASTProblemStatement)statement;
    print("String_Node_Str" + probStatement.getProblem().getMessageWithLocation());
  }
 else   if (statement instanceof IASTCompoundStatement) {
    IASTCompoundStatement compoundStatement=(IASTCompoundStatement)statement;
    print("String_Node_Str");
    m_localVariableStack.push(new StackVar(m_localVariableId,m_isLoop));
    m_isLoop=false;
    Block block=ast.newBlock();
    for (    IASTStatement childStatement : compoundStatement.getStatements())     block.statements().addAll(evalStmt(childStatement));
    block.statements().addAll(stmtQueue);
    stmtQueue.clear();
    int temp=m_localVariableStack.pop().id;
    if (!block.statements().isEmpty() && !(block.statements().get(block.statements().size() - 1) instanceof ReturnStatement) && m_localVariableId != -1) {
      block.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
    }
    m_localVariableId=temp;
    ret.add(block);
  }
 else   if (statement instanceof IASTDeclarationStatement) {
    IASTDeclarationStatement declarationStatement=(IASTDeclarationStatement)statement;
    print("String_Node_Str");
    List<VariableDeclarationFragment> frags=getDeclarationFragments(declarationStatement.getDeclaration());
    List<Type> types=evaluateDeclarationReturnTypes(declarationStatement.getDeclaration());
    for (int i=0; i < types.size(); i++) {
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(i));
      decl.setType(types.get(i));
      ret.add(decl);
    }
    ret.addAll(stmtQueue);
    stmtQueue.clear();
  }
 else   if (statement instanceof IASTDoStatement) {
    IASTDoStatement doStatement=(IASTDoStatement)statement;
    print("String_Node_Str");
    DoStatement dos=ast.newDoStatement();
    m_isLoop=true;
    dos.setBody(eval1Stmt(doStatement.getBody()));
    m_isLoop=false;
    dos.setExpression(evalExpr(doStatement.getCondition(),TypeEnum.BOOLEAN).get(0));
    ret.add(dos);
  }
 else   if (statement instanceof IASTExpressionStatement) {
    IASTExpressionStatement expressionStatement=(IASTExpressionStatement)statement;
    print("String_Node_Str");
    ret.add(ast.newExpressionStatement(eval1Expr(expressionStatement.getExpression())));
  }
 else   if (statement instanceof IASTForStatement) {
    IASTForStatement forStatement=(IASTForStatement)statement;
    print("String_Node_Str");
    if (forStatement instanceof ICPPASTForStatement)     ;
    ForStatement fs=ast.newForStatement();
    List<Expression> inits=evaluateForInitializer(forStatement.getInitializerStatement());
    Expression expr=evalExpr(forStatement.getConditionExpression(),TypeEnum.BOOLEAN).get(0);
    List<Expression> updaters=evalExpr(forStatement.getIterationExpression());
    if (inits != null)     fs.initializers().addAll(inits);
    if (expr != null)     fs.setExpression(expr);
    if (updaters.get(0) != null)     fs.updaters().addAll(updaters);
    m_isLoop=true;
    fs.setBody(eval1Stmt(forStatement.getBody()));
    m_isLoop=false;
    ret.add(fs);
  }
 else   if (statement instanceof IASTIfStatement) {
    IASTIfStatement ifStatement=(IASTIfStatement)statement;
    print("String_Node_Str");
    IfStatement ifs=ast.newIfStatement();
    if (ifStatement instanceof ICPPASTIfStatement && ((ICPPASTIfStatement)ifStatement).getConditionDeclaration() != null) {
      ICPPASTIfStatement cppIf=(ICPPASTIfStatement)ifStatement;
      List<VariableDeclarationFragment> frags=getDeclarationFragments(cppIf.getConditionDeclaration());
      frags.get(0).setInitializer(null);
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(0));
      Type jType=evaluateDeclarationReturnTypes(cppIf.getConditionDeclaration()).get(0);
      decl.setType(jType);
      ret.add(decl);
      List<Expression> exprs=evaluateDeclarationReturnInitializers(cppIf.getConditionDeclaration());
      Assignment assign=jast.newAssign().left(ast.newSimpleName(frags.get(0).getName().getIdentifier())).right(exprs.get(0)).op(Assignment.Operator.ASSIGN).toAST();
      IASTExpression expr=evalDeclarationReturnFirstInitializerExpression(cppIf.getConditionDeclaration());
      Expression finalExpr=makeExpressionBoolean(assign,expr);
      ifs.setExpression(finalExpr);
    }
 else {
      ifs.setExpression(evalExpr(ifStatement.getConditionExpression(),TypeEnum.BOOLEAN).get(0));
    }
    ifs.setThenStatement(eval1Stmt(ifStatement.getThenClause()));
    List<Statement> elseStmts=evalStmt(ifStatement.getElseClause());
    ifs.setElseStatement(!elseStmts.isEmpty() ? elseStmts.get(0) : null);
    ret.add(ifs);
  }
 else   if (statement instanceof IASTLabelStatement) {
    IASTLabelStatement labelStatement=(IASTLabelStatement)statement;
    print("String_Node_Str");
    evalStmt(labelStatement.getNestedStatement());
  }
 else   if (statement instanceof IASTReturnStatement) {
    IASTReturnStatement returnStatement=(IASTReturnStatement)statement;
    print("String_Node_Str");
    JASTHelper.Method method=jast.newMethod().on("String_Node_Str").call("String_Node_Str");
    ReturnStatement ret2=ast.newReturnStatement();
    if (returnStatement.getReturnValue() != null) {
      if (returnStatement.getReturnValue() != null && ((returnStatement.getReturnValue().getExpressionType() instanceof ICompositeType || (returnStatement.getReturnValue().getExpressionType() instanceof IQualifierType && ((IQualifierType)returnStatement.getReturnValue().getExpressionType()).getType() instanceof ICompositeType)) && !(eval1Expr(returnStatement.getReturnValue()) instanceof ClassInstanceCreation))) {
        ClassInstanceCreation create=jast.newClassCreate().type(cppToJavaType(returnStatement.getReturnValue().getExpressionType())).with(eval1Expr(returnStatement.getReturnValue())).toAST();
        if (m_localVariableId != -1)         method.with(create);
 else         ret2.setExpression(create);
      }
 else {
        if (m_localVariableId != -1)         method.with(eval1Expr(returnStatement.getReturnValue()));
 else         ret2.setExpression(eval1Expr(returnStatement.getReturnValue()));
      }
      if (m_localVariableId != -1) {
        method.with("String_Node_Str").with(0);
        ret2.setExpression(method.toAST());
      }
      ret.add(ret2);
    }
 else {
      if (m_localVariableId != -1) {
        Block blk=ast.newBlock();
        method.with(ast.newNullLiteral()).with("String_Node_Str").with(0);
        blk.statements().add(ast.newExpressionStatement(method.toAST()));
        blk.statements().add(ret2);
        ret.add(blk);
      }
 else       ret.add(ret2);
    }
  }
 else   if (statement instanceof IASTSwitchStatement) {
    IASTSwitchStatement switchStatement=(IASTSwitchStatement)statement;
    print("String_Node_Str");
    SwitchStatement swt=ast.newSwitchStatement();
    if (switchStatement instanceof ICPPASTSwitchStatement && ((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration() != null) {
      ICPPASTSwitchStatement cppSwitch=(ICPPASTSwitchStatement)switchStatement;
      List<VariableDeclarationFragment> frags=getDeclarationFragments(cppSwitch.getControllerDeclaration());
      frags.get(0).setInitializer(null);
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(0));
      Type jType=evaluateDeclarationReturnTypes(cppSwitch.getControllerDeclaration()).get(0);
      decl.setType(jType);
      ret.add(decl);
      List<Expression> exprs=evaluateDeclarationReturnInitializers(cppSwitch.getControllerDeclaration());
      Assignment assign=jast.newAssign().left(ast.newSimpleName(frags.get(0).getName().getIdentifier())).right(exprs.get(0)).op(Assignment.Operator.ASSIGN).toAST();
      swt.setExpression(assign);
    }
 else {
      swt.setExpression(evalExpr(switchStatement.getControllerExpression()).get(0));
    }
    if (switchStatement.getBody() instanceof IASTCompoundStatement) {
      IASTCompoundStatement compound=(IASTCompoundStatement)switchStatement.getBody();
      for (      IASTStatement stmt : compound.getStatements()) {
        swt.statements().addAll(evalStmt(stmt));
      }
    }
 else {
      swt.statements().addAll(evalStmt(switchStatement.getBody()));
    }
    ret.add(swt);
  }
 else   if (statement instanceof IASTWhileStatement) {
    IASTWhileStatement whileStatement=(IASTWhileStatement)statement;
    print("String_Node_Str");
    WhileStatement whs=ast.newWhileStatement();
    if (whileStatement instanceof ICPPASTWhileStatement && ((ICPPASTWhileStatement)whileStatement).getConditionDeclaration() != null) {
      ICPPASTWhileStatement cppWhile=(ICPPASTWhileStatement)whileStatement;
      List<VariableDeclarationFragment> frags=getDeclarationFragments(cppWhile.getConditionDeclaration());
      frags.get(0).setInitializer(null);
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(0));
      Type jType=evaluateDeclarationReturnTypes(cppWhile.getConditionDeclaration()).get(0);
      decl.setType(jType);
      ret.add(decl);
      List<Expression> exprs=evaluateDeclarationReturnInitializers(cppWhile.getConditionDeclaration());
      Assignment assign=jast.newAssign().left(ast.newSimpleName(frags.get(0).getName().getIdentifier())).right(exprs.get(0)).op(Assignment.Operator.ASSIGN).toAST();
      IASTExpression expr=evalDeclarationReturnFirstInitializerExpression(cppWhile.getConditionDeclaration());
      Expression finalExpr=makeExpressionBoolean(assign,expr);
      whs.setExpression(finalExpr);
    }
 else {
      whs.setExpression(evalExpr(whileStatement.getCondition(),TypeEnum.BOOLEAN).get(0));
    }
    whs.setBody(evalStmt(whileStatement.getBody()).get(0));
    ret.add(whs);
  }
 else   if (statement instanceof ICPPASTTryBlockStatement) {
    ICPPASTTryBlockStatement tryBlockStatement=(ICPPASTTryBlockStatement)statement;
    print("String_Node_Str");
    TryStatement trys=ast.newTryStatement();
    trys.setBody((Block)evalStmt(tryBlockStatement.getTryBody()));
    for (    ICPPASTCatchHandler catchHandler : tryBlockStatement.getCatchHandlers())     trys.catchClauses().add(evaluateCatchClause(catchHandler));
    ret.add(trys);
  }
 else   if (statement != null) {
    printerr(statement.getClass().getCanonicalName());
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Attempts to convert the given C++ statement to one or more Java statements.
 */
private List<Statement> evalStmt(IASTStatement statement) throws DOMException {
  List<Statement> ret=new ArrayList<Statement>();
  if (statement instanceof IASTBreakStatement) {
    print("String_Node_Str");
    int temp=findLastLoopId();
    if (temp != -1) {
      Block blk=ast.newBlock();
      blk.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
      blk.statements().add(ast.newBreakStatement());
      ret.add(blk);
    }
 else     ret.add(ast.newBreakStatement());
  }
 else   if (statement instanceof IASTCaseStatement) {
    IASTCaseStatement caseStatement=(IASTCaseStatement)statement;
    print("String_Node_Str");
    SwitchCase cs=ast.newSwitchCase();
    cs.setExpression(eval1Expr(caseStatement.getExpression()));
    ret.add(cs);
  }
 else   if (statement instanceof IASTContinueStatement) {
    print("String_Node_Str");
    int temp=findLastLoopId();
    if (temp != -1) {
      Block blk=ast.newBlock();
      blk.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
      blk.statements().add(ast.newContinueStatement());
      ret.add(blk);
    }
 else     ret.add(ast.newContinueStatement());
  }
 else   if (statement instanceof IASTDefaultStatement) {
    print("String_Node_Str");
    SwitchCase cs=ast.newSwitchCase();
    cs.setExpression(null);
    ret.add(cs);
  }
 else   if (statement instanceof IASTGotoStatement) {
    IASTGotoStatement gotoStatement=(IASTGotoStatement)statement;
    print("String_Node_Str");
    getSimpleName(gotoStatement.getName());
  }
 else   if (statement instanceof IASTNullStatement) {
    print("String_Node_Str");
    ret.add(ast.newEmptyStatement());
  }
 else   if (statement instanceof IASTProblemStatement) {
    IASTProblemStatement probStatement=(IASTProblemStatement)statement;
    print("String_Node_Str" + probStatement.getProblem().getMessageWithLocation());
  }
 else   if (statement instanceof IASTCompoundStatement) {
    IASTCompoundStatement compoundStatement=(IASTCompoundStatement)statement;
    print("String_Node_Str");
    int temp=m_localVariableId;
    m_localVariableStack.push(new StackVar(m_localVariableId,m_isLoop));
    m_isLoop=false;
    Block block=ast.newBlock();
    for (    IASTStatement childStatement : compoundStatement.getStatements())     block.statements().addAll(evalStmt(childStatement));
    block.statements().addAll(stmtQueue);
    stmtQueue.clear();
    if (m_localVariableId != -1 && !block.statements().isEmpty() && !(block.statements().get(block.statements().size() - 1) instanceof ReturnStatement) && !(block.statements().get(block.statements().size() - 1) instanceof BreakStatement) && !(block.statements().get(block.statements().size() - 1) instanceof ContinueStatement)) {
      block.statements().add(ast.newExpressionStatement(createCleanupCall(temp + 1)));
    }
    m_localVariableId=temp;
    ret.add(block);
  }
 else   if (statement instanceof IASTDeclarationStatement) {
    IASTDeclarationStatement declarationStatement=(IASTDeclarationStatement)statement;
    print("String_Node_Str");
    List<VariableDeclarationFragment> frags=getDeclarationFragments(declarationStatement.getDeclaration());
    List<Type> types=evaluateDeclarationReturnTypes(declarationStatement.getDeclaration());
    for (int i=0; i < types.size(); i++) {
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(i));
      decl.setType(types.get(i));
      ret.add(decl);
    }
    ret.addAll(stmtQueue);
    stmtQueue.clear();
  }
 else   if (statement instanceof IASTDoStatement) {
    IASTDoStatement doStatement=(IASTDoStatement)statement;
    print("String_Node_Str");
    DoStatement dos=ast.newDoStatement();
    m_isLoop=true;
    dos.setBody(eval1Stmt(doStatement.getBody()));
    dos.setExpression(eval1Expr(doStatement.getCondition(),TypeEnum.BOOLEAN));
    ret.add(dos);
  }
 else   if (statement instanceof IASTExpressionStatement) {
    IASTExpressionStatement expressionStatement=(IASTExpressionStatement)statement;
    print("String_Node_Str");
    ret.add(ast.newExpressionStatement(eval1Expr(expressionStatement.getExpression())));
  }
 else   if (statement instanceof IASTForStatement) {
    IASTForStatement forStatement=(IASTForStatement)statement;
    print("String_Node_Str");
    if (forStatement instanceof ICPPASTForStatement)     ;
    ForStatement fs=ast.newForStatement();
    List<Expression> inits=evaluateForInitializer(forStatement.getInitializerStatement());
    Expression expr=eval1Expr(forStatement.getConditionExpression(),TypeEnum.BOOLEAN);
    List<Expression> updaters=evalExpr(forStatement.getIterationExpression());
    if (inits != null)     fs.initializers().addAll(inits);
    if (expr != null)     fs.setExpression(expr);
    if (updaters.get(0) != null)     fs.updaters().addAll(updaters);
    m_isLoop=true;
    fs.setBody(eval1Stmt(forStatement.getBody()));
    ret.add(fs);
  }
 else   if (statement instanceof IASTIfStatement) {
    IASTIfStatement ifStatement=(IASTIfStatement)statement;
    print("String_Node_Str");
    IfStatement ifs=ast.newIfStatement();
    if (ifStatement instanceof ICPPASTIfStatement && ((ICPPASTIfStatement)ifStatement).getConditionDeclaration() != null) {
      ifs.setExpression(generateDeclarationForWhileIf(((ICPPASTIfStatement)ifStatement).getConditionDeclaration(),ret));
    }
 else {
      ifs.setExpression(eval1Expr(ifStatement.getConditionExpression(),TypeEnum.BOOLEAN));
    }
    ifs.setThenStatement(eval1Stmt(ifStatement.getThenClause()));
    List<Statement> elseStmts=evalStmt(ifStatement.getElseClause());
    ifs.setElseStatement(!elseStmts.isEmpty() ? elseStmts.get(0) : null);
    ret.add(ifs);
  }
 else   if (statement instanceof IASTLabelStatement) {
    IASTLabelStatement labelStatement=(IASTLabelStatement)statement;
    print("String_Node_Str");
    evalStmt(labelStatement.getNestedStatement());
  }
 else   if (statement instanceof IASTReturnStatement) {
    IASTReturnStatement returnStatement=(IASTReturnStatement)statement;
    print("String_Node_Str");
    JASTHelper.Method method=jast.newMethod().on("String_Node_Str").call("String_Node_Str");
    ReturnStatement ret2=ast.newReturnStatement();
    if (returnStatement.getReturnValue() != null) {
      if (((returnStatement.getReturnValue().getExpressionType() instanceof ICompositeType || (returnStatement.getReturnValue().getExpressionType() instanceof IQualifierType && ((IQualifierType)returnStatement.getReturnValue().getExpressionType()).getType() instanceof ICompositeType)) && !(eval1Expr(returnStatement.getReturnValue()) instanceof ClassInstanceCreation))) {
        ClassInstanceCreation create=jast.newClassCreate().type(cppToJavaType(returnStatement.getReturnValue().getExpressionType())).with(eval1Expr(returnStatement.getReturnValue())).toAST();
        if (m_localVariableId != -1)         method.with(create);
 else         ret2.setExpression(create);
      }
 else {
        if (m_localVariableId != -1)         method.with(eval1Expr(returnStatement.getReturnValue()));
 else         ret2.setExpression(eval1Expr(returnStatement.getReturnValue()));
      }
      if (m_localVariableId != -1) {
        method.with("String_Node_Str").with(0);
        ret2.setExpression(method.toAST());
      }
      ret.add(ret2);
    }
 else {
      if (m_localVariableId != -1) {
        Block blk=ast.newBlock();
        method.with(ast.newNullLiteral()).with("String_Node_Str").with(0);
        blk.statements().add(ast.newExpressionStatement(method.toAST()));
        blk.statements().add(ret2);
        ret.add(blk);
      }
 else       ret.add(ret2);
    }
  }
 else   if (statement instanceof IASTSwitchStatement) {
    IASTSwitchStatement switchStatement=(IASTSwitchStatement)statement;
    print("String_Node_Str");
    SwitchStatement swt=ast.newSwitchStatement();
    if (switchStatement instanceof ICPPASTSwitchStatement && ((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration() != null) {
      ICPPASTSwitchStatement cppSwitch=(ICPPASTSwitchStatement)switchStatement;
      List<VariableDeclarationFragment> frags=getDeclarationFragments(cppSwitch.getControllerDeclaration());
      frags.get(0).setInitializer(null);
      VariableDeclarationStatement decl=ast.newVariableDeclarationStatement(frags.get(0));
      Type jType=evaluateDeclarationReturnTypes(cppSwitch.getControllerDeclaration()).get(0);
      decl.setType(jType);
      ret.add(decl);
      List<Expression> exprs=evaluateDeclarationReturnInitializers(cppSwitch.getControllerDeclaration());
      Assignment assign=jast.newAssign().left(ast.newSimpleName(frags.get(0).getName().getIdentifier())).right(exprs.get(0)).op(Assignment.Operator.ASSIGN).toAST();
      swt.setExpression(assign);
    }
 else {
      swt.setExpression(evalExpr(switchStatement.getControllerExpression()).get(0));
    }
    if (switchStatement.getBody() instanceof IASTCompoundStatement) {
      IASTCompoundStatement compound=(IASTCompoundStatement)switchStatement.getBody();
      for (      IASTStatement stmt : compound.getStatements())       swt.statements().addAll(evalStmt(stmt));
    }
 else {
      swt.statements().addAll(evalStmt(switchStatement.getBody()));
    }
    ret.add(swt);
  }
 else   if (statement instanceof IASTWhileStatement) {
    IASTWhileStatement whileStatement=(IASTWhileStatement)statement;
    print("String_Node_Str");
    WhileStatement whs=ast.newWhileStatement();
    if (whileStatement instanceof ICPPASTWhileStatement && ((ICPPASTWhileStatement)whileStatement).getConditionDeclaration() != null) {
      whs.setExpression(generateDeclarationForWhileIf(((ICPPASTWhileStatement)whileStatement).getConditionDeclaration(),ret));
    }
 else {
      whs.setExpression(eval1Expr(whileStatement.getCondition(),TypeEnum.BOOLEAN));
    }
    whs.setBody(eval1Stmt(whileStatement.getBody()));
    ret.add(whs);
  }
 else   if (statement instanceof ICPPASTTryBlockStatement) {
    ICPPASTTryBlockStatement tryBlockStatement=(ICPPASTTryBlockStatement)statement;
    print("String_Node_Str");
    TryStatement trys=ast.newTryStatement();
    trys.setBody((Block)evalStmt(tryBlockStatement.getTryBody()));
    for (    ICPPASTCatchHandler catchHandler : tryBlockStatement.getCatchHandlers())     trys.catchClauses().add(evaluateCatchClause(catchHandler));
    ret.add(trys);
  }
 else   if (statement != null) {
    printerr(statement.getClass().getCanonicalName());
  }
  return ret;
}