add if-expression versions for the conditionals if_cc, if_cs, if_vc etc

This commit is contained in:
Irmen de Jong
2025-09-11 01:57:30 +02:00
parent 1c77d5d5e7
commit 79419a98d0
18 changed files with 294 additions and 19 deletions

View File

@@ -100,6 +100,7 @@ class SimplifiedAstMaker(private val program: Program, private val errors: IErro
is StringLiteral -> transform(expr)
is TypecastExpression -> transform(expr)
is IfExpression -> transform(expr)
is BranchConditionExpression -> transform(expr)
is PtrDereference -> transform(expr)
is StaticStructInitializer -> transform(expr)
is ArrayIndexedPtrDereference -> throw FatalAstException("this should have been converted to some other ast nodes")
@@ -141,6 +142,14 @@ class SimplifiedAstMaker(private val program: Program, private val errors: IErro
return ifexpr
}
private fun transform(branchExpr: BranchConditionExpression): PtBranchCondExpression {
val type = branchExpr.inferType(program).getOrElse { throw FatalAstException("unknown dt") }
val bexpr = PtBranchCondExpression(branchExpr.condition, type, branchExpr.position)
bexpr.add(transformExpression(branchExpr.truevalue))
bexpr.add(transformExpression(branchExpr.falsevalue))
return bexpr
}
private fun transform(srcDefer: Defer): PtDefer {
val defer = PtDefer(srcDefer.position)
srcDefer.scope.statements.forEach {