/** * {@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() + "]"; }
@Override public SourceBuilder newBuilder(String language, File origin) { return Source.newBuilder(language, origin); }
TextMap createTextMap() { final CharSequence code = getCharacters(); if (code == null) { throw new RuntimeException("can't read file " + getName()); } return TextMap.fromCharSequence(code); }
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(); }
final TextMap getTextMap() { if (hasBytes()) { throw new UnsupportedOperationException("Operation is only enabled for character based sources."); } TextMap res = textMap; if (res == null) { res = textMap = createTextMap(); } assert res != null; return res; }
private Source doResolve(Source source) { URI uri = source.getURI(); URLConnection connection = null; if (uri.isAbsolute()) { return Source.newBuilder(source.getLanguage(), new InputStreamReader(connection.getInputStream()), name).uri(uri).cached(false).interactive(source.isInteractive()).internal( source.isInternal()).mimeType(source.getMimeType()).build(); } catch (IOException ex) { return null;
private String formatFileName() { if (sourceSection == null) { return "<Unknown>"; } Source source = sourceSection.getSource(); if (source == null) { // TODO the source == null branch can be removed if the deprecated // SourceSection#createUnavailable has be removed. return "<Unknown>"; } else if (source.getPath() == null) { return source.getName(); } else { return source.getPath(); } }
@Override public String getName(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getName(); }
static JSONObject sourceSectionToJSON(SourceSection sourceSection) { JSONObject sourceSectionJson = new JSONObject(); if (sourceSection != null) { Source source = sourceSection.getSource(); if (source != null) { if (source.getLanguage() != null) { sourceSectionJson.put("language", source.getLanguage().toString()); } String path = source.getPath(); if (path != null) { sourceSectionJson.put("path", path); } } sourceSectionJson.put("source_name", sourceSection.getSource().getName()); sourceSectionJson.put("start_line", sourceSection.getStartLine()); sourceSectionJson.put("end_line", sourceSection.getEndLine()); sourceSectionJson.put("start_column", sourceSection.getStartColumn()); sourceSectionJson.put("end_column", sourceSection.getEndColumn()); } return sourceSectionJson; }
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)); } } }
@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; } });
@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); }
@Override public CharSequence getCode(Object impl, int lineNumber) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.getCharacters(lineNumber); }
@Override protected CallTarget parse(ParsingRequest request) throws Exception { Source code = request.getSource(); final RootNode root; final String txt = code.getCharacters().toString(); if (txt.startsWith("TCK42:")) { int nextColon = txt.indexOf(":", 6); String mimeType = txt.substring(6, nextColon); Source toParse = Source.newBuilder(txt.substring(nextColon + 1)).mimeType(mimeType).name("src.tck").build(); root = new MultiplyNode(this, toParse); } else { final double value = Double.parseDouble(txt); root = RootNode.createConstantNode(value); } return Truffle.getRuntime().createCallTarget(root); }
@Override public boolean isInternal(Object impl) { com.oracle.truffle.api.source.Source source = (com.oracle.truffle.api.source.Source) impl; return source.isInternal(); }
return rSource.createUnavailableSection(); } else if (section.hasCharIndex()) { return rSource.createSection(section.getCharIndex(), section.getCharLength()); } else if (section.hasColumns()) { return rSource.createSection(section.getStartLine(), section.getStartColumn(), section.getEndLine(), section.getEndColumn()); } else if (section.hasLines()) { int endLine = section.getEndLine(); int startColumn = 0; CharSequence firstLine = rSource.getCharacters(startLine); int length = firstLine.length(); while (startColumn < length && Character.isWhitespace(firstLine.charAt(startColumn))) { startColumn = 0; return rSource.createSection(startLine, startColumn + 1, endLine, rSource.getLineLength(endLine)); } else { return section;
@Override public String getLanguage() { return key.base.getLanguage(); }
/** * Sets the {@link com.oracle.truffle.api.source.SourceSection} of a given {@link Token} in * respect of {@link RegexSource#getSource()}. * * @param startIndex inclusive start index of the source section in respect of * {@link RegexSource#getPattern()}. * @param endIndex exclusive end index of the source section in respect of * {@link RegexSource#getPattern()}. */ private void setSourceSection(Token t, int startIndex, int endIndex) { if (options.isDumpAutomata()) { // RegexSource#getSource() prepends a slash ('/') to the pattern, so we have to add an // offset of 1 here. t.setSourceSection(source.getSource().createSection(startIndex + 1, endIndex - startIndex)); } }
@Override public String getPath() { return key.base.getPath(); }
@CompilerDirectives.TruffleBoundary @Override public SourceSection getSourceSection() { if (sourceSection == null) { String patternSrc = "/" + source.getPattern() + "/" + source.getFlags(); Source src = Source.newBuilder(RegexLanguage.ID, patternSrc, source.getPattern()).mimeType("application/js-regex").build(); sourceSection = src.createSection(0, patternSrc.length()); } return sourceSection; }