Program: 135969
Project: 135969
Buggy source:
private final ProofNode generateProof(TreeNode stn,ModuleNode cm) throws AbortException {
  int numberOfPops=0;
  if (stn.getKind() == N_TerminalProof) {
    return generateLeafProof(stn,cm);
  }
  ;
  Context pfCtxt=new Context(moduleTable,errors);
  symbolTable.pushContext(pfCtxt);
  TreeNode heirs[]=stn.heirs();
  int offset=0;
  if (heirs[0].getKind() == TLAplusParserConstants.PROOF) {
    offset=1;
  }
  ;
  LevelNode[] steps=new LevelNode[heirs.length - offset];
  Vector iVec=new Vector();
  boolean prevIsInfix=false;
  ExprNode prevRHS=null;
  for (int i=offset; i < heirs.length; i++) {
    boolean isAssumeProve=false;
    boolean isSuffices=false;
    Context assumeContext=null;
    boolean isPick=false;
    Context pickContext=null;
    TreeNode pfStepSTN=heirs[i];
    TreeNode stepNumSTN=pfStepSTN.heirs()[0];
    TreeNode stepBodySTN=pfStepSTN.heirs()[1];
    TreeNode stepPfSTN=null;
    if (pfStepSTN.heirs().length > 2) {
      stepPfSTN=pfStepSTN.heirs()[2];
    }
    ;
    LevelNode pfNumNode=null;
    boolean makePfNumNode=true;
    UniqueString stepNum=null;
switch (stepNumSTN.getKind()) {
case TLAplusParserConstants.ProofImplicitStepLexeme:
case TLAplusParserConstants.ProofStepLexeme:
      stepNum=stepNumSTN.getUS();
    break;
case TLAplusParserConstants.ProofStepDotLexeme:
  String stNum=stepNumSTN.getUS().toString();
stepNum=UniqueString.uniqueStringOf(stNum.substring(0,stNum.indexOf("String_Node_Str")));
break;
default :
makePfNumNode=false;
break;
}
;
if (stepNum != null) {
pushLS();
}
;
ThmOrAssumpDefNode tadn=null;
if (stepNum != null) {
tadn=new ThmOrAssumpDefNode(stepNum,stepNumSTN);
}
;
int stepKind=stepBodySTN.getKind();
if (stepKind != N_AssertStep) {
prevIsInfix=false;
}
;
switch (stepKind) {
case N_DefStep:
TreeNode[] defSTNs=stepBodySTN.heirs();
int defOffSet=0;
if (defSTNs[0].getKind() == DEFINE) {
defOffSet=1;
}
;
OpDefNode[] defs=new OpDefNode[defSTNs.length - defOffSet];
for (int j=defOffSet; j < defSTNs.length; j++) {
TreeNode defSTN=defSTNs[j];
;
Vector vec=new Vector();
switch (defSTN.getKind()) {
case N_FunctionDefinition:
processFunction(defSTN,vec,cm);
break;
case N_ModuleDefinition:
Vector defsVec=new Vector();
vec.addElement(processModuleDefinition(defSTN,defsVec,iVec,cm));
break;
case N_OperatorDefinition:
processOperator(defSTN,vec,cm);
break;
}
;
defs[j - defOffSet]=(OpDefNode)vec.elementAt(0);
}
;
pfNumNode=new DefStepNode(stepBodySTN,stepNum,defs);
steps[i - offset]=pfNumNode;
break;
case N_UseOrHide:
UseOrHideNode uohn=generateUseOrHide(stepBodySTN,cm);
uohn.stn=pfStepSTN;
uohn.setStepName(stepNum);
if (uohn.facts.length + uohn.defs.length == 0) {
errors.addError(stepBodySTN.getLocation(),"String_Node_Str");
}
;
uohn.factCheck();
pfNumNode=uohn;
steps[i - offset]=pfNumNode;
break;
case N_NonLocalInstance:
InstanceNode inst=generateInstance(stepBodySTN,cm,false);
inst.setStepName(stepNum);
pfNumNode=inst;
steps[i - offset]=pfNumNode;
break;
default :
makePfNumNode=false;
TreeNode[] bodyHeirs=stepBodySTN.heirs();
LevelNode body=null;
UniqueString op=null;
ExprNode[] args;
switch (stepBodySTN.getKind()) {
case N_AssertStep:
int bodyNext=0;
if (bodyHeirs[0].getKind() == TLAplusParserConstants.SUFFICES) {
bodyNext=1;
isSuffices=true;
}
;
if (bodyHeirs[bodyNext].getKind() == N_AssumeProve) {
isAssumeProve=true;
symbolTable.pushContext(new Context(moduleTable,errors));
currentGoal=tadn;
body=generateAssumeProve(bodyHeirs[bodyNext],cm);
if (isSuffices) {
((AssumeProveNode)body).setSuffices();
}
;
currentGoal=null;
assumeContext=symbolTable.getContext();
symbolTable.popContext();
prevIsInfix=false;
}
 else {
TreeNode curExpr=bodyHeirs[bodyNext];
if (isSuffices) {
args=new ExprNode[1];
args[0]=generateExpression(curExpr,cm);
body=new OpApplNode(OP_suffices,args,stepBodySTN,cm);
}
 else {
SyntaxTreeNode curLHS=null;
if (curExpr.getKind() == N_InfixExpr) {
curLHS=(SyntaxTreeNode)curExpr.heirs()[0];
}
;
if (prevIsInfix && (curLHS != null) && (curLHS.heirs().length > 0)&& (((SyntaxTreeNode)curLHS.heirs()[0]).heirs().length == 0)&& (curLHS.heirs()).length > 1 && (curLHS.heirs()[1].getKind() == IDENTIFIER) && (curLHS.heirs()[1].getUS() == AtUS)) {
TreeNode[] children=curExpr.heirs();
GenID genID=generateGenID(children[1],cm);
ExprNode[] sns=new ExprNode[2];
SymbolNode opn=symbolTable.resolveSymbol(Operators.resolveSynonym(genID.getCompoundIDUS()));
if (opn == null) {
errors.addError(curExpr.getLocation(),"String_Node_Str" + genID.getCompoundIDUS() + "String_Node_Str");
return null;
}
;
sns[1]=generateExpression(children[2],cm);
ExprNode[] nopArgs=new ExprNode[1];
nopArgs[0]=prevRHS;
sns[0]=new OpApplNode(OP_nop,nopArgs,curLHS,cm);
body=new OpApplNode(opn,sns,curExpr,cm);
}
 else {
body=generateExpression(curExpr,cm);
}
;
prevIsInfix=false;
if ((curLHS != null) && (body != null) && (body.getKind() == OpApplKind)&& (((OpApplNode)body).getArgs().length > 1)) {
prevIsInfix=true;
prevRHS=(ExprNode)((OpApplNode)body).getArgs()[1];
}
}
}
;
break;
case N_HaveStep:
case N_CaseStep:
if (stepBodySTN.getKind() == N_HaveStep) {
op=OP_have;
}
 else {
op=OP_pfcase;
}
;
args=new ExprNode[1];
args[0]=generateExpression(bodyHeirs[1],cm);
body=new OpApplNode(op,args,stepBodySTN,cm);
break;
case N_TakeStep:
case N_PickStep:
if (stepBodySTN.getKind() == N_TakeStep) {
op=OP_take;
}
 else {
op=OP_pick;
isPick=true;
symbolTable.pushContext(new Context(moduleTable,errors));
}
;
if (bodyHeirs[1].getKind() == N_QuantBound) {
int quants=1;
int nextTok=2;
while ((nextTok < bodyHeirs.length) && (bodyHeirs[nextTok].getKind() == TLAplusParserConstants.COMMA)) {
quants++;
nextTok=nextTok + 2;
}
;
FormalParamNode[][] params=new FormalParamNode[quants][0];
boolean[] bt=new boolean[quants];
ExprNode[] paramBounds=new ExprNode[quants];
processQuantBoundArgs(bodyHeirs,1,params,bt,paramBounds,cm);
if (isPick) {
pickContext=symbolTable.getContext();
nextTok++;
args=new ExprNode[1];
pushFormalParams(flattenParams(params));
args[0]=generateExpression(bodyHeirs[nextTok],cm);
popFormalParams();
symbolTable.popContext();
}
 else {
args=new ExprNode[0];
}
;
body=new OpApplNode(op,null,args,params,bt,paramBounds,stepBodySTN,cm);
}
 else {
int ids=1;
while ((2 * ids < bodyHeirs.length) && (bodyHeirs[2 * ids].getKind() == TLAplusParserConstants.COMMA)) {
ids++;
}
;
FormalParamNode[] params=new FormalParamNode[ids];
for (int j=0; j < ids; j++) {
params[j]=new FormalParamNode(bodyHeirs[2 * j + 1].getUS(),0,bodyHeirs[2 * j + 1],symbolTable,cm);
}
;
if (isPick) {
pickContext=symbolTable.getContext();
pushFormalParams(params);
args=new ExprNode[1];
args[0]=generateExpression(bodyHeirs[2 * ids + 1],cm);
popFormalParams();
symbolTable.popContext();
}
 else {
args=new ExprNode[0];
}
;
body=new OpApplNode(op,args,params,stepBodySTN,cm);
}
;
break;
case N_WitnessStep:
int ids=1;
while ((2 * ids < bodyHeirs.length) && (bodyHeirs[2 * ids].getKind() == TLAplusParserConstants.COMMA)) {
ids++;
}
;
args=new ExprNode[ids];
for (int j=0; j < ids; j++) {
args[j]=generateExpression(bodyHeirs[2 * j + 1],cm);
}
;
body=new OpApplNode(OP_witness,args,stepBodySTN,cm);
break;
case N_QEDStep:
args=new ExprNode[0];
body=new OpApplNode(OP_qed,args,stepBodySTN,cm);
break;
default :
errors.addAbort(stn.getLocation(),"String_Node_Str" + heirs[i].getKind());
break;
}
;
if (stepNum != null) {
tadn.construct(true,body,cm,symbolTable,null);
tadn.setLabels(popLabelNodeSet());
if (isSuffices) {
tadn.setSuffices();
}
;
}
;
ProofNode proof=null;
if (stepPfSTN != null) {
if (isAssumeProve && !isSuffices) {
symbolTable.pushContext(assumeContext);
}
;
proof=generateProof(stepPfSTN,cm);
if (isAssumeProve && !isSuffices) {
symbolTable.popContext();
}
;
}
;
if (isAssumeProve && isSuffices) {
numberOfPops++;
symbolTable.pushContext(assumeContext);
}
;
if (isAssumeProve) {
((AssumeProveNode)body).inProof=false;
}
;
TheoremNode thm=new TheoremNode(stepBodySTN,body,cm,proof,tadn);
thm.stn=pfStepSTN;
thm.suffices=isSuffices;
steps[i - offset]=thm;
}
;
if (makePfNumNode) {
OpDefNode nodeMadeOnlyToBePutInSymbolTable=new OpDefNode(stepNum,pfNumNode,cm,symbolTable,pfStepSTN);
nodeMadeOnlyToBePutInSymbolTable.setLabels(popLabelNodeSet());
}
if (isPick) {
Enumeration e=pickContext.content();
while (e.hasMoreElements()) {
SymbolNode sym=((Context.Pair)(e.nextElement())).getSymbol();
symbolTable.addSymbol(sym.getName(),sym);
}
}
}
;
InstanceNode[] insts=new InstanceNode[iVec.size()];
for (int i=0; i < insts.length; i++) {
insts[i]=(InstanceNode)iVec.elementAt(i);
}
;
for (int i=0; i < numberOfPops; i++) {
symbolTable.popContext();
}
;
symbolTable.popContext();
return new NonLeafProofNode(stn,steps,insts,pfCtxt);
}

