use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class TckLanguage method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source code = request.getSource();
final RootNode root;
final String txt = code.getCharacters().toString();
if (txt.startsWith("TCK42:")) {
int nextColon = txt.indexOf(":", 6);
String mimeType = txt.substring(6, nextColon);
Source toParse = Source.newBuilder(txt.substring(nextColon + 1)).mimeType(mimeType).name("src.tck").build();
root = new MultiplyNode(this, toParse);
} else {
final double value = Double.parseDouble(txt);
root = RootNode.createConstantNode(value);
}
return Truffle.getRuntime().createCallTarget(root);
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class Context method parse.
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source code = request.getSource();
SourceSection outer = code.createSection(0, code.getLength());
BaseNode node;
try {
node = parse(code);
} catch (LanguageError e) {
throw new IOException(e);
}
RootCallTarget afterTarget = getContextReference().get().afterTarget;
return Truffle.getRuntime().createCallTarget(new InstrumentationTestRootNode(this, "", outer, afterTarget, node));
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testLineNotIn.
@Test
public void testLineNotIn() {
Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 23));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 1)).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 2)).build(), root, createNode(sampleSource.createSection(2, 1), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(6, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 1, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(3 * LINE_LENGTH - 2, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH + 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(2, 2)).build(), root, createNode(sampleSource.createSection(1 * LINE_LENGTH - 2, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createUnavailableSection())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(0, LINE_LENGTH), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1), IndexRange.between(2, 3), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().lineNotIn(IndexRange.byLength(1, 1), IndexRange.byLength(3, 1)).build(), root, createNode(sampleSource.createSection(LINE_LENGTH, LINE_LENGTH), tags())));
Assert.assertNotNull(SourceSectionFilter.newBuilder().lineIn(2, 2).build().toString());
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testComplexFilter.
@Test
public void testComplexFilter() {
Source sampleSource1 = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType("mime2").build();
Node root = createNode(sampleSource1.createSection(0, 23));
SourceSectionFilter filter = //
SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION, InstrumentationTestLanguage.DEFINE).tagIsNot(InstrumentationTestLanguage.DEFINE, //
InstrumentationTestLanguage.ROOT).indexIn(0, //
3).sourceIs(sampleSource1).sourceSectionEquals(//
sampleSource1.createSection(0, 5)).lineIn(1, 1).lineIs(1).mimeTypeIs("mime1", "mime2").build();
Assert.assertFalse(isInstrumented(filter, root, source()));
Assert.assertTrue(isInstrumentedRoot(filter, null));
Assert.assertFalse(isInstrumentedNode(filter, source()));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createUnavailableSection())));
Assert.assertTrue(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.EXPRESSION))));
Assert.assertFalse(isInstrumented(filter, root, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(0, 5))));
Assert.assertTrue(isInstrumentedRoot(filter, createNode(sampleSource1.createSection(10, 5))));
Assert.assertFalse(isInstrumentedNode(filter, createNode(sampleSource1.createSection(0, 5), tags(InstrumentationTestLanguage.STATEMENT))));
Assert.assertNotNull(filter.toString());
}
use of com.oracle.truffle.api.source.Source in project graal by oracle.
the class SourceSectionFilterTest method testIndexNotIn.
@Test
public void testIndexNotIn() {
Source sampleSource = Source.newBuilder("line1\nline2\nline3\nline4").name("unknown").mimeType(InstrumentationTestLanguage.MIME_TYPE).build();
Node root = createNode(sampleSource.createSection(0, 23));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(0, 0)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(0, 1)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(0, 4), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(0, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(4, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(4, 6), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(10, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(9, 1), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createSection(9, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.byLength(5, 5)).build(), root, createNode(sampleSource.createUnavailableSection())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertFalse(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5), IndexRange.between(5, 6)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertTrue(isInstrumented(SourceSectionFilter.newBuilder().indexNotIn(IndexRange.between(0, 5), IndexRange.between(11, 12)).build(), root, createNode(sampleSource.createSection(5, 5), tags())));
Assert.assertNotNull(SourceSectionFilter.newBuilder().indexIn(5, 5).build().toString());
}
Aggregations