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();
}
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(), "");
}
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());
}
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());
}
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());
}
Aggregations