Fixed version (ground truth):
private final ProofNode generateProof(TreeNode stn,ModuleNode cm) throws AbortException {
  int numberOfPops=0;
  if (stn.getKind() == N_TerminalProof) {
    return generateLeafProof(stn,cm);
  }
  ;
  Context pfCtxt=new Context(moduleTable,errors);
  symbolTable.pushContext(pfCtxt);
  TreeNode heirs[]=stn.heirs();
  int offset=0;
  if (heirs[0].getKind() == TLAplusParserConstants.PROOF) {
    offset=1;
  }
  ;
  LevelNode[] steps=new LevelNode[heirs.length - offset];
  Vector iVec=new Vector();
  boolean prevIsInfix=false;
  ExprNode prevRHS=null;
  for (int i=offset; i < heirs.length; i++) {
    boolean isAssumeProve=false;
    boolean isSuffices=false;
    Context assumeContext=null;
    boolean isPick=false;
    Context pickContext=null;
    TreeNode pfStepSTN=heirs[i];
    TreeNode stepNumSTN=pfStepSTN.heirs()[0];
    TreeNode stepBodySTN=pfStepSTN.heirs()[1];
    TreeNode stepPfSTN=null;
    if (pfStepSTN.heirs().length > 2) {
      stepPfSTN=pfStepSTN.heirs()[2];
    }
    ;
    LevelNode pfNumNode=null;
    boolean makePfNumNode=true;
    UniqueString stepNum=null;
switch (stepNumSTN.getKind()) {
case TLAplusParserConstants.ProofImplicitStepLexeme:
case TLAplusParserConstants.ProofStepLexeme:
      stepNum=stepNumSTN.getUS();
    break;
case TLAplusParserConstants.ProofStepDotLexeme:
  String stNum=stepNumSTN.getUS().toString();
stepNum=UniqueString.uniqueStringOf(stNum.substring(0,stNum.indexOf("String_Node_Str")));
break;
default :
makePfNumNode=false;
break;
}
;
if (stepNum != null) {
pushLS();
}
;
ThmOrAssumpDefNode tadn=null;
if (stepNum != null) {
tadn=new ThmOrAssumpDefNode(stepNum,stepNumSTN);
}
;
int stepKind=stepBodySTN.getKind();
if (stepKind != N_AssertStep) {
prevIsInfix=false;
}
;
switch (stepKind) {
case N_DefStep:
TreeNode[] defSTNs=stepBodySTN.heirs();
int defOffSet=0;
if (defSTNs[0].getKind() == DEFINE) {
defOffSet=1;
}
;
OpDefNode[] defs=new OpDefNode[defSTNs.length - defOffSet];
for (int j=defOffSet; j < defSTNs.length; j++) {
TreeNode defSTN=defSTNs[j];
;
Vector vec=new Vector();
switch (defSTN.getKind()) {
case N_FunctionDefinition:
processFunction(defSTN,vec,cm);
break;
case N_ModuleDefinition:
Vector defsVec=new Vector();
vec.addElement(processModuleDefinition(defSTN,defsVec,iVec,cm));
break;
case N_OperatorDefinition:
processOperator(defSTN,vec,cm);
break;
}
;
defs[j - defOffSet]=(OpDefNode)vec.elementAt(0);
}
;
pfNumNode=new DefStepNode(stepBodySTN,stepNum,defs);
steps[i - offset]=pfNumNode;
break;
case N_UseOrHide:
UseOrHideNode uohn=generateUseOrHide(stepBodySTN,cm);
uohn.stn=pfStepSTN;
uohn.setStepName(stepNum);
if (uohn.facts.length + uohn.defs.length == 0) {
errors.addError(stepBodySTN.getLocation(),"String_Node_Str");
}
;
uohn.factCheck();
pfNumNode=uohn;
steps[i - offset]=pfNumNode;
break;
case N_NonLocalInstance:
InstanceNode inst=generateInstance(stepBodySTN,cm,false);
inst.setStepName(stepNum);
pfNumNode=inst;
steps[i - offset]=pfNumNode;
break;
default :
makePfNumNode=false;
TreeNode[] bodyHeirs=stepBodySTN.heirs();
LevelNode body=null;
UniqueString op=null;
ExprNode[] args;
switch (stepBodySTN.getKind()) {
case N_AssertStep:
int bodyNext=0;
if (bodyHeirs[0].getKind() == TLAplusParserConstants.SUFFICES) {
bodyNext=1;
isSuffices=true;
}
;
if (bodyHeirs[bodyNext].getKind() == N_AssumeProve) {
isAssumeProve=true;
symbolTable.pushContext(new Context(moduleTable,errors));
currentGoal=tadn;
body=generateAssumeProve(bodyHeirs[bodyNext],cm);
if (isSuffices) {
((AssumeProveNode)body).setSuffices();
}
;
currentGoal=null;
assumeContext=symbolTable.getContext();
symbolTable.popContext();
prevIsInfix=false;
}
 else {
TreeNode curExpr=bodyHeirs[bodyNext];
if (isSuffices) {
args=new ExprNode[1];
args[0]=generateExpression(curExpr,cm);
body=new OpApplNode(OP_suffices,args,stepBodySTN,cm);
}
 else {
SyntaxTreeNode curLHS=null;
if (curExpr.getKind() == N_InfixExpr) {
curLHS=(SyntaxTreeNode)curExpr.heirs()[0];
}
;
if (prevIsInfix && (curLHS != null) && (curLHS.heirs().length > 0)&& (((SyntaxTreeNode)curLHS.heirs()[0]).heirs().length == 0)&& (curLHS.heirs()).length > 1 && (curLHS.heirs()[1].getKind() == IDENTIFIER) && (curLHS.heirs()[1].getUS() == AtUS)) {
TreeNode[] children=curExpr.heirs();
GenID genID=generateGenID(children[1],cm);
ExprNode[] sns=new ExprNode[2];
SymbolNode opn=symbolTable.resolveSymbol(Operators.resolveSynonym(genID.getCompoundIDUS()));
if (opn == null) {
errors.addError(curExpr.getLocation(),"String_Node_Str" + genID.getCompoundIDUS() + "String_Node_Str");
return null;
}
;
sns[1]=generateExpression(children[2],cm);
ExprNode[] nopArgs=new ExprNode[1];
nopArgs[0]=prevRHS;
sns[0]=new OpApplNode(OP_nop,nopArgs,curLHS,cm);
body=new OpApplNode(opn,sns,curExpr,cm);
}
 else {
body=generateExpression(curExpr,cm);
}
;
prevIsInfix=false;
if ((curLHS != null) && (body != null) && (body.getKind() == OpApplKind)&& (((OpApplNode)body).getArgs().length > 1)) {
prevIsInfix=true;
prevRHS=(ExprNode)((OpApplNode)body).getArgs()[1];
}
}
}
;
break;
case N_HaveStep:
case N_CaseStep:
if (stepBodySTN.getKind() == N_HaveStep) {
op=OP_have;
}
 else {
op=OP_pfcase;
}
;
args=new ExprNode[1];
args[0]=generateExpression(bodyHeirs[1],cm);
body=new OpApplNode(op,args,stepBodySTN,cm);
break;
case N_TakeStep:
case N_PickStep:
if (stepBodySTN.getKind() == N_TakeStep) {
op=OP_take;
}
 else {
op=OP_pick;
isPick=true;
symbolTable.pushContext(new Context(moduleTable,errors));
}
;
if (bodyHeirs[1].getKind() == N_QuantBound) {
int quants=1;
int nextTok=2;
while ((nextTok < bodyHeirs.length) && (bodyHeirs[nextTok].getKind() == TLAplusParserConstants.COMMA)) {
quants++;
nextTok=nextTok + 2;
}
;
FormalParamNode[][] params=new FormalParamNode[quants][0];
boolean[] bt=new boolean[quants];
ExprNode[] paramBounds=new ExprNode[quants];
processQuantBoundArgs(bodyHeirs,1,params,bt,paramBounds,cm);
if (isPick) {
pickContext=symbolTable.getContext();
nextTok++;
args=new ExprNode[1];
pushFormalParams(flattenParams(params));
args[0]=generateExpression(bodyHeirs[nextTok],cm);
popFormalParams();
symbolTable.popContext();
}
 else {
args=new ExprNode[0];
}
;
body=new OpApplNode(op,null,args,params,bt,paramBounds,stepBodySTN,cm);
}
 else {
int ids=1;
while ((2 * ids < bodyHeirs.length) && (bodyHeirs[2 * ids].getKind() == TLAplusParserConstants.COMMA)) {
ids++;
}
;
FormalParamNode[] params=new FormalParamNode[ids];
for (int j=0; j < ids; j++) {
params[j]=new FormalParamNode(bodyHeirs[2 * j + 1].getUS(),0,bodyHeirs[2 * j + 1],symbolTable,cm);
}
;
if (isPick) {
pickContext=symbolTable.getContext();
pushFormalParams(params);
args=new ExprNode[1];
args[0]=generateExpression(bodyHeirs[2 * ids + 1],cm);
popFormalParams();
symbolTable.popContext();
}
 else {
args=new ExprNode[0];
}
;
body=new OpApplNode(op,args,params,stepBodySTN,cm);
}
;
break;
case N_WitnessStep:
int ids=1;
while ((2 * ids < bodyHeirs.length) && (bodyHeirs[2 * ids].getKind() == TLAplusParserConstants.COMMA)) {
ids++;
}
;
args=new ExprNode[ids];
for (int j=0; j < ids; j++) {
args[j]=generateExpression(bodyHeirs[2 * j + 1],cm);
}
;
body=new OpApplNode(OP_witness,args,stepBodySTN,cm);
break;
case N_QEDStep:
args=new ExprNode[0];
body=new OpApplNode(OP_qed,args,stepBodySTN,cm);
break;
default :
errors.addAbort(stn.getLocation(),"String_Node_Str" + heirs[i].getKind());
break;
}
;
if (stepNum != null) {
tadn.construct(true,body,cm,symbolTable,null);
tadn.setLabels(popLabelNodeSet());
if (isSuffices) {
tadn.setSuffices();
}
;
}
;
ProofNode proof=null;
if (stepPfSTN != null) {
if (isAssumeProve && !isSuffices) {
symbolTable.pushContext(assumeContext);
}
;
proof=generateProof(stepPfSTN,cm);
if (isAssumeProve && !isSuffices) {
symbolTable.popContext();
}
;
}
;
if (isAssumeProve && isSuffices) {
numberOfPops++;
symbolTable.pushContext(assumeContext);
}
;
if (isAssumeProve) {
((AssumeProveNode)body).inProof=false;
}
;
TheoremNode thm=new TheoremNode(stepBodySTN,body,cm,proof,tadn);
thm.stn=pfStepSTN;
thm.suffices=isSuffices;
steps[i - offset]=thm;
}
;
if (makePfNumNode) {
OpDefNode nodeMadeOnlyToBePutInSymbolTable=new OpDefNode(stepNum,pfNumNode,cm,symbolTable,pfStepSTN);
nodeMadeOnlyToBePutInSymbolTable.setLabels(popLabelNodeSet());
}
if (isPick) {
Enumeration e=pickContext.content();
while (e.hasMoreElements()) {
SymbolNode sym=((Context.Pair)(e.nextElement())).getSymbol();
symbolTable.addSymbol(sym.getName(),sym);
}
}
}
;
InstanceNode[] insts=new InstanceNode[iVec.size()];
for (int i=0; i < insts.length; i++) {
insts[i]=(InstanceNode)iVec.elementAt(i);
}
;
for (int i=0; i < numberOfPops; i++) {
Context topContext=symbolTable.getContext();
Enumeration e=topContext.content();
while (e.hasMoreElements()) {
SymbolNode sym=((Context.Pair)(e.nextElement())).getSymbol();
pfCtxt.addSymbolToContext(sym.getName(),sym);
}
symbolTable.popContext();
}
;
symbolTable.popContext();
return new NonLeafProofNode(stn,steps,insts,pfCtxt);
}