Program: 50087
Project: 50087
Buggy source:
/** 
 * Evaluates a function definition and converts it to Java.
 */
void evalFunction(IASTDeclaration declaration) throws DOMException {
  IASTFunctionDefinition func=(IASTFunctionDefinition)declaration;
  IBinding funcBinding=func.getDeclarator().getName().resolveBinding();
  CppFunction method=(CppFunction)ctx.typeMngr.getDeclFromType(ctx.converter.evalBindingReturnType(funcBinding));
  if (method == null) {
    method=new CppFunction();
    ctx.typeMngr.registerDecl(method,ctx.converter.evalBindingReturnType(funcBinding),func.getDeclarator().getName(),NameType.CAMEL_CASE,func.getDeclarator().getContainingFilename(),func.getDeclarator().getFileLocation().getStartingLineNumber());
  }
  method.isStatic=((IFunction)funcBinding).isStatic();
  method.retType=evalReturnType(funcBinding);
  if (funcBinding instanceof ICPPConstructor) {
    method.isCtor=true;
    method.retType=null;
  }
 else   if (funcBinding instanceof ICPPMethod) {
    if (((ICPPMethod)funcBinding).isDestructor()) {
      method.isDtor=true;
      method.retType=null;
    }
  }
  method.args.addAll(evalParameters(funcBinding));
  ctx.stackMngr.reset();
  if (funcBinding instanceof IFunction) {
    IFunction funcb=(IFunction)funcBinding;
    IFunctionType funcType=funcb.getType();
    ctx.currentReturnType=funcType.getReturnType();
  }
  method.body=(MCompoundStmt)ctx.stmtEvaluator.eval1Stmt(func.getBody());
  ctx.currentReturnType=null;
  if (ctx.stackMngr.getMaxLocalVariableId() != null) {
    MStringExpression expr=new MStringExpression();
    expr.contents="String_Node_Str" + ctx.stackMngr.getMaxLocalVariableId() + "String_Node_Str";
    method.body.statements.add(0,ModelCreation.createExprStmt(expr));
  }
  CompositeInfo info=ctx.converter.currentInfoStack.peekFirst();
  if (func instanceof ICPPASTFunctionDefinition && info != null) {
    List<FieldInfo> fields=ctx.converter.collectFieldsForClass(info.declSpecifier);
    MExpression superInit=null;
    ICPPASTFunctionDefinition funcCpp=(ICPPASTFunctionDefinition)func;
    ICPPASTConstructorChainInitializer[] chains=funcCpp.getMemberInitializers();
    if (chains != null && chains.length != 0) {
      for (      ICPPASTConstructorChainInitializer chain : chains) {
        if ((chain.getMemberInitializerId().resolveBinding() instanceof IVariable && ((IVariable)chain.getMemberInitializerId().resolveBinding()).getType() instanceof ICompositeType)) {
          MLiteralExpression lit=ModelCreation.createLiteral(ctx.typeMngr.cppToJavaType(((IVariable)chain.getMemberInitializerId().resolveBinding()).getType(),TypeType.IMPLEMENTATION));
          MClassInstanceCreation create=new MClassInstanceCreation();
          create.name=lit;
          create.args.add(ctx.initMngr.eval1Init(chain.getInitializer(),ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding()),chain.getMemberInitializerId()));
          for (          FieldInfo fieldInfo : fields) {
            if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName()))             fieldInfo.init=create;
          }
        }
 else         if (chain.getInitializer() != null) {
          for (          FieldInfo fieldInfo : fields) {
            if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName()) && ctx.bitfieldMngr.isBitfield(fieldInfo.declarator.getName())) {
              IType tp=ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding());
              fieldInfo.init=ctx.initMngr.eval1Init(chain.getInitializer(),tp,fieldInfo.declarator.getName());
            }
 else             if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName())) {
              IType tp=ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding());
              fieldInfo.init=ctx.initMngr.eval1Init(chain.getInitializer(),tp,fieldInfo.declarator.getName());
            }
          }
          if (info.hasSuper && chain.getMemberInitializerId().resolveBinding().getName().equals(info.superClass)) {
            superInit=ctx.initMngr.eval1Init(chain.getInitializer(),ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding()),chain.getMemberInitializerId());
          }
        }
 else {
        }
      }
    }
    if (method.isCtor) {
      MyLogger.log("String_Node_Str");
      ctx.specialGenerator.generateCtorStatements(fields,method.body);
      if (info.hasSuper) {
        MFunctionCallExpression expr=ModelCreation.createFuncCall("String_Node_Str");
        if (superInit != null)         expr.args.add(superInit);
        method.body.statements.add(0,ModelCreation.createExprStmt(expr));
      }
    }
 else     if (method.isDtor) {
      ctx.specialGenerator.generateDtorStatements(fields,method.body,info.hasSuper);
    }
  }
  makeDefaultCalls(func.getDeclarator(),funcBinding);
}

Fixed version (ground truth):
/** 
 * Evaluates a function definition and converts it to Java.
 */
