Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[docs] SARL compiler singleton in documentation generator.
In order to avoid too much memory consumption in the documentation
generator, the SARL compiler is injected once time.

see #664

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 3, 2017
1 parent 84ef43d commit 79f5dd7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
6 changes: 3 additions & 3 deletions appveyor.yml
Expand Up @@ -3,6 +3,9 @@ version: '{build}'
skip_tags: true

environment:
JAVA_OPTS: -XX:+CMSClassUnloadingEnabled -Xmx2g
MAVEN_OPTS: -XX:+CMSClassUnloadingEnabled -Xmx2g
PATH: C:\maven\apache-maven-3.3.9\bin;%JAVA_HOME%\bin;%PATH%
matrix:
- JAVA_HOME: C:\Program Files\Java\jdk1.8.0

Expand All @@ -13,9 +16,6 @@ install:
(new-object System.Net.WebClient).DownloadFile('http://www.us.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip', 'C:\maven-bin.zip')
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET PATH=C:\maven\apache-maven-3.3.9\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET MAVEN_OPTS=-XX:+CMSClassUnloadingEnabled -Xmx2g
- cmd: SET JAVA_OPTS=-XX:+CMSClassUnloadingEnabled -Xmx2g
- cmd: mvn --version
- cmd: java -version

Expand Down
Expand Up @@ -58,8 +58,6 @@
*/
public class SarlScriptExecutor implements ScriptExecutor {

private Injector injector;

private File tmpFolder = null;

private String classpath = Strings.emptyIfNull(null);
Expand All @@ -68,13 +66,20 @@ public class SarlScriptExecutor implements ScriptExecutor {

private String sourceVersion = Strings.emptyIfNull(null);

private SarlBatchCompiler compiler;

private IExpressionInterpreter interpreter;

/** Change the injector.
*
* @param injector the new injector.
*/
@Inject
public void setInjector(Injector injector) {
this.injector = injector;
if (injector != null) {
this.compiler = injector.getInstance(SarlBatchCompiler.class);
this.interpreter = injector.getInstance(IExpressionInterpreter.class);
}
}

@Override
Expand Down Expand Up @@ -133,33 +138,32 @@ public File compile(int lineno, String code, List<String> issues, ICompilatedRes
File sourceFolder = createSourceFolder(rootFolder);
File genFolder = createGenFolder(rootFolder);
File binFolder = createBinFolder(rootFolder);
SarlBatchCompiler compiler = this.injector.getInstance(SarlBatchCompiler.class);
compiler.setBasePath(rootFolder.getAbsolutePath());
compiler.addSourcePath(sourceFolder);
compiler.setClassOutputPath(binFolder);
compiler.setOutputPath(genFolder);
compiler.setGenerateGeneratedAnnotation(false);
compiler.setGenerateInlineAnnotation(false);
compiler.setGenerateSyntheticSuppressWarnings(true);
compiler.setDeleteTempDirectory(false);
compiler.setClassPath(this.classpath);
compiler.setBootClassPath(this.bootClasspath);
compiler.setJavaSourceVersion(this.sourceVersion);
compiler.setAllWarningSeverities(Severity.IGNORE);
compiler.setJavaCompilerVerbose(false);
compiler.getLogger().setLevel(Level.OFF);
compiler.addIssueMessageListener((issue, uri, message) -> {
this.compiler.setBasePath(rootFolder.getAbsolutePath());
this.compiler.addSourcePath(sourceFolder);
this.compiler.setClassOutputPath(binFolder);
this.compiler.setOutputPath(genFolder);
this.compiler.setGenerateGeneratedAnnotation(false);
this.compiler.setGenerateInlineAnnotation(false);
this.compiler.setGenerateSyntheticSuppressWarnings(true);
this.compiler.setDeleteTempDirectory(false);
this.compiler.setClassPath(this.classpath);
this.compiler.setBootClassPath(this.bootClasspath);
this.compiler.setJavaSourceVersion(this.sourceVersion);
this.compiler.setAllWarningSeverities(Severity.IGNORE);
this.compiler.setJavaCompilerVerbose(false);
this.compiler.getLogger().setLevel(Level.OFF);
this.compiler.addIssueMessageListener((issue, uri, message) -> {
if (issue.isSyntaxError() || issue.getSeverity().compareTo(Severity.ERROR) >= 0) {
final Integer line = issue.getLineNumber();
final int issueLine = (line == null ? 0 : line.intValue()) + lineno;
issues.add(message + "(line " + issueLine + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
});
if (receiver != null) {
compiler.addCompiledResourceReceiver(receiver);
this.compiler.addCompiledResourceReceiver(receiver);
}
File file = createFile(sourceFolder, code);
if (compiler.compile()) {
if (this.compiler.compile()) {
issues.clear();
}
return file;
Expand All @@ -174,13 +178,12 @@ public Object execute(int lineno, String code) throws Exception {
resources.add(it);
});
assertNoIssue(lineno, issues);
IExpressionInterpreter interpreter = this.injector.getInstance(IExpressionInterpreter.class);
for (Resource resource : resources) {
SarlScript script = (SarlScript) resource.getContents().get(0);
SarlClass clazz = (SarlClass) script.getXtendTypes().get(0);
SarlField field = (SarlField) clazz.getMembers().get(0);
XExpression xexpression = field.getInitialValue();
IEvaluationResult result = interpreter.evaluate(xexpression);
IEvaluationResult result = this.interpreter.evaluate(xexpression);
if (result.getException() == null) {
return result.getResult();
}
Expand Down

0 comments on commit 79f5dd7

Please sign in to comment.