Program: 99966
Project: 99966
Buggy source:
private CAstNode walkNodesInternal(final Node n,WalkContext context){
  int NT=n.getType();
switch (NT) {
case Token.FUNCTION:
{
      int fnIndex=n.getExistingIntProp(Node.FUNCTION_PROP);
      FunctionNode fn=context.top().getFunctionNode(fnIndex);
      CAstEntity fne=walkEntity(fn,context);
      if (context.expressionContext()) {
        CAstNode fun=Ast.makeNode(CAstNode.FUNCTION_EXPR,Ast.makeConstant(fne));
        context.addScopedEntity(fun,fne);
        return fun;
      }
 else {
        context.addInitializer(Ast.makeNode(CAstNode.FUNCTION_STMT,Ast.makeConstant(fne)));
        context.addScopedEntity(null,fne);
        return Ast.makeNode(CAstNode.EMPTY);
      }
    }
case Token.CATCH_SCOPE:
{
    Node catchVarNode=n.getFirstChild();
    String catchVarName=catchVarNode.getString();
    Assertions._assert(catchVarName != null);
    context.setCatchVar(catchVarName);
    return Ast.makeNode(CAstNode.EMPTY);
  }
case Token.LOCAL_BLOCK:
{
  return Ast.makeNode(CAstNode.BLOCK_EXPR,gatherChildren(n,context));
}
case Token.TRY:
{
Node catchNode=((Node.Jump)n).target;
Node finallyNode=((Node.Jump)n).getFinally();
ArrayList<Node> tryList=new ArrayList<Node>();
ArrayList<Node> catchList=new ArrayList<Node>();
ArrayList<Node> finallyList=new ArrayList<Node>();
ArrayList<Node> current=tryList;
Node c;
for (c=n.getFirstChild(); c.getNext() != null; c=c.getNext()) {
  if (c == catchNode) {
    current=catchList;
  }
 else   if (c == finallyNode) {
    current=finallyList;
  }
  if (c.getType() == Token.GOTO && (c.getNext() == catchNode || c.getNext() == finallyNode)) {
    continue;
  }
  current.add(c);
}
CAstNode finallyBlock=null;
if (finallyNode != null) {
  int i=0;
  CAstNode[] finallyAsts=new CAstNode[finallyList.size()];
  for (Iterator<Node> fns=finallyList.iterator(); fns.hasNext(); ) {
    finallyAsts[i++]=walkNodes(fns.next(),context);
  }
  finallyBlock=Ast.makeNode(CAstNode.BLOCK_STMT,finallyAsts);
}
if (catchNode != null) {
  int i=0;
  WalkContext catchChild=new CatchBlockContext(context);
  CAstNode[] catchAsts=new CAstNode[catchList.size()];
  for (Iterator<Node> cns=catchList.iterator(); cns.hasNext(); ) {
    catchAsts[i++]=walkNodes(cns.next(),catchChild);
  }
  CAstNode catchBlock=Ast.makeNode(CAstNode.CATCH,Ast.makeConstant(catchChild.getCatchVar()),Ast.makeNode(CAstNode.BLOCK_STMT,catchAsts));
  context.cfg().map(catchBlock,catchBlock);
  i=0;
  WalkContext tryChild=new TryBlockContext(context,catchBlock);
  CAstNode[] tryAsts=new CAstNode[tryList.size()];
  for (Iterator<Node> tns=tryList.iterator(); tns.hasNext(); ) {
    tryAsts[i++]=walkNodes(tns.next(),tryChild);
  }
  CAstNode tryBlock=Ast.makeNode(CAstNode.BLOCK_STMT,tryAsts);
  if (finallyBlock != null) {
    return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.UNWIND,Ast.makeNode(CAstNode.TRY,tryBlock,catchBlock),finallyBlock),walkNodes(c,context));
  }
 else {
    return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.TRY,tryBlock,catchBlock),walkNodes(c,context));
  }
}
 else {
  int i=0;
  CAstNode[] tryAsts=new CAstNode[tryList.size()];
  for (Iterator<Node> tns=tryList.iterator(); tns.hasNext(); ) {
    tryAsts[i++]=walkNodes(tns.next(),context);
  }
  CAstNode tryBlock=Ast.makeNode(CAstNode.BLOCK_STMT,tryAsts);
  return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.UNWIND,Ast.makeNode(CAstNode.BLOCK_STMT,tryBlock),Ast.makeNode(CAstNode.BLOCK_STMT,finallyBlock)),walkNodes(c,context));
}
}
case Token.JSR:
{
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.COMMA:
{
int count=0;
for (Node c=n.getFirstChild(); c != null; count++, c=c.getNext()) ;
CAstNode[] cs=new CAstNode[count];
int i=0;
for (Node c=n.getFirstChild(); c != null; i++, c=c.getNext()) {
if (c.getNext() == null) {
context.copyBase(n,c);
}
cs[i]=walkNodes(c,context);
}
return Ast.makeNode(CAstNode.BLOCK_EXPR,cs);
}
case Token.ENTERWITH:
case Token.LEAVEWITH:
{
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.LOOP:
{
LoopContext child=new LoopContext(context);
CAstNode[] nodes=gatherChildren(n,child);
if (child.forInInitExpr != null) {
String nm=child.forInVar;
return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl(nm,true)),walkNodes(child.forInInitExpr,context)),nodes);
}
 else {
return Ast.makeNode(CAstNode.BLOCK_STMT,nodes);
}
}
case Token.WITH:
case Token.FINALLY:
case Token.BLOCK:
case Token.LABEL:
{
Node c1=n.getFirstChild();
if (c1 != null && c1.getType() == Token.SWITCH) {
Node switchValue=c1.getFirstChild();
CAstNode defaultLabel=Ast.makeNode(CAstNode.LABEL_STMT,Ast.makeNode(CAstNode.EMPTY));
context.cfg().map(defaultLabel,defaultLabel);
for (Node kase=switchValue.getNext(); kase != null; kase=kase.getNext()) {
Assertions._assert(kase.getType() == Token.CASE);
Node caseLbl=kase.getFirstChild();
Node target=((Node.Jump)kase).target;
context.cfg().add(c1,target,walkNodes(caseLbl,context));
}
context.cfg().add(c1,defaultLabel,CAstControlFlowMap.SWITCH_DEFAULT);
CAstNode switchAst=Ast.makeNode(CAstNode.SWITCH,walkNodes(switchValue,context),Ast.makeNode(CAstNode.BLOCK_STMT,defaultLabel,gatherChildren(n,context,1)));
noteSourcePosition(context,switchAst,c1);
context.cfg().map(c1,switchAst);
return switchAst;
}
 else {
return Ast.makeNode(CAstNode.BLOCK_STMT,gatherChildren(n,context));
}
}
case Token.EXPR_VOID:
case Token.EXPR_RESULT:
case Token.POS:
{
WalkContext child=new ExpressionContext(context);
Node expr=n.getFirstChild();
if (NT == Token.EXPR_RESULT) {
child.copyBase(n,expr);
}
return walkNodes(expr,child);
}
case Token.CALL:
{
if (!isPrimitiveCall(context,n)) {
CAstNode base=Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"));
Node callee=n.getFirstChild();
WalkContext child=new BaseCollectingContext(context,callee,base);
CAstNode fun=walkNodes(callee,child);
if (child.foundBase(callee)) return Ast.makeNode(CAstNode.LOCAL_SCOPE,Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl("String_Node_Str")),Ast.makeConstant(null)),makeCall(fun,base,callee.getNext(),context)));
 else return makeCall(fun,Ast.makeConstant(null),callee.getNext(),context);
}
 else {
return Ast.makeNode(CAstNode.PRIMITIVE,gatherChildren(n,context,1));
}
}
case Token.NAME:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString()));
}
case Token.THIS:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"));
}
case Token.THISFN:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(((FunctionNode)context.top()).getFunctionName()));
}
case Token.STRING:
{
return Ast.makeConstant(n.getString());
}
case Token.NUMBER:
{
return Ast.makeConstant(n.getDouble());
}
case Token.FALSE:
{
return Ast.makeConstant(false);
}
case Token.TRUE:
{
return Ast.makeConstant(true);
}
case Token.NULL:
{
return Ast.makeConstant(null);
}
case Token.ADD:
case Token.DIV:
case Token.LSH:
case Token.MOD:
case Token.MUL:
case Token.RSH:
case Token.SUB:
case Token.URSH:
case Token.BITAND:
case Token.EQ:
case Token.SHEQ:
case Token.GE:
case Token.GT:
case Token.LE:
case Token.LT:
case Token.SHNE:
case Token.NE:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.BINARY_EXPR,translateOpcode(NT),walkNodes(l,context),walkNodes(r,context));
}
case Token.NEG:
{
return Ast.makeNode(CAstNode.BINARY_EXPR,translateOpcode(Token.SUB),Ast.makeConstant(0),walkNodes(n.getFirstChild(),context));
}
case Token.BITNOT:
case Token.NOT:
{
return Ast.makeNode(CAstNode.UNARY_EXPR,translateOpcode(NT),walkNodes(n.getFirstChild(),context));
}
case Token.VAR:
{
Node nm=n.getFirstChild();
context.addInitializer(Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl(nm.getString())),Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"))));
if (nm.getFirstChild() != null) {
WalkContext child=new ExpressionContext(context);
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(nm.getString())),walkNodes(nm.getFirstChild(),child));
}
 else {
if (n.getNext().getType() == Token.ENUM_INIT_KEYS) {
context.getForInVar(nm.getString(),n.getNext().getFirstChild());
}
return Ast.makeNode(CAstNode.EMPTY);
}
}
case Token.REGEXP:
{
int regexIdx=n.getIntProp(Node.REGEXP_PROP,-1);
Assertions._assert(regexIdx != -1,"String_Node_Str" + context.top().toStringTree(context.top()) + "String_Node_Str"+ n.toStringTree(context.top()));
String flags=context.top().getRegexpFlags(regexIdx);
Node flagsNode=Node.newString(flags);
String str=context.top().getRegexpString(regexIdx);
Node strNode=Node.newString(str);
strNode.addChildToFront(flagsNode);
return handleNew(context,"String_Node_Str",strNode);
}
case Token.ENUM_INIT_KEYS:
{
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.ENUM_ID:
{
return Ast.makeNode(CAstNode.EACH_ELEMENT_GET,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(context.getForInInitVar())));
}
case Token.ENUM_NEXT:
{
return Ast.makeNode(CAstNode.EACH_ELEMENT_HAS_NEXT,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(context.getForInInitVar())));
}
case Token.RETURN:
{
Node val=n.getFirstChild();
if (val != null) {
WalkContext child=new ExpressionContext(context);
return Ast.makeNode(CAstNode.RETURN,walkNodes(val,child));
}
 else {
return Ast.makeNode(CAstNode.RETURN);
}
}
case Token.SETNAME:
{
Node nm=n.getFirstChild();
return Ast.makeNode(CAstNode.ASSIGN,walkNodes(nm,context),walkNodes(nm.getNext(),context));
}
case Token.BINDNAME:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString()));
}
case Token.IFNE:
case Token.IFEQ:
{
context.cfg().add(n,((Node.Jump)n).target,Boolean.TRUE);
WalkContext child=new ExpressionContext(context);
CAstNode gotoAst=Ast.makeNode(CAstNode.IFGOTO,translateOpcode(NT),walkNodes(n.getFirstChild(),child),Ast.makeConstant(1));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.GOTO:
{
context.cfg().add(n,((Node.Jump)n).target,null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).target.labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.BREAK:
{
context.cfg().add(n,((Node.Jump)n).getJumpStatement().target,null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).getJumpStatement().target.labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.CONTINUE:
{
context.cfg().add(n,((Node.Jump)n).getJumpStatement().getContinue(),null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).getJumpStatement().getContinue().labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.TARGET:
{
CAstNode result=Ast.makeNode(CAstNode.LABEL_STMT,Ast.makeConstant(n.labelId()),Ast.makeNode(CAstNode.EMPTY));
context.cfg().map(n,result);
return result;
}
case Token.OR:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(l,context),Ast.makeConstant(true),walkNodes(r,context));
}
case Token.AND:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(l,context),walkNodes(r,context),Ast.makeConstant(false));
}
case Token.HOOK:
{
Node cond=n.getFirstChild();
Node thenBranch=cond.getNext();
Node elseBranch=thenBranch.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(cond,context),walkNodes(thenBranch,context),walkNodes(elseBranch,context));
}
case Token.INC:
case Token.DEC:
{
int flags=n.getIntProp(Node.INCRDECR_PROP,-1);
CAstNode op=((flags & Node.DECR_FLAG) != 0) ? CAstOperator.OP_SUB : CAstOperator.OP_ADD;
Node l=n.getFirstChild();
CAstNode last=walkNodes(l,context);
return Ast.makeNode((((flags & Node.POST_FLAG) != 0) ? CAstNode.ASSIGN_POST_OP : CAstNode.ASSIGN_PRE_OP),last,Ast.makeConstant(1),op);
}
case Token.NEW:
{
if (isPrimitiveCreation(context,n)) {
return makeBuiltinNew(context,n.getFirstChild().getString());
}
 else {
Node receiver=n.getFirstChild();
return handleNew(context,walkNodes(receiver,context),receiver.getNext());
}
}
case Token.ARRAYLIT:
{
int count=0;
for (Node x=n.getFirstChild(); x != null; count++, x=x.getNext()) ;
int i=0;
CAstNode[] args=new CAstNode[2 * count + 1];
args[i++]=(isPrologueScript(context)) ? makeBuiltinNew(context,"String_Node_Str") : handleNew(context,"String_Node_Str",null);
int[] skips=(int[])n.getProp(Node.SKIP_INDEXES_PROP);
int skip=0;
int idx=0;
Node elt=n.getFirstChild();
while (elt != null) {
if (skips != null && skip < skips.length && skips[skip] == idx) {
skip++;
idx++;
continue;
}
args[i++]=Ast.makeConstant(idx++);
args[i++]=walkNodes(elt,context);
elt=elt.getNext();
}
return Ast.makeNode(CAstNode.OBJECT_LITERAL,args);
}
case Token.OBJECTLIT:
{
Object[] propertyList=(Object[])n.getProp(Node.OBJECT_IDS_PROP);
CAstNode[] args=new CAstNode[propertyList.length * 2 + 1];
int i=0;
args[i++]=((isPrologueScript(context)) ? makeBuiltinNew(context,"String_Node_Str") : handleNew(context,"String_Node_Str",null));
Node val=n.getFirstChild();
int nameIdx=0;
for (; nameIdx < propertyList.length; nameIdx++, val=val.getNext()) {
args[i++]=Ast.makeConstant(propertyList[nameIdx]);
args[i++]=walkNodes(val,context);
}
return Ast.makeNode(CAstNode.OBJECT_LITERAL,args);
}
case Token.GETPROP:
case Token.GETELEM:
{
Node receiver=n.getFirstChild();
Node element=receiver.getNext();
CAstNode rcvr=walkNodes(receiver,context);
CAstNode baseVar=context.setBase(n);
CAstNode elt=walkNodes(element,context);
if (baseVar != null) {
return Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.ASSIGN,baseVar,rcvr),Ast.makeNode(CAstNode.OBJECT_REF,baseVar,elt));
}
 else {
return Ast.makeNode(CAstNode.OBJECT_REF,rcvr,elt);
}
}
case Token.SETPROP:
case Token.SETELEM:
{
Node receiver=n.getFirstChild();
Node elt=receiver.getNext();
Node val=elt.getNext();
CAstNode rcvr=walkNodes(receiver,context);
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,walkNodes(elt,context)),walkNodes(val,context));
}
case Token.DELPROP:
{
Node receiver=n.getFirstChild();
Node element=receiver.getNext();
CAstNode rcvr=walkNodes(receiver,context);
CAstNode baseVar=context.setBase(n);
CAstNode elt=walkNodes(element,context);
if (baseVar != null) {
return Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.ASSIGN,baseVar,rcvr),Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,baseVar,elt),Ast.makeConstant(null)));
}
 else {
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,elt),Ast.makeConstant(null));
}
}
case Token.TYPEOFNAME:
{
return Ast.makeNode(CAstNode.TYPE_OF,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString())));
}
case Token.TYPEOF:
{
return Ast.makeNode(CAstNode.TYPE_OF,walkNodes(n.getFirstChild(),context));
}
case Token.SETPROP_OP:
case Token.SETELEM_OP:
{
Node receiver=n.getFirstChild();
Node elt=receiver.getNext();
Node op=elt.getNext();
CAstNode rcvr=walkNodes(receiver,context);
return Ast.makeNode(CAstNode.ASSIGN_POST_OP,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,walkNodes(elt,context)),walkNodes(op.getFirstChild().getNext(),context),translateOpcode(op.getType()));
}
case Token.THROW:
{
CAstNode catchNode=context.getCatchTarget();
if (catchNode != null) context.cfg().add(n,context.getCatchTarget(),null);
 else context.cfg().add(n,CAstControlFlowMap.EXCEPTION_TO_EXIT,null);
CAstNode throwAst=Ast.makeNode(CAstNode.THROW,walkNodes(n.getFirstChild(),context));
context.cfg().map(n,throwAst);
return throwAst;
}
case Token.EMPTY:
{
return Ast.makeConstant(null);
}
default :
{
System.err.println("String_Node_Str" + context.top().toStringTree(context.top()) + "String_Node_Str"+ n.toStringTree(context.top())+ "String_Node_Str"+ NT+ "String_Node_Str"+ n.getClass()+ "String_Node_Str");
Assertions.UNREACHABLE();
return null;
}
}
}

