/** * Find a source location where a value is declared, if any. * * @param node a node * @param value a value to get the source location for * @return a source location of the object, or <code>null</code> * @since 0.22 * @deprecated use * {@link #findSourceLocation(com.oracle.truffle.api.nodes.LanguageInfo, java.lang.Object)} * and retrieve {@link LanguageInfo} from * <code>node.getRootNode().getLanguageInfo()</code>. */ @Deprecated public SourceSection findSourceLocation(Node node, Object value) { final TruffleLanguage.Env env = getLangEnv(node); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
/** * Find a source location where a value is declared, if any. * * @param node a node * @param value a value to get the source location for * @return a source location of the object, or <code>null</code> * @since 0.22 * @deprecated use * {@link #findSourceLocation(com.oracle.truffle.api.nodes.LanguageInfo, java.lang.Object)} * and retrieve {@link LanguageInfo} from * <code>node.getRootNode().getLanguageInfo()</code>. */ @Deprecated public SourceSection findSourceLocation(Node node, Object value) { final TruffleLanguage.Env env = getLangEnv(node); return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value); }
@Override public SourceSection getSourceLocation(Object receiver) { Object prev = enter(languageContext); try { if (languageContext == null) { return null; } final PolyglotLanguage resolvedLanguage = PolyglotImpl.EngineImpl.findObjectLanguage(languageContext.context, languageContext, receiver); if (resolvedLanguage == null) { return null; } final PolyglotLanguageContext resolvedLanguageContext = languageContext.context.getContext(resolvedLanguage); com.oracle.truffle.api.source.SourceSection result = LANGUAGE.findSourceLocation(resolvedLanguageContext.env, receiver); return result != null ? VMAccessor.engine().createSourceSection(resolvedLanguageContext, null, result) : null; } catch (final Throwable t) { throw PolyglotImpl.wrapGuestException(languageContext, t); } finally { leave(languageContext, prev); } }
/** * 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 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); }
@SuppressWarnings("try") @Override protected SourceSection compute() { Object prev = enter(); try { return LANGUAGE.findSourceLocation(language.getEnv(true), ConvertedObject.original(value())); } finally { leave(prev); } } };