use of org.snt.inmemantlr.exceptions.CompilationErrorException in project inmemantlr by julianthome.
the class StringCompiler method compile.
/**
* do the compilation for the antlr artifacts
* @param units string code generation pipeline
* @param oprov compiler option provider
* @throws CompilationErrorException if the compilation was not successful
*/
public void compile(Set<CunitProvider> units, CompilerOptionsProvider oprov) throws CompilationErrorException {
JavaCompiler javac = new EclipseCompiler();
StandardJavaFileManager sjfm = javac.getStandardFileManager(null, null, null);
SpecialJavaFileManager fileManager = new SpecialJavaFileManager(sjfm, cl);
List<MemorySource> cunit = new ArrayList<>();
Set<MemorySource> mset = new HashSet<>();
for (CunitProvider sc : units) {
cunit.addAll(sc.getItems());
for (MemorySource ms : sc.getItems()) {
LOGGER.debug(ms.toString());
}
}
mset.addAll(cunit);
DiagnosticListener<? super JavaFileObject> dlistener = null;
Iterable<String> classes = null;
Writer out = new StringWriter();
List<String> optionList = new ArrayList<>();
optionList.addAll(oprov.getOptions());
JavaCompiler.CompilationTask compile = javac.getTask(out, fileManager, dlistener, optionList, classes, cunit);
boolean ret = compile.call();
if (!ret) {
throw new CompilationErrorException(out.toString());
}
// the corresponding byte code
for (MemorySource ms : mset) {
Set<MemoryByteCode> mb = fileManager.getByteCodeFromClass(ms.getClassName());
if (mb.size() == 0)
throw new IllegalArgumentException("MemoryByteCode must not be empty");
// book keeping of source-bytecode tuples
mt.addMemoryTuple(ms, mb);
}
}
Aggregations