Search in sources :

Example 56 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class SuspendableLocationFinder method findNearestBound.

private static SourceSection findNearestBound(Source source, Set<Class<? extends Tag>> elementTags, int line, int column, SuspendAnchor anchor, TruffleInstrument.Env env) {
    int offset = source.getLineStartOffset(line);
    if (column > 0) {
        offset += column - 1;
    }
    NearestSections sectionsCollector = new NearestSections(elementTags, (column <= 0) ? line : 0, offset, anchor);
    // All SourceSections of the Source are loaded already when the source was executed
    env.getInstrumenter().attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().sourceIs(source).build(), sectionsCollector, true).dispose();
    SourceSection section = sectionsCollector.getExactSection();
    if (section != null) {
        return section;
    }
    InstrumentableNode contextNode = sectionsCollector.getContainsNode();
    if (contextNode == null) {
        contextNode = sectionsCollector.getNextNode();
    }
    if (contextNode == null) {
        contextNode = sectionsCollector.getPreviousNode();
    }
    if (contextNode == null) {
        return null;
    }
    Node node = contextNode.findNearestNodeAt(offset, elementTags);
    if (node == null) {
        return null;
    }
    return node.getSourceSection();
}
Also used : InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 57 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class SourceSectionTest method emptySectionTest3.

@Test
public void emptySectionTest3() {
    SourceSection section = longSource.createSection(0, 0);
    assertNotNull(section);
    assertEquals(section.getCharacters(), "");
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Test(org.junit.Test)

Example 58 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class SourceSectionTest method testUnavailable.

@Test
public void testUnavailable() {
    SourceSection section = longSource.createUnavailableSection();
    assertEquals(0, section.getCharEndIndex());
    assertEquals(0, section.getCharIndex());
    assertEquals(0, section.getCharLength());
    assertEquals(1, section.getStartColumn());
    assertEquals(1, section.getEndColumn());
    assertEquals(1, section.getStartLine());
    assertEquals(1, section.getEndLine());
    assertSame(longSource, section.getSource());
    assertFalse(section.isAvailable());
    assertEquals("", section.getCharacters());
    assertNotNull(section.toString());
    // Unavailable sections must not be equals otherwise builtins
    // will be considered all identical if they share the same source.
    SourceSection other = longSource.createUnavailableSection();
    assertFalse(section.equals(other));
    assertNotEquals(other.hashCode(), section.hashCode());
    SourceSection other2 = shortSource.createUnavailableSection();
    assertFalse(section.equals(other2));
    assertNotEquals(other2.hashCode(), section.hashCode());
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Test(org.junit.Test)

Example 59 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class SourceSectionTest method emptyLineTest0.

@Test
public void emptyLineTest0() {
    SourceSection section = emptyLineSource.createSection(0, 0);
    assertNotNull(section);
    assertEquals(section.getCharacters(), "");
    assertEquals(section.getCharIndex(), 0);
    assertEquals(section.getCharLength(), 0);
    assertEquals(section.getStartLine(), 1);
    assertEquals(section.getStartColumn(), 1);
    SourceSection other = emptyLineSource.createSection(0, 0);
    assertTrue(section.equals(other));
    assertEquals(other.hashCode(), section.hashCode());
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Test(org.junit.Test)

Example 60 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class SourceSectionTest method emptySourceTest1.

@Test
public void emptySourceTest1() {
    SourceSection section = emptySource.createSection(0, 0);
    assertNotNull(section);
    assertEquals(section.getCharIndex(), 0);
    assertEquals(section.getCharLength(), 0);
    assertEquals(section.getStartLine(), 1);
    assertEquals(section.getEndLine(), 1);
    assertEquals(section.getStartColumn(), 1);
    assertEquals(section.getEndColumn(), 1);
    assertEquals("", section.getCharacters());
    SourceSection other = emptySource.createSection(0, 0);
    assertTrue(section.equals(other));
    assertEquals(other.hashCode(), section.hashCode());
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) Test(org.junit.Test)

Aggregations

SourceSection (com.oracle.truffle.api.source.SourceSection)68 Test (org.junit.Test)23 Source (com.oracle.truffle.api.source.Source)15 Source (org.graalvm.polyglot.Source)12 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)11 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)8 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)8 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)6 Node (com.oracle.truffle.api.nodes.Node)6 RootNode (com.oracle.truffle.api.nodes.RootNode)6 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)5 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 DebugScope (com.oracle.truffle.api.debug.DebugScope)3 Counter (com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2