Program: 50098
Project: 50098
Buggy source:
/** 
 * Attempts to convert the given C++ statement to one or more Java statements.
 */
List<MStmt> evalStmt(IASTStatement statement) throws DOMException {
  List<MStmt> stmts=new ArrayList<MStmt>();
  if (statement instanceof IASTBreakStatement) {
    MyLogger.log("String_Node_Str");
    Integer temp=ctx.stackMngr.findLastSwitchOrLoopId();
    MBreakStmt brk=new MBreakStmt();
    stmts.add(brk);
    if (temp != null)     brk.cleanup=ctx.stackMngr.createCleanupCall(temp);
  }
 else   if (statement instanceof IASTCaseStatement) {
    MyLogger.log("String_Node_Str");
    IASTCaseStatement caseStatement=(IASTCaseStatement)statement;
    MCaseStmt cs=new MCaseStmt();
    stmts.add(cs);
    cs.expr=ctx.exprEvaluator.eval1Expr(caseStatement.getExpression());
  }
 else   if (statement instanceof IASTContinueStatement) {
    MyLogger.log("String_Node_Str");
    Integer temp=ctx.stackMngr.findLastLoopId();
    MContinueStmt con=new MContinueStmt();
    stmts.add(con);
    if (temp != null)     con.cleanup=ctx.stackMngr.createCleanupCall(temp);
  }
 else   if (statement instanceof IASTDefaultStatement) {
    MyLogger.log("String_Node_Str");
    MDefaultStmt def=new MDefaultStmt();
    stmts.add(def);
  }
 else   if (statement instanceof IASTGotoStatement) {
    MyLogger.log("String_Node_Str");
    IASTGotoStatement gotoStatement=(IASTGotoStatement)statement;
    MGotoStmt go=new MGotoStmt();
    stmts.add(go);
    go.lbl=gotoStatement.getName().toString();
  }
 else   if (statement instanceof IASTNullStatement) {
    MyLogger.log("String_Node_Str");
    MEmptyStmt empty=new MEmptyStmt();
    stmts.add(empty);
  }
 else   if (statement instanceof IASTProblemStatement) {
    IASTProblemStatement probStatement=(IASTProblemStatement)statement;
    MyLogger.log("String_Node_Str" + probStatement.getProblem().getMessageWithLocation());
    MProblemStmt prob=new MProblemStmt();
    stmts.add(prob);
    prob.problem=probStatement.getProblem().getMessageWithLocation();
  }
 else   if (statement instanceof IASTCompoundStatement) {
    IASTCompoundStatement compoundStatement=(IASTCompoundStatement)statement;
    MyLogger.log("String_Node_Str");
    ctx.stackMngr.startNewCompoundStmt(false,false);
    MCompoundStmt compound=new MCompoundStmt();
    stmts.add(compound);
    for (    IASTStatement s : compoundStatement.getStatements())     compound.statements.add(eval1Stmt(s));
    Integer idToCleanTo=ctx.stackMngr.endCompoundStmt();
    if (idToCleanTo != null && !compound.statements.isEmpty() && !isTerminatingStatement(compound.statements.get(compound.statements.size() - 1))) {
      compound.cleanup=ctx.stackMngr.createCleanupCall(idToCleanTo);
    }
  }
 else   if (statement instanceof IASTDeclarationStatement) {
    IASTDeclarationStatement declarationStatement=(IASTDeclarationStatement)statement;
    MyLogger.log("String_Node_Str");
    List<String> types=ctx.converter.evaluateDeclarationReturnTypes(declarationStatement.getDeclaration());
    List<String> names=ctx.converter.evaluateDeclarationReturnNames(declarationStatement.getDeclaration());
    List<MExpression> exprs=ctx.converter.evaluateDeclarationReturnInitializers((IASTSimpleDeclaration)declarationStatement.getDeclaration());
    for (int i=0; i < types.size(); i++) {
      MSimpleDecl simple=new MSimpleDecl();
      simple.type=types.get(i);
      simple.name=names.get(i);
      simple.initExpr=exprs.get(i);
      MDeclarationStmt stmt=new MDeclarationStmt();
      stmt.simple=simple;
      stmts.add(stmt);
    }
  }
 else   if (statement instanceof IASTDoStatement) {
    MyLogger.log("String_Node_Str");
    IASTDoStatement doStatement=(IASTDoStatement)statement;
    MDoStmt dos=new MDoStmt();
    stmts.add(dos);
    dos.body=surround(evalStmt(doStatement.getBody()));
    dos.expr=ctx.exprEvaluator.eval1Expr(doStatement.getCondition());
    dos.expr=ExpressionHelpers.makeExpressionBoolean(dos.expr,doStatement.getCondition());
  }
 else   if (statement instanceof IASTExpressionStatement) {
    MyLogger.log("String_Node_Str");
    IASTExpressionStatement expressionStatement=(IASTExpressionStatement)statement;
    MExprStmt exprStmt=new MExprStmt();
    stmts.add(exprStmt);
    exprStmt.expr=ctx.exprEvaluator.eval1Expr(expressionStatement.getExpression());
  }
 else   if (statement instanceof IASTForStatement) {
    MyLogger.log("String_Node_Str");
    IASTForStatement forStatement=(IASTForStatement)statement;
    MForStmt fs=new MForStmt();
    stmts.add(fs);
    if (forStatement.getInitializerStatement() != null)     fs.initializer=eval1Stmt(forStatement.getInitializerStatement());
    if (forStatement.getConditionExpression() != null) {
      fs.condition=ctx.exprEvaluator.eval1Expr(forStatement.getConditionExpression());
      fs.condition=ExpressionHelpers.makeExpressionBoolean(fs.condition,forStatement.getConditionExpression());
    }
    if (forStatement.getIterationExpression() != null)     fs.updater=ctx.exprEvaluator.eval1Expr(forStatement.getIterationExpression());
    fs.body=surround(evalStmt(forStatement.getBody()));
    if (forStatement instanceof ICPPASTForStatement && ((ICPPASTForStatement)forStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTForStatement)forStatement).getConditionDeclaration());
      fs.decl=ctx.converter.eval1Decl(((ICPPASTForStatement)forStatement).getConditionDeclaration());
      fs.condition=ctx.converter.makeInfixFromDecl(fs.decl.name,fs.decl.initExpr,tp,true);
      fs.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTIfStatement) {
    MyLogger.log("String_Node_Str");
    IASTIfStatement ifStatement=(IASTIfStatement)statement;
    MIfStmt ifs=new MIfStmt();
    stmts.add(ifs);
    ifs.condition=ctx.exprEvaluator.eval1Expr(ifStatement.getConditionExpression());
    ifs.condition=ExpressionHelpers.makeExpressionBoolean(ifs.condition,ifStatement.getConditionExpression());
    ifs.body=surround(evalStmt(ifStatement.getThenClause()));
    if (ifStatement.getElseClause() != null)     ifs.elseBody=eval1Stmt(ifStatement.getElseClause());
    if (ifStatement instanceof ICPPASTIfStatement && ((ICPPASTIfStatement)ifStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTIfStatement)ifStatement).getConditionDeclaration());
      ifs.decl=ctx.converter.eval1Decl(((ICPPASTIfStatement)ifStatement).getConditionDeclaration());
      ifs.condition=ctx.converter.makeInfixFromDecl(ifs.decl.name,ifs.decl.initExpr,tp,true);
      ifs.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTLabelStatement) {
    MyLogger.log("String_Node_Str");
    IASTLabelStatement labelStatement=(IASTLabelStatement)statement;
    MLabelStmt lbl=new MLabelStmt();
    stmts.add(lbl);
    lbl.lbl=labelStatement.getName().toString();
    lbl.body=eval1Stmt(labelStatement.getNestedStatement());
  }
 else   if (statement instanceof IASTReturnStatement) {
    MyLogger.log("String_Node_Str");
    IASTReturnStatement returnStatement=(IASTReturnStatement)statement;
    MReturnStmt retu=new MReturnStmt();
    stmts.add(retu);
    if (ExpressionHelpers.isNumberExpression(returnStatement.getReturnValue())) {
      MValueOfExpressionNumber valOfExpr=new MValueOfExpressionNumber();
      valOfExpr.type="String_Node_Str";
      valOfExpr.operand=ctx.exprEvaluator.eval1Expr(returnStatement.getReturnValue());
      retu.expr=valOfExpr;
    }
 else {
      retu.expr=ctx.exprEvaluator.eval1Expr(returnStatement.getReturnValue());
      retu.expr=ctx.converter.callCopyIfNeeded(retu.expr,returnStatement.getReturnValue());
    }
    if (ctx.stackMngr.getLocalVariableId() != 0)     retu.cleanup=ctx.stackMngr.createCleanupCall(0);
  }
 else   if (statement instanceof IASTSwitchStatement) {
    MyLogger.log("String_Node_Str");
    IASTSwitchStatement switchStatement=(IASTSwitchStatement)statement;
    MSwitchStmt swi=new MSwitchStmt();
    stmts.add(swi);
    swi.body=surround(evalStmt(switchStatement.getBody()));
    swi.expr=ctx.exprEvaluator.eval1Expr(switchStatement.getControllerExpression());
    if (switchStatement instanceof ICPPASTSwitchStatement && ((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration());
      swi.decl=ctx.converter.eval1Decl(((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration());
      swi.expr=ctx.converter.makeInfixFromDecl(swi.decl.name,swi.decl.initExpr,tp,false);
      swi.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTWhileStatement) {
    MyLogger.log("String_Node_Str");
    IASTWhileStatement whileStatement=(IASTWhileStatement)statement;
    MWhileStmt whi=new MWhileStmt();
    stmts.add(whi);
    whi.body=surround(evalStmt(whileStatement.getBody()));
    whi.expr=ctx.exprEvaluator.eval1Expr(whileStatement.getCondition());
    whi.expr=ExpressionHelpers.makeExpressionBoolean(whi.expr,whileStatement.getCondition());
    if (whileStatement instanceof ICPPASTWhileStatement && ((ICPPASTWhileStatement)whileStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTWhileStatement)whileStatement).getConditionDeclaration());
      whi.decl=ctx.converter.eval1Decl(((ICPPASTWhileStatement)whileStatement).getConditionDeclaration());
      whi.expr=ctx.converter.makeInfixFromDecl(whi.decl.name,whi.decl.initExpr,tp,true);
      whi.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof ICPPASTTryBlockStatement) {
  }
 else   if (statement != null) {
    MyLogger.logImportant(statement.getClass().getCanonicalName());
  }
  if (stmts.isEmpty())   stmts.add(new MEmptyStmt());
  return stmts;
}

Fixed version (ground truth):
/** 
 * Attempts to convert the given C++ statement to one or more Java statements.
 */
List<MStmt> evalStmt(IASTStatement statement) throws DOMException {
  List<MStmt> stmts=new ArrayList<MStmt>();
  if (statement instanceof IASTBreakStatement) {
    MyLogger.log("String_Node_Str");
    Integer temp=ctx.stackMngr.findLastSwitchOrLoopId();
    MBreakStmt brk=new MBreakStmt();
    stmts.add(brk);
    if (temp != null)     brk.cleanup=ctx.stackMngr.createCleanupCall(temp);
  }
 else   if (statement instanceof IASTCaseStatement) {
    MyLogger.log("String_Node_Str");
    IASTCaseStatement caseStatement=(IASTCaseStatement)statement;
    MCaseStmt cs=new MCaseStmt();
    stmts.add(cs);
    cs.expr=ctx.exprEvaluator.eval1Expr(caseStatement.getExpression());
  }
 else   if (statement instanceof IASTContinueStatement) {
    MyLogger.log("String_Node_Str");
    Integer temp=ctx.stackMngr.findLastLoopId();
    MContinueStmt con=new MContinueStmt();
    stmts.add(con);
    if (temp != null)     con.cleanup=ctx.stackMngr.createCleanupCall(temp);
  }
 else   if (statement instanceof IASTDefaultStatement) {
    MyLogger.log("String_Node_Str");
    MDefaultStmt def=new MDefaultStmt();
    stmts.add(def);
  }
 else   if (statement instanceof IASTGotoStatement) {
    MyLogger.log("String_Node_Str");
    IASTGotoStatement gotoStatement=(IASTGotoStatement)statement;
    MGotoStmt go=new MGotoStmt();
    stmts.add(go);
    go.lbl=gotoStatement.getName().toString();
  }
 else   if (statement instanceof IASTNullStatement) {
    MyLogger.log("String_Node_Str");
    MEmptyStmt empty=new MEmptyStmt();
    stmts.add(empty);
  }
 else   if (statement instanceof IASTProblemStatement) {
    IASTProblemStatement probStatement=(IASTProblemStatement)statement;
    MyLogger.log("String_Node_Str" + probStatement.getProblem().getMessageWithLocation());
    MProblemStmt prob=new MProblemStmt();
    stmts.add(prob);
    prob.problem=probStatement.getProblem().getMessageWithLocation();
  }
 else   if (statement instanceof IASTCompoundStatement) {
    IASTCompoundStatement compoundStatement=(IASTCompoundStatement)statement;
    MyLogger.log("String_Node_Str");
    ctx.stackMngr.startNewCompoundStmt(false,false);
    MCompoundStmt compound=new MCompoundStmt();
    stmts.add(compound);
    for (    IASTStatement s : compoundStatement.getStatements())     compound.statements.add(eval1Stmt(s));
    Integer idToCleanTo=ctx.stackMngr.endCompoundStmt();
    if (idToCleanTo != null && !compound.statements.isEmpty() && !isTerminatingStatement(compound.statements.get(compound.statements.size() - 1))) {
      compound.cleanup=ctx.stackMngr.createCleanupCall(idToCleanTo);
    }
  }
 else   if (statement instanceof IASTDeclarationStatement) {
    IASTDeclarationStatement declarationStatement=(IASTDeclarationStatement)statement;
    MyLogger.log("String_Node_Str");
    List<String> types=ctx.converter.evaluateDeclarationReturnTypes(declarationStatement.getDeclaration());
    List<String> names=ctx.converter.evaluateDeclarationReturnNames(declarationStatement.getDeclaration());
    List<MExpression> exprs=ctx.converter.evaluateDeclarationReturnInitializers((IASTSimpleDeclaration)declarationStatement.getDeclaration());
    for (int i=0; i < types.size(); i++) {
      MSimpleDecl simple=new MSimpleDecl();
      simple.type=types.get(i);
      simple.name=names.get(i);
      simple.initExpr=exprs.get(i);
      MDeclarationStmt stmt=new MDeclarationStmt();
      stmt.simple=simple;
      stmts.add(stmt);
    }
  }
 else   if (statement instanceof IASTDoStatement) {
    MyLogger.log("String_Node_Str");
    IASTDoStatement doStatement=(IASTDoStatement)statement;
    MDoStmt dos=new MDoStmt();
    stmts.add(dos);
    dos.body=surround(evalStmt(doStatement.getBody()));
    dos.expr=ctx.exprEvaluator.eval1Expr(doStatement.getCondition());
    dos.expr=ExpressionHelpers.makeExpressionBoolean(dos.expr,doStatement.getCondition());
  }
 else   if (statement instanceof IASTExpressionStatement) {
    MyLogger.log("String_Node_Str");
    IASTExpressionStatement expressionStatement=(IASTExpressionStatement)statement;
    MExprStmt exprStmt=new MExprStmt();
    stmts.add(exprStmt);
    exprStmt.expr=ctx.exprEvaluator.eval1Expr(expressionStatement.getExpression());
  }
 else   if (statement instanceof IASTForStatement) {
    MyLogger.log("String_Node_Str");
    IASTForStatement forStatement=(IASTForStatement)statement;
    MForStmt fs=new MForStmt();
    stmts.add(fs);
    if (forStatement.getInitializerStatement() != null)     fs.initializer=eval1Stmt(forStatement.getInitializerStatement());
    if (forStatement.getConditionExpression() != null) {
      fs.condition=ctx.exprEvaluator.eval1Expr(forStatement.getConditionExpression());
      fs.condition=ExpressionHelpers.makeExpressionBoolean(fs.condition,forStatement.getConditionExpression());
    }
    if (forStatement.getIterationExpression() != null)     fs.updater=ctx.exprEvaluator.eval1Expr(forStatement.getIterationExpression());
    fs.body=surround(evalStmt(forStatement.getBody()));
    if (forStatement instanceof ICPPASTForStatement && ((ICPPASTForStatement)forStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTForStatement)forStatement).getConditionDeclaration());
      fs.decl=ctx.converter.eval1Decl(((ICPPASTForStatement)forStatement).getConditionDeclaration());
      fs.condition=ctx.converter.makeInfixFromDecl(fs.decl.name,fs.decl.initExpr,tp,true);
      fs.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTIfStatement) {
    MyLogger.log("String_Node_Str");
    IASTIfStatement ifStatement=(IASTIfStatement)statement;
    MIfStmt ifs=new MIfStmt();
    stmts.add(ifs);
    if (ifStatement.getConditionExpression() != null) {
      ifs.condition=ctx.exprEvaluator.eval1Expr(ifStatement.getConditionExpression());
      ifs.condition=ExpressionHelpers.makeExpressionBoolean(ifs.condition,ifStatement.getConditionExpression());
    }
    ifs.body=surround(evalStmt(ifStatement.getThenClause()));
    if (ifStatement.getElseClause() != null)     ifs.elseBody=eval1Stmt(ifStatement.getElseClause());
    if (ifStatement instanceof ICPPASTIfStatement && ((ICPPASTIfStatement)ifStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTIfStatement)ifStatement).getConditionDeclaration());
      ifs.decl=ctx.converter.eval1Decl(((ICPPASTIfStatement)ifStatement).getConditionDeclaration());
      ifs.condition=ctx.converter.makeInfixFromDecl(ifs.decl.name,ifs.decl.initExpr,tp,true);
      ifs.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTLabelStatement) {
    MyLogger.log("String_Node_Str");
    IASTLabelStatement labelStatement=(IASTLabelStatement)statement;
    MLabelStmt lbl=new MLabelStmt();
    stmts.add(lbl);
    lbl.lbl=labelStatement.getName().toString();
    lbl.body=eval1Stmt(labelStatement.getNestedStatement());
  }
 else   if (statement instanceof IASTReturnStatement) {
    MyLogger.log("String_Node_Str");
    IASTReturnStatement returnStatement=(IASTReturnStatement)statement;
    MReturnStmt retu=new MReturnStmt();
    stmts.add(retu);
    if (ExpressionHelpers.isNumberExpression(returnStatement.getReturnValue())) {
      MValueOfExpressionNumber valOfExpr=new MValueOfExpressionNumber();
      valOfExpr.type="String_Node_Str";
      valOfExpr.operand=ctx.exprEvaluator.eval1Expr(returnStatement.getReturnValue());
      retu.expr=valOfExpr;
    }
 else {
      retu.expr=ctx.exprEvaluator.eval1Expr(returnStatement.getReturnValue());
      retu.expr=ctx.converter.callCopyIfNeeded(retu.expr,returnStatement.getReturnValue());
    }
    if (ctx.stackMngr.getLocalVariableId() != 0)     retu.cleanup=ctx.stackMngr.createCleanupCall(0);
  }
 else   if (statement instanceof IASTSwitchStatement) {
    MyLogger.log("String_Node_Str");
    IASTSwitchStatement switchStatement=(IASTSwitchStatement)statement;
    MSwitchStmt swi=new MSwitchStmt();
    stmts.add(swi);
    swi.body=surround(evalStmt(switchStatement.getBody()));
    if (switchStatement.getControllerExpression() != null) {
      swi.expr=ctx.exprEvaluator.eval1Expr(switchStatement.getControllerExpression());
    }
    if (switchStatement instanceof ICPPASTSwitchStatement && ((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration());
      swi.decl=ctx.converter.eval1Decl(((ICPPASTSwitchStatement)switchStatement).getControllerDeclaration());
      swi.expr=ctx.converter.makeInfixFromDecl(swi.decl.name,swi.decl.initExpr,tp,false);
      swi.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof IASTWhileStatement) {
    MyLogger.log("String_Node_Str");
    IASTWhileStatement whileStatement=(IASTWhileStatement)statement;
    MWhileStmt whi=new MWhileStmt();
    stmts.add(whi);
    whi.body=surround(evalStmt(whileStatement.getBody()));
    if (whileStatement.getCondition() != null) {
      whi.expr=ctx.exprEvaluator.eval1Expr(whileStatement.getCondition());
      whi.expr=ExpressionHelpers.makeExpressionBoolean(whi.expr,whileStatement.getCondition());
    }
    if (whileStatement instanceof ICPPASTWhileStatement && ((ICPPASTWhileStatement)whileStatement).getConditionDeclaration() != null) {
      IType tp=ctx.converter.eval1DeclReturnCppType(((ICPPASTWhileStatement)whileStatement).getConditionDeclaration());
      whi.decl=ctx.converter.eval1Decl(((ICPPASTWhileStatement)whileStatement).getConditionDeclaration());
      whi.expr=ctx.converter.makeInfixFromDecl(whi.decl.name,whi.decl.initExpr,tp,true);
      whi.decl.initExpr=ExpressionHelpers.makeSimpleCreationExpression(tp);
    }
  }
 else   if (statement instanceof ICPPASTTryBlockStatement) {
  }
 else   if (statement != null) {
    MyLogger.logImportant(statement.getClass().getCanonicalName());
  }
  if (stmts.isEmpty())   stmts.add(new MEmptyStmt());
  return stmts;
}