@Override public boolean matches(CAstNode node) { return node != null && node.getKind() == this.kind; } }
@Override public boolean matches(CAstNode node) { return node != null && node.getKind() == this.kind; } }
@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 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 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); } }
@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 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; }
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 public ExtractionPos caseChildPos(ChildPos pos) { int kind = pos.getParent().getKind(); if(kind == CAstNode.FUNCTION_STMT || kind == CAstNode.FUNCTION_EXPR) return null; return getOutermostEnclosingExtractionPos(pos.getParentPos()); }
@Override public ExtractionPos caseChildPos(ChildPos pos) { int kind = pos.getParent().getKind(); if(kind == CAstNode.FUNCTION_STMT || kind == CAstNode.FUNCTION_EXPR) return null; return getEnclosingExtractionPos(pos.getParentPos()); }
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 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; } } }
public CAstEntity getIncludedEntity(CAstNode n) { if (n.getChild(0).getKind() == CAstNode.NAMED_ENTITY_REF) { assert namedEntityResolver != null; return namedEntityResolver.get(n.getChild(0).getChild(0).getValue()); } else { return (CAstEntity) n.getChild(0).getValue(); } }
@Override public int hashCode() { int code = getKind() * (getChildCount() + 13); for (int i = 0; i < getChildCount() && i < 15; i++) { if (getChild(i) != null) { code *= getChild(i).getKind(); } } return code; } }
@Override public void leaveAssign(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { if (n.getKind() == CAstNode.ASSIGN) { c.setValue(n, c.getValue(n.getChild(1))); } else { c.setValue(n, c.getValue(n.getChild(0))); } }
@Override public void leaveAssign(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { if (n.getKind() == CAstNode.ASSIGN) { c.setValue(n, c.getValue(n.getChild(1))); } else { c.setValue(n, c.getValue(n.getChild(0))); } }
@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 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 doNewObject(WalkContext context, CAstNode newNode, int result, Object type, int[] arguments) { TypeReference typeRef = (TypeReference) type; NewSiteReference site = NewSiteReference.make(context.cfg().getCurrentInstruction(), typeRef); if (newNode.getKind() == CAstNode.NEW_ENCLOSING) { context.cfg().addInstruction(new AstJavaNewEnclosingInstruction(context.cfg().getCurrentInstruction(), result, site, arguments[0])); } else { context.cfg().addInstruction( (arguments == null) ? insts.NewInstruction(context.cfg().getCurrentInstruction(), result, site) : insts.NewInstruction(context.cfg().getCurrentInstruction(), result, site, arguments)); } processExceptions(newNode, context); }
@Override protected void doNewObject(WalkContext context, CAstNode newNode, int result, Object type, int[] arguments) { TypeReference typeRef = (TypeReference) type; NewSiteReference site = NewSiteReference.make(context.cfg().getCurrentInstruction(), typeRef); if (newNode.getKind() == CAstNode.NEW_ENCLOSING) { context.cfg().addInstruction(new AstJavaNewEnclosingInstruction(context.cfg().getCurrentInstruction(), result, site, arguments[0])); } else { context.cfg().addInstruction( (arguments == null) ? insts.NewInstruction(context.cfg().getCurrentInstruction(), result, site) : insts.NewInstruction(context.cfg().getCurrentInstruction(), result, site, arguments)); } processExceptions(newNode, context); }