Stmt: Introduce assert statement and related hooks

including two hooks called assertion_failure() and assertion_result() for
customization and tracking of assertion results.
This commit is contained in:
Arne Welzel 2023-06-05 19:13:14 +02:00
parent a25b1a9d59
commit 25ea678626
41 changed files with 635 additions and 3 deletions

View file

@ -7,7 +7,7 @@
%expect 211
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY
%token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY TOK_ASSERT
%token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF
%token TOK_BOOL TOK_BREAK TOK_CASE TOK_OPTION TOK_CONST
%token TOK_CONSTANT TOK_COPY TOK_COUNT TOK_DEFAULT TOK_DELETE
@ -78,6 +78,7 @@
%type <captures> capture_list opt_captures when_captures
%type <when_clause> when_head when_start when_clause
%type <re_modes> TOK_PATTERN_END
%type <expr> opt_assert_msg
%{
#include <cstdlib>
@ -1802,6 +1803,11 @@ stmt:
script_coverage_mgr.DecIgnoreDepth();
}
| TOK_ASSERT expr opt_assert_msg ';'
{
$$ = new AssertStmt(IntrusivePtr{AdoptRef{}, $2}, {AdoptRef{}, $3});
}
| TOK_PRINT expr_list ';' opt_no_test
{
set_location(@1, @3);
@ -2228,6 +2234,13 @@ resolve_id:
}
;
opt_assert_msg:
',' expr
{ $$ = $2; }
|
{ $$ = nullptr; }
;
opt_no_test:
TOK_NO_TEST
{ $$ = true; }