translator: translation state simplification
This commit is contained in:
Generated
+2
-2
@@ -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>
|
||||||
Generated
+1
-1
@@ -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
@@ -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
@@ -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">
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ buildscript {
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
|
|
||||||
sourceCompatibility = 1.5
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,65 +20,64 @@ 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()
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
fun parseAndAnalyze(sources: List<String>, disposer: Disposable): TranslationState {
|
||||||
val configuration = CompilerConfiguration()
|
|
||||||
val messageCollector = GroupingMessageCollector(object : MessageCollector {
|
|
||||||
private var hasError = false
|
|
||||||
|
|
||||||
override fun hasErrors(): Boolean = hasError
|
val configuration = CompilerConfiguration()
|
||||||
|
val messageCollector = GroupingMessageCollector(object : MessageCollector {
|
||||||
|
private var hasError = false
|
||||||
|
|
||||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
override fun hasErrors(): Boolean = hasError
|
||||||
println("[report] $message")
|
|
||||||
hasError = severity.isError || hasError
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||||
configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
|
println("[report] $message")
|
||||||
|
hasError = severity.isError || hasError
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
configuration.addKotlinSourceRoots(sources)
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||||
|
configuration.put(JVMConfigurationKeys.MODULE_NAME, JvmAbi.DEFAULT_MODULE_NAME)
|
||||||
|
|
||||||
environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
configuration.addKotlinSourceRoots(sources)
|
||||||
bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
|
val environment = KotlinCoreEnvironment.createForProduction(disposer, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
val collector = environment.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
val bindingContext = analyze(environment)?.bindingContext ?: throw TranslationException()
|
||||||
|
|
||||||
val analyzer = AnalyzerWithCompilerReport(collector)
|
return TranslationState(environment, bindingContext)
|
||||||
analyzer.analyzeAndReport(environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
|
}
|
||||||
override fun analyze(): AnalysisResult {
|
|
||||||
val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
|
||||||
val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.getModuleName())
|
|
||||||
|
|
||||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
fun analyze(environment: KotlinCoreEnvironment): AnalysisResult? {
|
||||||
moduleContext,
|
val collector = environment.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||||
environment.getSourceFiles(),
|
|
||||||
sharedTrace,
|
|
||||||
environment.configuration.get(JVMConfigurationKeys.MODULES),
|
|
||||||
environment.configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS),
|
|
||||||
JvmPackagePartProvider(environment))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun reportEnvironmentErrors() {
|
val analyzer = AnalyzerWithCompilerReport(collector)
|
||||||
val files = environment.configuration.jvmClasspathRoots
|
analyzer.analyzeAndReport(environment.getSourceFiles(), object : AnalyzerWithCompilerReport.Analyzer {
|
||||||
val runtimes = files.map { it.canonicalFile }.filter { it.name == PathUtil.KOTLIN_JAVA_RUNTIME_JAR && it.exists() }
|
override fun analyze(): AnalysisResult {
|
||||||
collector.report(CompilerMessageSeverity.ERROR, runtimes.joinToString { it.path }, CompilerMessageLocation.NO_LOCATION)
|
val sharedTrace = CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace()
|
||||||
println(runtimes.joinToString { it.toString() })
|
val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.getModuleName())
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return if (analyzer.hasErrors()) null else analyzer.analysisResult
|
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
||||||
}
|
moduleContext,
|
||||||
|
environment.getSourceFiles(),
|
||||||
|
sharedTrace,
|
||||||
|
environment.configuration.get(JVMConfigurationKeys.MODULES),
|
||||||
|
environment.configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS),
|
||||||
|
JvmPackagePartProvider(environment))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun reportEnvironmentErrors() {
|
||||||
|
val files = environment.configuration.jvmClasspathRoots
|
||||||
|
val runtimes = files.map { it.canonicalFile }.filter { it.name == PathUtil.KOTLIN_JAVA_RUNTIME_JAR && it.exists() }
|
||||||
|
collector.report(CompilerMessageSeverity.ERROR, runtimes.joinToString { it.path }, CompilerMessageLocation.NO_LOCATION)
|
||||||
|
println(runtimes.joinToString { it.toString() })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return if (analyzer.hasErrors()) null else analyzer.analysisResult
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user