@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // for Java, the creator node is exactly what we want return Collections.singleton(smik.getCreator()); }
InstanceKey ik = filter.getInstance(); if (ik instanceof ScopeMappingInstanceKey) { ik = ((ScopeMappingInstanceKey) ik).getBase();
system.findOrCreateIndexForInstanceKey(functionKey); ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) functionKey; Iterator<CGNode> x = K.getFunargNodes(definer); while (x.hasNext()) { result.add(x.next()); if (iKey instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) iKey; Iterator<CGNode> x = K.getFunargNodes(definer); while (x.hasNext()) { result.add(x.next());
system.findOrCreateIndexForInstanceKey(functionKey); ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) functionKey; Iterator<CGNode> x = K.getFunargNodes(definer); while (x.hasNext()) { result.add(x.next()); if (iKey instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey K = (ScopeMappingInstanceKey) iKey; Iterator<CGNode> x = K.getFunargNodes(definer); while (x.hasNext()) { result.add(x.next());
@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // in JavaScript, the 'new' instruction is wrapped in a synthetic constructor method. we want the // caller of that constructor method, which we obtain from the context for the constructor method final Context creatorContext = smik.getCreator().getContext(); CGNode callerOfConstructor = (CGNode) creatorContext.get(ContextKey.CALLER); Collection<CGNode> result = null; if (callerOfConstructor != null) { return Collections.singleton(callerOfConstructor); } else { CallString cs = (CallString) creatorContext.get(CallStringContextSelector.CALL_STRING); if (cs != null) { IMethod[] methods = cs.getMethods(); assert methods.length == 1; IMethod m = methods[0]; result = builder.getCallGraph().getNodes(m.getReference()); } } if (result == null) { IClassHierarchy cha = smik.getCreator().getClassHierarchy(); MethodReference ref = MethodReference.findOrCreate(JavaScriptLoader.JS, TypeReference.findOrCreate(cha.getLoaders()[0].getReference(), name.snd), AstMethodReference.fnAtomStr, AstMethodReference.fnDesc.toString()); final IMethod method = cha.resolveMethod(ref); if (method != null) { return builder.getCallGraph().getNodes(method.getReference()); } } return result; }
InstanceKey ik = filter.getInstance(); if (ik instanceof ScopeMappingInstanceKey) { ik = ((ScopeMappingInstanceKey) ik).getBase();
private boolean exceedsRecursionBound(Context baseContext, int curLevel) { if (curLevel > recursionBound) { return true; } // we just do a case analysis here. we might have to add cases later to // account for new types of context / recursion. CGNode callerNode = (CGNode) baseContext.get(ContextKey.CALLER); if (callerNode != null && exceedsRecursionBound(callerNode.getContext(), curLevel + 1)) { return true; } for (int i = 0; i < MAX_INTERESTING_PARAM; i++) { FilteredPointerKey.SingleInstanceFilter filter = (SingleInstanceFilter) baseContext.get(ContextKey.PARAMETERS[i]); if (filter != null) { InstanceKey ik = filter.getInstance(); if (ik instanceof ScopeMappingInstanceKey) { ik = ((ScopeMappingInstanceKey) ik).getBase(); } if (ik instanceof InstanceKeyWithNode) { if (exceedsRecursionBound(((InstanceKeyWithNode) ik).getNode().getContext(), curLevel + 1)) { return true; } } } } return false; }
private boolean exceedsRecursionBound(Context baseContext, int curLevel) { if (curLevel > recursionBound) { return true; } // we just do a case analysis here. we might have to add cases later to // account for new types of context / recursion. CGNode callerNode = (CGNode) baseContext.get(ContextKey.CALLER); if (callerNode != null && exceedsRecursionBound(callerNode.getContext(), curLevel + 1)) { return true; } for (int i = 0; i < MAX_INTERESTING_PARAM; i++) { FilteredPointerKey.SingleInstanceFilter filter = (SingleInstanceFilter) baseContext.get(ContextKey.PARAMETERS[i]); if (filter != null) { InstanceKey ik = filter.getInstance(); if (ik instanceof ScopeMappingInstanceKey) { ik = ((ScopeMappingInstanceKey) ik).getBase(); } if (ik instanceof InstanceKeyWithNode) { if (exceedsRecursionBound(((InstanceKeyWithNode) ik).getNode().getContext(), curLevel + 1)) { return true; } } } } return false; }
/** * get the CGNode representing the lexical parent of {@link #creator} with * name definer * */ public Iterator<CGNode> getFunargNodes(Pair<String, String> name) { Collection<CGNode> constructorCallers = getConstructorCallers(this, name); assert constructorCallers != null && !constructorCallers.isEmpty() : "no callers for constructor"; Iterator<CGNode> result = EmptyIterator.instance(); for (CGNode callerOfConstructor : constructorCallers) { if (callerOfConstructor.getMethod().getReference().getDeclaringClass().getName().toString().equals(name.snd)) { result = new CompoundIterator<>(result, new NonNullSingletonIterator<>(callerOfConstructor)); } else { PointerKey funcKey = builder.getPointerKeyForLocal(callerOfConstructor, 1); for (InstanceKey funcPtr : builder.getPointerAnalysis().getPointsToSet(funcKey)) { if (funcPtr instanceof ScopeMappingInstanceKey) { result = new CompoundIterator<>(result, ((ScopeMappingInstanceKey) funcPtr).getFunargNodes(name)); } } } } return result; }
@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // in JavaScript, the 'new' instruction is wrapped in a synthetic constructor method. we want the // caller of that constructor method, which we obtain from the context for the constructor method final Context creatorContext = smik.getCreator().getContext(); CGNode callerOfConstructor = (CGNode) creatorContext.get(ContextKey.CALLER); Collection<CGNode> result = null; if (callerOfConstructor != null) { return Collections.singleton(callerOfConstructor); } else { CallString cs = (CallString) creatorContext.get(CallStringContextSelector.CALL_STRING); if (cs != null) { IMethod[] methods = cs.getMethods(); assert methods.length == 1; IMethod m = methods[0]; result = builder.getCallGraph().getNodes(m.getReference()); } } if (result == null) { IClassHierarchy cha = smik.getCreator().getClassHierarchy(); MethodReference ref = MethodReference.findOrCreate(JavaScriptLoader.JS, TypeReference.findOrCreate(cha.getLoaders()[0].getReference(), name.snd), AstMethodReference.fnAtomStr, AstMethodReference.fnDesc.toString()); final IMethod method = cha.resolveMethod(ref); if (method != null) { return builder.getCallGraph().getNodes(method.getReference()); } } return result; }
/** * get the CGNode representing the lexical parent of {@link #creator} with * name definer * */ public Iterator<CGNode> getFunargNodes(Pair<String, String> name) { Collection<CGNode> constructorCallers = getConstructorCallers(this, name); assert constructorCallers != null && !constructorCallers.isEmpty() : "no callers for constructor"; Iterator<CGNode> result = EmptyIterator.instance(); for (CGNode callerOfConstructor : constructorCallers) { if (callerOfConstructor.getMethod().getReference().getDeclaringClass().getName().toString().equals(name.snd)) { result = new CompoundIterator<>(result, new NonNullSingletonIterator<>(callerOfConstructor)); } else { PointerKey funcKey = builder.getPointerKeyForLocal(callerOfConstructor, 1); for (InstanceKey funcPtr : builder.getPointerAnalysis().getPointsToSet(funcKey)) { if (funcPtr instanceof ScopeMappingInstanceKey) { result = new CompoundIterator<>(result, ((ScopeMappingInstanceKey) funcPtr).getFunargNodes(name)); } } } } return result; }
private Collection<Pair<CGNode, String>> getNodeNamePairsForAccess(CGNode n, Pair<String, String> nameAndDefiner) { Collection<Pair<CGNode, String>> result = HashSetFactory.make(); // use scope-mapping instance keys in pointer analysis. may need a different // scheme for CG construction not based on pointer analysis OrdinalSet<InstanceKey> functionValues = pa.getPointsToSet(pa.getHeapModel().getPointerKeyForLocal(n, 1)); for (InstanceKey ik : functionValues) { if (ik instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey smik = (ScopeMappingInstanceKey) ik; for (CGNode definerNode : Iterator2Iterable.make(smik.getFunargNodes(nameAndDefiner))) { result.add(Pair.make(definerNode, nameAndDefiner.fst)); } } } return result; } }
private Collection<Pair<CGNode, String>> getNodeNamePairsForAccess(CGNode n, Pair<String, String> nameAndDefiner) { Collection<Pair<CGNode, String>> result = HashSetFactory.make(); // use scope-mapping instance keys in pointer analysis. may need a different // scheme for CG construction not based on pointer analysis OrdinalSet<InstanceKey> functionValues = pa.getPointsToSet(pa.getHeapModel().getPointerKeyForLocal(n, 1)); for (InstanceKey ik : functionValues) { if (ik instanceof ScopeMappingInstanceKey) { ScopeMappingInstanceKey smik = (ScopeMappingInstanceKey) ik; for (CGNode definerNode : Iterator2Iterable.make(smik.getFunargNodes(nameAndDefiner))) { result.add(Pair.make(definerNode, nameAndDefiner.fst)); } } } return result; } }
@Override public InstanceKey getInstanceKeyForAllocation(CGNode creatorNode, NewSiteReference allocationSite) { InstanceKey base = basic.getInstanceKeyForAllocation(creatorNode, allocationSite); if (base != null && needsScopeMappingKey(base)) { return new ScopeMappingInstanceKey(creatorNode, base); } else { return base; } }
@Override protected Collection<CGNode> getConstructorCallers(ScopeMappingInstanceKey smik, Pair<String, String> name) { // for Java, the creator node is exactly what we want return Collections.singleton(smik.getCreator()); }
@Override public InstanceKey getInstanceKeyForAllocation(CGNode creatorNode, NewSiteReference allocationSite) { InstanceKey base = basic.getInstanceKeyForAllocation(creatorNode, allocationSite); if (base != null && needsScopeMappingKey(base)) { return new ScopeMappingInstanceKey(creatorNode, base); } else { return base; } }