void evalFunction(IASTDeclaration declaration) throws DOMException {
  IASTFunctionDefinition func=(IASTFunctionDefinition)declaration;
  IBinding funcBinding=func.getDeclarator().getName().resolveBinding();
  CppFunction method=(CppFunction)ctx.typeMngr.getDeclFromType(ctx.converter.evalBindingReturnType(funcBinding));
  if (method == null) {
    method=new CppFunction();
    ctx.typeMngr.registerDecl(method,ctx.converter.evalBindingReturnType(funcBinding),func.getDeclarator().getName(),NameType.CAMEL_CASE,func.getDeclarator().getContainingFilename(),func.getDeclarator().getFileLocation().getStartingLineNumber());
  }
  method.isStatic=((IFunction)funcBinding).isStatic();
  method.retType=evalReturnType(funcBinding);
  if (funcBinding instanceof ICPPConstructor) {
    method.isCtor=true;
    method.retType=null;
  }
 else   if (funcBinding instanceof ICPPMethod) {
    if (((ICPPMethod)funcBinding).isDestructor()) {
      method.isDtor=true;
      method.retType=null;
    }
  }
  method.args.addAll(evalParameters(funcBinding));
  ctx.stackMngr.reset();
  if (funcBinding instanceof IFunction) {
    IFunction funcb=(IFunction)funcBinding;
    IFunctionType funcType=funcb.getType();
    ctx.currentReturnType=funcType.getReturnType();
  }
  method.body=(MCompoundStmt)ctx.stmtEvaluator.eval1Stmt(func.getBody());
  ctx.currentReturnType=null;
  if (ctx.stackMngr.getMaxLocalVariableId() != null) {
    MStringExpression expr=new MStringExpression();
    expr.contents="String_Node_Str" + ctx.stackMngr.getMaxLocalVariableId() + "String_Node_Str";
    method.body.statements.add(0,ModelCreation.createExprStmt(expr));
  }
  CompositeInfo info=ctx.converter.currentInfoStack.peekFirst();
  if (func instanceof ICPPASTFunctionDefinition && info != null) {
    List<FieldInfo> fields=ctx.converter.collectFieldsForClass(info.declSpecifier);
    MExpression superInit=null;
    ICPPASTFunctionDefinition funcCpp=(ICPPASTFunctionDefinition)func;
    ICPPASTConstructorChainInitializer[] chains=funcCpp.getMemberInitializers();
    if (chains != null && chains.length != 0) {
      for (      ICPPASTConstructorChainInitializer chain : chains) {
        if ((chain.getMemberInitializerId().resolveBinding() instanceof IVariable && ((IVariable)chain.getMemberInitializerId().resolveBinding()).getType() instanceof ICompositeType)) {
          MLiteralExpression lit=ModelCreation.createLiteral(ctx.typeMngr.cppToJavaType(((IVariable)chain.getMemberInitializerId().resolveBinding()).getType(),TypeType.IMPLEMENTATION));
          MClassInstanceCreation create=new MClassInstanceCreation();
          create.name=lit;
          create.args.add(ctx.initMngr.eval1Init(chain.getInitializer(),ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding()),chain.getMemberInitializerId(),InitType.WRAPPED));
          for (          FieldInfo fieldInfo : fields) {
            if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName()))             fieldInfo.init=create;
          }
        }
 else         if (chain.getInitializer() != null) {
          for (          FieldInfo fieldInfo : fields) {
            if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName()) && ctx.bitfieldMngr.isBitfield(fieldInfo.declarator.getName())) {
              IType tp=ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding());
              fieldInfo.init=ctx.initMngr.eval1Init(chain.getInitializer(),tp,fieldInfo.declarator.getName(),InitType.WRAPPED);
            }
 else             if (chain.getMemberInitializerId().resolveBinding().getName().equals(fieldInfo.field.getName())) {
              IType tp=ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding());
              fieldInfo.init=ctx.initMngr.eval1Init(chain.getInitializer(),tp,fieldInfo.declarator.getName(),InitType.WRAPPED);
            }
          }
          if (info.hasSuper && chain.getMemberInitializerId().resolveBinding().getName().equals(info.superClass)) {
            superInit=ctx.initMngr.eval1Init(chain.getInitializer(),ctx.converter.evalBindingReturnType(chain.getMemberInitializerId().resolveBinding()),chain.getMemberInitializerId(),InitType.WRAPPED);
          }
        }
 else {
        }
      }
    }
    if (method.isCtor) {
      MyLogger.log("String_Node_Str");
      ctx.specialGenerator.generateCtorStatements(fields,method.body);
      if (info.hasSuper) {
        MFunctionCallExpression expr=ModelCreation.createFuncCall("String_Node_Str");
        if (superInit != null)         expr.args.add(superInit);
        method.body.statements.add(0,ModelCreation.createExprStmt(expr));
      }
    }
 else     if (method.isDtor) {
      ctx.specialGenerator.generateDtorStatements(fields,method.body,info.hasSuper);
    }
  }
  makeDefaultCalls(func.getDeclarator(),funcBinding);
}