Program: 61555
Project: 61555
Buggy source:
private GraphTargetItem command(TypeItem thisType,String pkg,Reference<Boolean> needsActivation,List<String> importedClasses,List<Integer> openedNamespaces,Stack<Loop> loops,Map<Loop,String> loopLabels,HashMap<String,Integer> registerVars,boolean inFunction,boolean inMethod,int forinlevel,boolean mustBeCommand,List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
  LexBufferer buf=new LexBufferer();
  lexer.addListener(buf);
  GraphTargetItem ret=null;
  if (debugMode) {
    System.out.println("String_Node_Str");
  }
  ParsedSymbol s=lex();
  if (s.type == SymbolType.EOF) {
    return null;
  }
  String loopLabel=null;
  if (s.group == SymbolGroup.IDENTIFIER) {
    ParsedSymbol sc=lex();
    if (sc.type == SymbolType.COLON) {
      loopLabel=s.value.toString();
      s=lex();
    }
 else {
      lexer.pushback(sc);
    }
  }
  if (s.type == SymbolType.DEFAULT) {
    ParsedSymbol sx=lex();
    if (sx.group != SymbolGroup.IDENTIFIER) {
      lexer.pushback(sx);
    }
 else {
      if (!sx.value.equals("String_Node_Str")) {
        lexer.pushback(sx);
      }
 else {
        expectedType(SymbolType.NAMESPACE);
        expectedType(SymbolType.ASSIGN);
        GraphTargetItem ns=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
        ret=new DefaultXMLNamespace(null,ns);
      }
    }
  }
  if (ret == null) {
switch (s.type) {
case USE:
      expectedType(SymbolType.NAMESPACE);
    GraphTargetItem ns=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
  openedNamespaces.add(abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE,abc.constants.getStringId(ns.toString(),true)),0,true));
break;
case WITH:
needsActivation.setVal(true);
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem wvar=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
if (!isNameOrProp(wvar)) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
List<AssignableAVM2Item> withVars=new ArrayList<>();
List<GraphTargetItem> wcmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,withVars);
variables.addAll(withVars);
for (AssignableAVM2Item a : withVars) {
if (a instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ua=(UnresolvedAVM2Item)a;
ua.scopeStack.add(0,wvar);
}
}
expectedType(SymbolType.CURLY_CLOSE);
ret=new WithAVM2Item(null,wvar,wcmd);
((WithAVM2Item)ret).subvariables=withVars;
break;
case FUNCTION:
s=lexer.lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER);
needsActivation.setVal(true);
ret=(function(pkg,false,needsActivation,importedClasses,0,thisType,openedNamespaces,s.value.toString(),false,variables));
break;
case VAR:
s=lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER);
String varIdentifier=s.value.toString();
s=lex();
GraphTargetItem type;
if (s.type == SymbolType.COLON) {
type=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
s=lex();
}
 else {
type=new UnboundedTypeItem();
}
if (s.type == SymbolType.ASSIGN) {
GraphTargetItem varval=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
ret=new NameAVM2Item(type,lexer.yyline(),varIdentifier,varval,true,openedNamespaces);
variables.add((NameAVM2Item)ret);
}
 else {
ret=new NameAVM2Item(type,lexer.yyline(),varIdentifier,null,true,openedNamespaces);
variables.add((NameAVM2Item)ret);
lexer.pushback(s);
}
break;
case CURLY_OPEN:
ret=new BlockItem(null,commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.CURLY_CLOSE);
break;
case SUPER:
ParsedSymbol ss2=lex();
if (ss2.type == SymbolType.PARENT_OPEN) {
List<GraphTargetItem> args=call(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,variables);
ret=new ConstructSuperAVM2Item(null,new LocalRegAVM2Item(null,0,null),args);
}
 else {
lexer.pushback(ss2);
lexer.pushback(s);
}
break;
case IF:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem ifExpr=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
GraphTargetItem onTrue=command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables);
List<GraphTargetItem> onTrueList=new ArrayList<>();
onTrueList.add(onTrue);
s=lex();
List<GraphTargetItem> onFalseList=null;
if (s.type == SymbolType.ELSE) {
onFalseList=new ArrayList<>();
onFalseList.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
}
 else {
lexer.pushback(s);
}
ret=new IfItem(null,ifExpr,onTrueList,onFalseList);
break;
case WHILE:
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> whileExpr=new ArrayList<>();
whileExpr.add(commaExpression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> whileBody=new ArrayList<>();
Loop wloop=new Loop(uniqId(),null,null);
if (loopLabel != null) {
loopLabels.put(wloop,loopLabel);
}
loops.push(wloop);
whileBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
ret=new WhileItem(null,wloop,whileExpr,whileBody);
break;
case DO:
List<GraphTargetItem> doBody=new ArrayList<>();
Loop dloop=new Loop(uniqId(),null,null);
loops.push(dloop);
if (loopLabel != null) {
loopLabels.put(dloop,loopLabel);
}
doBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
expectedType(SymbolType.WHILE);
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> doExpr=new ArrayList<>();
doExpr.add(commaExpression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.PARENT_CLOSE);
ret=new DoWhileItem(null,dloop,doBody,doExpr);
break;
case FOR:
s=lex();
boolean forin=false;
boolean each=false;
GraphTargetItem collection=null;
if (s.type == SymbolType.EACH) {
each=true;
forin=true;
s=lex();
}
expected(s,lexer.yyline(),SymbolType.PARENT_OPEN);
GraphTargetItem firstCommand=command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,false,variables);
if (firstCommand instanceof NameAVM2Item) {
NameAVM2Item nai=(NameAVM2Item)firstCommand;
if (nai.isDefinition() && nai.getAssignedValue() == null) {
firstCommand=expression1(firstCommand,firstCommand.getPrecedence(),thisType,pkg,needsActivation,importedClasses,openedNamespaces,true,registerVars,inFunction,inMethod,true,variables);
}
}
InAVM2Item inexpr=null;
if (firstCommand instanceof InAVM2Item) {
forin=true;
inexpr=(InAVM2Item)firstCommand;
}
 else {
if (forin) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
Loop floop=new Loop(uniqId(),null,null);
loops.push(floop);
if (loopLabel != null) {
loopLabels.put(floop,loopLabel);
}
List<GraphTargetItem> forFinalCommands=new ArrayList<>();
GraphTargetItem forExpr=null;
List<GraphTargetItem> forFirstCommands=new ArrayList<>();
if (!forin) {
if (firstCommand != null) {
forFirstCommands.add(firstCommand);
}
forExpr=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.SEMICOLON);
forFinalCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
}
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> forBody=new ArrayList<>();
forBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forin ? forinlevel + 1 : forinlevel,true,variables));
if (forin) {
if (each) {
ret=new ForEachInAVM2Item(null,floop,inexpr,forBody);
}
 else {
ret=new ForInAVM2Item(null,floop,inexpr,forBody);
}
}
 else {
ret=new ForItem(null,floop,forFirstCommands,forExpr,forFinalCommands,forBody);
}
break;
case SWITCH:
Loop sloop=new Loop(-uniqId(),null,null);
loops.push(sloop);
if (loopLabel != null) {
loopLabels.put(sloop,loopLabel);
}
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem switchExpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
s=lex();
int exprReg=0;
for (int i=0; i < 256; i++) {
if (!registerVars.containsValue(i)) {
registerVars.put("String_Node_Str" + uniqId(),i);
exprReg=i;
break;
}
}
List<List<ActionIf>> caseIfs=new ArrayList<>();
List<List<GraphTargetItem>> caseCmds=new ArrayList<>();
List<GraphTargetItem> caseExprsAll=new ArrayList<>();
List<Integer> valueMapping=new ArrayList<>();
int pos=0;
while (s.type == SymbolType.CASE) {
List<GraphTargetItem> caseExprs=new ArrayList<>();
while (s.type == SymbolType.CASE) {
GraphTargetItem curCaseExpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
caseExprs.add(curCaseExpr);
expectedType(SymbolType.COLON);
s=lex();
caseExprsAll.add(curCaseExpr);
valueMapping.add(pos);
}
pos++;
lexer.pushback(s);
List<GraphTargetItem> caseCmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables);
caseCmds.add(caseCmd);
s=lex();
}
List<GraphTargetItem> defCmd=new ArrayList<>();
if (s.type == SymbolType.DEFAULT) {
expectedType(SymbolType.COLON);
defCmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables);
s=lexer.lex();
}
expected(s,lexer.yyline(),SymbolType.CURLY_CLOSE);
ret=new SwitchItem(null,sloop,switchExpr,caseExprsAll,caseCmds,defCmd,valueMapping);
break;
case BREAK:
s=lex();
long bloopId=0;
if (loops.isEmpty()) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
if (s.group == SymbolGroup.IDENTIFIER) {
String breakLabel=s.value.toString();
for (Loop l : loops) {
if (breakLabel.equals(loopLabels.get(l))) {
bloopId=l.id;
break;
}
}
if (bloopId == 0) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
 else {
lexer.pushback(s);
bloopId=loops.peek().id;
}
ret=new BreakItem(null,bloopId);
break;
case CONTINUE:
s=lex();
long cloopId=0;
if (loops.isEmpty()) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
if (s.group == SymbolGroup.IDENTIFIER) {
String continueLabel=s.value.toString();
for (Loop l : loops) {
if (l.id < 0) {
continue;
}
if (continueLabel.equals(loopLabels.get(l))) {
cloopId=l.id;
break;
}
}
if (cloopId == -1) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
 else {
lexer.pushback(s);
for (int i=loops.size() - 1; i >= 0; i--) {
if (loops.get(i).id >= 0) {
cloopId=loops.get(i).id;
break;
}
}
if (cloopId <= 0) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
ret=new ContinueItem(null,cloopId);
break;
case RETURN:
GraphTargetItem retexpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,true,registerVars,inFunction,inMethod,true,variables);
if (retexpr == null) {
ret=new ReturnVoidAVM2Item(null);
}
 else {
ret=new ReturnValueAVM2Item(null,retexpr);
}
break;
case TRY:
needsActivation.setVal(true);
List<GraphTargetItem> tryCommands=new ArrayList<>();
tryCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
s=lex();
boolean found=false;
List<List<GraphTargetItem>> catchCommands=new ArrayList<>();
List<NameAVM2Item> catchExceptions=new ArrayList<>();
int varCnt=variables.size();
List<List<AssignableAVM2Item>> catchesVars=new ArrayList<>();
while (s.type == SymbolType.CATCH) {
expectedType(SymbolType.PARENT_OPEN);
s=lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER,SymbolType.THIS,SymbolType.SUPER,SymbolType.STRING_OP);
String enamestr=s.value.toString();
expectedType(SymbolType.COLON);
GraphTargetItem etype=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
NameAVM2Item e=new NameAVM2Item(etype,lexer.yyline(),enamestr,new ExceptionAVM2Item(null),true,openedNamespaces);
variables.add(e);
catchExceptions.add(e);
e.setSlotNumber(1);
e.setSlotScope(Integer.MAX_VALUE);
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> cc=new ArrayList<>();
List<AssignableAVM2Item> catchVars=new ArrayList<>();
cc.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,catchVars));
catchesVars.add(catchVars);
variables.addAll(catchVars);
for (AssignableAVM2Item a : catchVars) {
if (a instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ui=(UnresolvedAVM2Item)a;
if (ui.getVariableName().equals(e.getVariableName())) {
try {
ui.resolve(null,new ArrayList<GraphTargetItem>(),new ArrayList<String>(),abc,otherABCs,new ArrayList<MethodBody>(),variables);
}
 catch (CompilationException ex) {
}
ui.setSlotNumber(e.getSlotNumber());
ui.setSlotScope(e.getSlotScope());
}
}
}
catchCommands.add(cc);
s=lex();
found=true;
}
for (int i=varCnt; i < variables.size(); i++) {
AssignableAVM2Item av=variables.get(i);
if (av instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ui=(UnresolvedAVM2Item)av;
for (NameAVM2Item e : catchExceptions) {
if (ui.getVariableName().equals(e.getVariableName())) {
try {
ui.resolve(null,new ArrayList<GraphTargetItem>(),new ArrayList<String>(),abc,otherABCs,new ArrayList<MethodBody>(),variables);
}
 catch (CompilationException ex) {
}
ui.setSlotNumber(e.getSlotNumber());
ui.setSlotScope(e.getSlotScope());
}
}
}
}
List<GraphTargetItem> finallyCommands=null;
if (s.type == SymbolType.FINALLY) {
finallyCommands=new ArrayList<>();
finallyCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
found=true;
s=lex();
}
if (!found) {
expected(s,lexer.yyline(),SymbolType.CATCH,SymbolType.FINALLY);
}
lexer.pushback(s);
TryAVM2Item tai=new TryAVM2Item(tryCommands,null,catchCommands,finallyCommands);
tai.catchVariables=catchesVars;
tai.catchExceptions2=catchExceptions;
ret=tai;
break;
case THROW:
ret=new ThrowAVM2Item(null,expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
break;
default :
GraphTargetItem valcmd=expressionCommands(s,registerVars,inFunction,inMethod,forinlevel,variables);
if (valcmd != null) {
ret=valcmd;
break;
}
if (s.type == SymbolType.SEMICOLON) {
return null;
}
lexer.pushback(s);
ret=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
if (debugMode) {
System.out.println("String_Node_Str");
}
}
}
if (debugMode) {
System.out.println("String_Node_Str");
}
lexer.removeListener(buf);
if (ret == null) {
buf.pushAllBack(lexer);
ret=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
}
s=lex();
if ((s != null) && (s.type != SymbolType.SEMICOLON)) {
lexer.pushback(s);
}
return ret;
}

