use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLNodeFactory method finishBlock.
public SLStatementNode finishBlock(List<SLStatementNode> bodyNodes, int startPos, int length) {
lexicalScope = lexicalScope.outer;
if (containsNull(bodyNodes)) {
return null;
}
List<SLStatementNode> flattenedNodes = new ArrayList<>(bodyNodes.size());
flattenBlocks(bodyNodes, flattenedNodes);
for (SLStatementNode statement : flattenedNodes) {
if (statement.hasSource() && !isHaltInCondition(statement)) {
statement.addStatementTag();
}
}
SLBlockNode blockNode = new SLBlockNode(flattenedNodes.toArray(new SLStatementNode[flattenedNodes.size()]));
blockNode.setSourceSection(startPos, length);
return blockNode;
}
use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLLexicalScope method createScope.
// The parameter node should not be assigned
@SuppressWarnings("all")
public static SLLexicalScope createScope(Node node) {
SLBlockNode block = getParentBlock(node);
if (block == null) {
// We're in the root.
block = findChildrenBlock(node);
if (block == null) {
// Corrupted SL AST, no block was found
assert node.getRootNode() instanceof SLEvalRootNode : "Corrupted SL AST under " + node;
return new SLLexicalScope(null, null, (SLBlockNode) null);
}
// node is above the block
node = null;
}
// Test if there is a parent block. If not, we're in the root scope.
SLBlockNode parentBlock = getParentBlock(block);
if (parentBlock == null) {
return new SLLexicalScope(node, block, block.getRootNode());
} else {
return new SLLexicalScope(node, block, parentBlock);
}
}
use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLLexicalScope method findParent.
public SLLexicalScope findParent() {
if (parentBlock == null) {
// This was a root scope.
return null;
}
if (parent == null) {
Node node = block;
SLBlockNode newBlock = parentBlock;
// Test if there is a next parent block. If not, we're in the root scope.
SLBlockNode newParentBlock = getParentBlock(newBlock);
if (newParentBlock == null) {
parent = new SLLexicalScope(node, newBlock, newBlock.getRootNode());
} else {
parent = new SLLexicalScope(node, newBlock, newParentBlock);
}
}
return parent;
}
use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLLexicalScope method getParentBlock.
private static SLBlockNode getParentBlock(Node node) {
SLBlockNode block;
Node parent = node.getParent();
// Find a nearest block node.
while (parent != null && !(parent instanceof SLBlockNode)) {
parent = parent.getParent();
}
if (parent != null) {
block = (SLBlockNode) parent;
} else {
block = null;
}
return block;
}
use of com.oracle.truffle.sl.nodes.controlflow.SLBlockNode in project graal by oracle.
the class SLLexicalScope method findChildrenBlock.
private static SLBlockNode findChildrenBlock(Node node) {
SLBlockNode[] blockPtr = new SLBlockNode[1];
node.accept(new NodeVisitor() {
@Override
public boolean visit(Node n) {
if (n instanceof SLBlockNode) {
blockPtr[0] = (SLBlockNode) n;
return false;
} else {
return true;
}
}
});
return blockPtr[0];
}
Aggregations