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

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

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

Node.getSourceSection介绍

[英]Retrieves the segment of guest language source code that is represented by this Node. The default implementation of this method returns null. If your node represents a segment of the source code, override this method and return a eagerly or lazily computed source section value. This method is not designed to be invoked on compiled code paths. May be called on any thread and without a language context being active.

Simple example implementation using a simple implementation using a field: com.oracle.truffle.api.nodes.NodeSnippets.SimpleNode

Recommended implementation computing the source section lazily from primitive fields: com.oracle.truffle.api.nodes.NodeSnippets.RecommendedNode
[中]检索此节点表示的来宾语言源代码段。此方法的默认实现返回null。如果您的节点代表源代码的一段,请重写此方法并返回一个急切或延迟计算的源节值。此方法不是为在编译代码路径上调用而设计的。可以在任何线程上调用,且无需激活语言上下文。
简单示例实现使用一个简单的实现使用一个字段:com。神谕松露。应用程序编程接口。节点。点乳头。单纯形
推荐的实现是从基本字段:com惰性地计算源代码部分。神谕松露。应用程序编程接口。节点。点乳头。推荐节点

代码示例

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

  1. /**
  2. * Assigns a link to a guest language source section to this node.
  3. *
  4. * @param section the object representing a section in guest language source code
  5. */
  6. public final void assignSourceSection(SourceSection section) {
  7. if (sourceSection != null) {
  8. // Patch this test during the transition to constructor-based
  9. // source attribution, which would otherwise trigger this
  10. // exception. This method will eventually be deprecated.
  11. if (getSourceSection() != section) {
  12. throw new IllegalStateException("Source section is already assigned. Old: " + getSourceSection() + ", new: " + section);
  13. }
  14. }
  15. this.sourceSection = section;
  16. }

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

  1. /**
  2. * Originally returned the <em>tags</em> if any, associated with a node; now unsupported.
  3. *
  4. * @since 0.8 or earlier
  5. */
  6. public static String printSyntaxTags(final Object node) {
  7. if ((node instanceof Node) && ((Node) node).getSourceSection() != null) {
  8. return ((Node) node).getSourceSection().toString();
  9. }
  10. return "";
  11. }

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

  1. private static void updateSourceSection(Node oldNode, Node newNode) {
  2. if (newNode.getSourceSection() == null) {
  3. newNode.assignSourceSection(oldNode.getSourceSection());
  4. }
  5. }

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

  1. /**
  2. * Originally returned the <em>tags</em> if any, associated with a node; now unsupported.
  3. *
  4. * @since 0.8 or earlier
  5. */
  6. public static String printSyntaxTags(final Object node) {
  7. if ((node instanceof Node) && ((Node) node).getSourceSection() != null) {
  8. return ((Node) node).getSourceSection().toString();
  9. }
  10. return "";
  11. }

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

  1. private static String getSourceSectionInfo(Node newNode) {
  2. SourceSection sourceSection = newNode.getSourceSection();
  3. if (sourceSection != null) {
  4. return ", \"identifier\": \"" + sourceSection.getIdentifier() + "\" ";
  5. } else {
  6. return "";
  7. }
  8. }

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

  1. private static String extractSourceSection(OptimizedDirectCallNode node) {
  2. Node cnode = node;
  3. while (cnode.getSourceSection() == null && !(cnode instanceof RootNode)) {
  4. cnode = cnode.getParent();
  5. if (cnode == null) {
  6. return "";
  7. }
  8. }
  9. return getShortDescription(cnode.getSourceSection());
  10. }

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

  1. public boolean visit(Node node) {
  2. final SourceSection sourceSection = node.getSourceSection();
  3. if (sourceSection != null) {
  4. source = sourceSection.getSource();
  5. return false;
  6. }
  7. return true;
  8. }
  9. }

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

  1. /**
  2. * Retrieves the segment of guest language source code that is represented by this Node, if
  3. * present; otherwise retrieves the segment represented by the nearest AST ancestor that has
  4. * this information. Can be called on any thread and without a language context.
  5. *
  6. * @return an approximation of the source code represented by this Node
  7. * @since 0.8 or earlier
  8. */
  9. @ExplodeLoop
  10. public SourceSection getEncapsulatingSourceSection() {
  11. Node current = this;
  12. while (current != null) {
  13. final SourceSection currentSection = current.getSourceSection();
  14. if (currentSection != null) {
  15. return currentSection;
  16. }
  17. current = current.parent;
  18. }
  19. return null;
  20. }

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

  1. StackTraceEntry(Instrumenter instrumenter, Node node, byte state) {
  2. this.tags = instrumenter.queryTags(node);
  3. this.sourceSection = node.getSourceSection();
  4. this.instrumentedNode = node;
  5. this.rootName = extractRootName(instrumentedNode);
  6. this.state = state;
  7. }

