Skip to content

Commit 9259d27

Browse files
YuriUfimtsevmrbean-bremen
authored andcommitted
Add a token consistency check between enum and array
1 parent 6d90f6c commit 9259d27

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

generator/parser/tokens.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242

4343
#include <QtCore/qglobal.h>
44+
#include <iostream>
4445

4546
#include "tokens.h"
4647

@@ -152,7 +153,8 @@ static char const * const _S_token_names[] = {
152153
"xor",
153154
"xor_eq",
154155
"Q_ENUMS",
155-
"Q_ENUM"
156+
"Q_ENUM",
157+
"Q_INVOKABLE"
156158
};
157159

158160
static char _S_printable[][2] = {
@@ -254,6 +256,18 @@ static char _S_printable[][2] = {
254256
{ char(127), '\0' },
255257
};
256258

259+
int check_tokens_consistency()
260+
{
261+
if (sizeof(_S_token_names) / sizeof(_S_token_names[0]) != TOKEN_KIND_COUNT - Token_K_DCOP)
262+
{
263+
std::cerr << "** ERROR enum TOKEN_KIND and _S_token_names are not consistent" << std::endl;
264+
abort();
265+
}
266+
return 0;
267+
}
268+
269+
static int tokens_consistency = check_tokens_consistency();
270+
257271
char const *token_name(int token)
258272
{
259273
if (token == 0)
@@ -264,9 +278,9 @@ char const *token_name(int token)
264278
{
265279
return _S_printable[token - 32];
266280
}
267-
else if (token >= 1000)
281+
else if (token >= Token_K_DCOP)
268282
{
269-
return _S_token_names[token - 1000];
283+
return _S_token_names[token - Token_K_DCOP];
270284
}
271285

272286
Q_ASSERT(0);

0 commit comments

Comments
 (0)