private Set<String> getRequireTargets(PointerAnalysis<InstanceKey> pointerAnalysis, CGNode caller, JavaScriptInvoke callInstr) { HashSet<String> set = HashSetFactory.make(); PointerKey pk = builder.getPointerKeyForLocal(caller, callInstr.getUse(2)); OrdinalSet<InstanceKey> instanceKeys = pointerAnalysis.getPointsToSet(pk); for (InstanceKey instanceKey : instanceKeys) { if (instanceKey instanceof ConstantKey<?>) { Object value = ((ConstantKey<?>) instanceKey).getValue(); if (value instanceof String) { set.add((String) value); } else { System.err.println("NodejsRequireTargetSelector: Unexpected value: " + value); return HashSetFactory.make(); } } else if (instanceKey instanceof ConcreteTypeKey) { // Cannot do anything with this information... } else { System.err.println("NodejsRequireTargetSelector: Unexpected instanceKey: " + instanceKey.getClass() + " -- " + instanceKey); return HashSetFactory.make(); } } return set; }
/** * 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; }
/** * 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; }