代码示例来源: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.tools/profiler

  1. public ExecutionEventNode create(EventContext context) {
  2. Node instrumentedNode = context.getInstrumentedNode();
  3. if (instrumentedNode.getSourceSection() == null) {
  4. logger.warning("Instrumented node " + instrumentedNode + " has null SourceSection.");
  5. return null;
  6. }
  7. return new StackPushPopNode(ShadowStack.this, instrumenter, context, compiledOnly);
  8. }
  9. });

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

  1. @Override
  2. public void nodeProperties(PolymorphicSpecializeGraph graph, PolymorphicSpecializeGraph.DumpNode node, Map<String, ? super Object> properties) {
  3. properties.put("label", node.node.toString());
  4. properties.put("ROOT?", node.node instanceof RootNode);
  5. properties.put("LEAF?", node.edge == null);
  6. properties.put("RootNode", node.node.getRootNode());
  7. properties.putAll(node.node.getDebugProperties());
  8. properties.put("SourceSection", node.node.getSourceSection());
  9. if (Introspection.isIntrospectable(node.node)) {
  10. final List<Introspection.SpecializationInfo> specializations = Introspection.getSpecializations(node.node);
  11. for (Introspection.SpecializationInfo specialization : specializations) {
  12. properties.put(specialization.getMethodName() + ".isActive", specialization.isActive());
  13. properties.put(specialization.getMethodName() + ".isExcluded", specialization.isExcluded());
  14. properties.put(specialization.getMethodName() + ".instances", specialization.getInstances());
  15. }
  16. }
  17. }

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

  1. private static void reconstructStack(ArrayList<StackTraceEntry> sourceLocations, Node node, SourceSectionFilter sourceSectionFilter, Instrumenter instrumenter) {
  2. if (node == null || sourceSectionFilter == null) {
  3. return;
  4. }
  5. // We exclude the node itself as it will be pushed on the stack by the StackPushPopNode
  6. Node current = node.getParent();
  7. while (current != null) {
  8. if (sourceSectionFilter.includes(current) && current.getSourceSection() != null) {
  9. sourceLocations.add(new StackTraceEntry(instrumenter, current, StackTraceEntry.STATE_INTERPRETED));
  10. }
  11. current = current.getParent();
  12. }
  13. }

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

  1. protected static String sourceInfo(Node node) {
  2. final SourceSection src = node.getSourceSection();
  3. if (src != null) {
  4. if (src instanceof NullSourceSection) {
  5. final NullSourceSection nullSection = (NullSourceSection) src;
  6. return nullSection.getShortDescription();
  7. } else {
  8. return src.getSource().getName() + ":" + src.getStartLine();
  9. }
  10. }
  11. return "";
  12. }

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

  1. /**
  2. * Create a new {@link Probe} associated with, and attached to, a Guest Language specific
  3. * instance of {@link WrapperNode}.
  4. */
  5. public static Probe insertProbe(WrapperNode wrapper) {
  6. final SourceSection sourceSection = wrapper.getChild().getSourceSection();
  7. final ProbeNode probeNode = new ProbeNode(); // private constructor
  8. probeNode.probe = new Probe(probeNode, sourceSection); // package private access
  9. wrapper.insertProbe(probeNode);
  10. return probeNode.probe;
  11. }

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

  1. public final boolean visit(Node node) {
  2. SourceSection sourceSection = node.getSourceSection();
  3. if (InstrumentationHandler.isInstrumentableNode(node, sourceSection)) {
  4. if (binding.isChildInstrumentedFull(providedTags, rootNode, instrumentedNode, instrumentedNodeSourceSection, node, sourceSection)) {
  5. if (!visitChild(node)) {
  6. return false;
  7. }
  8. }
  9. return true;
  10. }
  11. NodeUtil.forEachChild(node, this);
  12. return true;
  13. }

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

  1. public final boolean visit(Node node) {
  2. SourceSection sourceSection = node.getSourceSection();
  3. if (InstrumentationHandler.isInstrumentableNode(node, sourceSection)) {
  4. if (binding.isChildInstrumentedFull(providedTags, rootNode, instrumentedNode, instrumentedNodeSourceSection, node, sourceSection)) {
  5. if (!visitChild(node)) {
  6. return false;
  7. }
  8. }
  9. return true;
  10. }
  11. NodeUtil.forEachChild(node, this);
  12. return true;
  13. }

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

  1. private static boolean hasLargerParent(Node ch, int sectionLength) {
  2. Node parent = ch.getParent();
  3. while (parent != null) {
  4. if (parent instanceof InstrumentableNode && ((InstrumentableNode) parent).isInstrumentable() || parent instanceof RootNode) {
  5. SourceSection pss = parent.getSourceSection();
  6. if (pss != null && pss.getCharLength() > sectionLength) {
  7. return true;
  8. }
  9. }
  10. parent = parent.getParent();
  11. }
  12. return false;
  13. }
  14. }

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

  1. @Override
  2. @SuppressWarnings("deprecation")
  3. public final ExecutionEventNode lookupExecutionEventNode(Node node, EventBinding<?> binding) {
  4. if (!InstrumentationHandler.isInstrumentableNode(node, node.getSourceSection())) {
  5. return null;
  6. }
  7. Node p = node.getParent();
  8. if (p instanceof InstrumentableFactory.WrapperNode) {
  9. InstrumentableFactory.WrapperNode w = (InstrumentableFactory.WrapperNode) p;
  10. return w.getProbeNode().lookupExecutionEventNode(binding);
  11. } else {
  12. return null;
  13. }
  14. }

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

  1. public void onNodeInserted(RootNode rootNode, Node tree) {
  2. // for input filters to be updated correctly we need to
  3. // start traversing with the parent instrumentable node.
  4. Node parentInstrumentable = tree;
  5. while (parentInstrumentable != null && parentInstrumentable.getParent() != null) {
  6. parentInstrumentable = parentInstrumentable.getParent();
  7. if (InstrumentationHandler.isInstrumentableNode(parentInstrumentable, parentInstrumentable.getSourceSection())) {
  8. break;
  9. }
  10. }
  11. assert parentInstrumentable != null;
  12. if (!sourceSectionBindings.isEmpty()) {
  13. visitRoot(rootNode, parentInstrumentable, new NotifyLoadedListenerVisitor(sourceSectionBindings), true);
  14. }
  15. if (!executionBindings.isEmpty()) {
  16. visitRoot(rootNode, parentInstrumentable, new InsertWrappersVisitor(executionBindings), true);
  17. }
  18. }

相关文章