in flex/tools/idea-flex-compiler-fix/src/flex2/compiler/API.java [450:877]
private static int nextSource(List sources, List units, DependencyGraph igraph, DependencyGraph dgraph,
List 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();
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 processed = new HashSet();
for (int i = sources.size() - 1; i >= 0; i--)
{
Source s = (Source) sources.get(i);
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, 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, 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, u.types, symbolTable, analyze2) &&
check(u, u.namespaces, symbolTable, analyze3) &&
((!strict && !warnings) || check(u, 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, u.namespaces, symbolTable, analyze4) &&
checkDeep(u, u.types, symbolTable, processed) &&
((!strict && !warnings) || checkDeep(u, 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 (count > 0)
{
boolean[] bits = new boolean[targets.size()];
double maxBudget = 100, budget = 0;
// Preferences
//
// 1. Compiler.generate()
// 2. Compiler.analyze3()
// 3. Compiler.analyze4()
// 4. Compiler.analyze1()
// 5. Compiler.preprocess()
// 6. Compiler.analyze2() for .abc
// 7. Compiler.parse2() for .abc
// 8. Compiler.parse1() for .abc
// 9. Compiler.analyze2() for .as and .mxml
// 10. Compiler.parse2() for .as and .mxml
// 11. Compiler.parse1() for .as and .mxml
// 1. Compiler.generate()
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.analyze3()
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.analyze4()
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.analyze1()
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.preprocess()
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) targets.get(i);
if (s == null) continue;
int w = getCompilationUnitWorkflow(s);
if (w == 0)
{
bits[i] = true;
}
}
// 6. Compiler.analyze2() for .abc
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.parse2() for .abc
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.parse1() for .abc
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.analyze2() for .as and .mxml
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.parse2() for .as and .mxml
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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. Compiler.parse1() for .as and .mxml
for (int i = targets.size() - 1; i >= 0 && budget < maxBudget; i--)
{
Source s = (Source) 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?
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;
}