@Override public String getMimeType(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getMimeType(); }
@Override String findMimeType() throws IOException { return base.getMimeType(); }
@Override public String getMimeType() { return key.base.getMimeType(); }
@Override boolean isSourceIncluded(Source source) { String mimeType = source.getMimeType(); if (mimeType != null) { for (String otherMimeType : mimeTypes) { if (otherMimeType.equals(mimeType)) { return true; } } } return false; }
@Override boolean isSourceIncluded(Source source) { String mimeType = source.getMimeType(); if (mimeType != null) { for (String otherMimeType : mimeTypes) { if (otherMimeType.equals(mimeType)) { return true; } } } return false; }
@Override boolean isInstrumentableSource(Source source) { String mimeType = source.getMimeType(); if (mimeType == null) { return false; } return languageInfo.getMimeTypes().contains(mimeType); }
@Override boolean isInstrumentableSource(Source source) { String mimeType = source.getMimeType(); if (mimeType == null) { return false; } return languageInfo.getMimeTypes().contains(mimeType); }
@Override public boolean test(Source source) { boolean internal = (internals || !source.isInternal()); boolean file = testWildcardExpressions(source.getPath(), filterFile); boolean mimeType = filterLanguage.equals("") || filterLanguage.equals(source.getMimeType()); return internal && file && mimeType; } });
final boolean equalAttributes(Source other) { return Objects.equals(getMimeType(), other.getMimeType()) && Objects.equals(getLanguage(), other.getLanguage()) && Objects.equals(getName(), other.getName()) && Objects.equals(getPath(), other.getPath()) && isInternal() == other.isInternal() && isInteractive() == other.isInteractive(); }
@Override public CallTarget parseForLanguage(Object vmObject, Source source, String[] argumentNames) { PolyglotLanguageContext sourceContext = (PolyglotLanguageContext) vmObject; PolyglotLanguage targetLanguage = sourceContext.context.engine.findLanguage(source.getLanguage(), source.getMimeType(), true); PolyglotLanguageContext targetContext = sourceContext.context.getContextInitialized(targetLanguage, sourceContext.language); return targetContext.parseCached(sourceContext.language, source, argumentNames); }
/** * Evaluates source of (potentially different) language using the current context.The names * of arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments * that can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 */ public CallTarget parse(Source source, String... argumentNames) throws IOException { TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); return AccessorInstrumentHandler.langAccess().parse(env, source, null, argumentNames); }
/** * Evaluates source of (potentially different) language using the current context.The names * of arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments * that can be referenced from the source * @return the call target representing the parsed result * @throws IOException if the parsing or evaluation fails for some reason * @since 0.12 */ public CallTarget parse(Source source, String... argumentNames) throws IOException { TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); return AccessorInstrumentHandler.langAccess().parse(env, source, null, argumentNames); }
assertNoCompilation(); assert checkThread(); return evalImpl(findLanguage(source.getMimeType(), true), source);
/** * Evaluates source of (potentially different) language. The {@link Source#getMimeType() * MIME type} is used to identify the {@link TruffleLanguage} to use to perform the * {@link #parse(com.oracle.truffle.api.TruffleLanguage.ParsingRequest)} . The names of * arguments are parameters for the resulting {#link CallTarget} that allow the * <code>source</code> to reference the actual parameters passed to * {@link CallTarget#call(java.lang.Object...)}. * * @param source the source to evaluate * @param argumentNames the names of {@link CallTarget#call(java.lang.Object...)} arguments * that can be referenced from the source * @return the call target representing the parsed result * @since 0.8 or earlier */ @TruffleBoundary public CallTarget parse(Source source, String... argumentNames) { CompilerAsserts.neverPartOfCompilation(); checkDisposed(); return AccessAPI.engineAccess().getEnvForLanguage(vmObject, source.getLanguage(), source.getMimeType()).spi.parse(source, null, null, argumentNames); }
/** * @since 0.15 * @deprecated see {@link SourceBuilder#build()} */ @SuppressWarnings("unused") @Deprecated public Source build() throws E1, E2, E3 { try { Source source = buildSource(this.language, this.origin, this.name, this.mime, this.characters, this.uri, this.internal, this.interactive, this.cached, true); // legacy sources must have character sources assert source.hasCharacters(); // make sure origin is not consumed again if builder is used twice this.characters = source.getCharacters(); if (source.getMimeType() == null) { throw raise(RuntimeException.class, new MissingMIMETypeException()); } if (source.getName() == null) { throw raise(RuntimeException.class, new MissingNameException()); } return source; } catch (IOException ex) { throw raise(RuntimeException.class, ex); } } }
/** * {@inheritDoc} * * @since 1.0 */ @Override public String toString() { return "Source [language=" + getLanguage() + ", name=" + getName() + ", path=" + getPath() + ", internal=" + isInternal() + ", cached=" + isCached() + ", interactive=" + isInteractive() + ", hasBytes=" + hasBytes() + ", hasCharacters=" + hasCharacters() + ", URL=" + getURL() + ", URI=" + getURI() + ", mimeType=" + getMimeType() + "]"; }
private void initializeConditional(MaterializedFrame frame) { Node instrumentedNode = context.getInstrumentedNode(); final RootNode rootNode = instrumentedNode.getRootNode(); if (rootNode == null) { throw new IllegalStateException("Probe was disconnected from the AST."); } Source instrumentedSource = context.getInstrumentedSourceSection().getSource(); Source conditionSource; synchronized (breakpoint) { conditionSource = Source.newBuilder(instrumentedSource.getLanguage(), breakpoint.condition, "breakpoint condition").mimeType(instrumentedSource.getMimeType()).build(); if (conditionSource == null) { throw new IllegalStateException("Condition is not resolved " + rootNode); } conditionUnchanged = breakpoint.getConditionUnchanged(); } ExecutableNode snippet = breakpoint.debugger.getEnv().parseInline(conditionSource, instrumentedNode, frame); if (snippet != null) { conditionSnippet = insert(snippet); notifyInserted(snippet); } else { CallTarget callTarget = Debugger.ACCESSOR.parse(conditionSource, instrumentedNode, new String[0]); conditionCallNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget)); } } }
/** * Parses source snippet of the node's language at the provided node location. The result is * an AST fragment represented by {@link ExecutableNode} that accepts frames valid at the * provided node location, or <code>null</code> when inline parsing is not supported by the * language. * * @param source a source snippet to parse at the provided node location * @param node a context location where the source is parsed at, must not be * <code>null</code> * @param frame a frame location where the source is parsed at, can be <code>null</code> * @return the executable fragment representing the parsed result, or <code>null</code> * @since 0.31 */ public ExecutableNode parseInline(Source source, Node node, MaterializedFrame frame) { if (node == null) { throw new IllegalArgumentException("Node must not be null."); } TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); // Assert that the languages match: assert AccessorInstrumentHandler.langAccess().getLanguageInfo(env) == node.getRootNode().getLanguageInfo(); ExecutableNode fragment = AccessorInstrumentHandler.langAccess().parseInline(env, source, node, frame); if (fragment != null) { TruffleLanguage<?> languageSPI = AccessorInstrumentHandler.langAccess().getSPI(env); fragment = new GuardedExecutableNode(languageSPI, fragment, frame); } return fragment; }
/** * Parses source snippet of the node's language at the provided node location. The result is * an AST fragment represented by {@link ExecutableNode} that accepts frames valid at the * provided node location, or <code>null</code> when inline parsing is not supported by the * language. * * @param source a source snippet to parse at the provided node location * @param node a context location where the source is parsed at, must not be * <code>null</code> * @param frame a frame location where the source is parsed at, can be <code>null</code> * @return the executable fragment representing the parsed result, or <code>null</code> * @since 0.31 */ public ExecutableNode parseInline(Source source, Node node, MaterializedFrame frame) { if (node == null) { throw new IllegalArgumentException("Node must not be null."); } TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(vmObject, source.getLanguage(), source.getMimeType()); // Assert that the languages match: assert AccessorInstrumentHandler.langAccess().getLanguageInfo(env) == node.getRootNode().getLanguageInfo(); ExecutableNode fragment = AccessorInstrumentHandler.langAccess().parseInline(env, source, node, frame); if (fragment != null) { TruffleLanguage<?> languageSPI = AccessorInstrumentHandler.langAccess().getSPI(env); fragment = new GuardedExecutableNode(languageSPI, fragment, frame); } return fragment; }
private void initializeConditional(MaterializedFrame frame) { Node instrumentedNode = context.getInstrumentedNode(); final RootNode rootNode = instrumentedNode.getRootNode(); if (rootNode == null) { throw new IllegalStateException("Probe was disconnected from the AST."); } Source instrumentedSource = context.getInstrumentedSourceSection().getSource(); Source conditionSource; synchronized (breakpoint) { conditionSource = Source.newBuilder(breakpoint.condition).language(instrumentedSource.getLanguage()).mimeType(instrumentedSource.getMimeType()).name( "breakpoint condition").build(); if (conditionSource == null) { throw new IllegalStateException("Condition is not resolved " + rootNode); } conditionUnchanged = breakpoint.getConditionUnchanged(); } ExecutableNode snippet = breakpoint.debugger.getEnv().parseInline(conditionSource, instrumentedNode, frame); if (snippet != null) { conditionSnippet = insert(snippet); notifyInserted(snippet); } else { CallTarget callTarget = Debugger.ACCESSOR.parse(conditionSource, instrumentedNode, new String[0]); conditionCallNode = insert(Truffle.getRuntime().createDirectCallNode(callTarget)); } } }