use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLLexicalScope method collectVars.
private Map<String, FrameSlot> collectVars(Node varsBlock, Node currentNode) {
// Variables are slot-based.
// To collect declared variables, traverse the block's AST and find slots associated
// with SLWriteLocalVariableNode. The traversal stops when we hit the current node.
Map<String, FrameSlot> slots = new LinkedHashMap<>(4);
NodeUtil.forEachChild(varsBlock, new NodeVisitor() {
@Override
public boolean visit(Node node) {
if (node == currentNode) {
return false;
}
// Do not enter any nested blocks.
if (!(node instanceof SLBlockNode)) {
boolean all = NodeUtil.forEachChild(node, this);
if (!all) {
return false;
}
}
// Write to a variable is a declaration unless it exists already in a parent scope.
if (node instanceof SLWriteLocalVariableNode) {
SLWriteLocalVariableNode wn = (SLWriteLocalVariableNode) node;
String name = Objects.toString(wn.getSlot().getIdentifier());
if (!hasParentVar(name)) {
slots.put(name, wn.getSlot());
}
}
return true;
}
});
return slots;
}
Aggregations