@Override public CAstNode getAST() { return base.getAST(); }
@Override public CAstNode getAST() { return base.getAST(); }
@Override protected void leaveFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) { if (n.getAST() != null) // non-abstract closeFunctionEntity(n, context, codeContext); }
@Override protected void leaveFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) { if (n.getAST() != null) // non-abstract closeFunctionEntity(n, context, codeContext); }
public static Collection<Segments> findAll(final CAstPattern p, final CAstEntity e) { return p.new Matcher().findAll(new Context() { @Override public CAstEntity top() { return e; } @Override public CAstSourcePositionMap getSourceMap() { return e.getSourceMap(); } }, e.getAST()); }
public static Collection<Segments> findAll(final CAstPattern p, final CAstEntity e) { return p.new Matcher().findAll(new Context() { @Override public CAstEntity top() { return e; } @Override public CAstSourcePositionMap getSourceMap() { return e.getSourceMap(); } }, e.getAST()); }
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); } } }
@Override protected boolean visitFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) { if (n.getAST() == null) // presumably abstract declareFunction(n, context); else { declareFunction(n, context); initFunctionEntity(n, codeContext); } return false; }
@Override protected boolean visitFunctionEntity(CAstEntity n, WalkContext context, WalkContext codeContext, CAstVisitor<WalkContext> visitor) { if (n.getAST() == null) // presumably abstract declareFunction(n, context); else { declareFunction(n, context); initFunctionEntity(n, codeContext); } return false; }
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); } } }
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; }
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; }
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)) {
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)) {
@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 static Set<ChildPos> findNodesAtPos(int kind, Position pos, CAstEntity entity) { Set<ChildPos> res = HashSetFactory.make(); CAstSourcePositionMap spmap = entity.getSourceMap(); CAstNode ast = entity.getAST(); for(int i=0;i<ast.getChildCount();++i) findNodesAtPos(kind, pos, spmap, new ChildPos(ast, i, new RootPos()), res); return res; }
private static Set<ChildPos> findNodesAtPos(int kind, Position pos, CAstEntity entity) { Set<ChildPos> res = HashSetFactory.make(); CAstSourcePositionMap spmap = entity.getSourceMap(); CAstNode ast = entity.getAST(); for(int i=0;i<ast.getChildCount();++i) findNodesAtPos(kind, pos, spmap, new ChildPos(ast, i, new RootPos()), res); return res; }
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); }
}.rewrite(ce.getAST(), ce.getControlFlow(), ce.getSourceMap(), ce.getNodeTypeMap(), ce.getAllScopedEntities(), ce.getArgumentDefaults()); return new DelegatingEntity(ce) {
}.rewrite(ce.getAST(), ce.getControlFlow(), ce.getSourceMap(), ce.getNodeTypeMap(), ce.getAllScopedEntities(), ce.getArgumentDefaults()); return new DelegatingEntity(ce) {