protected CAstSourcePositionMap copySource(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstSourcePositionMap orig) { CAstSourcePositionRecorder newMap = new CAstSourcePositionRecorder(); for (Entry<Pair<CAstNode, K>, CAstNode> entry : nodeMap.entrySet()) { Pair<CAstNode, K> N = entry.getKey(); CAstNode oldNode = N.fst; CAstNode newNode = entry.getValue(); if (orig.getPosition(oldNode) != null) { newMap.setPosition(newNode, orig.getPosition(oldNode)); } } return newMap; }
public void addAll(CAstSourcePositionMap other) { for(CAstNode node : Iterator2Iterable.make(other.getMappedNodes())) { setPosition(node, other.getPosition(node)); } } }
protected CAstSourcePositionMap copySource(Map<Pair<CAstNode, K>, CAstNode> nodeMap, CAstSourcePositionMap orig) { CAstSourcePositionRecorder newMap = new CAstSourcePositionRecorder(); for (Entry<Pair<CAstNode, K>, CAstNode> entry : nodeMap.entrySet()) { Pair<CAstNode, K> N = entry.getKey(); CAstNode oldNode = N.fst; CAstNode newNode = entry.getValue(); if (orig.getPosition(oldNode) != null) { newMap.setPosition(newNode, orig.getPosition(oldNode)); } } return newMap; }
public void addAll(CAstSourcePositionMap other) { for(CAstNode node : Iterator2Iterable.make(other.getMappedNodes())) { setPosition(node, other.getPosition(node)); } } }
@Override public Position getPosition() { return getSourceMap().getPosition(root); }
@Override public Position getPosition() { return getSourceMap().getPosition(root); }
@Override public String toString() { StringBuilder sb = new StringBuilder("control flow map\n"); for (Map.Entry<Key, Object> entry : table.entrySet()) { final Key key = entry.getKey(); sb.append(key.from); if (src != null && nodeToCAst.get(key.from) != null && src.getPosition(nodeToCAst.get(key.from)) != null) { sb.append(" (").append(src.getPosition(nodeToCAst.get(key.from))).append(") "); } sb.append(" -- "); sb.append(key.label); sb.append(" --> "); sb.append(entry.getValue()); sb.append('\n'); } sb.append('\n'); return sb.toString(); } }
@Override public String toString() { StringBuilder sb = new StringBuilder("control flow map\n"); for (Map.Entry<Key, Object> entry : table.entrySet()) { final Key key = entry.getKey(); sb.append(key.from); if (src != null && nodeToCAst.get(key.from) != null && src.getPosition(nodeToCAst.get(key.from)) != null) { sb.append(" (").append(src.getPosition(nodeToCAst.get(key.from))).append(") "); } sb.append(" -- "); sb.append(key.label); sb.append(" --> "); sb.append(entry.getValue()); sb.append('\n'); } sb.append('\n'); return sb.toString(); } }
private Position getPosition(CAstSourcePositionMap map, CAstNode n) { if (map.getPosition(n) != null) { return map.getPosition(n); } else { for (int i = 0; i < n.getChildCount(); i++) { Position p = getPosition(map, n.getChild(i)); if (p != null) { return p; } } return null; } }
private Position getPosition(CAstSourcePositionMap map, CAstNode n) { if (map.getPosition(n) != null) { return map.getPosition(n); } else { for (int i = 0; i < n.getChildCount(); i++) { Position p = getPosition(map, n.getChild(i)); if (p != null) { return p; } } return null; } }
public void doPrintTo(CAstNode top, CAstSourcePositionMap pos, Writer w, int depth, boolean uglyBrackets) { try { CAstSourcePositionMap.Position p = (pos!=null)? pos.getPosition( top ): null; for(int i = 0; i < depth; i++) w.write(" "); if (top == null) {
public void doPrintTo(CAstNode top, CAstSourcePositionMap pos, Writer w, int depth, boolean uglyBrackets) { try { CAstSourcePositionMap.Position p = (pos!=null)? pos.getPosition( top ): null; for(int i = 0; i < depth; i++) w.write(" "); if (top == null) {
private ScriptOrFnEntity(AstNode n, Map<CAstNode, Collection<CAstEntity>> subs, CAstNode ast, CAstControlFlowMap map, CAstSourcePositionMap pos, String name) { this.name = name; this.entityPosition = pos.getPosition(ast);
@Override protected void leaveEachElementHasNext(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); int currentInstruction = c.cfg().getCurrentInstruction(); c.cfg().addInstruction(new EachElementHasNextInstruction(currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); c.cfg().noteOperands(currentInstruction, c.getSourceMap().getPosition(n.getChild(0)), c.getSourceMap().getPosition(n.getChild(1))); }
@Override protected void leaveEachElementHasNext(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); int currentInstruction = c.cfg().getCurrentInstruction(); c.cfg().addInstruction(new EachElementHasNextInstruction(currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); c.cfg().noteOperands(currentInstruction, c.getSourceMap().getPosition(n.getChild(0)), c.getSourceMap().getPosition(n.getChild(1))); }
private static void findNodesAtPos(int kind, Position pos, CAstSourcePositionMap spmap, ChildPos nodep, Set<ChildPos> res) { CAstNode node = nodep.getChild(); if(node == null) return; Position ndpos = spmap.getPosition(node); if(ndpos != null) { // if we are in the wrong file or past the position pos, abort search if(!ndpos.getURL().equals(pos.getURL())) return; if(pos.getLastLine() >= 0 && ndpos.getFirstLine() > pos.getLastLine()) return; //if(node.getKind() == kind && ndpos.getFirstLine() == pos.getFirstLine() && ndpos.getLastLine() == pos.getLastLine()) if(node.getKind() == kind && ndpos.getFirstOffset() == pos.getFirstOffset() && ndpos.getLastOffset() == pos.getLastOffset()) res.add(nodep); } for(int i=0;i<node.getChildCount();++i) findNodesAtPos(kind, pos, spmap, nodep.getChildPos(i), res); }
private static void findNodesAtPos(int kind, Position pos, CAstSourcePositionMap spmap, ChildPos nodep, Set<ChildPos> res) { CAstNode node = nodep.getChild(); if(node == null) return; Position ndpos = spmap.getPosition(node); if(ndpos != null) { // if we are in the wrong file or past the position pos, abort search if(!ndpos.getURL().equals(pos.getURL())) return; if(pos.getLastLine() >= 0 && ndpos.getFirstLine() > pos.getLastLine()) return; //if(node.getKind() == kind && ndpos.getFirstLine() == pos.getFirstLine() && ndpos.getLastLine() == pos.getLastLine()) if(node.getKind() == kind && ndpos.getFirstOffset() == pos.getFirstOffset() && ndpos.getLastOffset() == pos.getLastOffset()) res.add(nodep); } for(int i=0;i<node.getChildCount();++i) findNodesAtPos(kind, pos, spmap, nodep.getChildPos(i), res); }
@Override protected void leaveArrayLength(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int result = c.getValue(n); CAstNode arrayExpr = n.getChild(0); int arrayValue = c.getValue(arrayExpr); int currentInstruction = context.cfg().currentInstruction; context.cfg().addInstruction(insts.ArrayLengthInstruction(currentInstruction, result, arrayValue)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(arrayExpr)); }
protected int processAssignOp(CAstNode v, CAstNode a, int temp, WalkContext c) { WalkContext context = c; int rval = c.getValue(v); CAstNode op = a.getChild(2); int temp2 = context.currentScope().allocateTempValue(); boolean mayBeInteger = handleBinaryOpThrow(a, op, context); int currentInstruction = context.cfg().getCurrentInstruction(); context.cfg().addInstruction( insts.BinaryOpInstruction(currentInstruction, translateBinaryOpcode(op), false, false, temp2, temp, rval, mayBeInteger)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(a.getChild(0)), context.getSourceMap().getPosition(v)); if (mayBeInteger) { context.cfg().newBlock(true); } return temp2; }
@Override protected void leaveArrayLength(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int result = c.getValue(n); CAstNode arrayExpr = n.getChild(0); int arrayValue = c.getValue(arrayExpr); int currentInstruction = context.cfg().currentInstruction; context.cfg().addInstruction(insts.ArrayLengthInstruction(currentInstruction, result, arrayValue)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(arrayExpr)); }