# HG changeset patch # User Michael Van De Vanter # Date 1449552182 28800 # Node ID e4dd15f04c7dfbb0892617ca4957baf9382c1afc # Parent 07f3efb4e32115139c11a0d8e7d3ae8712af64c2# Parent 825d0d0301c9a923065d5c52ecb4dd17e649ddab Merge with 825d0d0301c9a923065d5c52ecb4dd17e649ddab diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/source/LineLocationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/source/LineLocationTest.java Mon Dec 07 21:23:02 2015 -0800 @@ -0,0 +1,81 @@ +/* + * 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. + * + * 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.source; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +import org.junit.Test; + +public class LineLocationTest { + + @Test + public void lineLocationLiteralTest() { + final Source source = Source.fromText("line 1\nline2\n", "lineLocationTest"); + final LineLocation line1 = source.createLineLocation(1); + final LineLocation line2 = source.createLineLocation(2); + assertEquals(line1.getLineNumber(), 1); + assertNotEquals(line1, line2); + assertEquals(line1, source.createLineLocation(1)); + assertEquals(line1.compareTo(line2), -1); + assertEquals(line1.compareTo(source.createLineLocation(1)), 0); + } + + @Test + public void lineLocationPathTest() throws IOException { + final Source s1 = createSourceFile("Hello1 line 1\nline2\n", "LineLocation1"); + final Source s2 = createSourceFile("Hello2 line 1\nline2\n", "LineLocation2"); + assertNotNull(s1); + assertNotNull(s2); + final LineLocation s1l1 = s1.createLineLocation(1); + final LineLocation s1l2 = s1.createLineLocation(2); + final LineLocation s2l1 = s2.createLineLocation(1); + assertEquals(s1l1.compareTo(s1l2), -1); + assertEquals(s1l1.compareTo(s2l1), -1); + assertEquals(s1l2.compareTo(s2l1), -1); + } + + @Test + public void lineLocationMixedTest() throws IOException { + final Source s1 = createSourceFile("same contents", "Testfile"); + final Source s2 = Source.fromText("same contents", "literal test source"); + final LineLocation s1l1 = s1.createLineLocation(1); + final LineLocation s2l1 = s2.createLineLocation(1); + assertEquals(s1l1.compareTo(s2l1), 0); + assertEquals(s2l1.compareTo(s1l1), 0); + } + + private static Source createSourceFile(String contents, String name) throws IOException { + final File file = File.createTempFile(name, ".txt"); + try (FileWriter w = new FileWriter(file)) { + w.write(contents); + } + file.deleteOnExit(); + return Source.fromFileName(file.getAbsolutePath()); + } +} diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/source/SourceTest.java --- a/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/source/SourceTest.java Mon Dec 07 21:17:46 2015 -0800 +++ b/truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/source/SourceTest.java Mon Dec 07 21:23:02 2015 -0800 @@ -138,4 +138,19 @@ assertNotEquals("But different type", s1.getMimeType(), s2.getMimeType()); assertNotEquals("So they are different", s1, s2); } + + @Test + public void literalSources() throws IOException { + final String code = "test code"; + final String description = "test description"; + final Source literal = Source.fromText(code, description); + assertEquals(literal.getName(), description); + assertEquals(literal.getShortName(), description); + assertEquals(literal.getCode(), code); + assertNull(literal.getPath()); + assertNull(literal.getURL()); + final char[] buffer = new char[code.length()]; + assertEquals(literal.getReader().read(buffer), code.length()); + assertEquals(new String(buffer), code); + } } diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api.vm/src/com/oracle/truffle/api/vm/PolyglotEngine.java diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/FrameDebugDescription.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/FrameDebugDescription.java Mon Dec 07 21:23:02 2015 -0800 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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.debug; + +import com.oracle.truffle.api.frame.FrameInstance; +import com.oracle.truffle.api.frame.FrameInstance.FrameAccess; +import com.oracle.truffle.api.frame.MaterializedFrame; +import com.oracle.truffle.api.nodes.Node; + +/** + * Summary of information about a frame for use by debugging clients. + */ +public final class FrameDebugDescription { + private final int index; + private final Node node; + private final MaterializedFrame frame; + + FrameDebugDescription(int index, Node node, MaterializedFrame frame) { + this.index = index; + this.node = node; + this.frame = frame; + } + + FrameDebugDescription(int index, FrameInstance frameInstance) { + this.index = index; + this.node = frameInstance.getCallNode(); + this.frame = frameInstance.getFrame(FrameAccess.MATERIALIZE, true).materialize(); + } + + /** + * Position in the current stack: {@code 0} at the top. + */ + public int index() { + return index; + } + + /** + * AST location of the call that created the frame. + */ + public Node node() { + return node; + } + + public MaterializedFrame frame() { + return frame; + } +} diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java Mon Dec 07 21:17:46 2015 -0800 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/LineLocation.java Mon Dec 07 21:23:02 2015 -0800 @@ -93,10 +93,12 @@ int sourceResult = 0; final Source thisSource = this.getSource(); final String thisPath = thisSource.getPath(); - if (thisPath == null) { + final String otherPath = o.getSource().getPath(); + + if (thisPath == null || otherPath == null) { sourceResult = thisSource.getCode().compareTo(o.getSource().getCode()); } else { - final String thatPath = o.getSource().getPath(); + final String thatPath = otherPath; sourceResult = thisPath.compareTo(thatPath); } if (sourceResult != 0) { diff -r 07f3efb4e321 -r e4dd15f04c7d truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java --- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java Mon Dec 07 21:17:46 2015 -0800 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/SourceSection.java Mon Dec 07 21:23:02 2015 -0800 @@ -37,6 +37,12 @@ * @see #createUnavailable */ public final class SourceSection { + + /** + * The identifier stored when source information is unavailable. + */ + public static String UNKNOWN = ""; + private final Source source; private final String identifier; private final int startLine; @@ -275,6 +281,6 @@ * @return source section which is mostly empty */ public static SourceSection createUnavailable(String kind, String name) { - return new SourceSection(kind, null, name == null ? "" : name, -1, -1, -1, -1); + return new SourceSection(kind, null, name == null ? UNKNOWN : name, -1, -1, -1, -1); } }