@Override protected Position[] getParameterPositions(CAstEntity e) { if (e.getKind() == CAstEntity.SCRIPT_ENTITY) { return new Position[0]; } else { Position[] ps = new Position[ e.getArgumentCount() ]; for(int i = 2; i < e.getArgumentCount(); i++) { ps[i] = e.getPosition(i-2); } return ps; } }
@Override public CAstNode getAST() { return base.getAST(); }
@Override protected Position[] getParameterPositions(CAstEntity n) { int offset = 0; Position[] parameterPositions = new Position[ n.getArgumentCount() ]; if ((n.getType() instanceof CAstType.Method) && !((CAstType.Method)n.getType()).isStatic()) { offset = 1; } for(int i = 0; i < n.getArgumentCount() - offset; i++) { parameterPositions[i+offset] = n.getPosition(i); } return parameterPositions; } }
if (root.getAST() != null) { final Rewrite rewrite = rewrite(root.getAST(), root.getControlFlow(), root.getSourceMap(), root.getNodeTypeMap(), root.getAllScopedEntities(), root.getArgumentDefaults()); Map<CAstNode, Collection<CAstEntity>> children = root.getAllScopedEntities(); final Map<CAstNode, Collection<CAstEntity>> newChildren = new LinkedHashMap<>(); for (Entry<CAstNode, Collection<CAstEntity>> entry : children.entrySet()) {
private void dump(CAstEntity entity, int indent, StringBuilder buf) { Collection<CAstEntity> scopedEntities = Collections.emptySet(); if(entity.getKind() == CAstEntity.SCRIPT_ENTITY) { buf.append(indent(indent)).append(entity.getName()).append(":\n"); scopedEntities = dumpScopedEntities(entity, indent+2, buf); dump(entity.getAST(), indent, buf, entity.getControlFlow()); } else if(entity.getKind() == CAstEntity.FUNCTION_ENTITY) { buf.append(indent(indent)).append("function ").append(entity.getName()).append('('); for(int i=0;i<entity.getArgumentCount();++i) { if(i>0) buf.append(", "); buf.append(entity.getArgumentNames()[i]); } buf.append(") {\n"); scopedEntities = dumpScopedEntities(entity, indent+2, buf); dump(entity.getAST(), indent+2, buf, entity.getControlFlow()); buf.append(indent(indent)).append("}\n\n"); } else { throw new Error("Unknown entity kind " + entity.getKind()); } for(CAstEntity scopedEntity : scopedEntities) dump(scopedEntity, indent, buf); }
protected void doPrintTo(CAstEntity e, Writer w) { try { w.write(getEntityKindAsString(e.getKind())); w.write(": "); w.write(e.getName()); w.write('\n'); if (e.getArgumentNames().length > 0) { w.write("("); String[] names = e.getArgumentNames(); for (String name : names) { w.write(" " + name); } w.write(" )\n"); } if (e.getAST() != null) { doPrintTo(e.getAST(), e.getSourceMap(), w); w.write('\n'); } for (Collection<CAstEntity> collection : e.getAllScopedEntities().values()) { for (CAstEntity entity : collection) { doPrintTo(entity, w); } } w.flush(); } catch (IOException e1) { System.err.println("unexpected I/O exception " + e1); } } }
System.err.println(("from:\n" + namedEntityResolver)); } else { final boolean isMacroExpansion = (included.getKind() == CAstEntity.MACRO_ENTITY); System.err.println("found " + included.getName() + " for " + CAstPrinter.print(n)); if (copy.getAST() == null) { System.err.println((copy.getName() + " has no AST")); visit(copy.getAST(), new DelegatingContext(wc) { @Override public CAstSourcePositionMap getSourceMap() { visitor.visitScopedEntities(copy, copy.getAllScopedEntities(), wc, visitor);
final CAstSourcePositionMap theSource = copySource(nodes, entity.getSourceMap()); final CAstControlFlowMap theCfg = copyFlow(nodes, entity.getControlFlow(), theSource); final CAstNodeTypeMap theTypes = copyTypes(nodes, entity.getNodeTypeMap()); final Map<CAstNode, Collection<CAstEntity>> theChildren = HashMapFactory.make(); for(int i=context.getStart();i<context.getEnd();++i) theChildren.putAll(copyChildren(root.getChild(i), nodes, entity.getAllScopedEntities())); args.add(addNode(makeVarRef("__WALA__int3rnal__global"), entity.getControlFlow())); for(String parmName : context.getParameters()) args.add(addExnFlow(makeVarRef(parmName), JavaScriptTypes.ReferenceError, entity, context));
private static CorrelatedPairExtractionPolicy addCorrelations(CAstEntity entity, Map<Position, CorrelationSummary> summaries, CorrelatedPairExtractionPolicy policy) { // add correlations for this entity if(entity.getAST() != null && summaries.containsKey(entity.getPosition())) { CorrelationSummary correlations = summaries.get(entity.getPosition()); for(Correlation corr : correlations.getCorrelations()) policy.addCorrelation(entity, corr, correlations); } // recursively add correlations for scoped entities Map<CAstNode, Collection<CAstEntity>> allScopedEntities = entity.getAllScopedEntities(); for(Collection<CAstEntity> scopedEntities : allScopedEntities.values()) for(CAstEntity scopedEntity : scopedEntities) if(addCorrelations(scopedEntity, summaries, policy) == null) return null; return policy; }
protected JavaField(CAstEntity fieldEntity, IClassLoader loader, IClass declaringClass, Collection<Annotation> annotations) { super(FieldReference.findOrCreate(declaringClass.getReference(), Atom.findOrCreateUnicodeAtom(fieldEntity.getName()), TypeReference.findOrCreate(loader.getReference(), TypeName.string2TypeName(fieldEntity.getType().getName()))), fieldEntity.getQualifiers(), declaringClass, declaringClass.getClassHierarchy(), annotations); } }
public IClass defineType(CAstEntity type, String typeName, CAstEntity owner) { Collection<TypeName> superTypeNames = new ArrayList<>(); for (CAstType superType : type.getType().getSupertypes()) { superTypeNames.add(toWALATypeName(superType)); } JavaClass javaClass = new JavaClass(typeName, superTypeNames, type.getPosition(), type.getQualifiers(), this, (owner != null) ? (JavaClass) fTypeMap.get(owner) : (JavaClass) null, getAnnotations(type)); if (getParent().lookupClass(javaClass.getName()) != null) { return null; } fTypeMap.put(type, javaClass); loadedClasses.put(javaClass.getName(), javaClass); return javaClass; }
@Override protected void declareFunction(CAstEntity N, WalkContext context) { String fnName = composeEntityName(context, N); if (N.getKind() == CAstEntity.SCRIPT_ENTITY) { ((JavaScriptLoader) loader).defineScriptType('L' + fnName, N.getPosition(), N, context); } else if (N.getKind() == CAstEntity.FUNCTION_ENTITY) { ((JavaScriptLoader) loader).defineFunctionType('L' + fnName, N.getPosition(), N, context); } else { Assertions.UNREACHABLE(); } }
@Override public CAstControlFlowMap getControlFlow() { return copy.getControlFlow(); } }, visitor);
@Override public int getArgumentCount() { return base.getArgumentCount(); }
private Collection<CAstEntity> dumpScopedEntities(CAstEntity entity, int indent, StringBuilder buf) { ArrayList<CAstEntity> scopedEntities = new ArrayList<>(); Map<CAstEntity, CAstNode> m = HashMapFactory.make(); for(Entry<CAstNode, Collection<CAstEntity>> e : entity.getAllScopedEntities().entrySet()) for(CAstEntity scopedEntity : e.getValue()) { scopedEntities.add(scopedEntity); m.put(scopedEntity, e.getKey()); } Collections.sort(scopedEntities, (o1, o2) -> o1.getName().compareTo(o2.getName())); buf.append(indent(indent)).append("> "); boolean first = true; for(CAstEntity scopedEntity : scopedEntities) { if(first) first = false; else buf.append(", "); buf.append(scopedEntity.getName()).append('@').append(labeller.addNode(m.get(scopedEntity))); } buf.append('\n'); return scopedEntities; }
private boolean inFunction() { for(CAstEntity e : getEnclosingEntities()) if(e.getKind() == CAstEntity.FUNCTION_ENTITY) return true; return false; }
@Override public String toString() { return "scope for " + f.getName(); }
public static Map<String,Object> collectConstants(CAstEntity function, Map<String,Object> values) { if (function.getAST() != null) { Set<String> bad = HashSetFactory.make(); for(Segments s : CAstPattern.findAll(simplePreUpdatePattern, function)) { for(Collection<CAstEntity> ces : function.getAllScopedEntities().values()) { for(CAstEntity ce : ces) { collectConstants(ce, values);