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