Fixed version (ground truth):
private CAstNode walkNodesInternal(final Node n,WalkContext context){
  int NT=n.getType();
switch (NT) {
case Token.FUNCTION:
{
      int fnIndex=n.getExistingIntProp(Node.FUNCTION_PROP);
      FunctionNode fn=context.top().getFunctionNode(fnIndex);
      CAstEntity fne=walkEntity(fn,context);
      if (context.expressionContext()) {
        CAstNode fun=Ast.makeNode(CAstNode.FUNCTION_EXPR,Ast.makeConstant(fne));
        context.addScopedEntity(fun,fne);
        return fun;
      }
 else {
        context.addInitializer(Ast.makeNode(CAstNode.FUNCTION_STMT,Ast.makeConstant(fne)));
        context.addScopedEntity(null,fne);
        return Ast.makeNode(CAstNode.EMPTY);
      }
    }
case Token.CATCH_SCOPE:
{
    Node catchVarNode=n.getFirstChild();
    String catchVarName=catchVarNode.getString();
    Assertions._assert(catchVarName != null);
    context.setCatchVar(catchVarName);
    return Ast.makeNode(CAstNode.EMPTY);
  }
case Token.LOCAL_BLOCK:
{
  return Ast.makeNode(CAstNode.BLOCK_EXPR,gatherChildren(n,context));
}
case Token.TRY:
{
Node catchNode=((Node.Jump)n).target;
Node finallyNode=((Node.Jump)n).getFinally();
ArrayList<Node> tryList=new ArrayList<Node>();
ArrayList<Node> catchList=new ArrayList<Node>();
ArrayList<Node> finallyList=new ArrayList<Node>();
ArrayList<Node> current=tryList;
Node c;
for (c=n.getFirstChild(); c.getNext() != null; c=c.getNext()) {
  if (c == catchNode) {
    current=catchList;
  }
 else   if (c == finallyNode) {
    current=finallyList;
  }
  if (c.getType() == Token.GOTO && (c.getNext() == catchNode || c.getNext() == finallyNode)) {
    continue;
  }
  current.add(c);
}
CAstNode finallyBlock=null;
if (finallyNode != null) {
  int i=0;
  CAstNode[] finallyAsts=new CAstNode[finallyList.size()];
  for (Iterator<Node> fns=finallyList.iterator(); fns.hasNext(); ) {
    finallyAsts[i++]=walkNodes(fns.next(),context);
  }
  finallyBlock=Ast.makeNode(CAstNode.BLOCK_STMT,finallyAsts);
}
if (catchNode != null) {
  int i=0;
  WalkContext catchChild=new CatchBlockContext(context);
  CAstNode[] catchAsts=new CAstNode[catchList.size()];
  for (Iterator<Node> cns=catchList.iterator(); cns.hasNext(); ) {
    catchAsts[i++]=walkNodes(cns.next(),catchChild);
  }
  CAstNode catchBlock=Ast.makeNode(CAstNode.CATCH,Ast.makeConstant(catchChild.getCatchVar()),Ast.makeNode(CAstNode.BLOCK_STMT,catchAsts));
  context.cfg().map(catchBlock,catchBlock);
  i=0;
  WalkContext tryChild=new TryBlockContext(context,catchBlock);
  CAstNode[] tryAsts=new CAstNode[tryList.size()];
  for (Iterator<Node> tns=tryList.iterator(); tns.hasNext(); ) {
    tryAsts[i++]=walkNodes(tns.next(),tryChild);
  }
  CAstNode tryBlock=Ast.makeNode(CAstNode.BLOCK_STMT,tryAsts);
  if (finallyBlock != null) {
    return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.UNWIND,Ast.makeNode(CAstNode.TRY,tryBlock,catchBlock),finallyBlock),walkNodes(c,context));
  }
 else {
    return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.TRY,tryBlock,catchBlock),walkNodes(c,context));
  }
}
 else {
  int i=0;
  CAstNode[] tryAsts=new CAstNode[tryList.size()];
  for (Iterator<Node> tns=tryList.iterator(); tns.hasNext(); ) {
    tryAsts[i++]=walkNodes(tns.next(),context);
  }
  CAstNode tryBlock=Ast.makeNode(CAstNode.BLOCK_STMT,tryAsts);
  return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.UNWIND,Ast.makeNode(CAstNode.BLOCK_STMT,tryBlock),Ast.makeNode(CAstNode.BLOCK_STMT,finallyBlock)),walkNodes(c,context));
}
}
case Token.JSR:
{
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.COMMA:
{
int count=0;
for (Node c=n.getFirstChild(); c != null; count++, c=c.getNext()) ;
CAstNode[] cs=new CAstNode[count];
int i=0;
for (Node c=n.getFirstChild(); c != null; i++, c=c.getNext()) {
if (c.getNext() == null) {
context.copyBase(n,c);
}
cs[i]=walkNodes(c,context);
}
return Ast.makeNode(CAstNode.BLOCK_EXPR,cs);
}
case Token.ENTERWITH:
case Token.LEAVEWITH:
{
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.LOOP:
{
LoopContext child=new LoopContext(context);
CAstNode[] nodes=gatherChildren(n,child);
if (child.forInInitExpr != null) {
String nm=child.forInVar;
return Ast.makeNode(CAstNode.BLOCK_STMT,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl(nm,true)),walkNodes(child.forInInitExpr,context)),nodes);
}
 else {
return Ast.makeNode(CAstNode.BLOCK_STMT,nodes);
}
}
case Token.WITH:
case Token.FINALLY:
case Token.BLOCK:
case Token.LABEL:
{
Node c1=n.getFirstChild();
if (c1 != null && c1.getType() == Token.SWITCH) {
Node switchValue=c1.getFirstChild();
CAstNode defaultLabel=Ast.makeNode(CAstNode.LABEL_STMT,Ast.makeNode(CAstNode.EMPTY));
context.cfg().map(defaultLabel,defaultLabel);
for (Node kase=switchValue.getNext(); kase != null; kase=kase.getNext()) {
Assertions._assert(kase.getType() == Token.CASE);
Node caseLbl=kase.getFirstChild();
Node target=((Node.Jump)kase).target;
context.cfg().add(c1,target,walkNodes(caseLbl,context));
}
context.cfg().add(c1,defaultLabel,CAstControlFlowMap.SWITCH_DEFAULT);
CAstNode switchAst=Ast.makeNode(CAstNode.SWITCH,walkNodes(switchValue,context),Ast.makeNode(CAstNode.BLOCK_STMT,defaultLabel,gatherChildren(n,context,1)));
noteSourcePosition(context,switchAst,c1);
context.cfg().map(c1,switchAst);
return switchAst;
}
 else {
return Ast.makeNode(CAstNode.BLOCK_STMT,gatherChildren(n,context));
}
}
case Token.EXPR_VOID:
case Token.EXPR_RESULT:
case Token.POS:
{
WalkContext child=new ExpressionContext(context);
Node expr=n.getFirstChild();
if (NT == Token.EXPR_RESULT) {
child.copyBase(n,expr);
}
return walkNodes(expr,child);
}
case Token.CALL:
{
if (!isPrimitiveCall(context,n)) {
CAstNode base=Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"));
Node callee=n.getFirstChild();
WalkContext child=new BaseCollectingContext(context,callee,base);
CAstNode fun=walkNodes(callee,child);
if (child.foundBase(callee)) return Ast.makeNode(CAstNode.LOCAL_SCOPE,Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl("String_Node_Str")),Ast.makeConstant(null)),makeCall(fun,base,callee.getNext(),context)));
 else return makeCall(fun,Ast.makeConstant(null),callee.getNext(),context);
}
 else {
return Ast.makeNode(CAstNode.PRIMITIVE,gatherChildren(n,context,1));
}
}
case Token.NAME:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString()));
}
case Token.THIS:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"));
}
case Token.THISFN:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(((FunctionNode)context.top()).getFunctionName()));
}
case Token.STRING:
{
return Ast.makeConstant(n.getString());
}
case Token.NUMBER:
{
return Ast.makeConstant(n.getDouble());
}
case Token.FALSE:
{
return Ast.makeConstant(false);
}
case Token.TRUE:
{
return Ast.makeConstant(true);
}
case Token.NULL:
case Token.VOID:
{
return Ast.makeConstant(null);
}
case Token.ADD:
case Token.DIV:
case Token.LSH:
case Token.MOD:
case Token.MUL:
case Token.RSH:
case Token.SUB:
case Token.URSH:
case Token.BITAND:
case Token.BITOR:
case Token.BITXOR:
case Token.EQ:
case Token.SHEQ:
case Token.GE:
case Token.GT:
case Token.LE:
case Token.LT:
case Token.SHNE:
case Token.NE:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.BINARY_EXPR,translateOpcode(NT),walkNodes(l,context),walkNodes(r,context));
}
case Token.NEG:
{
return Ast.makeNode(CAstNode.BINARY_EXPR,translateOpcode(Token.SUB),Ast.makeConstant(0),walkNodes(n.getFirstChild(),context));
}
case Token.BITNOT:
case Token.NOT:
{
return Ast.makeNode(CAstNode.UNARY_EXPR,translateOpcode(NT),walkNodes(n.getFirstChild(),context));
}
case Token.VAR:
{
Node nm=n.getFirstChild();
context.addInitializer(Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new CAstSymbolImpl(nm.getString())),Ast.makeNode(CAstNode.VAR,Ast.makeConstant("String_Node_Str"))));
if (nm.getFirstChild() != null) {
WalkContext child=new ExpressionContext(context);
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(nm.getString())),walkNodes(nm.getFirstChild(),child));
}
 else {
return Ast.makeNode(CAstNode.EMPTY);
}
}
case Token.REGEXP:
{
int regexIdx=n.getIntProp(Node.REGEXP_PROP,-1);
Assertions._assert(regexIdx != -1,"String_Node_Str" + context.top().toStringTree(context.top()) + "String_Node_Str"+ n.toStringTree(context.top()));
String flags=context.top().getRegexpFlags(regexIdx);
Node flagsNode=Node.newString(flags);
String str=context.top().getRegexpString(regexIdx);
Node strNode=Node.newString(str);
strNode.addChildToFront(flagsNode);
return handleNew(context,"String_Node_Str",strNode);
}
case Token.ENUM_INIT_KEYS:
{
context.getForInVar(n.getFirstChild());
return Ast.makeNode(CAstNode.EMPTY);
}
case Token.ENUM_ID:
{
return Ast.makeNode(CAstNode.EACH_ELEMENT_GET,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(context.getForInInitVar())));
}
case Token.ENUM_NEXT:
{
return Ast.makeNode(CAstNode.EACH_ELEMENT_HAS_NEXT,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(context.getForInInitVar())));
}
case Token.RETURN:
{
Node val=n.getFirstChild();
if (val != null) {
WalkContext child=new ExpressionContext(context);
return Ast.makeNode(CAstNode.RETURN,walkNodes(val,child));
}
 else {
return Ast.makeNode(CAstNode.RETURN);
}
}
case Token.SETNAME:
{
Node nm=n.getFirstChild();
return Ast.makeNode(CAstNode.ASSIGN,walkNodes(nm,context),walkNodes(nm.getNext(),context));
}
case Token.BINDNAME:
{
return Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString()));
}
case Token.IFNE:
case Token.IFEQ:
{
context.cfg().add(n,((Node.Jump)n).target,Boolean.TRUE);
WalkContext child=new ExpressionContext(context);
CAstNode gotoAst=Ast.makeNode(CAstNode.IFGOTO,translateOpcode(NT),walkNodes(n.getFirstChild(),child),Ast.makeConstant(1));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.GOTO:
{
context.cfg().add(n,((Node.Jump)n).target,null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).target.labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.BREAK:
{
context.cfg().add(n,((Node.Jump)n).getJumpStatement().target,null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).getJumpStatement().target.labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.CONTINUE:
{
context.cfg().add(n,((Node.Jump)n).getJumpStatement().getContinue(),null);
CAstNode gotoAst=Ast.makeNode(CAstNode.GOTO,Ast.makeConstant(((Node.Jump)n).getJumpStatement().getContinue().labelId()));
context.cfg().map(n,gotoAst);
return gotoAst;
}
case Token.TARGET:
{
CAstNode result=Ast.makeNode(CAstNode.LABEL_STMT,Ast.makeConstant(n.labelId()),Ast.makeNode(CAstNode.EMPTY));
context.cfg().map(n,result);
return result;
}
case Token.OR:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(l,context),Ast.makeConstant(true),walkNodes(r,context));
}
case Token.AND:
{
Node l=n.getFirstChild();
Node r=l.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(l,context),walkNodes(r,context),Ast.makeConstant(false));
}
case Token.HOOK:
{
Node cond=n.getFirstChild();
Node thenBranch=cond.getNext();
Node elseBranch=thenBranch.getNext();
return Ast.makeNode(CAstNode.IF_EXPR,walkNodes(cond,context),walkNodes(thenBranch,context),walkNodes(elseBranch,context));
}
case Token.INC:
case Token.DEC:
{
int flags=n.getIntProp(Node.INCRDECR_PROP,-1);
CAstNode op=((flags & Node.DECR_FLAG) != 0) ? CAstOperator.OP_SUB : CAstOperator.OP_ADD;
Node l=n.getFirstChild();
CAstNode last=walkNodes(l,context);
return Ast.makeNode((((flags & Node.POST_FLAG) != 0) ? CAstNode.ASSIGN_POST_OP : CAstNode.ASSIGN_PRE_OP),last,Ast.makeConstant(1),op);
}
case Token.NEW:
{
if (isPrimitiveCreation(context,n)) {
return makeBuiltinNew(context,n.getFirstChild().getString());
}
 else {
Node receiver=n.getFirstChild();
return handleNew(context,walkNodes(receiver,context),receiver.getNext());
}
}
case Token.ARRAYLIT:
{
int count=0;
for (Node x=n.getFirstChild(); x != null; count++, x=x.getNext()) ;
int i=0;
CAstNode[] args=new CAstNode[2 * count + 1];
args[i++]=(isPrologueScript(context)) ? makeBuiltinNew(context,"String_Node_Str") : handleNew(context,"String_Node_Str",null);
int[] skips=(int[])n.getProp(Node.SKIP_INDEXES_PROP);
int skip=0;
int idx=0;
Node elt=n.getFirstChild();
while (elt != null) {
if (skips != null && skip < skips.length && skips[skip] == idx) {
skip++;
idx++;
continue;
}
args[i++]=Ast.makeConstant(idx++);
args[i++]=walkNodes(elt,context);
elt=elt.getNext();
}
return Ast.makeNode(CAstNode.OBJECT_LITERAL,args);
}
case Token.OBJECTLIT:
{
Object[] propertyList=(Object[])n.getProp(Node.OBJECT_IDS_PROP);
CAstNode[] args=new CAstNode[propertyList.length * 2 + 1];
int i=0;
args[i++]=((isPrologueScript(context)) ? makeBuiltinNew(context,"String_Node_Str") : handleNew(context,"String_Node_Str",null));
Node val=n.getFirstChild();
int nameIdx=0;
for (; nameIdx < propertyList.length; nameIdx++, val=val.getNext()) {
args[i++]=Ast.makeConstant(propertyList[nameIdx]);
args[i++]=walkNodes(val,context);
}
return Ast.makeNode(CAstNode.OBJECT_LITERAL,args);
}
case Token.GETPROP:
case Token.GETELEM:
{
Node receiver=n.getFirstChild();
Node element=receiver.getNext();
CAstNode rcvr=walkNodes(receiver,context);
CAstNode baseVar=context.setBase(n);
CAstNode elt=walkNodes(element,context);
if (baseVar != null) {
return Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.ASSIGN,baseVar,rcvr),Ast.makeNode(CAstNode.OBJECT_REF,baseVar,elt));
}
 else {
return Ast.makeNode(CAstNode.OBJECT_REF,rcvr,elt);
}
}
case Token.SETPROP:
case Token.SETELEM:
{
Node receiver=n.getFirstChild();
Node elt=receiver.getNext();
Node val=elt.getNext();
CAstNode rcvr=walkNodes(receiver,context);
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,walkNodes(elt,context)),walkNodes(val,context));
}
case Token.DELPROP:
{
Node receiver=n.getFirstChild();
Node element=receiver.getNext();
CAstNode rcvr=walkNodes(receiver,context);
CAstNode baseVar=context.setBase(n);
CAstNode elt=walkNodes(element,context);
if (baseVar != null) {
return Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.ASSIGN,baseVar,rcvr),Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,baseVar,elt),Ast.makeConstant(null)));
}
 else {
return Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,elt),Ast.makeConstant(null));
}
}
case Token.TYPEOFNAME:
{
return Ast.makeNode(CAstNode.TYPE_OF,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(n.getString())));
}
case Token.TYPEOF:
{
return Ast.makeNode(CAstNode.TYPE_OF,walkNodes(n.getFirstChild(),context));
}
case Token.SETPROP_OP:
case Token.SETELEM_OP:
{
Node receiver=n.getFirstChild();
Node elt=receiver.getNext();
Node op=elt.getNext();
CAstNode rcvr=walkNodes(receiver,context);
return Ast.makeNode(CAstNode.ASSIGN_POST_OP,Ast.makeNode(CAstNode.OBJECT_REF,rcvr,walkNodes(elt,context)),walkNodes(op.getFirstChild().getNext(),context),translateOpcode(op.getType()));
}
case Token.THROW:
{
CAstNode catchNode=context.getCatchTarget();
if (catchNode != null) context.cfg().add(n,context.getCatchTarget(),null);
 else context.cfg().add(n,CAstControlFlowMap.EXCEPTION_TO_EXIT,null);
CAstNode throwAst=Ast.makeNode(CAstNode.THROW,walkNodes(n.getFirstChild(),context));
context.cfg().map(n,throwAst);
return throwAst;
}
case Token.EMPTY:
{
return Ast.makeConstant(null);
}
default :
{
System.err.println("String_Node_Str" + context.top().toStringTree(context.top()) + "String_Node_Str"+ n.toStringTree(context.top())+ "String_Node_Str"+ NT+ "String_Node_Str"+ n.getClass()+ "String_Node_Str");
Assertions.UNREACHABLE();
return null;
}
}
}