com.oracle.truffle.api.nodes.Node.getEncapsulatingSourceSection()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(691)

本文整理了Java中com.oracle.truffle.api.nodes.Node.getEncapsulatingSourceSection()方法的一些代码示例,展示了Node.getEncapsulatingSourceSection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getEncapsulatingSourceSection()方法的具体详情如下:
包路径:com.oracle.truffle.api.nodes.Node
类名称:Node
方法名:getEncapsulatingSourceSection

Node.getEncapsulatingSourceSection介绍

[英]Retrieves the segment of guest language source code that is represented by this Node, if present; otherwise retrieves the segment represented by the nearest AST ancestor that has this information. Can be called on any thread and without a language context.
[中]检索此节点表示的来宾语言源代码段(如果存在);否则,检索由具有此信息的最近AST祖先表示的段。可以在任何线程上调用,无需语言上下文。

代码示例

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. @Override
  2. public SourceSection getInstrumentedSourceSection() {
  3. if (node == null) {
  4. return null;
  5. } else {
  6. return node.getEncapsulatingSourceSection();
  7. }
  8. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. @Override
  2. public SourceSection getInstrumentedSourceSection() {
  3. if (node == null) {
  4. return null;
  5. } else {
  6. return node.getEncapsulatingSourceSection();
  7. }
  8. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /**
  2. * Returns a location where this exception occurred in the AST. This method may return
  3. * <code>null</code> to indicate that the location is not available.
  4. *
  5. * @return the {@link SourceSection} or null
  6. * @since 0.33
  7. */
  8. default SourceSection getSourceLocation() {
  9. final Node node = getLocation();
  10. return node == null ? null : node.getEncapsulatingSourceSection();
  11. }
  12. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. /**
  2. * Returns a location where this exception occurred in the AST. This method may return
  3. * <code>null</code> to indicate that the location is not available.
  4. *
  5. * @return the {@link SourceSection} or null
  6. * @since 0.33
  7. */
  8. default SourceSection getSourceLocation() {
  9. final Node node = getLocation();
  10. return node == null ? null : node.getEncapsulatingSourceSection();
  11. }
  12. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. /**
  2. * Get a source section representing this scope. Please note that while this scope does not
  3. * provide variables that are valid only after the suspension point, the source section can
  4. * actually span after the suspension point.
  5. *
  6. * @return the source section, or <code>null</code> when not available.
  7. * @since 0.29
  8. */
  9. public SourceSection getSourceSection() {
  10. Node node = scope.getNode();
  11. if (node != null) {
  12. return node.getEncapsulatingSourceSection();
  13. } else {
  14. return null;
  15. }
  16. }

代码示例来源:origin: com.oracle/truffle

  1. public String displaySourceLocation(Node node) {
  2. if (node == null) {
  3. return "<unknown>";
  4. }
  5. SourceSection section = node.getSourceSection();
  6. boolean estimated = false;
  7. if (section == null) {
  8. section = node.getEncapsulatingSourceSection();
  9. estimated = true;
  10. }
  11. return section.getShortDescription() + (estimated ? "~" : "");
  12. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. public SourceSection getInstrumentedSourceSection() {
  2. SourceSection ss = eventContext.getInstrumentedSourceSection();
  3. if (ss == null) {
  4. Node node = eventContext.getInstrumentedNode();
  5. // Nodes tagged with standard tags should have a source section attached.
  6. PrintStream err = new PrintStream(env.err());
  7. err.print("WARNING: Instrumented node " + node + " of class " + node.getClass() + " has null SourceSection.");
  8. ss = node.getEncapsulatingSourceSection();
  9. if (ss == null) {
  10. RootNode root = node.getRootNode();
  11. err.print("WARNING: and null encapsulating SourceSection under " + root + " of class = " + root.getClass());
  12. }
  13. err.flush();
  14. }
  15. return ss;
  16. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /**
  2. * Returns the source section location of this trace element. The source section is
  3. * <code>null</code> if the source location is not available.
  4. *
  5. * @since 1.0
  6. */
  7. public SourceSection getSourceSection() {
  8. Node node = traceElement.getLocation();
  9. if (node != null) {
  10. return session.resolveSection(node.getEncapsulatingSourceSection());
  11. }
  12. return null;
  13. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. @Override
  2. public Caller visitFrame(FrameInstance frameInstance) {
  3. // we stop at eval root stack frames
  4. if (!SuspendedEvent.isEvalRootStackFrame(DebuggerSession.this, frameInstance) && (depth++ == 0)) {
  5. return null;
  6. }
  7. Node callNode = frameInstance.getCallNode();
  8. // Prefer call node with a source section
  9. if (callNode != null && callNode.getEncapsulatingSourceSection() != null) {
  10. return new Caller(frameInstance);
  11. } else {
  12. if (nearestCaller[0] == null) {
  13. nearestCaller[0] = new Caller(frameInstance);
  14. }
  15. return null;
  16. }
  17. }
  18. });

代码示例来源:origin: org.graalvm.compiler/compiler

  1. SourceSection sourceSection = null;
  2. if (callNode != null) {
  3. sourceSection = callNode.getEncapsulatingSourceSection();

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) {
  2. if (TruffleOptions.TraceRewritesFilterFromCost != null) {
  3. if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) {
  4. return;
  5. }
  6. }
  7. if (TruffleOptions.TraceRewritesFilterToCost != null) {
  8. if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) {
  9. return;
  10. }
  11. }
  12. String filter = TruffleOptions.TraceRewritesFilterClass;
  13. Class<? extends Node> from = oldNode.getClass();
  14. Class<? extends Node> to = newNode.getClass();
  15. if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) {
  16. return;
  17. }
  18. final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection();
  19. PrintStream out = System.out;
  20. out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s %s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode),
  21. reason != null && reason.length() > 0 ? reason : "unknown", formatLocation(reportedSourceSection));
  22. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /**
  2. * Get a source section representing this scope. Please note that while this scope does not
  3. * provide variables that are valid only after the suspension point, the source section can
  4. * actually span after the suspension point.
  5. *
  6. * @return the source section, or <code>null</code> when not available.
  7. * @throws DebugException when guest language code throws an exception
  8. * @since 0.29
  9. */
  10. public SourceSection getSourceSection() throws DebugException {
  11. try {
  12. Node node = scope.getNode();
  13. if (node != null) {
  14. return session.resolveSection(node.getEncapsulatingSourceSection());
  15. } else {
  16. return null;
  17. }
  18. } catch (ThreadDeath td) {
  19. throw td;
  20. } catch (Throwable ex) {
  21. throw new DebugException(session, ex, language, null, true, null);
  22. }
  23. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) {
  2. if (TruffleOptions.TraceRewritesFilterFromCost != null) {
  3. if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) {
  4. return;
  5. }
  6. }
  7. if (TruffleOptions.TraceRewritesFilterToCost != null) {
  8. if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) {
  9. return;
  10. }
  11. }
  12. String filter = TruffleOptions.TraceRewritesFilterClass;
  13. Class<? extends Node> from = oldNode.getClass();
  14. Class<? extends Node> to = newNode.getClass();
  15. if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) {
  16. return;
  17. }
  18. final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection();
  19. PrintStream out = System.out;
  20. out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s %s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode),
  21. reason != null && reason.length() > 0 ? reason : "unknown", formatLocation(reportedSourceSection));
  22. }

