Mercurial > hg > graal-jvmci-8
changeset 9257:542712a4732a
Merge.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 23 Apr 2013 15:08:11 +0200 |
parents | 9640bb930327 (diff) 27c75e4016db (current diff) |
children | 07f8d136a05e |
files | |
diffstat | 3 files changed, 204 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/Source.java Tue Apr 23 15:08:11 2013 +0200 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2013, 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. + * + * 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; + +/** + * Represents the source code of a guest language program. + */ +public interface Source { + + /** + * Returns the name of this resource holding a guest language program. An example would be the + * name of a guest language source code file. + * + * @return the name of the guest language program + */ + String getName(); + + /** + * Returns the guest language source code represented by this source object. + * + * @return the source code as a String object + */ + String getCode(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/SourceSection.java Tue Apr 23 15:08:11 2013 +0200 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013, 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. + * + * 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; + +/** + * Represents a section in the source code of a guest language program. + */ +public class SourceSection { + + private final Source source; + private final String identifier; + private final int startLine; + private final int startColumn; + private final int endLine; + private final int endColumn; + + /** + * Creates a new object representing a section in the source code of a guest language program. + * + * @param source object representing the source program this is should be a section of + * @param identifier an identifier used when printing the section + * @param startLine the index of the start line of the section (inclusive) + * @param startColumn the index of the start column of the section (inclusive) + * @param endLine the index of the end line of the section (inclusive) + * @param endColumn the index of the end column of the section (inclusive) + */ + public SourceSection(Source source, String identifier, int startLine, int startColumn, int endLine, int endColumn) { + this.source = source; + this.identifier = identifier; + this.startLine = startLine; + this.startColumn = startColumn; + this.endLine = endLine; + this.endColumn = endColumn; + } + + /** + * Returns the source object representing the source program this is a section of. + * + * @return the source object + */ + public final Source getSource() { + return source; + } + + /** + * Returns the index of the start line of this source section (inclusive). + * + * @return the start line + */ + public final int getStartLine() { + return startLine; + } + + /** + * Returns the index of the start column of this source section (inclusive). + * + * @return the start column + */ + public final int getStartColumn() { + return startColumn; + } + + /** + * Returns the index of the end line of this source section (inclusive). + * + * @return the end line + */ + public final int getEndLine() { + return endLine; + } + + /** + * Returns the index of the end column of this source section (inclusive). + * + * @return the end column + */ + public final int getEndColumn() { + return endColumn; + } + + /** + * Returns the identifier of this source section that is used for printing the section. + * + * @return the identifier of the section + */ + public final String getIdentifier() { + return identifier; + } +}
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Apr 23 14:03:32 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Tue Apr 23 15:08:11 2013 +0200 @@ -25,6 +25,8 @@ import java.lang.annotation.*; import java.util.*; +import com.oracle.truffle.api.*; + /** * Abstract base class for all Truffle nodes. */ @@ -37,6 +39,8 @@ private Node parent; + private SourceSection sourceSection; + /** * Marks array fields that are children of this node. */ @@ -54,6 +58,34 @@ } /** + * Assigns a link to a guest language source section to this node. + * + * @param section the object representing a section in guest language source code + */ + public final void assignSourceSection(SourceSection section) { + if (sourceSection != null) { + throw new IllegalStateException("Source section is already assigned."); + } + this.sourceSection = section; + } + + /** + * Clears any previously assigned guest language source code from this node. + */ + public final void clearSourceSection() { + this.sourceSection = null; + } + + /** + * Retrieves the guest language source code section that is currently assigned to this node. + * + * @return the assigned source code section + */ + public final SourceSection getSourceSection() { + return sourceSection; + } + + /** * Method that updates the link to the parent in the array of specified new child nodes to this * node. * @@ -103,38 +135,37 @@ } /** - * Replaces one child of this node with another node. + * Replaces this node with another node. If there is a source section (see + * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. * - * @param oldChild the old child - * @param newChild the new child that should replace the old child - * @return the new child + * @param newNode the new node that is the replacement + * @param reason a description of the reason for the replacement + * @return the new node */ - public final <T extends Node> T replaceChild(T oldChild, T newChild) { + @SuppressWarnings({"unchecked"}) + public final <T extends Node> T replace(T newNode, String reason) { + assert this.getParent() != null; + if (sourceSection != null) { + // Pass on the source section to the new node. + newNode.assignSourceSection(sourceSection); + } + return (T) this.getParent().replaceChild(this, newNode); + } + + private <T extends Node> T replaceChild(T oldChild, T newChild) { NodeUtil.replaceChild(this, oldChild, newChild); adoptChild(newChild); return newChild; } /** - * Replaces this node with another node. - * - * @param newNode the new node that is the replacement - * @param reason a description of the reason for the replacement - * @return the new node - */ - @SuppressWarnings({"unchecked"}) - public <T extends Node> T replace(T newNode, String reason) { - assert this.getParent() != null; - return (T) this.getParent().replaceChild(this, newNode); - } - - /** - * Replaces this node with another node. + * Replaces this node with another node. If there is a source section (see + * {@link #getSourceSection()}) associated with this node, it is transferred to the new node. * * @param newNode the new node that is the replacement * @return the new node */ - public <T extends Node> T replace(T newNode) { + public final <T extends Node> T replace(T newNode) { return replace(newNode, ""); }