/** * 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; }
/** * 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 ""; }
private static void updateSourceSection(Node oldNode, Node newNode) { if (newNode.getSourceSection() == null) { newNode.assignSourceSection(oldNode.getSourceSection()); } }
/** * 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 ""; }
private static String getSourceSectionInfo(Node newNode) { SourceSection sourceSection = newNode.getSourceSection(); if (sourceSection != null) { return ", \"identifier\": \"" + sourceSection.getIdentifier() + "\" "; } else { return ""; } }
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()); }
public boolean visit(Node node) { final SourceSection sourceSection = node.getSourceSection(); if (sourceSection != null) { source = sourceSection.getSource(); return false; } return true; } }
/** * 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; }
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; }
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 ? "~" : ""); }
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); } });
@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()); } } }
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(); } }
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 ""; }
/** * 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; }
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; }
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; }
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; } }
@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; } }
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); } }