translator: translation state simplification

This commit is contained in:
e5l
2016-07-13 09:54:14 +03:00
parent 5324b9d631
commit 947c144eef
7 changed files with 52 additions and 55 deletions
+2 -2
View File
@@ -19,8 +19,8 @@
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="ast-kotlin_main" target="1.5" /> <module name="ast-kotlin_main" target="1.8" />
<module name="ast-kotlin_test" target="1.5" /> <module name="ast-kotlin_test" target="1.8" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>
+1 -1
View File
@@ -13,7 +13,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
</project> </project>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="ast-kotlin:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="ast-kotlin" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4"> <module external.linked.project.id="ast-kotlin:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="ast-kotlin" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/../../build/classes/main" /> <output url="file://$MODULE_DIR$/../../build/classes/main" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/main"> <content url="file://$MODULE_DIR$/../../src/main">
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="ast-kotlin:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="ast-kotlin" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4"> <module external.linked.project.id="ast-kotlin:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="ast-kotlin" external.system.module.type="sourceSet" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false"> <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output-test url="file://$MODULE_DIR$/../../build/classes/test" /> <output-test url="file://$MODULE_DIR$/../../build/classes/test" />
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../../src/test"> <content url="file://$MODULE_DIR$/../../src/test">
-2
View File
@@ -13,8 +13,6 @@ buildscript {
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'kotlin' apply plugin: 'kotlin'
sourceCompatibility = 1.5
repositories { repositories {
mavenCentral() mavenCentral()
} }
+2 -2
View File
@@ -1,6 +1,6 @@
import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.Disposer
import org.kotlinnative.translator.FileTranslator import org.kotlinnative.translator.FileTranslator
import org.kotlinnative.translator.TranslationState import org.kotlinnative.translator.parseAndAnalyze
fun main(args: Array<String>) { fun main(args: Array<String>) {
@@ -10,7 +10,7 @@ fun main(args: Array<String>) {
} }
val disposer = Disposer.newDisposable() val disposer = Disposer.newDisposable()
val state = TranslationState(args.asList(), disposer) val state = parseAndAnalyze(args.asList(), disposer)
val files = state.environment.getSourceFiles() val files = state.environment.getSourceFiles()
if (files.isEmpty()) { if (files.isEmpty()) {
@@ -20,17 +20,15 @@ import org.jetbrains.kotlin.utils.PathUtil
import org.kotlinnative.translator.exceptions.TranslationException import org.kotlinnative.translator.exceptions.TranslationException
import java.util.* import java.util.*
class TranslationState(val environment: KotlinCoreEnvironment, val bindingContext: BindingContext) {
class TranslationState(sources: List<String>, disposer: Disposable) {
val environment: KotlinCoreEnvironment
val bindingContext: BindingContext
var functions = HashMap<String, FunctionCodegen>() var functions = HashMap<String, FunctionCodegen>()
var classes = HashMap<String, ClassCodegen>() var classes = HashMap<String, ClassCodegen>()
val variableManager = VariableManager() val variableManager = VariableManager()
}
fun parseAndAnalyze(sources: List<String>, disposer: Disposable): TranslationState {
init {
val configuration = CompilerConfiguration() val configuration = CompilerConfiguration()
val messageCollector = GroupingMessageCollector(object : MessageCollector { val messageCollector = GroupingMessageCollector(object : MessageCollector {
private var hasError = false private var hasError = false
@@ -48,8 +46,10 @@ class TranslationState(sources: List<String>, disposer: Disposable) {
configuration.addKotlinSourceRoots(sources) configuration.addKotlinSourceRoots(sources)
environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) val environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException() val bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException()
return TranslationState(environment, bindingContext)
} }
fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? { fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
@@ -81,4 +81,3 @@ class TranslationState(sources: List<String>, disposer: Disposable) {
return if (analyzer.hasErrors()) null else analyzer.analysisResult return if (analyzer.hasErrors()) null else analyzer.analysisResult
} }
}