/** * Set arguments of the scope. * <p> * The properties representing the arguments needs to have deterministic iteration order, * argument declaration order is recommended. * * @param arguments arguments of the scope * @since 0.30 */ @SuppressWarnings("hiding") public Builder arguments(Object arguments) { assert arguments == null || TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(arguments) : Objects.toString(arguments); this.arguments = arguments; return this; }
@SuppressWarnings("unchecked") boolean validEventContext() { Node node = getInstrumentedNode(); if (node instanceof RootNode) { throw new IllegalStateException("Instrumentable node must not be a root node."); } Object object = null; if (node instanceof InstrumentableNode) { object = ((InstrumentableNode) node).getNodeObject(); } else { // legacy support return true; } if (object != null) { assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object); } boolean foundStandardTag = false; for (Class<?> clazz : StandardTags.ALL_TAGS) { if (hasTag((Class<? extends Tag>) clazz)) { foundStandardTag = true; } } if (foundStandardTag) { RootNode root = probeNode.getRootNode(); if (root != null && root.getSourceSection() != null) { assert sourceSection != null : "All nodes tagged with a standard tag and with a root node that has a source section must also have a source section."; } } return true; }
@SuppressWarnings("unchecked") boolean validEventContext() { Node node = getInstrumentedNode(); if (node instanceof RootNode) { throw new IllegalStateException("Instrumentable node must not be a root node."); } Object object = null; if (node instanceof InstrumentableNode) { object = ((InstrumentableNode) node).getNodeObject(); } else { // legacy support return true; } if (object != null) { assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object); } boolean foundStandardTag = false; for (Class<?> clazz : StandardTags.ALL_TAGS) { if (hasTag((Class<? extends Tag>) clazz)) { foundStandardTag = true; } } if (foundStandardTag) { RootNode root = probeNode.getRootNode(); if (root != null && root.getSourceSection() != null) { assert sourceSection != null : "All nodes tagged with a standard tag and with a root node that has a source section must also have a source section."; } } return true; }
/** * Returns a language provided object that represents the instrumented node properties. The * returned is alwasy a valid interop object. The returned object is never <code>null</code> and * always returns <code>true</code> for the HAS_KEYS message. Multiple calls to * {@link #getNodeObject()} return the same node object instance. * * @see InstrumentableNode#getNodeObject() * @since 0.33 */ public Object getNodeObject() { Object object = this.nodeObject; if (object == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); Node node = getInstrumentedNode(); if (node instanceof InstrumentableNode) { object = ((InstrumentableNode) node).getNodeObject(); } else { return null; } if (object == null) { object = AccessorInstrumentHandler.interopAccess().createDefaultNodeObject(node); } else { assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object); } this.nodeObject = object; } return object; }
/** * Uses the provided language to find a meta-object of a value, if any. The meta-object * represents a description of the object, reveals it's kind and it's features. Some * information that a meta-object might define includes the base object's type, interface, * class, methods, attributes, etc. When no meta-object is known, <code>null</code> is * returned. For the best results, use the {@link #findLanguage(java.lang.Object) value's * language}, if any. * * @param language a language * @param value a value to find the meta-object of, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return the meta-object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public Object findMetaObject(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); Object metaObject = AccessorInstrumentHandler.langAccess().findMetaObject(env, value); assert checkNullOrInterop(metaObject); return metaObject; }
/** * Returns a language provided object that represents the instrumented node properties. The * returned is alwasy a valid interop object. The returned object is never <code>null</code> and * always returns <code>true</code> for the HAS_KEYS message. Multiple calls to * {@link #getNodeObject()} return the same node object instance. * * @see InstrumentableNode#getNodeObject() * @since 0.33 */ public Object getNodeObject() { Object object = this.nodeObject; if (object == null) { CompilerDirectives.transferToInterpreterAndInvalidate(); Node node = getInstrumentedNode(); if (node instanceof InstrumentableNode) { object = ((InstrumentableNode) node).getNodeObject(); } else { return null; } if (object == null) { object = AccessorInstrumentHandler.interopAccess().createDefaultNodeObject(node); } else { assert AccessorInstrumentHandler.interopAccess().isValidNodeObject(object); } this.nodeObject = object; } return object; }
/** * Uses the provided language to find a meta-object of a value, if any. The meta-object * represents a description of the object, reveals it's kind and it's features. Some * information that a meta-object might define includes the base object's type, interface, * class, methods, attributes, etc. When no meta-object is known, <code>null</code> is * returned. For the best results, use the {@link #findLanguage(java.lang.Object) value's * language}, if any. * * @param language a language * @param value a value to find the meta-object of, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return the meta-object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public Object findMetaObject(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findMetaObject(env, value); }
/** * Uses the provided language to find a source location where a value is declared, if any. * For the best results, use the {@link #findLanguage(java.lang.Object) value's language}, * if any. * * @param language a language * @param value a value to get the source location for, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a source location of the object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public SourceSection findSourceLocation(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
/** * Uses the provided language to print a string representation of this value. The behavior * of this method is undefined if a type unknown to the language is passed as a value. * * @param language a language * @param value a known value of that language, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a human readable string representation of the value. * @see #findLanguage(java.lang.Object) * @since 0.27 */ public String toString(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().toStringIfVisible(env, value, false); }
/** * Uses the provided language to find a source location where a value is declared, if any. * For the best results, use the {@link #findLanguage(java.lang.Object) value's language}, * if any. * * @param language a language * @param value a value to get the source location for, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a source location of the object, or <code>null</code> * @see #findLanguage(java.lang.Object) * @since 0.27 */ public SourceSection findSourceLocation(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
/** * Uses the provided language to print a string representation of this value. The behavior * of this method is undefined if a type unknown to the language is passed as a value. * * @param language a language * @param value a known value of that language, must be an interop type (i.e. either * implementing TruffleObject or be a primitive value) * @return a human readable string representation of the value. * @see #findLanguage(java.lang.Object) * @since 0.27 */ public String toString(LanguageInfo language, Object value) { AccessorInstrumentHandler.interopAccess().checkInteropType(value); final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language); return AccessorInstrumentHandler.langAccess().toStringIfVisible(env, value, false); }
protected boolean isTruffleObject(Object value) { return interopSupport().isTruffleObject(value); }
/** * Set arguments of the scope. * <p> * The properties representing the arguments needs to have deterministic iteration order, * argument declaration order is recommended. * * @param arguments arguments of the scope * @since 0.30 */ @SuppressWarnings("hiding") public Builder arguments(Object arguments) { assert arguments == null || TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(arguments) : Objects.toString(arguments); this.arguments = arguments; return this; }
protected boolean isTruffleObject(Object value) { return interopSupport().isTruffleObject(value); }
private boolean isNullOrInteropValue(Object result) { if (!(context.getInstrumentedNode() instanceof InstrumentableNode)) { // legacy support return true; } if (result == null) { return true; } AccessorInstrumentHandler.interopAccess().checkInteropType(result); return true; }
private boolean isNullOrInteropValue(Object result) { if (!(context.getInstrumentedNode() instanceof InstrumentableNode)) { // legacy support return true; } if (result == null) { return true; } AccessorInstrumentHandler.interopAccess().checkInteropType(result); return true; }
private boolean checkNullOrInterop(Object obj) { if (obj == null) { return true; } AccessorInstrumentHandler.interopAccess().checkInteropType(obj); return true; } }
Builder(String name, Object variables) { assert name != null; assert TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(variables) : Objects.toString(variables); this.name = name; this.variables = variables; }
Scope(String name, Node node, Object arguments, Object variables) { this.name = name; this.node = node; assert arguments == null || TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(arguments) : Objects.toString(arguments); this.arguments = arguments; assert TruffleLanguage.AccessAPI.interopAccess().isTruffleObject(variables) : Objects.toString(variables); this.variables = variables; }
private static boolean checkNullOrInterop(Object obj) { if (obj == null) { return true; } AccessorInstrumentHandler.interopAccess().checkInteropType(obj); return true; }