private static int[] gatherArrayDims(WalkContext c, CAstNode n) { int numDims = n.getChildCount() - 2; int[] dims = new int[numDims]; for (int i = 0; i < numDims; i++) dims[i] = c.getValue(n.getChild(i + 2)); return dims; }
@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; } }
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; } } }
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 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 public boolean matches(CAstNode node) { return node != null && node.getKind() == this.kind; } }
@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))); } }
@Test public void testNativeCAst() throws IOException { CAst Ast = new CAstImpl(); URL junk = IR.class.getClassLoader().getResource("primordial.txt"); SmokeXlator xlator = new SmokeXlator(Ast, junk); CAstNode ast = xlator.translateToCAst().getAST(); System.err.println(ast); assert ast.getChildCount() == 3; } }
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 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 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); }
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 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 public boolean matches(CAstNode node) { return node != null && node.getKind() == this.kind; } }
@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))); } }