Program: 136049
Project: 136049
Buggy source:
LevelNode selectorToNode(Selector sel,int expectedArity,boolean isFact,boolean isDef,ModuleNode cm) throws AbortException {
  Vector substInPrefix=new Vector();
  Vector params=new Vector();
  Vector allArgs=new Vector();
  UniqueString curName=null;
  UniqueString newName=null;
  SemanticNode curNode=null;
  SemanticNode newNode;
  int idx=0;
  int mode=FindingOpName;
  int prevMode=-999;
  Context letInContext=null;
  int opDefArityFound=0;
  Vector opDefArgs=new Vector();
  boolean firstFindingOpName=true;
  SymbolNode subExprOf=null;
  boolean inAPsuffices=false;
  while (idx < sel.args.length) {
    if ((((sel.ops[idx] != NameSel) && (sel.ops[idx] != NullSel)) || (expectedArity != 0)) && (sel.args[idx] != null)) {
      errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + selectorItemToString(sel,idx) + "String_Node_Str");
      return nullOAN;
    }
    if ((sel.args[idx] != null) && (sel.args[idx].getKind() != N_OpArgs)) {
      errors.addAbort(sel.args[idx].getLocation(),"String_Node_Str");
    }
    ;
switch (mode) {
case FindingOpName:
      SymbolNode newSymbolNode=null;
    Vector tempArgs=new Vector();
  while (newSymbolNode == null && idx < sel.args.length) {
    if (sel.ops[idx] == NameSel) {
      if (curName == null) {
        newName=Operators.resolveSynonym(sel.opNames[idx]);
      }
 else {
        newName=UniqueString.uniqueStringOf(curName.toString() + "String_Node_Str" + Operators.resolveSynonym(sel.opNames[idx]).toString());
      }
      ;
    }
 else {
      newName=null;
    }
    ;
    if ((curName == null) && (sel.ops[idx] != NameSel)) {
      if (idx == 0) {
        errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx] + "String_Node_Str");
        return nullOAN;
      }
 else {
        errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
      }
      ;
    }
    ;
    if (newName != null) {
      if (letInContext == null) {
        newSymbolNode=symbolTable.resolveSymbol(newName);
      }
 else {
        newSymbolNode=letInContext.getSymbol(newName);
      }
      ;
    }
    ;
    if (newSymbolNode == null) {
      curName=newName;
      if (sel.args[idx] != null) {
        int numOfOpArgs=(sel.args[idx].heirs().length - 1) / 2;
        for (int i=0; i < numOfOpArgs; i++) {
          tempArgs.addElement(sel.args[idx].heirs()[2 * i + 1]);
        }
      }
      idx++;
    }
  }
