Search in sources :

Example 61 with SourceSection

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

the class SourceSectionTest method emptyLineTest1.

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

Example 62 with SourceSection

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

the class SourceSectionTest method emptySectionTest2.

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

Example 63 with SourceSection

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

the class NodeUtil method displaySourceAttribution.

private static String displaySourceAttribution(Node node) {
    final SourceSection section = node.getSourceSection();
    if (section == null) {
        return "";
    }
    if (section.getSource() == null) {
        // then source cannot become null anymore.
        return "source: <unknown>";
    }
    final String srcText = section.getCharacters().toString();
    final StringBuilder sb = new StringBuilder();
    sb.append("source:");
    sb.append(" (" + section.getCharIndex() + "," + (section.getCharEndIndex() - 1) + ")");
    sb.append(" line=" + section.getStartLine());
    sb.append(" len=" + srcText.length());
    sb.append(" text=\"" + srcText + "\"");
    return sb.toString();
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 64 with SourceSection

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

the class NodeUtil method traceRewrite.

static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) {
    if (TruffleOptions.TraceRewritesFilterFromCost != null) {
        if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) {
            return;
        }
    }
    if (TruffleOptions.TraceRewritesFilterToCost != null) {
        if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) {
            return;
        }
    }
    String filter = TruffleOptions.TraceRewritesFilterClass;
    Class<? extends Node> from = oldNode.getClass();
    Class<? extends Node> to = newNode.getClass();
    if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) {
        return;
    }
    final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection();
    PrintStream out = System.out;
    out.printf("[truffle]   rewrite %-50s |From %-40s |To %-40s |Reason %s %s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode), reason != null && reason.length() > 0 ? reason : "unknown", formatLocation(reportedSourceSection));
}
Also used : PrintStream(java.io.PrintStream) SourceSection(com.oracle.truffle.api.source.SourceSection)

Example 65 with SourceSection

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

the class BreakpointsHandler method createBreakpoint.

Params createBreakpoint(Location location, String condition) throws CommandProcessException {
    Script script = slh.getScript(location.getScriptId());
    if (script == null) {
        throw new CommandProcessException("No script with id '" + location.getScriptId() + "'");
    }
    Breakpoint bp = createBuilder(script.getSource(), location.getLine(), location.getColumn()).resolveListener(resolvedHandler).build();
    if (condition != null && !condition.isEmpty()) {
        bp.setCondition(condition);
    }
    bp = ds.install(bp);
    JSONArray locations = new JSONArray();
    long id;
    synchronized (bpIDs) {
        id = ++lastID;
        bpIDs.put(bp, id);
        SourceSection section = resolvedBreakpoints.remove(bp);
        if (section != null) {
            Location resolvedLocation = new Location(location.getScriptId(), section.getStartLine(), section.getStartColumn());
            locations.put(resolvedLocation.toJSON());
        }
    }
    JSONObject json = new JSONObject();
    json.put("breakpointId", Long.toString(id));
    locations.put(location.toJSON());
    json.put("locations", locations);
    return new Params(json);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

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