Skip to content
Snippets Groups Projects
Commit 0d46445b authored by Martin Entlicher's avatar Martin Entlicher
Browse files

[GR-9400] Deparse to textual sources by default.

PullRequest: fastr/1485
parents e5bb6f6b e9346887
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,7 @@ public enum FastROptions {
SharedContexts("Whether all child contexts are to be shared contexts", true),
SearchPathForcePromises("Whether all promises for frames on shared path are forced in presence of shared contexts", false),
LoadPackagesNativeCode("Load native code of packages, including builtin packages.", !FastRConfig.ManagedMode),
EmitTmpSource("Write deparsed source code to temporary files for better debugging.", true),
EmitTmpSource("Write deparsed source code to temporary files for better debugging.", false),
EmitTmpDir("The directory where to allocate temporary files with deparsed source code.", null, true),
EmitTmpHashed("Use an SHA-256 hash as file name to reduce temporary file creation.", true),
SynchronizeNativeCode("allow only one thread to enter packages' native code", false),
......
......@@ -392,12 +392,20 @@ public class RDeparse {
if (FastROptions.EmitTmpSource.getBooleanValue() && deparsePath != null) {
fixupSourcesTempFile(deparsePath);
} else {
fixupSourcesTextInternal();
fixupSourcesText();
}
}
private void fixupSourcesTextInternal() {
Source source = RSource.fromTextInternal(sb.toString(), RSource.Internal.DEPARSE);
private void fixupSourcesText() {
RootNode rootNode = getRootNode();
String name = rootNode != null ? rootNode.getName() : null;
String text = sb.toString();
if (name != null && !name.isEmpty() && !name.equals("<no source>")) {
name = name.replace(File.separatorChar, '_') + ".r";
} else {
name = "unknown.r";
}
Source source = RSource.fromText(text, name);
for (SourceSectionElement s : sources) {
s.element.setSourceSection(source.createSection(s.start, s.length));
}
......@@ -416,10 +424,10 @@ public class RDeparse {
}
} catch (AccessDeniedException | FileAlreadyExistsException | IllegalArgumentException e) {
// do not report because these exceptions are legitimate
fixupSourcesTextInternal();
fixupSourcesText();
} catch (Throwable e) {
RInternalError.reportError(e);
fixupSourcesTextInternal();
fixupSourcesText();
}
}
......
......@@ -117,6 +117,13 @@ public class RSource {
return builder.build();
}
/**
* Create a cached source from {@code text} and {@code name}.
*/
public static Source fromText(String text, String name) {
return getCachedByOrigin(text, origin -> Source.newBuilder(text).name(name).language(RRuntime.R_LANGUAGE_ID).build());
}
/**
* Create an {@code internal} source from {@code text} and {@code description}.
*/
......@@ -294,7 +301,7 @@ public class RSource {
}
}
private static <T> Source getCachedByOrigin(T origin, SourceGenerator<T> generator) throws IOException {
private static <T, E extends Exception> Source getCachedByOrigin(T origin, SourceGenerator<T, E> generator) throws E {
CompilerAsserts.neverPartOfCompilation();
Source src;
synchronized (deserializedSources) {
......@@ -309,7 +316,7 @@ public class RSource {
}
@FunctionalInterface
private interface SourceGenerator<T> {
Source apply(T origin) throws IOException;
private interface SourceGenerator<T, E extends Exception> {
Source apply(T origin) throws E;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment