Skip to content

Commit

Permalink
Merge remote-tracking branch 'main-upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
egorklementev committed May 25, 2022
2 parents 933a71e + 675dcf2 commit 32f0f8a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
20 changes: 10 additions & 10 deletions src/main/java/translator/Blocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import tree.Statement.BlockStatement
*/
fun mapBlock(block: Block,
name: String? = null,
additionalStmt: Pair<String, List<EOBndExpr>>? = null): List<EOBndExpr> {
firstStmts: List<Pair<String, List<EOBndExpr>>>? = null,
lastStmts: List<Pair<String, List<EOBndExpr>>>? = null): List<EOBndExpr> {
if (name != null) {
return listOf(
EOBndExpr(
EOObject(
listOf(),
None,
mapBlock(block, additionalStmt = additionalStmt)
mapBlock(block, firstStmts = firstStmts, lastStmts = lastStmts)
),
name
)
Expand All @@ -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())
}


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/translator/MethodInvocations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
45 changes: 25 additions & 20 deletions src/main/java/translator/Methods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/translator/preprocessor/Preprocessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 32f0f8a

Please sign in to comment.