/** * Visit children of a node starting at a given index. * @param n the parent node of the nodes to process * @param start the starting index of the nodes to process * @param context a visitor-specific context */ public final void visitChildren(CAstNode n, int start, C context, CAstVisitor<C> visitor) { int end = n.getChildCount(); for (int i = start; i < end; i++) visitor.visit(n.getChild(i), context, visitor); } /**
@Override public boolean equals(Object o) { if (! (o instanceof CAstNode)) return false; if (kind != ((CAstNode)o).getKind()) return false; if (((CAstNode)o).getChildCount() != cs.length) return false; for(int i = 0; i < cs.length; i++) if (! cs[i].equals(((CAstNode)o).getChild(i))) return false; return true; } }
@Override protected void leaveVar(CAstNode n, EntityContext c, CAstVisitor<EntityContext> visitor) { String nm = (String) n.getChild(0).getValue(); checkForLexicalAccess(c, nm); }
default <X extends WalkContext<X,Y>, Y> void pushSourcePosition(WalkContext<X, Y> context, CAstNode n, Position p) { if (context.pos().getPosition(n) == null && !(n.getKind()==CAstNode.FUNCTION_EXPR || n.getKind()==CAstNode.FUNCTION_STMT)) { context.pos().setPosition(n, p); for(int i = 0; i < n.getChildCount(); i++) { pushSourcePosition(context, n.getChild(i), p); } } }
@Override protected void leaveObjectRefAssignOp(CAstNode n, CAstNode v, CAstNode a, boolean pre, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int temp = context.currentScope().allocateTempValue(); doFieldRead(context, temp, c.getValue(n.getChild(0)), n.getChild(1), n); int rval = processAssignOp(v, a, temp, c); c.setValue(n, pre ? rval : temp); doFieldWrite(context, c.getValue(n.getChild(0)), n.getChild(1), n, rval); }
@Override protected void leaveObjectRefAssignOp(CAstNode n, CAstNode v, CAstNode a, boolean pre, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int temp = context.currentScope().allocateTempValue(); doFieldRead(context, temp, c.getValue(n.getChild(0)), n.getChild(1), n); int rval = processAssignOp(v, a, temp, c); c.setValue(n, pre ? rval : temp); doFieldWrite(context, c.getValue(n.getChild(0)), n.getChild(1), n, rval); }
@Override protected void leaveArrayLiteralInitElement(CAstNode n, int i, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; arrayOpHandler.doArrayWrite(context, c.getValue(n.getChild(0)), n, new int[] { context.currentScope().getConstantValue(Integer.valueOf(i - 1)) }, c.getValue(n.getChild(i))); }
private static CAstNode addSpuriousExnFlow(CAstNode node, CAstControlFlowMap cfg) { CAstControlFlowRecorder flow = (CAstControlFlowRecorder)cfg; if(node.getKind() == ASSIGN) { if(node.getChild(0).getKind() == VAR) { CAstNode var = node.getChild(0); if(!flow.isMapped(var)) flow.map(var, var); flow.add(var, CAstControlFlowMap.EXCEPTION_TO_EXIT, JavaScriptTypes.ReferenceError); } } return node; }
@Override protected void leaveDeclStmt(CAstNode n, EntityContext c, CAstVisitor<EntityContext> visitor) { CAstSymbol s = (CAstSymbol) n.getChild(0).getValue(); String nm = s.name(); // System.err.println("declaration of " + nm + " in " + c.top()); MapUtil.findOrCreateSet(entity2DeclaredNames, c.top()).add(nm); }
@Override public void doArrayWrite(WalkContext context, int arrayValue, CAstNode arrayRefNode, int[] dimValues, int rval) { TypeReference arrayTypeRef = arrayRefNode.getKind() == CAstNode.ARRAY_LITERAL ? ((TypeReference) arrayRefNode.getChild(0) .getChild(0).getValue()).getArrayElementType() : (TypeReference) arrayRefNode.getChild(1).getValue(); context.cfg().addInstruction(insts.ArrayStoreInstruction(context.cfg().getCurrentInstruction(), arrayValue, dimValues[0], rval, arrayTypeRef)); processExceptions(arrayRefNode, context); }
@Override protected void leaveEachElementHasNext(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); int currentInstruction = c.cfg().getCurrentInstruction(); c.cfg().addInstruction(new EachElementHasNextInstruction(currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); c.cfg().noteOperands(currentInstruction, c.getSourceMap().getPosition(n.getChild(0)), c.getSourceMap().getPosition(n.getChild(1))); }
@Override protected void leaveInstanceOf(CAstNode n, WalkContext context, CAstVisitor<WalkContext> visitor) { int result = context.getValue(n); CAstType type = (CAstType) n.getChild(0).getValue(); TypeReference ref = makeType( type ); context.cfg().addInstruction( insts.InstanceofInstruction( context.cfg().getCurrentInstruction(), result, context.getValue(n.getChild(1)), ref)); }
@Override protected void leaveArrayRef(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int arrayValue = c.getValue(n.getChild(0)); int result = context.currentScope().allocateTempValue(); c.setValue(n, result); arrayOpHandler.doArrayRead(context, result, arrayValue, n, gatherArrayDims(c, n)); }
@Override protected void leaveTypeLiteralExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext wc = c; assert n.getChild(0).getKind() == CAstNode.CONSTANT; String typeNameStr = (String) n.getChild(0).getValue(); TypeName typeName = TypeName.string2TypeName(typeNameStr); TypeReference typeRef = TypeReference.findOrCreate(loader.getReference(), typeName); int result = wc.currentScope().allocateTempValue(); c.setValue(n, result); wc.cfg().addInstruction(insts.LoadMetadataInstruction(wc.cfg().currentInstruction, result, loader.getLanguage().getConstantType(typeRef), typeRef)); }
@Override public void doArrayRead(WalkContext context, int result, int arrayValue, CAstNode arrayRefNode, int[] dimValues) { TypeReference arrayTypeRef = (TypeReference) arrayRefNode.getChild(1).getValue(); context.cfg().addInstruction(insts.ArrayLoadInstruction(context.cfg().getCurrentInstruction(), result, arrayValue, dimValues[0], arrayTypeRef)); processExceptions(arrayRefNode, context); }
@Override protected void leaveGetCaughtException(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; String nm = (String) n.getChild(0).getValue(); context.currentScope().declare(new FinalCAstSymbol(nm, exceptionType())); context.cfg().addInstruction( insts.GetCaughtExceptionInstruction(context.cfg().currentInstruction, context.cfg().getCurrentBlock().getNumber(), context.currentScope().lookup(nm) .valueNumber())); }