Skip to content

Commit

Permalink
impl preprocessing tenaries
Browse files Browse the repository at this point in the history
  • Loading branch information
omdxp committed Sep 8, 2024
1 parent b68da46 commit 49f5e15
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion preprocessor/preprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,13 @@ int preprocessor_evaluate_exp(struct compile_process *compiler,

long left_operand = preprocessor_evaluate(compiler, node->exp.left);
if (node->exp.right->type == PREPROCESSOR_TENARY_NODE) {
#warning "handle ternary"
if (left_operand) {
return preprocessor_evaluate(compiler,
node->exp.right->tenary_node.true_node);
} else {
return preprocessor_evaluate(compiler,
node->exp.right->tenary_node.false_node);
}
}

long right_operand = preprocessor_evaluate(compiler, node->exp.right);
Expand Down
2 changes: 1 addition & 1 deletion test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define ABC (1 + 2 * (9 - 3))
#define ABC 0 ? 2 : 3

int main() { return ABC; }

0 comments on commit 49f5e15

Please sign in to comment.