Search in sources :

Example 1 with SLBlockNode

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;
}
Also used : SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) ArrayList(java.util.ArrayList) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode)

Example 2 with SLBlockNode

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);
    }
}
Also used : SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode)

Example 3 with SLBlockNode

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;
}
Also used : SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)

Example 4 with SLBlockNode

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;
}
Also used : SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)

Example 5 with SLBlockNode

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];
}
Also used : SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Aggregations

SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)6 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 Node (com.oracle.truffle.api.nodes.Node)4 RootNode (com.oracle.truffle.api.nodes.RootNode)4 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1