Program: 50094
Project: 50094
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.addAll(evalStmt(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=ctx.exprEvaluator.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=ctx.exprEvaluator.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);
    retu.expr=ctx.exprEvaluator.wrapIfNeeded(returnStatement.getReturnValue(),ctx.currentReturnType);
    if (ctx.stackMngr.getLocalVariableId() != 0 && TypeManager.isOneOf(ctx.currentReturnType,TypeEnum.VOID)) {
      retu.cleanup=ctx.stackMngr.createCleanupCall(0);
    }
 else     if (ctx.stackMngr.getLocalVariableId() != 0) {
      retu.expr=ctx.stackMngr.wrapCleanupCall(retu.expr);
    }
  }
 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=ctx.exprEvaluator.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=ctx.exprEvaluator.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.addAll(evalStmt(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(),InitType.WRAPPED);
    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(),InitType.RAW);
      fs.condition=ctx.converter.makeInfixFromDecl(fs.decl.name,fs.decl.initExpr,tp,true);
      fs.decl.initExpr=ctx.exprEvaluator.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(),InitType.RAW);
      ifs.condition=ctx.converter.makeInfixFromDecl(ifs.decl.name,ifs.decl.initExpr,tp,true);
      ifs.decl.initExpr=ctx.exprEvaluator.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);
    retu.expr=ctx.exprEvaluator.wrapIfNeeded(returnStatement.getReturnValue(),ctx.currentReturnType);
    if (ctx.stackMngr.getLocalVariableId() != 0 && TypeManager.isOneOf(ctx.currentReturnType,TypeEnum.VOID)) {
      retu.cleanup=ctx.stackMngr.createCleanupCall(0);
    }
 else     if (ctx.stackMngr.getLocalVariableId() != 0) {
      retu.expr=ctx.stackMngr.wrapCleanupCall(retu.expr);
    }
  }
 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(),InitType.RAW);
      swi.expr=ctx.converter.makeInfixFromDecl(swi.decl.name,swi.decl.initExpr,tp,false);
      swi.decl.initExpr=ctx.exprEvaluator.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(),InitType.RAW);
      whi.expr=ctx.converter.makeInfixFromDecl(whi.decl.name,whi.decl.initExpr,tp,true);
      whi.decl.initExpr=ctx.exprEvaluator.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;
}