Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locations in intermediate statements #253

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 53 additions & 29 deletions jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,48 +180,72 @@
}
}

is NopStmtDto -> EtsNopStmt(location = loc())
is NopStmtDto -> {
EtsNopStmt(location = loc())

Check warning on line 184 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt#L184

Added line #L184 was not covered by tests
}

is AssignStmtDto -> EtsAssignStmt(
location = loc(),
lhv = convertToEtsEntity(stmt.left) as EtsValue,
rhv = ensureOneAddress(convertToEtsEntity(stmt.right)),
)
is AssignStmtDto -> {
val lhv = convertToEtsEntity(stmt.left) as EtsValue
val rhv = ensureOneAddress(convertToEtsEntity(stmt.right))
EtsAssignStmt(
location = loc(),
lhv = lhv,
rhv = rhv,
)
}

is CallStmtDto -> EtsCallStmt(
location = loc(),
expr = convertToEtsEntity(stmt.expr) as EtsCallExpr,
)
is CallStmtDto -> {
val expr = convertToEtsEntity(stmt.expr) as EtsCallExpr
EtsCallStmt(
location = loc(),
expr = expr,
)
}

is ReturnStmtDto -> {
val returnValue = ensureOneAddress(convertToEtsEntity(stmt.arg))
EtsReturnStmt(
location = loc(),
returnValue = ensureOneAddress(convertToEtsEntity(stmt.arg)),
returnValue = returnValue,
)
}

is ReturnVoidStmtDto -> EtsReturnStmt(
location = loc(),
returnValue = null,
)
is ReturnVoidStmtDto -> {
EtsReturnStmt(
location = loc(),
returnValue = null,
)
}

is ThrowStmtDto -> EtsThrowStmt(
location = loc(),
arg = convertToEtsEntity(stmt.arg),
)
is ThrowStmtDto -> {
val arg = convertToEtsEntity(stmt.arg)
EtsThrowStmt(
location = loc(),
arg = arg,
)
}

is GotoStmtDto -> EtsGotoStmt(location = loc())
is GotoStmtDto -> {
EtsGotoStmt(location = loc())
}

is IfStmtDto -> EtsIfStmt(
location = loc(),
condition = convertToEtsEntity(stmt.condition),
)
is IfStmtDto -> {
val condition = convertToEtsEntity(stmt.condition)
EtsIfStmt(
location = loc(),
condition = condition,
)
}

is SwitchStmtDto -> EtsSwitchStmt(
location = loc(),
arg = convertToEtsEntity(stmt.arg),
cases = stmt.cases.map { convertToEtsEntity(it) },
)
is SwitchStmtDto -> {
val arg = convertToEtsEntity(stmt.arg)
val cases = stmt.cases.map { convertToEtsEntity(it) }
EtsSwitchStmt(
location = loc(),
arg = arg,
cases = cases,

Check warning on line 246 in jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt

View check run for this annotation

Codecov / codecov/patch

jacodb-ets/src/main/kotlin/org/jacodb/ets/dto/Convert.kt#L240-L246

Added lines #L240 - L246 were not covered by tests
)
}

// else -> error("Unknown Stmt: $stmt")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.jacodb.ets.dto.LocalDto
import org.jacodb.ets.dto.MethodDto
import org.jacodb.ets.dto.ModifierDto
import org.jacodb.ets.dto.NumberTypeDto
import org.jacodb.ets.dto.ReturnVoidStmtDto
import org.jacodb.ets.dto.StmtDto
import org.jacodb.ets.dto.convertToEtsFile
import org.jacodb.ets.dto.convertToEtsMethod
Expand Down Expand Up @@ -133,9 +134,7 @@ class EtsFromJsonTest {
""".trimIndent()
val stmtDto = Json.decodeFromString<StmtDto>(jsonString)
println("stmtDto = $stmtDto")
val ctx = EtsMethodBuilder(defaultSignature)
val stmt = ctx.convertToEtsStmt(stmtDto)
Assertions.assertEquals(EtsReturnStmt(EtsInstLocation(ctx.etsMethod, 0), null), stmt)
Assertions.assertEquals(ReturnVoidStmtDto, stmtDto)
}

@Test
Expand Down
Loading