translator: fix string moving

This commit is contained in:
Alexey Stepanov
2016-08-16 17:54:26 +03:00
parent 56659a6c2a
commit 8e079033a1
3 changed files with 18 additions and 4 deletions
@@ -13,10 +13,11 @@ class ProjectTranslator(val files: List<KtFile>, val state: TranslationState) {
}
fun addDeclarations(file: KtFile) {
val variableManager = VariableManager(state.globalVariableCollection)
for (declaration in file.declarations) {
when (declaration) {
is KtNamedFunction -> {
val function = FunctionCodegen(state, VariableManager(state.globalVariableCollection), declaration, codeBuilder)
val function = FunctionCodegen(state, variableManager, declaration, codeBuilder)
if (function.external) {
state.externalFunctions.put(function.fullName, function)
} else {
@@ -24,15 +25,15 @@ class ProjectTranslator(val files: List<KtFile>, val state: TranslationState) {
}
}
is KtClass -> {
val codegen = ClassCodegen(state, VariableManager(state.globalVariableCollection), declaration, codeBuilder)
val codegen = ClassCodegen(state, variableManager, declaration, codeBuilder)
state.classes.put(declaration.name!!, codegen)
}
is KtProperty -> {
val property = PropertyCodegen(state, VariableManager(state.globalVariableCollection), declaration, codeBuilder)
val property = PropertyCodegen(state, variableManager, declaration, codeBuilder)
state.properties.put(declaration.name!!, property)
}
is KtObjectDeclaration -> {
val property = ObjectCodegen(state, VariableManager(state.globalVariableCollection), declaration, codeBuilder)
val property = ObjectCodegen(state, variableManager, declaration, codeBuilder)
state.objects.put(declaration.name!!, property)
}
}
@@ -0,0 +1,2 @@
string_print_test_1_inline() == 23
string_print_test_1_variable() == 1
@@ -0,0 +1,11 @@
fun string_print_test_1_inline(): Int {
println("STRING INLINE PRINT WORKS")
return 23
}
fun string_print_test_1_variable(): Int {
val x = "STRING VARIABLE WORKS"
val y = x
println(y)
return 1
}