minor codegen refactoring

* cleanup after yesterday
* remove BindingContext stack in GenerationState
* use more power and strength of di

TODO: also initialize GenerationState by DI
This commit is contained in:
Stepan Koltsov
2012-03-29 19:47:50 +04:00
parent d76454ce08
commit e6fda5b3d3
16 changed files with 247 additions and 139 deletions
@@ -236,7 +236,7 @@ public class CompileEnvironment {
if (!scriptCompileSession.analyze()) {
return null;
}
ClassFileFactory factory = scriptCompileSession.generate(true);
ClassFileFactory factory = scriptCompileSession.generate(true).getFactory();
return runDefineModules(moduleFile, factory);
}
@@ -295,7 +295,7 @@ public class CompileEnvironment {
if (!moduleCompileSession.analyze() && !ignoreErrors) {
return null;
}
return moduleCompileSession.generate(false);
return moduleCompileSession.generate(false).getFactory();
}
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable FqName mainClass, boolean includeRuntime) {
@@ -383,7 +383,7 @@ public class CompileEnvironment {
return null;
}
ClassFileFactory factory = session.generate(false);
ClassFileFactory factory = session.generate(false).getFactory();
return new GeneratedClassLoader(factory);
}
@@ -408,7 +408,7 @@ public class CompileEnvironment {
return false;
}
ClassFileFactory factory = session.generate(false);
ClassFileFactory factory = session.generate(false).getFactory();
if (jar != null) {
try {
writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
@@ -212,11 +212,11 @@ public class CompileSession {
}
@NotNull
public ClassFileFactory generate(boolean module) {
public GenerationState generate(boolean module) {
Project project = environment.getProject();
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), isVerbose ? new BackendProgress() : Progress.DEAF);
generationState.compileCorrectFiles(bindingContext, sourceFiles, CompilationErrorHandler.THROW_EXCEPTION, true);
ClassFileFactory answer = generationState.getFactory();
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs),
isVerbose ? new BackendProgress() : Progress.DEAF, bindingContext, sourceFiles);
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
List<CompilerPlugin> plugins = environment.getCompilerPlugins();
if (!module) {
@@ -227,7 +227,7 @@ public class CompileSession {
}
}
}
return answer;
return generationState;
}
private class BackendProgress implements Progress {