Search in sources :

Example 1 with TaskEvent

use of org.eclipse.ceylon.langtools.source.util.TaskEvent in project ceylon by eclipse.

the class JavaCompiler method enterTrees.

/**
 * Enter the symbols found in a list of parse trees.
 * As a side-effect, this puts elements on the "todo" list.
 * Also stores a list of all top level classes in rootClasses.
 */
public List<JCCompilationUnit> enterTrees(List<JCCompilationUnit> roots) {
    // enter symbols for all files
    if (!taskListener.isEmpty()) {
        for (JCCompilationUnit unit : roots) {
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
            taskListener.started(e);
        }
    }
    enter.main(roots);
    if (!taskListener.isEmpty()) {
        for (JCCompilationUnit unit : roots) {
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, unit);
            taskListener.finished(e);
        }
    }
    // the original compilation units listed on the command line.
    if (needRootClasses || sourceOutput || stubOutput) {
        ListBuffer<JCClassDecl> cdefs = new ListBuffer<>();
        for (JCCompilationUnit unit : roots) {
            for (List<JCTree> defs = unit.defs; defs.nonEmpty(); defs = defs.tail) {
                if (defs.head instanceof JCClassDecl)
                    cdefs.append((JCClassDecl) defs.head);
            }
        }
        rootClasses = cdefs.toList();
    }
    // cleaned and are being reused.
    for (JCCompilationUnit unit : roots) {
        inputFiles.add(unit.sourcefile);
    }
    return roots;
}
Also used : TaskEvent(org.eclipse.ceylon.langtools.source.util.TaskEvent) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 2 with TaskEvent

use of org.eclipse.ceylon.langtools.source.util.TaskEvent in project ceylon by eclipse.

the class JavaCompiler method flow.

/**
 * Perform dataflow checks on an attributed parse tree.
 */
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
    if (compileStates.isDone(env, CompileState.FLOW)) {
        results.add(env);
        return;
    }
    try {
        if (shouldStop(CompileState.FLOW))
            return;
        if (relax) {
            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.isEmpty()) {
            TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
            taskListener.finished(e);
        }
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) TaskEvent(org.eclipse.ceylon.langtools.source.util.TaskEvent)

Example 3 with TaskEvent

use of org.eclipse.ceylon.langtools.source.util.TaskEvent in project ceylon by eclipse.

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.isEmpty()) {
            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 {
                if (fileManager.hasLocation(StandardLocation.NATIVE_HEADER_OUTPUT) && jniWriter.needsHeader(cdef.sym)) {
                    jniWriter.write(cdef.sym);
                }
                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.isEmpty()) {
            TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
            taskListener.finished(e);
        }
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) TaskEvent(org.eclipse.ceylon.langtools.source.util.TaskEvent)

Example 4 with TaskEvent

use of org.eclipse.ceylon.langtools.source.util.TaskEvent in project ceylon by eclipse.

the class JavaCompiler method parse.

/**
 * Parse contents of input stream.
 *  @param filename     The name of the file from which input stream comes.
 *  @param content      The characters to be parsed.
 */
protected JCCompilationUnit parse(JavaFileObject filename, CharSequence content) {
    long msec = now();
    JCCompilationUnit tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
    if (content != null) {
        if (verbose) {
            log.printVerbose("parsing.started", filename);
        }
        if (!taskListener.isEmpty()) {
            TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, filename);
            taskListener.started(e);
            keepComments = true;
            genEndPos = true;
        }
        Parser parser = parserFactory.newParser(content, keepComments(), genEndPos, lineDebugInfo);
        tree = parser.parseCompilationUnit();
        if (verbose) {
            log.printVerbose("parsing.done", Long.toString(elapsed(msec)));
        }
    }
    tree.sourcefile = filename;
    if (content != null && !taskListener.isEmpty()) {
        TaskEvent e = new TaskEvent(TaskEvent.Kind.PARSE, tree);
        taskListener.finished(e);
    }
    return tree;
}
Also used : TaskEvent(org.eclipse.ceylon.langtools.source.util.TaskEvent) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 5 with TaskEvent

use of org.eclipse.ceylon.langtools.source.util.TaskEvent in project ceylon by eclipse.

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.isEmpty()) {
        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.tree);
        }
        compileStates.put(env, CompileState.ATTR);
        if (rootClasses != null && rootClasses.contains(env.enclClass)) {
            // This was a class that was explicitly supplied for compilation.
            // If we want to capture the public api of this class,
            // then now is a good time to do it.
            reportPublicApi(env.enclClass.sym);
        }
    } finally {
        log.useSource(prev);
    }
    return env;
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) TaskEvent(org.eclipse.ceylon.langtools.source.util.TaskEvent)

Aggregations

TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)13 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)5 TaskListener (org.eclipse.ceylon.langtools.source.util.TaskListener)5 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 File (java.io.File)3 ZipFile (java.util.zip.ZipFile)3 DiagnosticListener (org.eclipse.ceylon.javax.tools.DiagnosticListener)3 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)3 JavaPositionsRetriever (org.eclipse.ceylon.compiler.java.codegen.JavaPositionsRetriever)2 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)2 JavacTaskImpl (org.eclipse.ceylon.langtools.tools.javac.api.JavacTaskImpl)2 Context (org.eclipse.ceylon.langtools.tools.javac.util.Context)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 CeylonCompilationUnit (org.eclipse.ceylon.compiler.java.codegen.CeylonCompilationUnit)1 CeylonModelLoader (org.eclipse.ceylon.compiler.java.loader.CeylonModelLoader)1 RuntimeModelLoader (org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader)1