use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class AbstractRequestHandler method getScope.
protected static Object getScope(TextDocumentSurrogate surrogate, InstrumentableNode node) {
List<CoverageData> coverageData = surrogate.getCoverageData(((Node) node).getSourceSection());
MaterializedFrame frame = null;
if (coverageData != null) {
CoverageData data = coverageData.stream().findFirst().orElse(null);
if (data != null) {
frame = data.getFrame();
}
}
NodeLibrary nodeLibrary = NodeLibrary.getUncached(node);
if (nodeLibrary.hasScope(node, frame)) {
try {
return nodeLibrary.getScope(node, frame, true);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
} else {
return null;
}
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class SourceCodeEvaluator method evalWithCoverageData.
private EvaluationResult evalWithCoverageData(TextDocumentSurrogate textDocumentSurrogate, Node nearestNode) {
if (!textDocumentSurrogate.hasCoverageData()) {
return EvaluationResult.createEvaluationSectionNotReached();
}
List<CoverageData> dataBeforeNode = findCoverageDataBeforeNode(textDocumentSurrogate, nearestNode);
if (dataBeforeNode == null || dataBeforeNode.isEmpty()) {
return EvaluationResult.createEvaluationSectionNotReached();
}
CoverageData coverageData = dataBeforeNode.get(dataBeforeNode.size() - 1);
if (((InstrumentableNode) nearestNode).hasTag(StandardTags.ReadVariableTag.class)) {
// Shortcut for variables
InteropUtils.VariableInfo[] variables = InteropUtils.getNodeObjectVariables((InstrumentableNode) nearestNode);
if (variables.length == 1) {
InteropUtils.VariableInfo var = variables[0];
NodeLibrary nodeLibrary = NodeLibrary.getUncached(nearestNode);
if (nodeLibrary.hasScope(nearestNode, coverageData.getFrame())) {
try {
Object scope = nodeLibrary.getScope(nearestNode, coverageData.getFrame(), true);
if (INTEROP.isMemberReadable(scope, var.getName())) {
logger.fine("Coverage-based variable look-up");
Object value = INTEROP.readMember(scope, var.getName());
return EvaluationResult.createResult(value);
}
} catch (UnknownIdentifierException | UnsupportedMessageException ex) {
throw CompilerDirectives.shouldNotReachHere(ex);
}
}
}
}
LanguageInfo info = nearestNode.getRootNode().getLanguageInfo();
String code = nearestNode.getSourceSection().getCharacters().toString();
Source inlineEvalSource = Source.newBuilder(info.getId(), code, "in-line eval (hover request)").cached(false).build();
ExecutableNode executableNode = env.parseInline(inlineEvalSource, nearestNode, coverageData.getFrame());
CoverageEventNode coverageEventNode = coverageData.getCoverageEventNode();
coverageEventNode.insertOrReplaceChild(executableNode);
try {
logger.fine("Trying coverage-based eval...");
Object result = executableNode.execute(coverageData.getFrame());
return EvaluationResult.createResult(result);
} catch (Exception e) {
e.printStackTrace();
} finally {
coverageEventNode.clearChild();
}
return EvaluationResult.createEvaluationSectionNotReached();
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class DebugStackFrame method initName.
// Initialize the stack frame name while we're on the execution thread
private String initName() throws DebugException {
verifyValidState(false);
Node node;
if (currentFrame == null) {
node = getContext().getInstrumentedNode();
} else {
node = currentFrame.getCallNode();
node = InstrumentableNode.findInstrumentableParent(node);
}
try {
if (node != null) {
Frame frame = findTruffleFrame(FrameAccess.READ_ONLY);
NodeLibrary nodeLibrary = NodeLibrary.getUncached();
if (nodeLibrary.hasRootInstance(node, frame)) {
Object instance = nodeLibrary.getRootInstance(node, frame);
InteropLibrary interop = InteropLibrary.getUncached();
if (interop.hasExecutableName(instance)) {
return interop.asString(interop.getExecutableName(instance));
}
}
}
RootNode root = findCurrentRoot();
if (root == null) {
return null;
}
return root.getName();
} catch (ThreadDeath td) {
throw td;
} catch (Throwable ex) {
RootNode root = findCurrentRoot();
LanguageInfo languageInfo = root != null ? root.getLanguageInfo() : null;
throw DebugException.create(event.getSession(), ex, languageInfo);
}
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class CompletionRequestHandler method fillCompletionsWithLocals.
private void fillCompletionsWithLocals(final TextDocumentSurrogate surrogate, Node nearestNode, List<CompletionItem> completions, MaterializedFrame frame) {
NodeLibrary nodeLibrary = NodeLibrary.getUncached(nearestNode);
if (nodeLibrary.hasScope(nearestNode, frame)) {
try {
Object scope = nodeLibrary.getScope(nearestNode, frame, true);
fillCompletionsWithScopesValues(surrogate, completions, scope, CompletionItemKind.Variable, SORTING_PRIORITY_LOCALS);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
}
use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.
the class DebugExprVarNode method findMemberAndType.
private Pair<Object, DebugExprType> findMemberAndType(VirtualFrame frameValue) {
NodeLibrary nodeLibrary = NodeLibrary.getUncached();
InteropLibrary interopLibrary = InteropLibrary.getUncached();
try {
LLVMDebuggerValue entries = (LLVMDebuggerValue) nodeLibrary.getScope(location, frameValue, true);
if (interopLibrary.isMemberReadable(entries, name)) {
Object member = interopLibrary.readMember(entries, name);
LLVMDebuggerValue ldv = (LLVMDebuggerValue) member;
Object metaObj = ldv.resolveMetaObject();
DebugExprType type = DebugExprType.getTypeFromSymbolTableMetaObject(metaObj);
return Pair.create(member, type);
}
} catch (ClassCastException e) {
// OR metaObj is no primitive type
throw DebugExprException.create(this, "\"%s\" cannot be casted to a LLVMDebuggerValue", name);
} catch (UnsupportedMessageException e) {
// should only happen if hasMembers == false
throw DebugExprException.symbolNotFound(this, name, null);
} catch (UnknownIdentifierException e) {
throw DebugExprException.symbolNotFound(this, e.getUnknownIdentifier(), null);
}
// not found: no exception is thrown as this node might be a function name
return Pair.create(null, DebugExprType.getVoidType());
}
Aggregations