if (newSymbolNode == null) {
  int eidx=(idx < sel.args.length) ? idx : (sel.args.length - 1);
  errors.addError(sel.opsSTN[eidx].getLocation(),"String_Node_Str" + selectorItemToString(sel,eidx) + "String_Node_Str");
  return nullOAN;
}
;
if (newSymbolNode.getKind() == ModuleKind) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
curNode=newSymbolNode;
SymbolNode curSymbolNode=newSymbolNode;
curName=newName;
switch (curSymbolNode.getKind()) {
case ConstantDeclKind:
case VariableDeclKind:
case FormalParamKind:
case BuiltInKind:
case NewConstantKind:
case NewVariableKind:
case NewStateKind:
case NewActionKind:
case NewTemporalKind:
case NumberedProofStepKind:
if (idx != 0) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
 else if (sel.ops.length != 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
case UserDefinedOpKind:
case ThmOrAssumpDefKind:
case ModuleInstanceKind:
int nodeArity=curSymbolNode.getArity();
if (expectedArity == 0) {
SyntaxTreeNode opArgs=sel.args[idx];
int numOfOpArgs=0;
if (opArgs != null) {
numOfOpArgs=(opArgs.heirs().length - 1) / 2;
for (int i=0; i < numOfOpArgs; i++) {
tempArgs.addElement(sel.args[idx].heirs()[2 * i + 1]);
}
;
}
;
if (opDefArityFound + tempArgs.size() != nodeArity) {
errors.addError((opArgs == null) ? sel.selSTN.getLocation() : sel.args[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str"+ (nodeArity - opDefArityFound)+ "String_Node_Str");
return nullOAN;
}
;
ExprOrOpArgNode[] opArgNodes=new ExprOrOpArgNode[tempArgs.size()];
for (int i=0; i < tempArgs.size(); i++) {
opDefArgs.addElement(generateExprOrOpArg(curSymbolNode,sel.opsSTN[idx],i + opDefArityFound,(TreeNode)tempArgs.elementAt(i),cm));
}
;
}
 else {
if (expectedArity > 0) {
}
}
;
opDefArityFound=nodeArity;
if (curNode.getKind() == ModuleInstanceKind) {
if ((idx == sel.ops.length - 1) && !(isDef || isFact)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
;
}
 else {
if ((curNode.getKind() == UserDefinedOpKind) && (!((OpDefNode)curNode).isDefined) && (sel.ops.length != 1)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
;
if (firstFindingOpName && ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ThmOrAssumpDefKind))) {
subExprOf=(SymbolNode)curNode;
}
if (idx != sel.ops.length - 1) {
FormalParamNode[] opParams;
if (curNode.getKind() == UserDefinedOpKind) {
opParams=((OpDefNode)curNode).getParams();
newNode=((OpDefNode)curNode).getBody();
}
 else {
opParams=((ThmOrAssumpDefNode)curNode).getParams();
newNode=((ThmOrAssumpDefNode)curNode).getBody();
}
;
for (int i=0; i < opParams.length; i++) {
params.addElement(opParams[i]);
}
;
curName=null;
if (sel.ops[idx + 1] == NameSel) {
mode=FollowingLabels;
}
 else {
mode=FindingSubExpr;
}
;
for (int i=0; i < opDefArgs.size(); i++) {
allArgs.addElement(opDefArgs.elementAt(i));
}
;
opDefArityFound=0;
opDefArgs=new Vector();
if (newNode != null) {
while (newNode.getKind() == SubstInKind) {
substInPrefix.addElement(newNode);
newNode=((SubstInNode)newNode).getBody();
}
;
}
;
if (mode == FindingSubExpr) {
curNode=newNode;
}
;
}
}
prevMode=FindingOpName;
break;
default :
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
break;
}
;
break;
case FollowingLabels:
if (((prevMode == FindingOpName) && (curNode.getKind() != UserDefinedOpKind) && (curNode.getKind() != ThmOrAssumpDefKind)) || ((prevMode != FindingOpName) && (curNode.getKind() != LabelKind))) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
;
LabelNode newLabelNode=((OpDefOrLabelNode)curNode).getLabel(sel.opNames[idx]);
if (newLabelNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
curNode=newLabelNode;
if (illegalLabelRef(newLabelNode,sel.opsSTN[idx])) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str"+ "String_Node_Str");
return nullOAN;
}
;
if (expectedArity == 0) {
if (newLabelNode.getArity() != ((sel.args[idx] == null) ? 0 : (sel.args[idx].heirs().length - 1) / 2)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < newLabelNode.getArity(); i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
for (int i=0; i < newLabelNode.getArity(); i++) {
FormalParamNode pdecl=newLabelNode.params[i];
params.addElement(pdecl);
}
;
if ((idx < sel.ops.length - 1) && (sel.ops[idx + 1] != NameSel)) {
mode=FindingSubExpr;
}
;
if ((mode == FindingSubExpr) || (idx == sel.ops.length)) {
curNode=newLabelNode.getBody();
}
;
prevMode=FollowingLabels;
break;
case FindingSubExpr:
if (sel.ops[idx] == ColonSel) {
if ((prevMode == FindingSubExpr) || !(((idx == sel.ops.length - 1) && (prevMode == FindingOpName)) || ((idx < sel.ops.length - 1) && (sel.ops[idx + 1] == NameSel)))) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
}
 else if (curNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
 else if (curNode.getKind() == LetInKind) {
if (ArgNum(sel.ops[idx],1) == 1) {
curNode=((LetInNode)curNode).getBody();
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
}
 else if (curNode.getKind() == OpApplKind) {
OpApplNode curOpApplNode=(OpApplNode)curNode;
ExprOrOpArgNode[] curArgs=curOpApplNode.getArgs();
SymbolNode opNode=curOpApplNode.getOperator();
if ((opNode.getKind() == FormalParamKind) || (opNode.getKind() == ConstantDeclKind) || (opNode.getKind() == UserDefinedOpKind)) {
int temp=ArgNum(sel.ops[idx],opNode.getArity());
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curArgs[temp - 1];
}
 else if (opNode.getKind() == BuiltInKind) {
if ((opNode.getName() == OP_rc) || (opNode.getName() == OP_sor)) {
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curOpApplNode=(OpApplNode)curArgs[temp - 1];
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
curNode=curOpApplNode.getArgs()[1];
}
 else if (opNode.getName() == OP_case) {
if (idx == sel.ops.length - 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curOpApplNode=(OpApplNode)curArgs[temp - 1];
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
idx=idx + 1;
temp=ArgNum(sel.ops[idx],2);
if (temp == -1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
curNode=curOpApplNode.getArgs()[temp - 1];
if (curNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
}
 else if (opNode.getName() == OP_exc) {
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
if (temp > 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
curNode=curArgs[temp - 1];
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if (temp > 1) {
curOpApplNode=(OpApplNode)curNode;
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
curNode=curOpApplNode.getArgs()[1];
}
;
}
 else {
if ((curOpApplNode.getNumberOfBoundedBoundSymbols() == 0) && ((curOpApplNode.getUnbdedQuantSymbols() == null) || (curOpApplNode.getUnbdedQuantSymbols().length == 0))) {
int temp=ArgNum(sel.ops[idx],curOpApplNode.getArgs().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curOpApplNode.getArgs()[temp - 1];
}
 else {
if ((sel.ops[idx] == NullSel) || (sel.ops[idx] == AtSel)) {
FormalParamNode[] temp;
if (curOpApplNode.getNumberOfBoundedBoundSymbols() > 0) {
FormalParamNode[][] symbs=curOpApplNode.getBdedQuantSymbolLists();
int numSymbs=0;
for (int i=0; i < symbs.length; i++) {
numSymbs=numSymbs + symbs[i].length;
}
;
temp=new FormalParamNode[numSymbs];
int k=0;
for (int i=0; i < symbs.length; i++) {
for (int j=0; j < symbs[i].length; j++) {
temp[k]=symbs[i][j];
k++;
}
;
}
;
}
 else {
temp=curOpApplNode.getUnbdedQuantSymbols();
}
;
for (int i=0; i < temp.length; i++) {
params.addElement(temp[i]);
}
;
if (sel.ops[idx] == NullSel) {
int numOfArgs=(sel.args[idx].heirs().length - 1) / 2;
if (temp.length != numOfArgs) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + numOfArgs + "String_Node_Str"+ temp.length+ "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < numOfArgs; i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
curNode=curOpApplNode.getArgs()[0];
}
 else {
int temp=ArgNum(sel.ops[idx],curOpApplNode.getBdedQuantBounds().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curOpApplNode.getBdedQuantBounds()[temp - 1];
}
;
}
;
}
;
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + selectorItemToString(sel,idx) + "String_Node_Str");
return nullOAN;
}
;
}
 else if (curNode.getKind() == AssumeProveKind) {
AssumeProveNode curAPNode=(AssumeProveNode)curNode;
if ((curAPNode.isSuffices()) && (!inAPsuffices)) {
if (ArgNum(sel.ops[idx],1) != 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
inAPsuffices=true;
}
 else {
inAPsuffices=false;
int temp=ArgNum(sel.ops[idx],1 + curAPNode.getAssumes().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
if (illegalAPPosRef(curAPNode,temp)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
if (temp <= curAPNode.getAssumes().length) {
curNode=curAPNode.getAssumes()[temp - 1];
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if ((curNode.getKind() == NewSymbKind) && (idx != sel.args.length - 1)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
 else {
curNode=curAPNode.getProve();
}
;
}
}
 else if (curNode.getKind() == OpArgKind) {
SymbolNode opNode=((OpArgNode)curNode).getOp();
if ((opNode.getKind() != UserDefinedOpKind) || (opNode.getName() != S_lambda)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
OpDefNode opDefOpNode=(OpDefNode)opNode;
if ((sel.ops[idx] != NullSel) && (sel.ops[idx] != AtSel)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
if (sel.ops[idx] == NullSel) {
int numOfArgs=(sel.args[idx].heirs().length - 1) / 2;
if (opDefOpNode.getArity() != numOfArgs) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + numOfArgs + "String_Node_Str"+ opDefOpNode.getArity()+ "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < numOfArgs; i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
for (int i=0; i < opDefOpNode.getArity(); i++) {
params.addElement(opDefOpNode.getParams()[i]);
}
;
curNode=opDefOpNode.getBody();
}
 else if ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == BuiltInKind) || (curNode.getKind() == NumberedProofStepKind)) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
}
 else if ((curNode.getKind() == AtNodeKind) || (curNode.getKind() == DecimalKind) || (curNode.getKind() == NumeralKind)|| (curNode.getKind() == StringKind)|| (curNode.getKind() == FormalParamKind)|| (curNode.getKind() == ConstantDeclKind)|| (curNode.getKind() == VariableDeclKind)|| (curNode.getKind() == BoundSymbolKind)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
 else if (curNode.getKind() == LabelKind) {
curNode=((LabelNode)curNode).getBody();
idx=idx - 1;
}
 else {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
}
;
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if (idx != sel.ops.length - 1) {
if (sel.ops[idx + 1] == NameSel) {
while (curNode.getKind() == LabelKind) {
curNode=((LabelNode)curNode).getBody();
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
}
;
if (curNode.getKind() == LetInKind) {
letInContext=((LetInNode)curNode).context;
mode=FindingOpName;
firstFindingOpName=false;
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
 else if (sel.ops[idx + 1] == ColonSel) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
;
prevMode=FindingSubExpr;
break;
default :
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
idx++;
}
if (curNode.getKind() == AssumeProveKind) {
if (isFact) {
return (AssumeProveNode)curNode;
}
;
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if (curNode.getKind() == NewSymbKind) {
if (isFact) {
return (LevelNode)curNode;
}
;
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if (expectedArity < 0) {
if ((prevMode != FindingOpName) || !((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ThmOrAssumpDefKind) || (curNode.getKind() == NumberedProofStepKind)|| ((curNode.getKind() == ModuleInstanceKind) && isDef))) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if ((curNode.getKind() == NumberedProofStepKind) && (((OpDefNode)curNode).getStepNode().getKind() != DefStepKind)) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
return (LevelNode)curNode;
}
;
if (curNode.getKind() == NumberedProofStepKind) {
errors.addError(sel.selSTN.getLocation(),isFact ? "String_Node_Str" : "String_Node_Str");
return nullOAN;
}
if (expectedArity > 0) {
int temp=params.size();
if (curNode.getKind() == OpArgKind) {
temp=temp + ((OpArgNode)curNode).getArity();
}
 else if (prevMode == FindingOpName) {
temp=temp + ((SymbolNode)curNode).getArity();
}
;
if (expectedArity != temp) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ temp+ "String_Node_Str");
return nullOAN;
}
;
}
;
ExprOrOpArgNode[] opDefArgArray=new ExprOrOpArgNode[opDefArgs.size()];
for (int i=0; i < opDefArgs.size(); i++) {
opDefArgArray[i]=(ExprOrOpArgNode)opDefArgs.elementAt(i);
}
;
if ((prevMode == FindingOpName) && (params.size() + substInPrefix.size() > 0)) {
FormalParamNode[] nodeParams=null;
if (curNode.getKind() == UserDefinedOpKind) {
nodeParams=((OpDefNode)curNode).getParams();
}
 else {
if (curNode.getKind() != ThmOrAssumpDefKind) {
errors.addAbort(sel.opsSTN[sel.opsSTN.length - 1].getLocation(),"String_Node_Str" + "String_Node_Str");
}
;
nodeParams=((ThmOrAssumpDefNode)curNode).getParams();
}
;
for (int i=0; i < opDefArgs.size(); i++) {
allArgs.addElement(opDefArgArray[i]);
}
;
ExprOrOpArgNode[] temp=new ExprOrOpArgNode[nodeParams.length];
for (int i=0; i < nodeParams.length; i++) {
FormalParamNode pm=nodeParams[i];
FormalParamNode newpm=new FormalParamNode(pm.getName(),pm.getArity(),pm.stn,null,cm);
ExprOrOpArgNode eoag=null;
if (pm.getArity() == 0) {
eoag=new OpApplNode(newpm,new ExprNode[0],sel.selSTN,cm);
}
 else {
eoag=new OpArgNode(newpm,sel.selSTN,cm);
}
;
temp[i]=eoag;
params.addElement(newpm);
}
;
SymbolNode curSymNode=(SymbolNode)curNode;
curNode=new OpApplNode(curSymNode,temp,sel.selSTN,cm);
}
;
if (curNode.getKind() == OpArgKind) {
OpArgNode curOpArgNode=(OpArgNode)curNode;
if (expectedArity == 0) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
int temp=params.size() + curOpArgNode.getArity();
if (expectedArity != temp) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ temp+ "String_Node_Str");
return nullOAN;
}
;
if (params.size() + substInPrefix.size() > 0) {
FormalParamNode[] temp2=new FormalParamNode[curOpArgNode.getArity()];
for (int i=0; i < temp2.length; i++) {
UniqueString temp3=UniqueString.uniqueStringOf("String_Node_Str" + i);
temp2[i]=new FormalParamNode(temp3,0,new SyntaxTreeNode(temp3),null,cm);
params.addElement(temp2[i]);
}
;
curNode=new OpApplNode(curOpArgNode.getOp(),opDefArgArray,sel.selSTN,cm);
}
;
}
;
if (!isFact && (((curNode.getKind() == ThmOrAssumpDefKind) && (((ThmOrAssumpDefNode)curNode).getBody().getKind() == AssumeProveKind)) || ((curNode.getKind() == LabelKind) && (((LabelNode)curNode).isAssumeProve)))) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if ((!isFact) && (curNode.getKind() == ThmOrAssumpDefKind) && (((ThmOrAssumpDefNode)curNode).getBody().getKind() == OpApplKind)) {
UniqueString opName=((OpApplNode)((ThmOrAssumpDefNode)curNode).getBody()).getOperator().getName();
String exprType=null;
if (opName == OP_qed) {
exprType="String_Node_Str";
}
 else if (opName == OP_pfcase) {
exprType="String_Node_Str";
}
 else if (opName == OP_have) {
exprType="String_Node_Str";
}
 else if (opName == OP_take) {
exprType="String_Node_Str";
}
 else if (opName == OP_pick) {
exprType="String_Node_Str";
}
 else if (opName == OP_witness) {
exprType="String_Node_Str";
}
 else if (opName == OP_suffices) {
exprType="String_Node_Str";
}
;
if (exprType != null) {
errors.addError(sel.selSTN.getLocation(),exprType + "String_Node_Str");
return nullOAN;
}
;
}
if ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ConstantDeclKind) || (curNode.getKind() == VariableDeclKind)|| (curNode.getKind() == FormalParamKind)|| (curNode.getKind() == BuiltInKind)|| (curNode.getKind() == BoundSymbolKind)|| (curNode.getKind() == ThmOrAssumpDefKind)|| (curNode.getKind() == NewConstantKind)|| (curNode.getKind() == NewVariableKind)|| (curNode.getKind() == NewStateKind)|| (curNode.getKind() == NewActionKind)|| (curNode.getKind() == NewTemporalKind)) {
SymbolNode curSymbolNode=(SymbolNode)curNode;
if (expectedArity > 0) {
return new OpArgNode(curSymbolNode,sel.selSTN,cm);
}
 else {
OpApplNode oan=new OpApplNode(curSymbolNode,opDefArgArray,sel.selSTN,cm);
oan.subExpressionOf=subExprOf;
return oan;
}
}
;
if (curNode.getKind() == OpArgKind) {
return (OpArgNode)curNode;
}
;
if (curNode.getKind() == ModuleInstanceKind) {
if (isFact || isDef) {
return (OpDefNode)curNode;
}
 else {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
}
;
if (!(curNode instanceof ExprNode)) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
;
ExprNode curExprNode=(ExprNode)curNode;
int temp=substInPrefix.size();
while (temp > 0) {
SubstInNode subst=(SubstInNode)substInPrefix.elementAt(temp - 1);
curExprNode=new SubstInNode(subst.stn,subst.getSubsts(),curExprNode,subst.getInstantiatingModule(),subst.getInstantiatedModule());
temp=temp - 1;
}
;
FormalParamNode[] paramsArray=new FormalParamNode[params.size()];
for (int i=0; i < params.size(); i++) {
paramsArray[i]=(FormalParamNode)params.elementAt(i);
}
;
OpDefNode newLambda=null;
if (paramsArray.length > 0) {
newLambda=new OpDefNode(S_lambda,UserDefinedOpKind,paramsArray,false,curExprNode,cm,null,sel.selSTN,true,null);
}
;
if (expectedArity > 0) {
if (paramsArray.length != expectedArity) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ paramsArray.length+ "String_Node_Str");
return nullOAN;
}
;
return new OpArgNode(newLambda,sel.selSTN,cm);
}
if (paramsArray.length != allArgs.size()) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + paramsArray.length + "String_Node_Str"+ allArgs.size()+ "String_Node_Str");
return nullOAN;
}
;
if (paramsArray.length == 0) {
ExprOrOpArgNode[] args=new ExprOrOpArgNode[1];
args[0]=curExprNode;
OpApplNode ln=new OpApplNode(OP_nop,args,sel.selSTN,cm);
ln.subExpressionOf=subExprOf;
return ln;
}
ExprOrOpArgNode[] allArgsArray=new ExprOrOpArgNode[allArgs.size()];
for (int i=0; i < allArgs.size(); i++) {
allArgsArray[i]=(ExprOrOpArgNode)allArgs.elementAt(i);
}
;
OpApplNode oan=new OpApplNode(newLambda,allArgsArray,sel.selSTN,cm);
oan.subExpressionOf=subExprOf;
return oan;
}

Fixed version (ground truth):
LevelNode selectorToNode(Selector sel,int expectedArity,boolean isFact,boolean isDef,ModuleNode cm) throws AbortException {
  Vector substInPrefix=new Vector();
  Vector params=new Vector();
  Vector allArgs=new Vector();
  UniqueString curName=null;
  UniqueString newName=null;
  SemanticNode curNode=null;
  SemanticNode newNode;
  int idx=0;
  int mode=FindingOpName;
  int prevMode=-999;
  Context letInContext=null;
  int opDefArityFound=0;
  Vector opDefArgs=new Vector();
  boolean firstFindingOpName=true;
  SymbolNode subExprOf=null;
  boolean inAPsuffices=false;
  while (idx < sel.args.length) {
    if ((((sel.ops[idx] != NameSel) && (sel.ops[idx] != NullSel)) || (expectedArity != 0)) && (sel.args[idx] != null)) {
      errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + selectorItemToString(sel,idx) + "String_Node_Str");
      return nullOAN;
    }
    if ((sel.args[idx] != null) && (sel.args[idx].getKind() != N_OpArgs)) {
      errors.addAbort(sel.args[idx].getLocation(),"String_Node_Str");
    }
    ;
switch (mode) {
case FindingOpName:
      SymbolNode newSymbolNode=null;
    Vector tempArgs=new Vector();
  while (newSymbolNode == null && idx < sel.args.length) {
    if (sel.ops[idx] == NameSel) {
      if (curName == null) {
        newName=Operators.resolveSynonym(sel.opNames[idx]);
      }
 else {
        newName=UniqueString.uniqueStringOf(curName.toString() + "String_Node_Str" + Operators.resolveSynonym(sel.opNames[idx]).toString());
      }
      ;
    }
 else {
      newName=null;
    }
    ;
    if ((curName == null) && (sel.ops[idx] != NameSel)) {
      if (idx == 0) {
        errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx] + "String_Node_Str");
        return nullOAN;
      }
 else {
        errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
      }
      ;
    }
    ;
    if (newName != null) {
      if (letInContext == null) {
        newSymbolNode=symbolTable.resolveSymbol(newName);
      }
 else {
        newSymbolNode=letInContext.getSymbol(newName);
      }
      ;
    }
    ;
    if (newSymbolNode == null) {
      curName=newName;
      if (sel.args[idx] != null) {
        int numOfOpArgs=(sel.args[idx].heirs().length - 1) / 2;
        for (int i=0; i < numOfOpArgs; i++) {
          tempArgs.addElement(sel.args[idx].heirs()[2 * i + 1]);
        }
      }
      idx++;
    }
  }
if (newSymbolNode == null) {
  int eidx=(idx < sel.args.length) ? idx : (sel.args.length - 1);
  errors.addError(sel.opsSTN[eidx].getLocation(),"String_Node_Str" + selectorItemToString(sel,eidx) + "String_Node_Str");
  return nullOAN;
}
;
if (newSymbolNode.getKind() == ModuleKind) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
curNode=newSymbolNode;
SymbolNode curSymbolNode=newSymbolNode;
curName=newName;
switch (curSymbolNode.getKind()) {
case ConstantDeclKind:
case VariableDeclKind:
case FormalParamKind:
case BuiltInKind:
case NewConstantKind:
case NewVariableKind:
case NewStateKind:
case NewActionKind:
case NewTemporalKind:
case NumberedProofStepKind:
if (idx != 0) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
 else if (sel.ops.length != 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
case UserDefinedOpKind:
case ThmOrAssumpDefKind:
case ModuleInstanceKind:
int nodeArity=curSymbolNode.getArity();
if (expectedArity == 0) {
SyntaxTreeNode opArgs=sel.args[idx];
int numOfOpArgs=0;
if (opArgs != null) {
numOfOpArgs=(opArgs.heirs().length - 1) / 2;
for (int i=0; i < numOfOpArgs; i++) {
tempArgs.addElement(sel.args[idx].heirs()[2 * i + 1]);
}
;
}
;
if (opDefArityFound + tempArgs.size() != nodeArity) {
errors.addError((opArgs == null) ? sel.selSTN.getLocation() : sel.args[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str"+ (nodeArity - opDefArityFound)+ "String_Node_Str");
return nullOAN;
}
;
ExprOrOpArgNode[] opArgNodes=new ExprOrOpArgNode[tempArgs.size()];
for (int i=0; i < tempArgs.size(); i++) {
opDefArgs.addElement(generateExprOrOpArg(curSymbolNode,sel.opsSTN[idx],i + opDefArityFound,(TreeNode)tempArgs.elementAt(i),cm));
}
;
}
 else {
if (expectedArity > 0) {
}
}
;
opDefArityFound=nodeArity;
if (curNode.getKind() == ModuleInstanceKind) {
if ((idx == sel.ops.length - 1) && !(isDef || isFact)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
;
}
 else {
if ((curNode.getKind() == UserDefinedOpKind) && (!((OpDefNode)curNode).isDefined) && (sel.ops.length != 1)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + curName.toString() + "String_Node_Str");
return nullOAN;
}
;
if (firstFindingOpName && ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ThmOrAssumpDefKind))) {
subExprOf=(SymbolNode)curNode;
}
if (idx != sel.ops.length - 1) {
FormalParamNode[] opParams;
if (curNode.getKind() == UserDefinedOpKind) {
opParams=((OpDefNode)curNode).getParams();
newNode=((OpDefNode)curNode).getBody();
}
 else {
opParams=((ThmOrAssumpDefNode)curNode).getParams();
newNode=((ThmOrAssumpDefNode)curNode).getBody();
}
;
for (int i=0; i < opParams.length; i++) {
params.addElement(opParams[i]);
}
;
curName=null;
if (sel.ops[idx + 1] == NameSel) {
mode=FollowingLabels;
}
 else {
mode=FindingSubExpr;
}
;
for (int i=0; i < opDefArgs.size(); i++) {
allArgs.addElement(opDefArgs.elementAt(i));
}
;
opDefArityFound=0;
opDefArgs=new Vector();
if (newNode != null) {
while (newNode.getKind() == SubstInKind) {
substInPrefix.addElement(newNode);
newNode=((SubstInNode)newNode).getBody();
}
;
while (newNode.getKind() == APSubstInKind) {
substInPrefix.addElement(newNode);
newNode=((APSubstInNode)newNode).getBody();
}
;
}
;
if (mode == FindingSubExpr) {
curNode=newNode;
}
;
}
}
prevMode=FindingOpName;
break;
default :
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
break;
}
;
break;
case FollowingLabels:
if (((prevMode == FindingOpName) && (curNode.getKind() != UserDefinedOpKind) && (curNode.getKind() != ThmOrAssumpDefKind)) || ((prevMode != FindingOpName) && (curNode.getKind() != LabelKind))) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
;
LabelNode newLabelNode=((OpDefOrLabelNode)curNode).getLabel(sel.opNames[idx]);
if (newLabelNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
curNode=newLabelNode;
if (illegalLabelRef(newLabelNode,sel.opsSTN[idx])) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str"+ "String_Node_Str");
return nullOAN;
}
;
if (expectedArity == 0) {
if (newLabelNode.getArity() != ((sel.args[idx] == null) ? 0 : (sel.args[idx].heirs().length - 1) / 2)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < newLabelNode.getArity(); i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
for (int i=0; i < newLabelNode.getArity(); i++) {
FormalParamNode pdecl=newLabelNode.params[i];
params.addElement(pdecl);
}
;
if ((idx < sel.ops.length - 1) && (sel.ops[idx + 1] != NameSel)) {
mode=FindingSubExpr;
}
;
if ((mode == FindingSubExpr) || (idx == sel.ops.length)) {
curNode=newLabelNode.getBody();
}
;
prevMode=FollowingLabels;
break;
case FindingSubExpr:
if (sel.ops[idx] == ColonSel) {
if ((prevMode == FindingSubExpr) || !(((idx == sel.ops.length - 1) && (prevMode == FindingOpName)) || ((idx < sel.ops.length - 1) && (sel.ops[idx + 1] == NameSel)))) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
}
 else if (curNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
 else if (curNode.getKind() == LetInKind) {
if (ArgNum(sel.ops[idx],1) == 1) {
curNode=((LetInNode)curNode).getBody();
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
}
 else if (curNode.getKind() == OpApplKind) {
OpApplNode curOpApplNode=(OpApplNode)curNode;
ExprOrOpArgNode[] curArgs=curOpApplNode.getArgs();
SymbolNode opNode=curOpApplNode.getOperator();
if ((opNode.getKind() == FormalParamKind) || (opNode.getKind() == ConstantDeclKind) || (opNode.getKind() == UserDefinedOpKind)) {
int temp=ArgNum(sel.ops[idx],opNode.getArity());
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curArgs[temp - 1];
}
 else if (opNode.getKind() == BuiltInKind) {
if ((opNode.getName() == OP_rc) || (opNode.getName() == OP_sor)) {
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curOpApplNode=(OpApplNode)curArgs[temp - 1];
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
curNode=curOpApplNode.getArgs()[1];
}
 else if (opNode.getName() == OP_case) {
if (idx == sel.ops.length - 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curOpApplNode=(OpApplNode)curArgs[temp - 1];
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
idx=idx + 1;
temp=ArgNum(sel.ops[idx],2);
if (temp == -1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
curNode=curOpApplNode.getArgs()[temp - 1];
if (curNode == null) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
}
 else if (opNode.getName() == OP_exc) {
int temp=ArgNum(sel.ops[idx],curArgs.length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
if (temp > 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
curNode=curArgs[temp - 1];
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if (temp > 1) {
curOpApplNode=(OpApplNode)curNode;
if (curOpApplNode.getOperator().getName() != OP_pair) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str");
}
;
curNode=curOpApplNode.getArgs()[1];
}
;
}
 else {
if ((curOpApplNode.getNumberOfBoundedBoundSymbols() == 0) && ((curOpApplNode.getUnbdedQuantSymbols() == null) || (curOpApplNode.getUnbdedQuantSymbols().length == 0))) {
int temp=ArgNum(sel.ops[idx],curOpApplNode.getArgs().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curOpApplNode.getArgs()[temp - 1];
}
 else {
if ((sel.ops[idx] == NullSel) || (sel.ops[idx] == AtSel)) {
FormalParamNode[] temp;
if (curOpApplNode.getNumberOfBoundedBoundSymbols() > 0) {
FormalParamNode[][] symbs=curOpApplNode.getBdedQuantSymbolLists();
int numSymbs=0;
for (int i=0; i < symbs.length; i++) {
numSymbs=numSymbs + symbs[i].length;
}
;
temp=new FormalParamNode[numSymbs];
int k=0;
for (int i=0; i < symbs.length; i++) {
for (int j=0; j < symbs[i].length; j++) {
temp[k]=symbs[i][j];
k++;
}
;
}
;
}
 else {
temp=curOpApplNode.getUnbdedQuantSymbols();
}
;
for (int i=0; i < temp.length; i++) {
params.addElement(temp[i]);
}
;
if (sel.ops[idx] == NullSel) {
int numOfArgs=(sel.args[idx].heirs().length - 1) / 2;
if (temp.length != numOfArgs) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + numOfArgs + "String_Node_Str"+ temp.length+ "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < numOfArgs; i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
curNode=curOpApplNode.getArgs()[0];
}
 else {
int temp=ArgNum(sel.ops[idx],curOpApplNode.getBdedQuantBounds().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
curNode=curOpApplNode.getBdedQuantBounds()[temp - 1];
}
;
}
;
}
;
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + selectorItemToString(sel,idx) + "String_Node_Str");
return nullOAN;
}
;
}
 else if (curNode.getKind() == AssumeProveKind) {
AssumeProveNode curAPNode=(AssumeProveNode)curNode;
if ((curAPNode.isSuffices()) && (!inAPsuffices)) {
if (ArgNum(sel.ops[idx],1) != 1) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
inAPsuffices=true;
}
 else {
inAPsuffices=false;
int temp=ArgNum(sel.ops[idx],1 + curAPNode.getAssumes().length);
if (temp == -1) {
reportSelectorError(sel,idx);
return nullOAN;
}
;
if (illegalAPPosRef(curAPNode,temp)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
return nullOAN;
}
;
if (temp <= curAPNode.getAssumes().length) {
curNode=curAPNode.getAssumes()[temp - 1];
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if ((curNode.getKind() == NewSymbKind) && (idx != sel.args.length - 1)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
 else {
curNode=curAPNode.getProve();
}
;
}
}
 else if (curNode.getKind() == OpArgKind) {
SymbolNode opNode=((OpArgNode)curNode).getOp();
if ((opNode.getKind() != UserDefinedOpKind) || (opNode.getName() != S_lambda)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
;
OpDefNode opDefOpNode=(OpDefNode)opNode;
if ((sel.ops[idx] != NullSel) && (sel.ops[idx] != AtSel)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + sel.opNames[idx].toString() + "String_Node_Str");
return nullOAN;
}
;
if (sel.ops[idx] == NullSel) {
int numOfArgs=(sel.args[idx].heirs().length - 1) / 2;
if (opDefOpNode.getArity() != numOfArgs) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str" + numOfArgs + "String_Node_Str"+ opDefOpNode.getArity()+ "String_Node_Str");
return nullOAN;
}
;
for (int i=0; i < numOfArgs; i++) {
allArgs.addElement(generateExpression(sel.args[idx].heirs()[2 * i + 1],cm));
}
;
}
;
for (int i=0; i < opDefOpNode.getArity(); i++) {
params.addElement(opDefOpNode.getParams()[i]);
}
;
curNode=opDefOpNode.getBody();
}
 else if ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == BuiltInKind) || (curNode.getKind() == NumberedProofStepKind)) {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
}
 else if ((curNode.getKind() == AtNodeKind) || (curNode.getKind() == DecimalKind) || (curNode.getKind() == NumeralKind)|| (curNode.getKind() == StringKind)|| (curNode.getKind() == FormalParamKind)|| (curNode.getKind() == ConstantDeclKind)|| (curNode.getKind() == VariableDeclKind)|| (curNode.getKind() == BoundSymbolKind)) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
 else if (curNode.getKind() == LabelKind) {
curNode=((LabelNode)curNode).getBody();
idx=idx - 1;
}
 else {
errors.addAbort(sel.opsSTN[idx].getLocation(),"String_Node_Str" + "String_Node_Str");
}
;
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
if (idx != sel.ops.length - 1) {
if (sel.ops[idx + 1] == NameSel) {
while (curNode.getKind() == LabelKind) {
curNode=((LabelNode)curNode).getBody();
if (isNullSelection(curNode,sel,idx)) {
return nullOAN;
}
;
}
;
if (curNode.getKind() == LetInKind) {
letInContext=((LetInNode)curNode).context;
mode=FindingOpName;
firstFindingOpName=false;
}
 else {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
 else if (sel.ops[idx + 1] == ColonSel) {
errors.addError(sel.opsSTN[idx].getLocation(),"String_Node_Str");
return nullOAN;
}
}
;
prevMode=FindingSubExpr;
break;
default :
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
idx++;
}
if (curNode.getKind() == AssumeProveKind) {
if (isFact) {
return (AssumeProveNode)curNode;
}
;
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if (curNode.getKind() == NewSymbKind) {
if (isFact) {
return (LevelNode)curNode;
}
;
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if (expectedArity < 0) {
if ((prevMode != FindingOpName) || !((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ThmOrAssumpDefKind) || (curNode.getKind() == NumberedProofStepKind)|| ((curNode.getKind() == ModuleInstanceKind) && isDef))) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if ((curNode.getKind() == NumberedProofStepKind) && (((OpDefNode)curNode).getStepNode().getKind() != DefStepKind)) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
return (LevelNode)curNode;
}
;
if (curNode.getKind() == NumberedProofStepKind) {
errors.addError(sel.selSTN.getLocation(),isFact ? "String_Node_Str" : "String_Node_Str");
return nullOAN;
}
if (expectedArity > 0) {
int temp=params.size();
if (curNode.getKind() == OpArgKind) {
temp=temp + ((OpArgNode)curNode).getArity();
}
 else if (prevMode == FindingOpName) {
temp=temp + ((SymbolNode)curNode).getArity();
}
;
if (expectedArity != temp) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ temp+ "String_Node_Str");
return nullOAN;
}
;
}
;
ExprOrOpArgNode[] opDefArgArray=new ExprOrOpArgNode[opDefArgs.size()];
for (int i=0; i < opDefArgs.size(); i++) {
opDefArgArray[i]=(ExprOrOpArgNode)opDefArgs.elementAt(i);
}
;
if ((prevMode == FindingOpName) && (params.size() + substInPrefix.size() > 0)) {
FormalParamNode[] nodeParams=null;
if (curNode.getKind() == UserDefinedOpKind) {
nodeParams=((OpDefNode)curNode).getParams();
}
 else {
if (curNode.getKind() != ThmOrAssumpDefKind) {
errors.addAbort(sel.opsSTN[sel.opsSTN.length - 1].getLocation(),"String_Node_Str" + "String_Node_Str");
}
;
nodeParams=((ThmOrAssumpDefNode)curNode).getParams();
}
;
for (int i=0; i < opDefArgs.size(); i++) {
allArgs.addElement(opDefArgArray[i]);
}
;
ExprOrOpArgNode[] temp=new ExprOrOpArgNode[nodeParams.length];
for (int i=0; i < nodeParams.length; i++) {
FormalParamNode pm=nodeParams[i];
FormalParamNode newpm=new FormalParamNode(pm.getName(),pm.getArity(),pm.stn,null,cm);
ExprOrOpArgNode eoag=null;
if (pm.getArity() == 0) {
eoag=new OpApplNode(newpm,new ExprNode[0],sel.selSTN,cm);
}
 else {
eoag=new OpArgNode(newpm,sel.selSTN,cm);
}
;
temp[i]=eoag;
params.addElement(newpm);
}
;
SymbolNode curSymNode=(SymbolNode)curNode;
curNode=new OpApplNode(curSymNode,temp,sel.selSTN,cm);
}
;
if (curNode.getKind() == OpArgKind) {
OpArgNode curOpArgNode=(OpArgNode)curNode;
if (expectedArity == 0) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
int temp=params.size() + curOpArgNode.getArity();
if (expectedArity != temp) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ temp+ "String_Node_Str");
return nullOAN;
}
;
if (params.size() + substInPrefix.size() > 0) {
FormalParamNode[] temp2=new FormalParamNode[curOpArgNode.getArity()];
for (int i=0; i < temp2.length; i++) {
UniqueString temp3=UniqueString.uniqueStringOf("String_Node_Str" + i);
temp2[i]=new FormalParamNode(temp3,0,new SyntaxTreeNode(temp3),null,cm);
params.addElement(temp2[i]);
}
;
curNode=new OpApplNode(curOpArgNode.getOp(),opDefArgArray,sel.selSTN,cm);
}
;
}
;
if (!isFact && (((curNode.getKind() == ThmOrAssumpDefKind) && (((ThmOrAssumpDefNode)curNode).getBody().getKind() == AssumeProveKind)) || ((curNode.getKind() == LabelKind) && (((LabelNode)curNode).isAssumeProve)))) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
;
if ((!isFact) && (curNode.getKind() == ThmOrAssumpDefKind) && (((ThmOrAssumpDefNode)curNode).getBody().getKind() == OpApplKind)) {
UniqueString opName=((OpApplNode)((ThmOrAssumpDefNode)curNode).getBody()).getOperator().getName();
String exprType=null;
if (opName == OP_qed) {
exprType="String_Node_Str";
}
 else if (opName == OP_pfcase) {
exprType="String_Node_Str";
}
 else if (opName == OP_have) {
exprType="String_Node_Str";
}
 else if (opName == OP_take) {
exprType="String_Node_Str";
}
 else if (opName == OP_pick) {
exprType="String_Node_Str";
}
 else if (opName == OP_witness) {
exprType="String_Node_Str";
}
 else if (opName == OP_suffices) {
exprType="String_Node_Str";
}
;
if (exprType != null) {
errors.addError(sel.selSTN.getLocation(),exprType + "String_Node_Str");
return nullOAN;
}
;
}
if ((curNode.getKind() == UserDefinedOpKind) || (curNode.getKind() == ConstantDeclKind) || (curNode.getKind() == VariableDeclKind)|| (curNode.getKind() == FormalParamKind)|| (curNode.getKind() == BuiltInKind)|| (curNode.getKind() == BoundSymbolKind)|| (curNode.getKind() == ThmOrAssumpDefKind)|| (curNode.getKind() == NewConstantKind)|| (curNode.getKind() == NewVariableKind)|| (curNode.getKind() == NewStateKind)|| (curNode.getKind() == NewActionKind)|| (curNode.getKind() == NewTemporalKind)) {
SymbolNode curSymbolNode=(SymbolNode)curNode;
if (expectedArity > 0) {
return new OpArgNode(curSymbolNode,sel.selSTN,cm);
}
 else {
OpApplNode oan=new OpApplNode(curSymbolNode,opDefArgArray,sel.selSTN,cm);
oan.subExpressionOf=subExprOf;
return oan;
}
}
;
if (curNode.getKind() == OpArgKind) {
return (OpArgNode)curNode;
}
;
if (curNode.getKind() == ModuleInstanceKind) {
if (isFact || isDef) {
return (OpDefNode)curNode;
}
 else {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str");
return nullOAN;
}
}
;
if (!(curNode instanceof ExprNode)) {
errors.addAbort(sel.selSTN.getLocation(),"String_Node_Str");
}
;
ExprNode curExprNode=(ExprNode)curNode;
int temp=substInPrefix.size();
while (temp > 0) {
Object substOb=substInPrefix.elementAt(temp - 1);
if (substOb instanceof SubstInNode) {
SubstInNode subst=(SubstInNode)substOb;
curExprNode=new SubstInNode(subst.stn,subst.getSubsts(),curExprNode,subst.getInstantiatingModule(),subst.getInstantiatedModule());
}
 else {
APSubstInNode subst=(APSubstInNode)substOb;
curExprNode=new SubstInNode(subst.stn,subst.getSubsts(),curExprNode,subst.getInstantiatingModule(),subst.getInstantiatedModule());
}
temp=temp - 1;
}
;
FormalParamNode[] paramsArray=new FormalParamNode[params.size()];
for (int i=0; i < params.size(); i++) {
paramsArray[i]=(FormalParamNode)params.elementAt(i);
}
;
OpDefNode newLambda=null;
if (paramsArray.length > 0) {
newLambda=new OpDefNode(S_lambda,UserDefinedOpKind,paramsArray,false,curExprNode,cm,null,sel.selSTN,true,null);
}
;
if (expectedArity > 0) {
if (paramsArray.length != expectedArity) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + expectedArity + "String_Node_Str"+ paramsArray.length+ "String_Node_Str");
return nullOAN;
}
;
return new OpArgNode(newLambda,sel.selSTN,cm);
}
if (paramsArray.length != allArgs.size()) {
errors.addError(sel.selSTN.getLocation(),"String_Node_Str" + paramsArray.length + "String_Node_Str"+ allArgs.size()+ "String_Node_Str");
return nullOAN;
}
;
if (paramsArray.length == 0) {
ExprOrOpArgNode[] args=new ExprOrOpArgNode[1];
args[0]=curExprNode;
OpApplNode ln=new OpApplNode(OP_nop,args,sel.selSTN,cm);
ln.subExpressionOf=subExprOf;
return ln;
}
ExprOrOpArgNode[] allArgsArray=new ExprOrOpArgNode[allArgs.size()];
for (int i=0; i < allArgs.size(); i++) {
allArgsArray[i]=(ExprOrOpArgNode)allArgs.elementAt(i);
}
;
OpApplNode oan=new OpApplNode(newLambda,allArgsArray,sel.selSTN,cm);
oan.subExpressionOf=subExprOf;
return oan;
}