public CompilationUnit parse1(Source source, SymbolTable symbolTable)
{
if (benchmarkHelper != null)
benchmarkHelper.startPhase(CompilerBenchmarkHelper.PARSE1, source.getNameForReporting());
CompilationUnit unit = source.getCompilationUnit();
if (unit != null && unit.hasTypeInfo)
{
if (unit.bytes.isEmpty())
{
copyBytecodes(source, unit);
}
return unit;
}
if ((unit != null) && (unit.getSyntaxTree() != null))
{
return unit;
}
final String path = source.getName();
ProgramNode node = null;
CompilerContext context = new CompilerContext();
Context cx = new Context(symbolTable.perCompileData);
cx.setScriptName(source.getName());
cx.setPath(source.getParent());
cx.setEmitter(symbolTable.emitter);
cx.setHandler(new As3Compiler.CompilerHandler()
{
public void error2(String filename, int ln, int col, Object msg, String source)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
ThreadLocalToolkit.log((flex2.compiler.util.CompilerMessage) msg, filename);
}
public void warning2(String filename, int ln, int col, Object msg, String source)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
ThreadLocalToolkit.log((CompilerMessage) msg, filename);
}
public void error(String filename, int ln, int col, String msg, String source, int errorCode)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
if (errorCode != -1)
{
ThreadLocalToolkit.logError(filename, msg, errorCode);
}
else
{
ThreadLocalToolkit.logError(filename, msg);
}
}
public void warning(String filename, int ln, int col, String msg, String source, int errorCode)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
if (errorCode != -1)
{
ThreadLocalToolkit.logWarning(filename, msg, errorCode);
}
else
{
ThreadLocalToolkit.logWarning(filename, msg);
}
}
public void error(String filename, int ln, int col, String msg, String source)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
ThreadLocalToolkit.logError(filename, msg);
}
public void warning(String filename, int ln, int col, String msg, String source)
{
filename = (filename == null || filename.length() == 0) ? path : filename;
ThreadLocalToolkit.logWarning(filename, msg);
}
public FileInclude findFileInclude(String parentPath, String filespec)
{
return null;
}
});
symbolTable.perCompileData.handler = cx.getHandler();
context.setAscContext(cx);
byte[] abc = null;
try
{
abc = source.toByteArray();
if (abc == null)
{
abc = FileUtils.toByteArray(source.getInputStream());
}
if (abc == null || abc.length == 0)
{
ThreadLocalToolkit.log(new NoBytecodeIsAvailable(), source);
}
else
{
AbcParser parser = new AbcParser(cx, abc);
node = parser.parseAbc();
if (node == null && ThreadLocalToolkit.errorCount() == 0)
{
ThreadLocalToolkit.log(new BytecodeDecodingFailed(), source);
}
As3Compiler.cleanNodeFactory(cx.getNodeFactory());
}
}
catch (IOException ex)
{
ThreadLocalToolkit.logError(source.getNameForReporting(), ex.getLocalizedMessage());
}
if (ThreadLocalToolkit.errorCount() > 0)
{
return null;
}
if (unit == null)
{
unit = source.newCompilationUnit(node, context);
}
else
{
unit.setSyntaxTree(node);
unit.getContext().setAttributes(context);
}
unit.bytes.set(abc, abc.length);
SyntaxTreeEvaluator treeEvaluator = new SyntaxTreeEvaluator(unit);