From 9b8f937cbd26df1d47e5f5aa37b5c076eb51ecae Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 11 Jun 2024 21:24:50 +0200 Subject: Assert that we don’t have too many tokens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lexer.h | 5 +++++ src/parser.h | 5 +++++ 2 files changed, 10 insertions(+) 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 #include #include @@ -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 #include #include #include @@ -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) -- cgit v1.2.3