Fixed version (ground truth):
private GraphTargetItem command(TypeItem thisType,String pkg,Reference<Boolean> needsActivation,List<String> importedClasses,List<Integer> openedNamespaces,Stack<Loop> loops,Map<Loop,String> loopLabels,HashMap<String,Integer> registerVars,boolean inFunction,boolean inMethod,int forinlevel,boolean mustBeCommand,List<AssignableAVM2Item> variables) throws IOException, AVM2ParseException {
  LexBufferer buf=new LexBufferer();
  lexer.addListener(buf);
  GraphTargetItem ret=null;
  if (debugMode) {
    System.out.println("String_Node_Str");
  }
  ParsedSymbol s=lex();
  if (s.type == SymbolType.EOF) {
    return null;
  }
  String loopLabel=null;
  if (s.group == SymbolGroup.IDENTIFIER) {
    ParsedSymbol sc=lex();
    if (sc.type == SymbolType.COLON) {
      loopLabel=s.value.toString();
      s=lex();
    }
 else {
      lexer.pushback(sc);
    }
  }
  if (s.type == SymbolType.DEFAULT) {
    ParsedSymbol sx=lex();
    if (sx.group != SymbolGroup.IDENTIFIER) {
      lexer.pushback(sx);
    }
 else {
      if (!sx.value.equals("String_Node_Str")) {
        lexer.pushback(sx);
      }
 else {
        expectedType(SymbolType.NAMESPACE);
        expectedType(SymbolType.ASSIGN);
        GraphTargetItem ns=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
        ret=new DefaultXMLNamespace(null,ns);
      }
    }
  }
  if (ret == null) {
switch (s.type) {
case USE:
      expectedType(SymbolType.NAMESPACE);
    GraphTargetItem ns=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
  openedNamespaces.add(abc.constants.getNamespaceId(new Namespace(Namespace.KIND_PACKAGE,abc.constants.getStringId(ns.toString(),true)),0,true));
break;
case WITH:
needsActivation.setVal(true);
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem wvar=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
if (!isNameOrProp(wvar)) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
List<AssignableAVM2Item> withVars=new ArrayList<>();
List<GraphTargetItem> wcmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,withVars);
variables.addAll(withVars);
for (AssignableAVM2Item a : withVars) {
if (a instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ua=(UnresolvedAVM2Item)a;
ua.scopeStack.add(0,wvar);
}
}
expectedType(SymbolType.CURLY_CLOSE);
ret=new WithAVM2Item(null,wvar,wcmd);
((WithAVM2Item)ret).subvariables=withVars;
break;
case FUNCTION:
s=lexer.lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER);
needsActivation.setVal(true);
ret=(function(pkg,false,needsActivation,importedClasses,0,thisType,openedNamespaces,s.value.toString(),false,variables));
break;
case VAR:
s=lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER);
String varIdentifier=s.value.toString();
s=lex();
GraphTargetItem type;
if (s.type == SymbolType.COLON) {
type=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
s=lex();
}
 else {
type=new UnboundedTypeItem();
}
if (s.type == SymbolType.ASSIGN) {
GraphTargetItem varval=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
ret=new NameAVM2Item(type,lexer.yyline(),varIdentifier,varval,true,openedNamespaces);
variables.add((NameAVM2Item)ret);
}
 else {
ret=new NameAVM2Item(type,lexer.yyline(),varIdentifier,null,true,openedNamespaces);
variables.add((NameAVM2Item)ret);
lexer.pushback(s);
}
break;
case CURLY_OPEN:
ret=new BlockItem(null,commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.CURLY_CLOSE);
break;
case SUPER:
ParsedSymbol ss2=lex();
if (ss2.type == SymbolType.PARENT_OPEN) {
List<GraphTargetItem> args=call(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,variables);
ret=new ConstructSuperAVM2Item(null,new LocalRegAVM2Item(null,0,null),args);
}
 else {
lexer.pushback(ss2);
lexer.pushback(s);
}
break;
case IF:
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem ifExpr=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.PARENT_CLOSE);
GraphTargetItem onTrue=command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables);
List<GraphTargetItem> onTrueList=new ArrayList<>();
onTrueList.add(onTrue);
s=lex();
List<GraphTargetItem> onFalseList=null;
if (s.type == SymbolType.ELSE) {
onFalseList=new ArrayList<>();
onFalseList.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
}
 else {
lexer.pushback(s);
}
ret=new IfItem(null,ifExpr,onTrueList,onFalseList);
break;
case WHILE:
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> whileExpr=new ArrayList<>();
whileExpr.add(commaExpression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> whileBody=new ArrayList<>();
Loop wloop=new Loop(uniqId(),null,null);
if (loopLabel != null) {
loopLabels.put(wloop,loopLabel);
}
loops.push(wloop);
whileBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
ret=new WhileItem(null,wloop,whileExpr,whileBody);
break;
case DO:
List<GraphTargetItem> doBody=new ArrayList<>();
Loop dloop=new Loop(uniqId(),null,null);
loops.push(dloop);
if (loopLabel != null) {
loopLabels.put(dloop,loopLabel);
}
doBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
expectedType(SymbolType.WHILE);
expectedType(SymbolType.PARENT_OPEN);
List<GraphTargetItem> doExpr=new ArrayList<>();
doExpr.add(commaExpression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables));
expectedType(SymbolType.PARENT_CLOSE);
ret=new DoWhileItem(null,dloop,doBody,doExpr);
break;
case FOR:
s=lex();
boolean forin=false;
boolean each=false;
GraphTargetItem collection=null;
if (s.type == SymbolType.EACH) {
each=true;
forin=true;
s=lex();
}
expected(s,lexer.yyline(),SymbolType.PARENT_OPEN);
GraphTargetItem firstCommand=command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,false,variables);
if (firstCommand instanceof NameAVM2Item) {
NameAVM2Item nai=(NameAVM2Item)firstCommand;
if (nai.isDefinition() && nai.getAssignedValue() == null) {
firstCommand=expression1(firstCommand,GraphTargetItem.NOPRECEDENCE,thisType,pkg,needsActivation,importedClasses,openedNamespaces,true,registerVars,inFunction,inMethod,true,variables);
}
}
InAVM2Item inexpr=null;
if (firstCommand instanceof InAVM2Item) {
forin=true;
inexpr=(InAVM2Item)firstCommand;
}
 else {
if (forin) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
Loop floop=new Loop(uniqId(),null,null);
loops.push(floop);
if (loopLabel != null) {
loopLabels.put(floop,loopLabel);
}
List<GraphTargetItem> forFinalCommands=new ArrayList<>();
GraphTargetItem forExpr=null;
List<GraphTargetItem> forFirstCommands=new ArrayList<>();
if (!forin) {
if (firstCommand != null) {
forFirstCommands.add(firstCommand);
}
forExpr=(expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
expectedType(SymbolType.SEMICOLON);
forFinalCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
}
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> forBody=new ArrayList<>();
forBody.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forin ? forinlevel + 1 : forinlevel,true,variables));
if (forin) {
if (each) {
ret=new ForEachInAVM2Item(null,floop,inexpr,forBody);
}
 else {
ret=new ForInAVM2Item(null,floop,inexpr,forBody);
}
}
 else {
ret=new ForItem(null,floop,forFirstCommands,forExpr,forFinalCommands,forBody);
}
break;
case SWITCH:
Loop sloop=new Loop(-uniqId(),null,null);
loops.push(sloop);
if (loopLabel != null) {
loopLabels.put(sloop,loopLabel);
}
expectedType(SymbolType.PARENT_OPEN);
GraphTargetItem switchExpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.CURLY_OPEN);
s=lex();
int exprReg=0;
for (int i=0; i < 256; i++) {
if (!registerVars.containsValue(i)) {
registerVars.put("String_Node_Str" + uniqId(),i);
exprReg=i;
break;
}
}
List<List<ActionIf>> caseIfs=new ArrayList<>();
List<List<GraphTargetItem>> caseCmds=new ArrayList<>();
List<GraphTargetItem> caseExprsAll=new ArrayList<>();
List<Integer> valueMapping=new ArrayList<>();
int pos=0;
while (s.type == SymbolType.CASE) {
List<GraphTargetItem> caseExprs=new ArrayList<>();
while (s.type == SymbolType.CASE) {
GraphTargetItem curCaseExpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
caseExprs.add(curCaseExpr);
expectedType(SymbolType.COLON);
s=lex();
caseExprsAll.add(curCaseExpr);
valueMapping.add(pos);
}
pos++;
lexer.pushback(s);
List<GraphTargetItem> caseCmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables);
caseCmds.add(caseCmd);
s=lex();
}
List<GraphTargetItem> defCmd=new ArrayList<>();
if (s.type == SymbolType.DEFAULT) {
expectedType(SymbolType.COLON);
defCmd=commands(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,variables);
s=lexer.lex();
}
expected(s,lexer.yyline(),SymbolType.CURLY_CLOSE);
ret=new SwitchItem(null,sloop,switchExpr,caseExprsAll,caseCmds,defCmd,valueMapping);
break;
case BREAK:
s=lex();
long bloopId=0;
if (loops.isEmpty()) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
if (s.group == SymbolGroup.IDENTIFIER) {
String breakLabel=s.value.toString();
for (Loop l : loops) {
if (breakLabel.equals(loopLabels.get(l))) {
bloopId=l.id;
break;
}
}
if (bloopId == 0) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
 else {
lexer.pushback(s);
bloopId=loops.peek().id;
}
ret=new BreakItem(null,bloopId);
break;
case CONTINUE:
s=lex();
long cloopId=0;
if (loops.isEmpty()) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
if (s.group == SymbolGroup.IDENTIFIER) {
String continueLabel=s.value.toString();
for (Loop l : loops) {
if (l.id < 0) {
continue;
}
if (continueLabel.equals(loopLabels.get(l))) {
cloopId=l.id;
break;
}
}
if (cloopId == -1) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
 else {
lexer.pushback(s);
for (int i=loops.size() - 1; i >= 0; i--) {
if (loops.get(i).id >= 0) {
cloopId=loops.get(i).id;
break;
}
}
if (cloopId <= 0) {
throw new AVM2ParseException("String_Node_Str",lexer.yyline());
}
}
ret=new ContinueItem(null,cloopId);
break;
case RETURN:
GraphTargetItem retexpr=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,true,registerVars,inFunction,inMethod,true,variables);
if (retexpr == null) {
ret=new ReturnVoidAVM2Item(null);
}
 else {
ret=new ReturnValueAVM2Item(null,retexpr);
}
break;
case TRY:
needsActivation.setVal(true);
List<GraphTargetItem> tryCommands=new ArrayList<>();
tryCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
s=lex();
boolean found=false;
List<List<GraphTargetItem>> catchCommands=new ArrayList<>();
List<NameAVM2Item> catchExceptions=new ArrayList<>();
int varCnt=variables.size();
List<List<AssignableAVM2Item>> catchesVars=new ArrayList<>();
while (s.type == SymbolType.CATCH) {
expectedType(SymbolType.PARENT_OPEN);
s=lex();
expected(s,lexer.yyline(),SymbolGroup.IDENTIFIER,SymbolType.THIS,SymbolType.SUPER,SymbolType.STRING_OP);
String enamestr=s.value.toString();
expectedType(SymbolType.COLON);
GraphTargetItem etype=type(thisType,pkg,needsActivation,importedClasses,openedNamespaces,variables);
NameAVM2Item e=new NameAVM2Item(etype,lexer.yyline(),enamestr,new ExceptionAVM2Item(null),true,openedNamespaces);
variables.add(e);
catchExceptions.add(e);
e.setSlotNumber(1);
e.setSlotScope(Integer.MAX_VALUE);
expectedType(SymbolType.PARENT_CLOSE);
List<GraphTargetItem> cc=new ArrayList<>();
List<AssignableAVM2Item> catchVars=new ArrayList<>();
cc.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,catchVars));
catchesVars.add(catchVars);
variables.addAll(catchVars);
for (AssignableAVM2Item a : catchVars) {
if (a instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ui=(UnresolvedAVM2Item)a;
if (ui.getVariableName().equals(e.getVariableName())) {
try {
ui.resolve(null,new ArrayList<GraphTargetItem>(),new ArrayList<String>(),abc,otherABCs,new ArrayList<MethodBody>(),variables);
}
 catch (CompilationException ex) {
}
ui.setSlotNumber(e.getSlotNumber());
ui.setSlotScope(e.getSlotScope());
}
}
}
catchCommands.add(cc);
s=lex();
found=true;
}
for (int i=varCnt; i < variables.size(); i++) {
AssignableAVM2Item av=variables.get(i);
if (av instanceof UnresolvedAVM2Item) {
UnresolvedAVM2Item ui=(UnresolvedAVM2Item)av;
for (NameAVM2Item e : catchExceptions) {
if (ui.getVariableName().equals(e.getVariableName())) {
try {
ui.resolve(null,new ArrayList<GraphTargetItem>(),new ArrayList<String>(),abc,otherABCs,new ArrayList<MethodBody>(),variables);
}
 catch (CompilationException ex) {
}
ui.setSlotNumber(e.getSlotNumber());
ui.setSlotScope(e.getSlotScope());
}
}
}
}
List<GraphTargetItem> finallyCommands=null;
if (s.type == SymbolType.FINALLY) {
finallyCommands=new ArrayList<>();
finallyCommands.add(command(thisType,pkg,needsActivation,importedClasses,openedNamespaces,loops,loopLabels,registerVars,inFunction,inMethod,forinlevel,true,variables));
found=true;
s=lex();
}
if (!found) {
expected(s,lexer.yyline(),SymbolType.CATCH,SymbolType.FINALLY);
}
lexer.pushback(s);
TryAVM2Item tai=new TryAVM2Item(tryCommands,null,catchCommands,finallyCommands);
tai.catchVariables=catchesVars;
tai.catchExceptions2=catchExceptions;
ret=tai;
break;
case THROW:
ret=new ThrowAVM2Item(null,expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables));
break;
default :
GraphTargetItem valcmd=expressionCommands(s,registerVars,inFunction,inMethod,forinlevel,variables);
if (valcmd != null) {
ret=valcmd;
break;
}
if (s.type == SymbolType.SEMICOLON) {
return null;
}
lexer.pushback(s);
ret=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
if (debugMode) {
System.out.println("String_Node_Str");
}
}
}
if (debugMode) {
System.out.println("String_Node_Str");
}
lexer.removeListener(buf);
if (ret == null) {
buf.pushAllBack(lexer);
ret=expression(thisType,pkg,needsActivation,importedClasses,openedNamespaces,registerVars,inFunction,inMethod,true,variables);
}
s=lex();
if ((s != null) && (s.type != SymbolType.SEMICOLON)) {
lexer.pushback(s);
}
return ret;
}