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

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

本文整理了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

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

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

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

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

private static void updateSourceSection(Node oldNode, Node newNode) {
  if (newNode.getSourceSection() == null) {
    newNode.assignSourceSection(oldNode.getSourceSection());
  }
}

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

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

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

private static String getSourceSectionInfo(Node newNode) {
  SourceSection sourceSection = newNode.getSourceSection();
  if (sourceSection != null) {
    return ", \"identifier\": \"" + sourceSection.getIdentifier() + "\" ";
  } else {
    return "";
  }
}

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

private static String extractSourceSection(OptimizedDirectCallNode node) {
  Node cnode = node;
  while (cnode.getSourceSection() == null && !(cnode instanceof RootNode)) {
    cnode = cnode.getParent();
    if (cnode == null) {
      return "";
    }
  }
  return getShortDescription(cnode.getSourceSection());
}

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

public boolean visit(Node node) {
    final SourceSection sourceSection = node.getSourceSection();
    if (sourceSection != null) {
      source = sourceSection.getSource();
      return false;
    }
    return true;
  }
}

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

/**
 * 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.
 *
 * @return an approximation of the source code represented by this Node
 * @since 0.8 or earlier
 */
@ExplodeLoop
public SourceSection getEncapsulatingSourceSection() {
  Node current = this;
  while (current != null) {
    final SourceSection currentSection = current.getSourceSection();
    if (currentSection != null) {
      return currentSection;
    }
    current = current.parent;
  }
  return null;
}

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

StackTraceEntry(Instrumenter instrumenter, Node node, byte state) {
  this.tags = instrumenter.queryTags(node);
  this.sourceSection = node.getSourceSection();
  this.instrumentedNode = node;
  this.rootName = extractRootName(instrumentedNode);
  this.state = state;
}

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

public String displaySourceLocation(Node node) {
  if (node == null) {
    return "<unknown>";
  }
  SourceSection section = node.getSourceSection();
  boolean estimated = false;
  if (section == null) {
    section = node.getEncapsulatingSourceSection();
    estimated = true;
  }
  return section.getShortDescription() + (estimated ? "~" : "");
}

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

public ExecutionEventNode create(EventContext context) {
    Node instrumentedNode = context.getInstrumentedNode();
    if (instrumentedNode.getSourceSection() == null) {
      logger.warning("Instrumented node " + instrumentedNode + " has null SourceSection.");
      return null;
    }
    return new StackPushPopNode(ShadowStack.this, instrumenter, context, compiledOnly);
  }
});

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

@Override
public void nodeProperties(PolymorphicSpecializeGraph graph, PolymorphicSpecializeGraph.DumpNode node, Map<String, ? super Object> properties) {
  properties.put("label", node.node.toString());
  properties.put("ROOT?", node.node instanceof RootNode);
  properties.put("LEAF?", node.edge == null);
  properties.put("RootNode", node.node.getRootNode());
  properties.putAll(node.node.getDebugProperties());
  properties.put("SourceSection", node.node.getSourceSection());
  if (Introspection.isIntrospectable(node.node)) {
    final List<Introspection.SpecializationInfo> specializations = Introspection.getSpecializations(node.node);
    for (Introspection.SpecializationInfo specialization : specializations) {
      properties.put(specialization.getMethodName() + ".isActive", specialization.isActive());
      properties.put(specialization.getMethodName() + ".isExcluded", specialization.isExcluded());
      properties.put(specialization.getMethodName() + ".instances", specialization.getInstances());
    }
  }
}

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

private static void reconstructStack(ArrayList<StackTraceEntry> sourceLocations, Node node, SourceSectionFilter sourceSectionFilter, Instrumenter instrumenter) {
  if (node == null || sourceSectionFilter == null) {
    return;
  }
  // We exclude the node itself as it will be pushed on the stack by the StackPushPopNode
  Node current = node.getParent();
  while (current != null) {
    if (sourceSectionFilter.includes(current) && current.getSourceSection() != null) {
      sourceLocations.add(new StackTraceEntry(instrumenter, current, StackTraceEntry.STATE_INTERPRETED));
    }
    current = current.getParent();
  }
}

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

protected static String sourceInfo(Node node) {
  final SourceSection src = node.getSourceSection();
  if (src != null) {
    if (src instanceof NullSourceSection) {
      final NullSourceSection nullSection = (NullSourceSection) src;
      return nullSection.getShortDescription();
    } else {
      return src.getSource().getName() + ":" + src.getStartLine();
    }
  }
  return "";
}

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

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

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

public final boolean visit(Node node) {
  SourceSection sourceSection = node.getSourceSection();
  if (InstrumentationHandler.isInstrumentableNode(node, sourceSection)) {
    if (binding.isChildInstrumentedFull(providedTags, rootNode, instrumentedNode, instrumentedNodeSourceSection, node, sourceSection)) {
      if (!visitChild(node)) {
        return false;
      }
    }
    return true;
  }
  NodeUtil.forEachChild(node, this);
  return true;
}

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

public final boolean visit(Node node) {
  SourceSection sourceSection = node.getSourceSection();
  if (InstrumentationHandler.isInstrumentableNode(node, sourceSection)) {
    if (binding.isChildInstrumentedFull(providedTags, rootNode, instrumentedNode, instrumentedNodeSourceSection, node, sourceSection)) {
      if (!visitChild(node)) {
        return false;
      }
    }
    return true;
  }
  NodeUtil.forEachChild(node, this);
  return true;
}

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

private static boolean hasLargerParent(Node ch, int sectionLength) {
    Node parent = ch.getParent();
    while (parent != null) {
      if (parent instanceof InstrumentableNode && ((InstrumentableNode) parent).isInstrumentable() || parent instanceof RootNode) {
        SourceSection pss = parent.getSourceSection();
        if (pss != null && pss.getCharLength() > sectionLength) {
          return true;
        }
      }
      parent = parent.getParent();
    }
    return false;
  }
}

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

@Override
@SuppressWarnings("deprecation")
public final ExecutionEventNode lookupExecutionEventNode(Node node, EventBinding<?> binding) {
  if (!InstrumentationHandler.isInstrumentableNode(node, node.getSourceSection())) {
    return null;
  }
  Node p = node.getParent();
  if (p instanceof InstrumentableFactory.WrapperNode) {
    InstrumentableFactory.WrapperNode w = (InstrumentableFactory.WrapperNode) p;
    return w.getProbeNode().lookupExecutionEventNode(binding);
  } else {
    return null;
  }
}

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

public void onNodeInserted(RootNode rootNode, Node tree) {
  // for input filters to be updated correctly we need to
  // start traversing with the parent instrumentable node.
  Node parentInstrumentable = tree;
  while (parentInstrumentable != null && parentInstrumentable.getParent() != null) {
    parentInstrumentable = parentInstrumentable.getParent();
    if (InstrumentationHandler.isInstrumentableNode(parentInstrumentable, parentInstrumentable.getSourceSection())) {
      break;
    }
  }
  assert parentInstrumentable != null;
  if (!sourceSectionBindings.isEmpty()) {
    visitRoot(rootNode, parentInstrumentable, new NotifyLoadedListenerVisitor(sourceSectionBindings), true);
  }
  if (!executionBindings.isEmpty()) {
    visitRoot(rootNode, parentInstrumentable, new InsertWrappersVisitor(executionBindings), true);
  }
}

相关文章