use of com.sun.source.util.TaskEvent in project ceylon-compiler by ceylon.
the class JavaCompiler method attribute.
/**
* Attribute a parse tree.
* @returns the attributed parse tree
*/
public Env<AttrContext> attribute(Env<AttrContext> env) {
if (compileStates.isDone(env, CompileState.ATTR))
return env;
if (verboseCompilePolicy)
printNote("[attribute " + env.enclClass.sym + "]");
if (verbose)
log.printVerbose("checking.attribution", env.enclClass.sym);
if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
taskListener.started(e);
}
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
try {
attr.attrib(env);
if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) {
//if in fail-over mode, ensure that AST expression nodes
//are correctly initialized (e.g. they have a type/symbol)
attr.postAttr(env);
}
compileStates.put(env, CompileState.ATTR);
} finally {
log.useSource(prev);
}
return env;
}
use of com.sun.source.util.TaskEvent in project ceylon-compiler by ceylon.
the class JavaCompiler method generate.
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
if (shouldStop(CompileState.GENERATE))
return;
boolean usePrintSource = (stubOutput || sourceOutput || printFlat);
for (Pair<Env<AttrContext>, JCClassDecl> x : queue) {
Env<AttrContext> env = x.fst;
JCClassDecl cdef = x.snd;
if (verboseCompilePolicy) {
printNote("[generate " + (usePrintSource ? " source" : "code") + " " + cdef.sym + "]");
}
if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
taskListener.started(e);
}
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
try {
JavaFileObject file;
if (usePrintSource)
file = printSource(env, cdef);
else
file = genCode(env, cdef);
if (results != null && file != null)
results.add(file);
} catch (IOException ex) {
log.error(cdef.pos(), "class.cant.write", cdef.sym, ex.getMessage());
return;
} finally {
log.useSource(prev);
}
if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
taskListener.finished(e);
}
}
}
use of com.sun.source.util.TaskEvent in project ceylon-compiler by ceylon.
the class JavaCompiler method flow.
/**
* Perform dataflow checks on an attributed parse tree.
*/
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
try {
if (shouldStop(CompileState.FLOW))
return;
if (relax || compileStates.isDone(env, CompileState.FLOW)) {
results.add(env);
return;
}
if (verboseCompilePolicy)
printNote("[flow " + env.enclClass.sym + "]");
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
try {
make.at(Position.FIRSTPOS);
TreeMaker localMake = make.forToplevel(env.toplevel);
flow.analyzeTree(env, localMake);
compileStates.put(env, CompileState.FLOW);
if (shouldStop(CompileState.FLOW))
return;
results.add(env);
} finally {
log.useSource(prev);
}
} finally {
if (taskListener != null) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
taskListener.finished(e);
}
}
}
use of com.sun.source.util.TaskEvent in project ceylon-compiler by ceylon.
the class CheckAttributedTree method read.
/**
* Read a file.
* @param file the file to be read
* @return the tree for the content of the file
* @throws IOException if any IO errors occur
* @throws TreePosTest.ParseException if any errors occur while parsing the file
*/
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
JavacTool tool = JavacTool.create();
r.errors = 0;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
final List<Element> analyzedElems = new ArrayList<>();
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ANALYZE)
analyzedElems.add(e.getTypeElement());
}
public void finished(TaskEvent e) {
}
});
try {
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
//System.out.println("Try to add pairs. Elems are " + analyzedElems);
for (CompilationUnitTree t : trees) {
JCCompilationUnit cu = (JCCompilationUnit) t;
for (JCTree def : cu.defs) {
if (def.getTag() == JCTree.CLASSDEF && analyzedElems.contains(((JCTree.JCClassDecl) def).sym)) {
//System.out.println("Adding pair...");
res.add(new Pair<>(cu, def));
}
}
}
return res;
} catch (Throwable t) {
throw new AttributionException("Exception while attributing file: " + file);
}
}
use of com.sun.source.util.TaskEvent in project ceylon-compiler by ceylon.
the class CeylonEnter method completeCeylonTrees.
public void completeCeylonTrees(List<JCCompilationUnit> trees) {
// run the type checker
timer.startTask("Ceylon type checking");
typeCheck();
// some debugging
//printModules();
timer.startTask("Ceylon code generation");
/*
* Here we convert the ceylon tree to its javac AST, after the typechecker has run
*/
Timer nested = timer.nestedTimer();
if (sp != null) {
sp.clearLine();
sp.log("Generating AST");
}
int i = 1;
int size = trees.size();
for (JCCompilationUnit tree : trees) {
if (tree instanceof CeylonCompilationUnit) {
CeylonCompilationUnit ceylonTree = (CeylonCompilationUnit) tree;
gen.setMap(ceylonTree.lineMap);
CeylonPhasedUnit phasedUnit = (CeylonPhasedUnit) ceylonTree.phasedUnit;
if (sp != null) {
sp.clearLine();
sp.log("Generating [" + (i++) + "/" + size + "] ");
sp.log(phasedUnit.getPathRelativeToSrcDir());
}
gen.setFileObject(phasedUnit.getFileObject());
nested.startTask("Ceylon code generation for " + phasedUnit.getUnitFile().getName());
TaskEvent event = new TaskEvent(TaskEvent.Kind.PARSE, tree);
if (taskListener != null) {
taskListener.started(event);
}
ceylonTree.defs = gen.transformAfterTypeChecking(ceylonTree.ceylonTree).toList();
if (taskListener != null) {
taskListener.finished(event);
}
nested.endTask();
if (isVerbose("ast")) {
log.errWriter.println("Model tree for " + tree.getSourceFile());
log.errWriter.println(ceylonTree.ceylonTree);
}
if (isVerbose("code")) {
log.errWriter.println("Java code generated for " + tree.getSourceFile());
log.errWriter.println(ceylonTree);
}
}
}
timer.startTask("Ceylon error generation");
printGeneratorErrors();
timer.endTask();
// write some stats
if (verbose)
modelLoader.printStats();
}
Aggregations