代码示例来源:origin: com.oracle/truffle

  1. static void traceRewrite(Node oldNode, Node newNode, CharSequence reason) {
  2. if (TruffleOptions.TraceRewritesFilterFromCost != null) {
  3. if (filterByKind(oldNode, TruffleOptions.TraceRewritesFilterFromCost)) {
  4. return;
  5. }
  6. }
  7. if (TruffleOptions.TraceRewritesFilterToCost != null) {
  8. if (filterByKind(newNode, TruffleOptions.TraceRewritesFilterToCost)) {
  9. return;
  10. }
  11. }
  12. String filter = TruffleOptions.TraceRewritesFilterClass;
  13. Class<? extends Node> from = oldNode.getClass();
  14. Class<? extends Node> to = newNode.getClass();
  15. if (filter != null && (filterByContainsClassName(from, filter) || filterByContainsClassName(to, filter))) {
  16. return;
  17. }
  18. final SourceSection reportedSourceSection = oldNode.getEncapsulatingSourceSection();
  19. PrintStream out = System.out;
  20. out.printf("[truffle] rewrite %-50s |From %-40s |To %-40s |Reason %s%s%n", oldNode.toString(), formatNodeInfo(oldNode), formatNodeInfo(newNode),
  21. reason != null && reason.length() > 0 ? reason : "unknown", reportedSourceSection != null ? " at " + reportedSourceSection.getShortDescription() : "");
  22. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. /**
  2. * Returns the source section of the location where the debugging session was suspended. The
  3. * source section is <code>null</code> if the source location is not available.
  4. *
  5. * <p>
  6. * This method is thread-safe.
  7. *
  8. * @since 0.17
  9. */
  10. public SourceSection getSourceSection() {
  11. verifyValidState(true);
  12. if (currentFrame == null) {
  13. SuspendedContext context = getContext();
  14. return context.getInstrumentedSourceSection();
  15. } else {
  16. Node callNode = currentFrame.getCallNode();
  17. if (callNode != null) {
  18. return callNode.getEncapsulatingSourceSection();
  19. }
  20. return null;
  21. }
  22. }

代码示例来源:origin: cesquivias/mumbler

  1. SourceSection sourceSection = callNode.getEncapsulatingSourceSection();
  2. Source source = sourceSection != null ? sourceSection.getSource() : null;
  3. String sourceName = source != null ? source.getName() : null;

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. /**
  2. * Returns the source section of the location where the debugging session was suspended. The
  3. * source section is <code>null</code> if the source location is not available.
  4. *
  5. * <p>
  6. * This method is thread-safe.
  7. *
  8. * @since 0.17
  9. */
  10. public SourceSection getSourceSection() {
  11. verifyValidState(true);
  12. if (currentFrame == null) {
  13. SuspendedContext context = getContext();
  14. return event.getSession().resolveSection(context.getInstrumentedSourceSection());
  15. } else {
  16. Node callNode = currentFrame.getCallNode();
  17. if (callNode != null) {
  18. return event.getSession().resolveSection(callNode.getEncapsulatingSourceSection());
  19. }
  20. return null;
  21. }
  22. }

代码示例来源:origin: org.graalvm.truffle/truffle-api

  1. static PolyglotExceptionFrame createGuest(PolyglotExceptionImpl exception, TruffleStackTraceElement frame, boolean first) {
  2. if (frame == null) {
  3. return null;
  4. }
  5. RootNode targetRoot = frame.getTarget().getRootNode();
  6. if (targetRoot.isInternal()) {
  7. return null;
  8. }
  9. LanguageInfo info = targetRoot.getLanguageInfo();
  10. if (info == null) {
  11. return null;
  12. }
  13. PolyglotEngineImpl engine = exception.getEngine();
  14. PolyglotLanguage language = engine.idToLanguage.get(info.getId());
  15. String rootName = targetRoot.getName();
  16. SourceSection location;
  17. Node callNode = frame.getLocation();
  18. if (callNode != null) {
  19. com.oracle.truffle.api.source.SourceSection section = callNode.getEncapsulatingSourceSection();
  20. if (section != null) {
  21. Source source = engine.getAPIAccess().newSource(language.getId(), section.getSource());
  22. location = engine.getAPIAccess().newSourceSection(source, section);
  23. } else {
  24. location = null;
  25. }
  26. } else {
  27. location = first ? exception.getSourceLocation() : null;
  28. }
  29. return new PolyglotExceptionFrame(exception, language, location, rootName, false, null);
  30. }

代码示例来源:origin: com.oracle.truffle/truffle-api

  1. static PolyglotExceptionFrame createGuest(PolyglotExceptionImpl exception, TruffleStackTraceElement frame, boolean first) {
  2. if (frame == null) {
  3. return null;
  4. }
  5. RootNode targetRoot = frame.getTarget().getRootNode();
  6. if (targetRoot.isInternal()) {
  7. return null;
  8. }
  9. LanguageInfo info = targetRoot.getLanguageInfo();
  10. if (info == null) {
  11. return null;
  12. }
  13. PolyglotEngineImpl engine = exception.context.getEngine();
  14. PolyglotLanguage language = engine.idToLanguage.get(info.getId());
  15. String rootName = targetRoot.getName();
  16. SourceSection location;
  17. Node callNode = frame.getLocation();
  18. if (callNode != null) {
  19. com.oracle.truffle.api.source.SourceSection section = callNode.getEncapsulatingSourceSection();
  20. if (section != null) {
  21. Source source = engine.getAPIAccess().newSource(language.getId(), section.getSource());
  22. location = engine.getAPIAccess().newSourceSection(source, section);
  23. } else {
  24. location = null;
  25. }
  26. } else {
  27. location = first ? exception.getSourceLocation() : null;
  28. }
  29. return new PolyglotExceptionFrame(exception, language, location, rootName, false, null);
  30. }

相关文章