From d75ffb62d682420b80696a36a3ef66b720266e66 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Sat, 30 Mar 2024 07:41:46 +0000 Subject: Implement else branching logic including 'else if'. Statement lists for if & else conditions are now wrapped in a new 'struct bt_cond'. Handling B_AC_TEST statements moved to stmt_eval() to handle nested conditional statements. From Christian Ludwig christian_ludwig at genua.de --- regress/usr.sbin/btrace/if.bt | 29 +++++++++++++++++++++++++++++ regress/usr.sbin/btrace/if.ok | 4 ++++ 2 files changed, 33 insertions(+) (limited to 'regress') diff --git a/regress/usr.sbin/btrace/if.bt b/regress/usr.sbin/btrace/if.bt index 053801cac54..41f30815ba5 100644 --- a/regress/usr.sbin/btrace/if.bt +++ b/regress/usr.sbin/btrace/if.bt @@ -9,6 +9,20 @@ BEGIN { if (1) { printf("printed!\n"); } + + if (0) + printf("simple if\n"); + else + printf("simple else\n"); + + if (0) { + printf("disabled if\n"); + } else if (1) { + printf("multiple statements in "); + printf("else-if branch\n"); + } else { + printf("no else\n"); + } } END { @@ -18,4 +32,19 @@ END { printf("(%d) ", @var); printf("statements\n"); } + + if (0) printf("single-line if\n"); else printf("single-line else\n"); + + if (0) { + printf("not printed\n"); + } else { + if (0) { + printf("nested not printed\n"); + } else { + printf("nested printed\n"); + exit(); + printf("nested not printed\n"); + } + printf("also not printed\n"); + } } diff --git a/regress/usr.sbin/btrace/if.ok b/regress/usr.sbin/btrace/if.ok index c2d5a91bc90..cfac256dac6 100644 --- a/regress/usr.sbin/btrace/if.ok +++ b/regress/usr.sbin/btrace/if.ok @@ -1,2 +1,6 @@ printed! +simple else +multiple statements in else-if branch multiple (4) statements +single-line else +nested printed -- cgit v1.2.3