Mercurial > hg > truffle
changeset 22042:7be57462fa84
Merge
author | Mick Jordan <mick.jordan@oracle.com> |
---|---|
date | Tue, 28 Jul 2015 17:28:29 -0700 |
parents | 551da6052741 (current diff) 52ba013fd495 (diff) |
children | a96b05205d3b b26deb163f16 |
files | truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java |
diffstat | 2 files changed, 60 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Jul 28 18:33:42 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Jul 28 17:28:29 2015 -0700 @@ -146,6 +146,33 @@ } /** + * Handles the discovery of the {@link SyntaxNode} that this node is derived from. + */ + public SyntaxNode asSyntaxNode() { + if (this instanceof SyntaxNode) { + return (SyntaxNode) this; + } else { + return getSyntaxNode(); + } + } + + /** + * Locates the {@link SyntaxNode} with which this node is associated/derived. Many nodes + * organize themselves in such a way that the relevant {@link SyntaxNode} can be found by + * following the parent chain, which is therefore the default implementation. + */ + protected SyntaxNode getSyntaxNode() { + Node current = this; + while (current != null) { + if (current instanceof SyntaxNode) { + return (SyntaxNode) current; + } + current = current.getParent(); + } + throw new IllegalStateException("no SyntaxNode found"); + } + + /** * Method that updates the link to the parent in the array of specified new child nodes to this * node. *
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/SyntaxNode.java Tue Jul 28 17:28:29 2015 -0700 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.api.nodes; + +/** + * An tagging interface that identifies an AST node as being part of the syntactic structure of the + * (original) AST. There are some useful {@code default} methods that could be added once Truffle + * moves to 1.8. + */ +public interface SyntaxNode { +}