diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-06-11 21:24:50 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-06-11 21:24:50 +0200 |
commit | 9b8f937cbd26df1d47e5f5aa37b5c076eb51ecae (patch) | |
tree | 1cfcb65aacecf355056f6815db5ed22f309724a8 | |
parent | 1cc4571579f675923677366acc65f4dd6d8750a7 (diff) |
Assert that we don’t have too many tokens
-rw-r--r-- | src/lexer.h | 5 | ||||
-rw-r--r-- | src/parser.h | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/lexer.h b/src/lexer.h index 636237f..bb780ee 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1,6 +1,7 @@ #ifndef ORYX_LEXER_H #define ORYX_LEXER_H +#include <assert.h> #include <stddef.h> #include <stdint.h> @@ -35,9 +36,13 @@ enum { token T to the doubled equivalent by doing T += 193. */ LEXLANGL_DBL = UINT8_MAX - 2, /* << */ LEXRANGL_DBL = UINT8_MAX - 0, /* >> */ + + _LEX_LAST_ENT, }; typedef uint8_t lexeme_kind_t_; +static_assert(_LEX_LAST_ENT - 1 <= (lexeme_kind_t_)-1, + "Too many lexer tokens to fix in LEXEME_KIND_T_"); #define LEXEMES_BLKSZ (sizeof(lexeme_kind_t_) + sizeof(struct strview)) diff --git a/src/parser.h b/src/parser.h index 4fcdacd..ee6b324 100644 --- a/src/parser.h +++ b/src/parser.h @@ -1,6 +1,7 @@ #ifndef ORYX_PARSER_H #define ORYX_PARSER_H +#include <assert.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> @@ -44,9 +45,13 @@ enum { /* Binary sub ‘lhs - rhs’ */ ASTBINSUB = '-', + + _AST_LAST_ENT = 256, }; typedef uint8_t ast_kind_t_; +static_assert(_AST_LAST_ENT - 1 <= (ast_kind_t_)-1, + "Too many AST tokens to fix in AST_KIND_T_"); #define AST_EMPTY ((idx_t_)-1) #define AST_SOA_BLKSZ (sizeof(ast_kind_t_) + sizeof(idx_t_) * 3) |