@Override protected void leaveVar(CAstNode n, EntityContext c, CAstVisitor<EntityContext> visitor) { String nm = (String) n.getChild(0).getValue(); checkForLexicalAccess(c, nm); }
private static void filterNames(Set<ChildPos> nodes, String indexName) { for(Iterator<ChildPos> iter=nodes.iterator();iter.hasNext();) { CAstNode node = iter.next().getChild(); if(node.getKind() == CAstNode.OBJECT_REF) { CAstNode index = node.getChild(1); if(index.getKind() != CAstNode.VAR || !index.getChild(0).getValue().equals(indexName)) { iter.remove(); } } } }
@Override protected CAstNode copyNodes(CAstNode root, CAstControlFlowMap cfg, NonCopyingContext c, Map<Pair<CAstNode, NoKey>, CAstNode> nodeMap) { if (root.getKind() == CAstNode.ASSIGN) { ((AssignSkipContext)c).skip.add(root.getChild(0)); } if (root.getKind() == CAstNode.VAR && constants.containsKey(root.getChild(0).getValue()) && ! ((AssignSkipContext)c).skip.contains(root)) { return Ast.makeConstant(constants.get(root.getChild(0).getValue())); } else { return super.copyNodes(root, cfg, c, nodeMap); } }
private CAstNode copyConstant(CAstNode root, NodePos context, Map<Pair<CAstNode, NoKey>, CAstNode> nodeMap) { CAstNode newNode = Ast.makeConstant(root.getValue()); nodeMap.put(Pair.make(root, context.key()), newNode); return newNode; }
@Override protected void leaveConstant(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; c.setValue(n, context.currentScope().getConstantValue(n.getValue())); }
@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 protected void leaveConstant(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; c.setValue(n, context.currentScope().getConstantValue(n.getValue())); }
private boolean usesArguments(CAstNode node) { if(node.getKind() == CAstNode.VAR) { return node.getChild(0).getValue().equals("arguments"); } else { for(int i=0;i<node.getChildCount();++i) if(usesArguments(node.getChild(i))) return true; return false; } } }
@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 leaveVarAssign(CAstNode n, CAstNode v, CAstNode a, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int rval = c.getValue(v); String nm = (String) n.getChild(0).getValue(); Symbol ls = context.currentScope().lookup(nm); c.setValue(n, rval); assignValue(n, context, ls, nm, rval); }
@Override protected void doIsFieldDefined(WalkContext context, int result, int ref, CAstNode f) { if (f.getKind() == CAstNode.CONSTANT && f.getValue() instanceof String) { String field = (String) f.getValue(); FieldReference fieldRef = FieldReference.findOrCreate(JavaScriptTypes.Root, Atom.findOrCreateUnicodeAtom(field), JavaScriptTypes.Root); context.cfg().addInstruction(((JSInstructionFactory) insts).IsDefinedInstruction(context.cfg().getCurrentInstruction(), result, ref, fieldRef)); } else { context.cfg().addInstruction(((JSInstructionFactory) insts).IsDefinedInstruction(context.cfg().getCurrentInstruction(), result, ref, context.getValue(f))); } }
protected int processFunctionExpr(CAstNode n, WalkContext context) { CAstEntity fn = (CAstEntity) n.getChild(0).getValue(); declareFunction(fn, context); int result = context.currentScope().allocateTempValue(); int ex = context.currentScope().allocateTempValue(); doMaterializeFunction(n, context, result, ex, fn); return result; }
@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 leaveThis(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { if (n.getChildCount() == 0) { super.leaveThis(n, c, visitor); } else { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); c.cfg().addInstruction(new EnclosingObjectReference(c.cfg().getCurrentInstruction(), result, (TypeReference) n.getChild(0).getValue())); } }
@Override protected void doFieldRead(WalkContext context, int result, int receiver, CAstNode elt, CAstNode parent) { // elt is a constant CAstNode whose value is a FieldReference. FieldReference fieldRef = (FieldReference) elt.getValue(); if (receiver == -1) { // a static field: AstTranslator.getValue() produces // -1 for null, we hope context.cfg().addInstruction(insts.GetInstruction(context.cfg().getCurrentInstruction(), result, fieldRef)); } else { context.cfg().addInstruction(insts.GetInstruction(context.cfg().getCurrentInstruction(), result, receiver, fieldRef)); processExceptions(parent, context); } }
@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 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())); }