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

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

parent 53f5c6c9
No related branches found
No related tags found
No related merge requests found
...@@ -57,7 +57,7 @@ public enum FastROptions { ...@@ -57,7 +57,7 @@ public enum FastROptions {
SharedContexts("Whether all child contexts are to be shared contexts", true), 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), 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), 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), 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), 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), SynchronizeNativeCode("allow only one thread to enter packages' native code", false),
......
...@@ -392,12 +392,20 @@ public class RDeparse { ...@@ -392,12 +392,20 @@ public class RDeparse {
if (FastROptions.EmitTmpSource.getBooleanValue() && deparsePath != null) { if (FastROptions.EmitTmpSource.getBooleanValue() && deparsePath != null) {
fixupSourcesTempFile(deparsePath); fixupSourcesTempFile(deparsePath);
} else { } else {
fixupSourcesTextInternal(); fixupSourcesText();
} }
} }
private void fixupSourcesTextInternal() { private void fixupSourcesText() {
Source source = RSource.fromTextInternal(sb.toString(), RSource.Internal.DEPARSE); 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) { for (SourceSectionElement s : sources) {
s.element.setSourceSection(source.createSection(s.start, s.length)); s.element.setSourceSection(source.createSection(s.start, s.length));
} }
...@@ -416,10 +424,10 @@ public class RDeparse { ...@@ -416,10 +424,10 @@ public class RDeparse {
} }
} catch (AccessDeniedException | FileAlreadyExistsException | IllegalArgumentException e) { } catch (AccessDeniedException | FileAlreadyExistsException | IllegalArgumentException e) {
// do not report because these exceptions are legitimate // do not report because these exceptions are legitimate
fixupSourcesTextInternal(); fixupSourcesText();
} catch (Throwable e) { } catch (Throwable e) {
RInternalError.reportError(e); RInternalError.reportError(e);
fixupSourcesTextInternal(); fixupSourcesText();
} }
} }
......
...@@ -117,6 +117,14 @@ public class RSource { ...@@ -117,6 +117,14 @@ public class RSource {
return builder.build(); return builder.build();
} }
/**
* Create a cached source from {@code text} and {@code name}.
*/
public static Source fromText(String text, String name) {
String uniqueText = text.intern();
return getCachedByOrigin(uniqueText, origin -> Source.newBuilder(uniqueText).name(name).language(RRuntime.R_LANGUAGE_ID).build());
}
/** /**
* Create an {@code internal} source from {@code text} and {@code description}. * Create an {@code internal} source from {@code text} and {@code description}.
*/ */
...@@ -294,7 +302,7 @@ public class RSource { ...@@ -294,7 +302,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(); CompilerAsserts.neverPartOfCompilation();
Source src; Source src;
synchronized (deserializedSources) { synchronized (deserializedSources) {
...@@ -309,7 +317,7 @@ public class RSource { ...@@ -309,7 +317,7 @@ public class RSource {
} }
@FunctionalInterface @FunctionalInterface
private interface SourceGenerator<T> { private interface SourceGenerator<T, E extends Exception> {
Source apply(T origin) throws IOException; 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