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; }
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; }
@Override public Position getPosition() { return getSourceMap().getPosition(root); }
@Override public Position getPosition() { return getSourceMap().getPosition(root); }
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 addAll(CAstSourcePositionMap other) { for(CAstNode node : Iterator2Iterable.make(other.getMappedNodes())) { setPosition(node, other.getPosition(node)); } } }
public void addAll(CAstSourcePositionMap other) { for(CAstNode node : Iterator2Iterable.make(other.getMappedNodes())) { setPosition(node, other.getPosition(node)); } } }
@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))); }
@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)); }
@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)); }
@Override protected void leaveEachElementGet(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 EachElementGetInstruction(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))); if (handlePossibleThrow(n, c)) { c.cfg().newBlock(true); } }
@Override protected void leaveEachElementGet(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 EachElementGetInstruction(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))); if (handlePossibleThrow(n, c)) { c.cfg().newBlock(true); } }
@Override protected void leaveAssert(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; boolean fromSpec = true; CAstNode assertion = n.getChild(0); int result = c.getValue(assertion); if (n.getChildCount() == 2) { assert n.getChild(1).getKind() == CAstNode.CONSTANT; assert n.getChild(1).getValue() instanceof Boolean; fromSpec = n.getChild(1).getValue().equals(Boolean.TRUE); } int currentInstruction = context.cfg().currentInstruction; context.cfg().addInstruction(new AstAssertInstruction(currentInstruction, result, fromSpec)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(assertion)); }
@Override protected void leaveUnaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int result = c.getValue(n); CAstNode v = n.getChild(1); int currentInstruction = context.cfg().currentInstruction; context.cfg().addInstruction(insts.UnaryOpInstruction(currentInstruction, translateUnaryOpcode(n.getChild(0)), result, c.getValue(v))); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(v)); }
@Override protected void leaveUnaryExpr(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int result = c.getValue(n); CAstNode v = n.getChild(1); int currentInstruction = context.cfg().currentInstruction; context.cfg().addInstruction(insts.UnaryOpInstruction(currentInstruction, translateUnaryOpcode(n.getChild(0)), result, c.getValue(v))); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(v)); }
@Override protected void leaveYield(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext wc = c; int rvals[] = new int[n.getChildCount()]; Position rposs[] = new Position[n.getChildCount()]; for (int i = 0; i < n.getChildCount(); i++) { rvals[i] = c.getValue(n.getChild(i)); rposs[i] = c.getSourceMap().getPosition(n.getChild(i)); } int currentInstruction = wc.cfg().getCurrentInstruction(); wc.cfg().addInstruction(new AstYieldInstruction(currentInstruction, rvals)); wc.cfg().noteOperands(currentInstruction, rposs); }
@Override protected void leaveEcho(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext wc = c; int rvals[] = new int[n.getChildCount()]; Position rposs[] = new Position[n.getChildCount()]; for (int i = 0; i < n.getChildCount(); i++) { rvals[i] = c.getValue(n.getChild(i)); rposs[i] = c.getSourceMap().getPosition(n.getChild(i)); } int currentInstruction = wc.cfg().getCurrentInstruction(); wc.cfg().addInstruction(new AstEchoInstruction(currentInstruction, rvals)); wc.cfg().noteOperands(currentInstruction, rposs); }
@Override protected void leaveYield(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext wc = c; int rvals[] = new int[n.getChildCount()]; Position rposs[] = new Position[n.getChildCount()]; for (int i = 0; i < n.getChildCount(); i++) { rvals[i] = c.getValue(n.getChild(i)); rposs[i] = c.getSourceMap().getPosition(n.getChild(i)); } int currentInstruction = wc.cfg().getCurrentInstruction(); wc.cfg().addInstruction(new AstYieldInstruction(currentInstruction, rvals)); wc.cfg().noteOperands(currentInstruction, rposs); }
@Override protected void leaveReturn(CAstNode n, WalkContext c, CAstVisitor<WalkContext> visitor) { WalkContext context = c; int currentInstruction = context.cfg().currentInstruction; if (n.getChildCount() > 0) { CAstNode returnExpr = n.getChild(0); context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction, c.getValue(returnExpr), false)); context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(returnExpr)); } else { context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction)); } context.cfg().addPreNode(n, context.getUnwindState()); context.cfg().newBlock(false); context.cfg().addPreEdgeToExit(n, false); }