private static int nextSource()

in modules/compiler/src/java/flex2/compiler/CompilerAPI.java [604:1048]


    private static int nextSource(List<Source> sources, DependencyGraph<CompilationUnit> igraph, DependencyGraph<Source> dgraph,
                                  List<Source> targets, SymbolTable symbolTable, Configuration configuration)
    {
        int count = 0, isDone = 0;
        boolean strict = configuration.getCompilerConfiguration().strict();
        boolean warnings = configuration.getCompilerConfiguration().warnings();
        int factor = configuration.getCompilerConfiguration().factor();

        // The notDoneList is used to debug which files are not being completed on a pass
        // thru the source files. To turn on the debugging uncomment the uses of "notDoneList"
        // in this method.
//        HashMap notDoneList = new HashMap(sources.size());
        targets.clear();

        // if 'targets' is smaller than 'sources', fill it up.
        for (int i = targets.size(), size = sources.size(); i < size; i++)
        {
            targets.add(null);
        }

        // Map notOkay = new HashMap();
        Set<String> processed = new HashSet<String>();

        for (int i = sources.size() - 1; i >= 0; i--)
        {
            Source s = sources.get(i);
//            if (notDoneList.get(s.getName()) == null)
//            {
//                notDoneList.put(s.getName(), s);
//            }
            CompilationUnit u = s != null ? s.getCompilationUnit() : null;
            int w = getCompilationUnitWorkflow(s);

            if (w == 0 || (w & preprocess) == 0 || (w & parse1) == 0)
            {
                // anything before 'parse2' requires no dependencies
                boolean okay = s.getLogger() == null || s.getLogger().errorCount() == 0;

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
                /*
                else
                {
                    notOkay.put(s, "1");
                }
                */
            }
            else if ((w & parse2) == 0)
            {
                boolean okay = ((s.getLogger() == null || s.getLogger().errorCount() == 0) &&
                                check(u, INHERITANCE, u.inheritance, symbolTable, parse2));

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
            }
            else if ((w & analyze1) == 0)
            {
                boolean okay = (s.getLogger() == null || s.getLogger().errorCount() == 0);

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
            }
            else if ((w & analyze2) == 0)
            {
                // analyze1 --> analyze2? focus on inheritance and namespaces
                //
                // 1. get their workflow values... must be greater than or equal to analyze2.
                // 2. CompilationUnit.typeinfo must be present.
                // 3. error count must be zero.

                boolean okay =  ((s.getLogger() == null || s.getLogger().errorCount() == 0) &&
                                 checkInheritance(u, u.inheritance, symbolTable, analyze2, processed) &&
                                 check(u, NAMESPACES, u.namespaces, symbolTable, analyze2));
                processed.clear();

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
                /*
                else
                {
                    notOkay.put(s, "2");
                }
                */
            }
            else if ((w & analyze3) == 0)
            {
                // analyze2 --> analyze3? focus on types, expressions and namespaces
                //
                // 1. get their workflow values... must be greater than or equal to analyze3.
                // 2. CompilationUnit.typeinfo must be present.
                // 3. error count must be zero.

                boolean okay = ((s.getLogger() == null || s.getLogger().errorCount() == 0) &&
                                checkInheritance(u, u.inheritance, symbolTable, analyze3, processed) &&
                                check(u, TYPES, u.types, symbolTable, analyze2) &&
                                check(u, NAMESPACES, u.namespaces, symbolTable, analyze3) &&
                                ((!strict && !warnings) || check(u, EXPRESSIONS, u.expressions, symbolTable, analyze2)));
                processed.clear();

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
                /*
                else
                {
                    notOkay.put(s, "3");
                }
                */
            }
            else if ((w & analyze4) == 0)
            {
                // analyze3 --> analyze4?
                //
                // 1. get their workflow values... must be greater than or equal to analyze4.
                // 3. error count must be zero.

                boolean okay = ((s.getLogger() == null || s.getLogger().errorCount() == 0) &&
                                checkInheritance(u, u.inheritance, symbolTable, analyze4, processed) &&
                                check(u, NAMESPACES, u.namespaces, symbolTable, analyze4) &&
                                checkDeep(u, TYPES, u.types, symbolTable, processed) &&
                                ((!strict && !warnings) || checkDeep(u, EXPRESSIONS, u.expressions, symbolTable, processed)));
                processed.clear();

                if (okay)
                {
                    targets.set(i, s);
                    count++;
                }
                /*
                else
                {
                    notOkay.put(s, "4");
                }
                */
            }
            else if ((w & generate) == 0)
            {
                // analyze4 --> generate
                //
                // 1. error count must be zero.

                if ((s.getLogger() == null) || (s.getLogger().errorCount() == 0))
                {
                    targets.set(i, s);
                    count++;
                }
                /*
                else
                {
                    notOkay.put(s, "5");
                }
                */
            }
            else
            {
                isDone = (s.getLogger() == null || s.getLogger().errorCount() == 0) ? isDone + 1 : isDone;
//                if ((s.getLogger() == null || s.getLogger().errorCount() == 0))
//                {
//                    notDoneList.remove(s.getName());
//                }
            }
        }

        if (count > 0)
        {
            boolean[] bits = new boolean[targets.size()];
            double maxBudget = 100, budget = 0;

            // Preferences
            //
            // 1. SubCompiler.generate()
            // 2. SubCompiler.analyze3()
            // 3. SubCompiler.analyze4()
            // 4. SubCompiler.analyze1()
            // 5. SubCompiler.preprocess()
            // 6. SubCompiler.analyze2() for .abc
            // 7. SubCompiler.parse2() for .abc
            // 8. SubCompiler.parse1() for .abc
            // 9. SubCompiler.analyze2() for .as and .mxml
            // 10. SubCompiler.parse2() for .as and .mxml
            // 11. SubCompiler.parse1() for .as and .mxml


            // 1. SubCompiler.generate()
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) != 0 &&
                    (w & analyze2) != 0 &&
                    (w & analyze3) != 0 &&
                    (w & analyze4) != 0 &&
                    (w & generate) == 0)
                {
                    bits[i] = true;
                }
            }

            // 2. SubCompiler.analyze3()
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) != 0 &&
                    (w & analyze2) != 0 &&
                    (w & analyze3) == 0)
                {
                    bits[i] = true;
                }
            }

            // 3. SubCompiler.analyze4()
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) != 0 &&
                    (w & analyze2) != 0 &&
                    (w & analyze3) != 0 &&
                    (w & analyze4) == 0)
                {
                    bits[i] = true;
                }
            }

            // 4. SubCompiler.analyze1()
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) == 0)
                {
                    bits[i] = true;
                }
            }

            // 5. SubCompiler.preprocess()
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w == 0)
                {
                    bits[i] = true;
                }
            }

            // 6. SubCompiler.analyze2() for .abc
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) != 0 &&
                    (w & analyze2) == 0)
                {
                    if (MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        bits[i] = true;
                    }
                }
            }

            // 7. SubCompiler.parse2() for .abc
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) == 0)
                {
                    if (MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        bits[i] = true;
                    }
                }
            }

            // 8. SubCompiler.parse1() for .abc
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) == 0)
                {
                    if (MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        bits[i] = true;
                    }
                }
            }

            // 9. SubCompiler.analyze2() for .as and .mxml
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) != 0 &&
                    (w & analyze1) != 0 &&
                    (w & analyze2) == 0)
                {
                    if (!MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        budget += calculateBudget(s, factor);
                        bits[i] = true;
                    }
                }
            }

            // 10. SubCompiler.parse2() for .as and .mxml
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) != 0 &&
                    (w & parse2) == 0)
                {
                    if (!MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        budget += calculateBudget(s, factor);
                        bits[i] = true;
                    }
                }
            }

            // 11. SubCompiler.parse1() for .as and .mxml
            for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
            {
                Source s = targets.get(i);
                if (s == null) continue;

                int w = getCompilationUnitWorkflow(s);
                if (w != 0 &&
                    (w & preprocess) != 0 &&
                    (w & parse1) == 0)
                {
                    if (!MimeMappings.ABC.equals(s.getMimeType()))
                    {
                        budget += calculateBudget(s, factor);
                        bits[i] = true;
                    }
                }
            }

            count = 0;
            for (int i = 0, size = bits.length; i < size; i++)
            {
                if (!bits[i])
                {
                    targets.set(i, null);
                }
                else
                {
                    count++;
                }
            }
        }
        else if (count == 0 && isDone == sources.size())
        {
            // successful... start postprocessing. batch2() won't call nextSource() again if postprocess()
            // stops generating new Sources...
            targets.clear();
            targets.addAll(sources);
            count = targets.size();
        }
        else if (count == 0 && isDone != sources.size())
        {
            // problem...
            //
            // 1. detect circular inheritance
            // 2. what else?
//            for (Iterator iter = notDoneList.entrySet().iterator(); iter.hasNext();)
//            {
//                Entry entry = (Entry)iter.next();
//                System.out.println("Did not finish compiling " + entry.getKey().toString());
//            }
            detectCycles(sources, igraph);
            assert ThreadLocalToolkit.errorCount() > 0 : "There is a problem in one of the compiler algorithms. Please use --conservative=true to compile. Also, please file a bug report.";
        }

        // C: sources.size() == targets.size() when this returns.
        return count;
    }