// process source AS3 files
Set<ICompilationUnit> mainUnits = new LinkedHashSet<ICompilationUnit>(getSourceFilenames().size());
final HashMap<ICompilationUnit, Integer> unitOrdering = new HashMap<ICompilationUnit, Integer>();
ASCProject applicationProject = createProject(workspace, problemQuery);
// Add any problems from parsing config vars supplied on the command line
List<ICompilerProblem> configProblems = new ArrayList<ICompilerProblem>();
applicationProject.collectProblems(configProblems);
problemQuery.addAll(configProblems);
int i = 0;
for (final String sourceFilename : sourceFilenames)
{
// If we are not merging then create a new project
// and set the compilation units.
if (i > 0 && !getMergeABCs())
{
applicationProject = createProject(workspace, problemQuery);
mainUnits.clear();
unitOrdering.clear();
problemQuery.clear();
}
final IFileSpecification sourceFileSpec = new FileSpecification(sourceFilename);
workspace.fileAdded(sourceFileSpec);
final ICompilationUnit cu = ASCompilationUnit.createMainCompilationUnitForASC(
applicationProject,
sourceFileSpec,
this);
mainUnits.add(cu);
unitOrdering.put(cu,unitOrdering.size());
// add compilation unit to project
applicationProject.addCompilationUnit(cu);
applicationProject.updatePublicAndInternalDefinitions(Collections.singletonList(cu));
// The logic that re-parses a garbage collected syntax tree, does not
// know about the files included with the -in option, so we'll pin
// the syntax tree here so we know we will never need to re-parse the
// the synax tree for the root compilation unit.
rootedSyntaxTrees.add(cu.getSyntaxTreeRequest().get().getAST());
// syntax errors
for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits())
{
final ICompilerProblem[] problems = compilationUnit.getSyntaxTreeRequest().get().getProblems();
problemQuery.addAll(problems);
}
// Parse trees
if ( getShowParseTrees() )
{
final String outputSyntaxFilename = FilenameUtils.removeExtension(sourceFilename).concat(".p");
try
{
PrintWriter syntaxFile = new PrintWriter(outputSyntaxFilename);
final IASNode ast = cu.getSyntaxTreeRequest().get().getAST();
if(ast instanceof FileNode)
{
// Parse the full tree and add the new problems found in the
// function bodies into the problem collection.
final FileNode fileNode = (FileNode)ast;
final ImmutableSet<ICompilerProblem> skeletonProblems =
ImmutableSet.copyOf(fileNode.getProblems());
fileNode.populateFunctionNodes();
final ImmutableSet<ICompilerProblem> allProblems =
ImmutableSet.copyOf(fileNode.getProblems());
// Only add newly found problems. Otherwise, there will be
// duplicates in "problemQuery".
final SetView<ICompilerProblem> difference = Sets.difference(skeletonProblems, allProblems);
problemQuery.addAll(difference);
}
syntaxFile.println(ast);
syntaxFile.flush();
syntaxFile.close();
}
catch (FileNotFoundException e)
{
problemQuery.add(new FileWriteProblem(e));
}
}
// output
// For the merged case, wait until the last source file.
// For the non-merged case, make each source file individually
if (!getMergeABCs() ||
(getMergeABCs() && (i == sourceFilenames.size() - 1)))
{
// Let's start up all the compilation units to try and get more threads generating code
// at the same time.
for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits())
{
compilationUnit.startBuildAsync(TargetType.SWF);
}
// Run the resolveRefs() logic for as long as it's relevant.
for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits())
{
final ICompilerProblem[] problems = compilationUnit.getOutgoingDependenciesRequest().get().getProblems();
problemQuery.addAll(problems);
}
String outputFileBaseName = FilenameUtils.getBaseName(sourceFilename);
String outputDirectoryName = FilenameUtils.getFullPath(sourceFilename);
// Apply user specified basename and output directory. The
// basename is only changed ABCs are merged since each abc
// needs a unique filename.
if (getMergeABCs() && getOutputBasename() != null)
outputFileBaseName = getOutputBasename();
final String specifiedOutputDirectory = getOutputDirectory();
if (!Strings.isNullOrEmpty(specifiedOutputDirectory))
outputDirectoryName = normalizeDirectoryName(specifiedOutputDirectory);
// Output to either a SWF or ABC file.
if (isGenerateSWF())
{
final boolean swfBuilt = generateSWF(outputDirectoryName, outputFileBaseName, applicationProject,
mainUnits, sourceFilename, problemQuery, startTime);
if (!swfBuilt)
success = false;
}
else
{
Collection<ICompilationUnit> units = mainUnits;
if(getMergeABCs())
{
// Run the topological sort to figure out which order to output the ABCs in
// Resorts to using commandline order rather than a filename based lexical sort in
// cases where there are no real dependencies between the scripts
units = applicationProject.getDependencyGraph().topologicalSort(mainUnits,
new Comparator<ICompilationUnit>()
{
@Override
public int compare(ICompilationUnit o1, ICompilationUnit o2)
{