Skip to content

Commit

Permalink
Add a token consistency check between enum and array
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriUfimtsev authored and mrbean-bremen committed Nov 9, 2023
1 parent 6d90f6c commit 9259d27
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions generator/parser/tokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@


#include <QtCore/qglobal.h>
#include <iostream>

#include "tokens.h"

Expand Down Expand Up @@ -152,7 +153,8 @@ static char const * const _S_token_names[] = {
"xor",
"xor_eq",
"Q_ENUMS",
"Q_ENUM"
"Q_ENUM",
"Q_INVOKABLE"
};

static char _S_printable[][2] = {
Expand Down Expand Up @@ -254,6 +256,18 @@ static char _S_printable[][2] = {
{ char(127), '\0' },
};

int check_tokens_consistency()
{
if (sizeof(_S_token_names) / sizeof(_S_token_names[0]) != TOKEN_KIND_COUNT - Token_K_DCOP)
{
std::cerr << "** ERROR enum TOKEN_KIND and _S_token_names are not consistent" << std::endl;
abort();
}
return 0;
}

static int tokens_consistency = check_tokens_consistency();

char const *token_name(int token)
{
if (token == 0)
Expand All @@ -264,9 +278,9 @@ char const *token_name(int token)
{
return _S_printable[token - 32];
}
else if (token >= 1000)
else if (token >= Token_K_DCOP)
{
return _S_token_names[token - 1000];
return _S_token_names[token - Token_K_DCOP];
}

Q_ASSERT(0);
Expand Down

0 comments on commit 9259d27

Please sign in to comment.