diff --git a/src/main/java/translator/Blocks.kt b/src/main/java/translator/Blocks.kt index 33a3b08f..ab3c2e19 100644 --- a/src/main/java/translator/Blocks.kt +++ b/src/main/java/translator/Blocks.kt @@ -14,14 +14,15 @@ import tree.Statement.BlockStatement */ fun mapBlock(block: Block, name: String? = null, - additionalStmt: Pair>? = null): List { + firstStmts: List>>? = null, + lastStmts: List>>? = null): List { if (name != null) { return listOf( EOBndExpr( EOObject( listOf(), None, - mapBlock(block, additionalStmt = additionalStmt) + mapBlock(block, firstStmts = firstStmts, lastStmts = lastStmts) ), name ) @@ -35,24 +36,23 @@ fun mapBlock(block: Block, EOBndExpr( EOCopy( "seq", - if (additionalStmt != null) { - listOf(additionalStmt.first.eoDot()) - } else { - listOf() - } + + (firstStmts?.map { it.first.eoDot() } ?: listOf()) + if (parsedStatements.isNotEmpty()) parsedStatements.keys.map { it.eoDot() } else { - if (additionalStmt == null) { + if (firstStmts == null && lastStmts == null) { listOf("TRUE".eoDot()) } else { listOf() } - } + } + + (lastStmts?.map { it.first.eoDot() } ?: listOf()) ), "@" ) - ) + (additionalStmt?.second ?: listOf()) + parsedStatements.values.toList().flatten() + ) + (firstStmts?.map { it.second }?.flatten() ?: listOf()) + + parsedStatements.values.toList().flatten() + + (lastStmts?.map { it.second }?.flatten() ?: listOf()) } diff --git a/src/main/java/translator/MethodInvocations.kt b/src/main/java/translator/MethodInvocations.kt index 9c5ddf8a..24e8d9f6 100644 --- a/src/main/java/translator/MethodInvocations.kt +++ b/src/main/java/translator/MethodInvocations.kt @@ -74,9 +74,9 @@ fun mapMethodInvocation(methodInvocation: MethodInvocation, name: String): List< if (methodQualifier.compoundName.names.size > 0) methodQualifier.compoundName.names.eoDot() else - "this".eoDot() + if (!methodInvocation.superSign) "this".eoDot() else listOf("this", "super").eoDot() is FieldAccess -> getFullIdentifier(methodQualifier).eoDot() - null -> "this".eoDot() + null -> if (!methodInvocation.superSign) "this".eoDot() else listOf("this", "super").eoDot() else -> { util.logger.warn { "Unsupported method qualifier $methodQualifier; falling back to unsupported_qualifier" } "unsupported_qualifier".eoDot() diff --git a/src/main/java/translator/Methods.kt b/src/main/java/translator/Methods.kt index e1eefd63..e397ec59 100644 --- a/src/main/java/translator/Methods.kt +++ b/src/main/java/translator/Methods.kt @@ -10,6 +10,24 @@ import tree.Declaration.ConstructorDeclaration import tree.Declaration.MethodDeclaration import tree.Declaration.ParameterDeclaration +fun genInit(): EOBndExpr = + EOBndExpr( + EOObject( + listOf(), + None, + listOf( + EOBndExpr( + EOCopy( + listOf("this", "init").eoDot(), + "this".eoDot() + ), + "@" + ) + ) + ), + "initialization" + ) + fun mapMethodDeclaration(dec: MethodDeclaration): EOBndExpr { val isStatic = dec.modifiers != null && dec.modifiers.modifiers.modifiers.find { it == TokenCode.Static } != null @@ -40,26 +58,13 @@ fun mapMethodDeclaration(dec: MethodDeclaration): EOBndExpr { if (dec.methodBody != null) { mapBlock( dec.methodBody, - additionalStmt = if (dec is ConstructorDeclaration) { - "initialization" to listOf( - EOBndExpr( - EOObject( - listOf(), - None, - listOf( - EOBndExpr( - EOCopy( - listOf("this", "init").eoDot(), - "this".eoDot() - ), - "@" - ) - ) - ), - "initialization" - ) - - ) + firstStmts = if (dec is ConstructorDeclaration) { + listOf("initialization" to listOf(genInit())) + } else { + null + }, + lastStmts = if (dec is ConstructorDeclaration) { + listOf("this" to listOf()) } else { null } diff --git a/src/main/java/translator/preprocessor/Preprocessor.kt b/src/main/java/translator/preprocessor/Preprocessor.kt index 7d778d05..0193ed86 100644 --- a/src/main/java/translator/preprocessor/Preprocessor.kt +++ b/src/main/java/translator/preprocessor/Preprocessor.kt @@ -268,7 +268,9 @@ private fun preprocessStmt(state: PreprocessorState, stmt: Statement) { } private fun preprocessVarDecl(state: PreprocessorState, varDecl: VariableDeclaration) { - preprocessInitializer(state, varDecl.initializer) + if (varDecl.initializer != null) { + preprocessInitializer(state, varDecl.initializer) + } when (varDecl.type) { is TypeName -> { preprocessType(state, varDecl.type)