751 lines · 29.3 KB · Java
RawDownload
            // Parse all input files            for (Enumeration e = v.elements() ; e.hasMoreElements() ;) {                File file = new File((String)e.nextElement());                try {                    env.parseFile(new ClassFile(file));                } catch (FileNotFoundException ee) {                    env.error(0, "cant.read", file.getPath());                    exitStatus = EXIT_CMDERR;                }            }             // Do a post-read check on all newly-parsed classes,            // after they have all been read.            for (Enumeration e = env.getClasses() ; e.hasMoreElements() ; ) {                ClassDeclaration c = (ClassDeclaration)e.nextElement();                if (c.getStatus() == CS_PARSED) {                    if (c.getClassDefinition().isLocal())                        continue;                    try {                        c.getClassDefinition(env);                    } catch (ClassNotFound ee) {                    }                }            }             // compile all classes that need compilation            ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);            boolean done;             do {                done = true;                env.flushErrors();                for (Enumeration e = env.getClasses() ; e.hasMoreElements() ; ) {                    ClassDeclaration c = (ClassDeclaration)e.nextElement();                    SourceClass src;                     switch (c.getStatus()) {                      case CS_UNDEFINED:                        if (!env.dependencies()) {                            break;                        }                        // fall through                       case CS_SOURCE:                        if (tracing)                            env.dtEvent("Main.compile (SOURCE): loading, " + c);                        done = false;                        env.loadDefinition(c);                        if (c.getStatus() != CS_PARSED) {                            if (tracing)                                env.dtEvent("Main.compile (SOURCE): not parsed, " + c);                            break;                        }                        // fall through                       case CS_PARSED:                        if (c.getClassDefinition().isInsideLocal()) {                            // the enclosing block will check this one                            if (tracing)                                env.dtEvent("Main.compile (PARSED): skipping local class, " + c);                            continue;                        }                        done = false;                        if (tracing) env.dtEvent("Main.compile (PARSED): checking, " + c);                        src = (SourceClass)c.getClassDefinition(env);                        src.check(env);                        c.setDefinition(src, CS_CHECKED);                        // fall through                       case CS_CHECKED:                        src = (SourceClass)c.getClassDefinition(env);                        // bail out if there were any errors                        if (src.getError()) {                            if (tracing)                                env.dtEvent("Main.compile (CHECKED): bailing out on error, " + c);                            c.setDefinition(src, CS_COMPILED);                            break;                        }                        done = false;                        buf.reset();                        if (tracing)                            env.dtEvent("Main.compile (CHECKED): compiling, " + c);                        src.compile(buf);                        c.setDefinition(src, CS_COMPILED);                        src.cleanup(env);                         if (src.getNestError() || nowrite) {                            continue;                        }                         String pkgName = c.getName().getQualifier().toString().replace('.', File.separatorChar);                        String className = c.getName().getFlatName().toString().replace('.', SIGC_INNERCLASS) + ".class";                         File file;                        if (destDir != null) {                            if (pkgName.length() > 0) {                                file = new File(destDir, pkgName);                                if (!file.exists()) {                                    file.mkdirs();                                }                                file = new File(file, className);                            } else {                                file = new File(destDir, className);                            }                        } else {                            ClassFile classfile = (ClassFile)src.getSource();                            if (classfile.isZipped()) {                                env.error(0, "cant.write", classfile.getPath());                                exitStatus = EXIT_CMDERR;                                continue;                            }                            file = new File(classfile.getPath());                            file = new File(file.getParent(), className);                        }                         // Create the file                        try {                            FileOutputStream out = new FileOutputStream(file.getPath());                            buf.writeTo(out);                            out.close();                             if (env.verbose()) {                                output(getText("main.wrote", file.getPath()));                            }                        } catch (IOException ee) {                            env.error(0, "cant.write", file.getPath());                            exitStatus = EXIT_CMDERR;                        }                         // Print class dependencies if requested (-xdepend)                        if (env.print_dependencies()) {                            src.printClassDependencies(env);                        }                    }                }            } while (!done);        } catch (OutOfMemoryError ee) {            // The compiler has run out of memory.  Use the error string            // which we preloaded.            env.output(noMemoryErrorString);            exitStatus = EXIT_SYSERR;            return false;        } catch (StackOverflowError ee) {            env.output(stackOverflowErrorString);            exitStatus = EXIT_SYSERR;            return false;        } catch (Error ee) {            // We allow the compiler to take an exception silently if a program            // error has previously been detected.  Presumably, this makes the            // compiler more robust in the face of bad error recovery.            if (env.nerrors == 0 || env.dump()) {                ee.printStackTrace();                env.error(0, "fatal.error");                exitStatus = EXIT_ABNORMAL;            }        } catch (Exception ee) {            if (env.nerrors == 0 || env.dump()) {                ee.printStackTrace();                env.error(0, "fatal.exception");                exitStatus = EXIT_ABNORMAL;            }        }         int ndepfiles = env.deprecationFiles.size();        if (ndepfiles > 0 && env.warnings()) {            int ndeps = env.ndeprecations;            Object file1 = env.deprecationFiles.elementAt(0);            if (env.deprecation()) {                if (ndepfiles > 1) {                    env.error(0, "warn.note.deprecations",                              new Integer(ndepfiles), new Integer(ndeps));                } else {                    env.error(0, "warn.note.1deprecation",                              file1, new Integer(ndeps));                }            } else {                if (ndepfiles > 1) {                    env.error(0, "warn.note.deprecations.silent",                              new Integer(ndepfiles), new Integer(ndeps));                } else {                    env.error(0, "warn.note.1deprecation.silent",                              file1, new Integer(ndeps));                }            }        }         env.flushErrors();        env.shutdown();         boolean status = true;        if (env.nerrors > 0) {            String msg = "";            if (env.nerrors > 1) {                msg = getText("main.errors", env.nerrors);            } else {                msg = getText("main.1error");            }            if (env.nwarnings > 0) {                if (env.nwarnings > 1) {                    msg += ", " + getText("main.warnings", env.nwarnings);                } else {                    msg += ", " + getText("main.1warning");                }            }            output(msg);            if (exitStatus == EXIT_OK) {                // Allow EXIT_CMDERR or EXIT_ABNORMAL to take precedence.                exitStatus = EXIT_ERROR;            }            status = false;        } else {            if (env.nwarnings > 0) {                if (env.nwarnings > 1) {                    output(getText("main.warnings", env.nwarnings));                } else {                    output(getText("main.1warning"));                }            }        }//JCOV        if (env.covdata()) {            Assembler CovAsm = new Assembler();            CovAsm.GenJCov(env);        }// end JCOV         // We're done        if (env.verbose()) {            tm = System.currentTimeMillis() - tm;            output(getText("main.done_in", Long.toString(tm)));        }         return status;    }     /**     * Main program     */    public static void main(String argv[]) {        OutputStream out = System.err;         // This is superceeded by the -Xstdout option, but we leave        // in the old property check for compatibility.        if (Boolean.getBoolean("javac.pipe.output")) {            out = System.out;        }         Main compiler = new Main(out, "javac");        System.exit(compiler.compile(argv) ? 0 : compiler.exitStatus);    }}

Lines 501–751 of 751. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t