From 2a7933973507dfe5d4625ca9ec7eff2aea91cf26 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Sat, 17 Aug 2013 23:39:06 +0000 Subject: [PATCH] Remove that idiom, and use GMQCC_ARRAY_COUNT. --- exec.c | 3 +-- ftepp.c | 16 ++++++++-------- lexer.c | 8 ++------ lexer.h | 5 ----- main.c | 14 +++++++------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/exec.c b/exec.c index 81c2361..1856248 100644 --- a/exec.c +++ b/exec.c @@ -834,7 +834,6 @@ static prog_builtin_t qc_builtins[] = { &qc_sqrt, /* 13 */ &qc_floor /* 14 */ }; -static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]); static const char *arg0 = NULL; @@ -1080,7 +1079,7 @@ int main(int argc, char **argv) { } prog->builtins = qc_builtins; - prog->builtins_count = qc_builtins_count; + prog->builtins_count = GMQCC_ARRAY_COUNT(qc_builtins); if (opts_info) { printf("Program's system-checksum = 0x%04x\n", (unsigned int)prog->crc16); diff --git a/ftepp.c b/ftepp.c index 8edb644..e79dcd7 100644 --- a/ftepp.c +++ b/ftepp.c @@ -227,24 +227,24 @@ static const ftepp_predef_t ftepp_predefs[] = { { "__TIME_STAMP__", &ftepp_predef_timestamp } }; -static GMQCC_INLINE int ftepp_predef_index(const char *name) { +static GMQCC_INLINE size_t ftepp_predef_index(const char *name) { /* no hashtable here, we simply check for one to exist the naive way */ - int i; - for(i = 0; i < (int)(sizeof(ftepp_predefs)/sizeof(*ftepp_predefs)); i++) - if (!strcmp(ftepp_predefs[i].name, name)) + size_t i; + for(i = 1; i < GMQCC_ARRAY_COUNT(ftepp_predefs) + 1; i++) + if (!strcmp(ftepp_predefs[i-1].name, name)) return i; - return -1; + return 0; } bool ftepp_predef_exists(const char *name); bool ftepp_predef_exists(const char *name) { - return ftepp_predef_index(name) != -1; + return ftepp_predef_index(name) != 0; } /* singleton because we're allowed */ static GMQCC_INLINE char *(*ftepp_predef(const char *name))(lex_file *context) { - int i = ftepp_predef_index(name); - return (i != -1) ? ftepp_predefs[i].func : NULL; + size_t i = ftepp_predef_index(name); + return (i != 0) ? ftepp_predefs[i-1].func : NULL; } #define ftepp_tokval(f) ((f)->lex->tok.value) diff --git a/lexer.c b/lexer.c index 5411041..feea8a2 100644 --- a/lexer.c +++ b/lexer.c @@ -37,8 +37,6 @@ static const char *keywords_qc[] = { "return", "const" }; -static size_t num_keywords_qc = sizeof(keywords_qc) / sizeof(keywords_qc[0]); - /* For fte/gmgqcc */ static const char *keywords_fg[] = { "switch", "case", "default", @@ -49,12 +47,10 @@ static const char *keywords_fg[] = { "__builtin_debug_printtype" }; -static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]); /* * Lexer code */ - static char* *lex_filenames; static void lexerror(lex_file *lex, const char *fmt, ...) @@ -1416,12 +1412,12 @@ int lex_do(lex_file *lex) lex->tok.constval.t = TYPE_VECTOR; } else { size_t kw; - for (kw = 0; kw < num_keywords_qc; ++kw) { + for (kw = 0; kw < GMQCC_ARRAY_COUNT(keywords_qc); ++kw) { if (!strcmp(v, keywords_qc[kw])) return (lex->tok.ttype = TOKEN_KEYWORD); } if (OPTS_OPTION_U32(OPTION_STANDARD) != COMPILER_QCC) { - for (kw = 0; kw < num_keywords_fg; ++kw) { + for (kw = 0; kw < GMQCC_ARRAY_COUNT(keywords_fg); ++kw) { if (!strcmp(v, keywords_fg[kw])) return (lex->tok.ttype = TOKEN_KEYWORD); } diff --git a/lexer.h b/lexer.h index d0ca190..2d67f39 100644 --- a/lexer.h +++ b/lexer.h @@ -241,7 +241,6 @@ static const oper_info c_operators[] = { { ",", 2, opid1(','), ASSOC_LEFT, 0, 0, false} }; -static const size_t c_operator_count = (sizeof(c_operators) / sizeof(c_operators[0])); static const oper_info fte_operators[] = { { "(", 0, opid1('('), ASSOC_LEFT, 99, OP_PREFIX, false}, /* paren expression - non function call */ @@ -295,7 +294,6 @@ static const oper_info fte_operators[] = { { ",", 2, opid1(','), ASSOC_LEFT, 2, 0, false}, { ":", 0, opid2(':','?'), ASSOC_RIGHT, 1, 0, false} }; -static const size_t fte_operator_count = (sizeof(fte_operators) / sizeof(fte_operators[0])); static const oper_info qcc_operators[] = { { "(", 0, opid1('('), ASSOC_LEFT, 99, OP_PREFIX, false}, /* paren expression - non function call */ @@ -337,10 +335,7 @@ static const oper_info qcc_operators[] = { { ",", 2, opid1(','), ASSOC_LEFT, 2, 0, false}, }; -static const size_t qcc_operator_count = (sizeof(qcc_operators) / sizeof(qcc_operators[0])); - extern const oper_info *operators; extern size_t operator_count; -/*void lexerror(lex_file*, const char *fmt, ...);*/ #endif diff --git a/main.c b/main.c index 48ff96e..652ee61 100644 --- a/main.c +++ b/main.c @@ -355,7 +355,7 @@ static bool options_parse(int argc, char **argv) { else if (!strcmp(argv[0]+2, "NO_ERROR") || !strcmp(argv[0]+2, "NO_ERROR_ALL")) { - for (itr = 0; itr < sizeof(opts.werror)/sizeof(opts.werror[0]); ++itr) + for (itr = 0; itr < GMQCC_ARRAY_COUNT(opts.werror); ++itr) opts.werror[itr] = 0; break; } @@ -363,19 +363,19 @@ static bool options_parse(int argc, char **argv) { !strcmp(argv[0]+2, "ERROR_ALL")) { opts_backup_non_Werror_all(); - for (itr = 0; itr < sizeof(opts.werror)/sizeof(opts.werror[0]); ++itr) + for (itr = 0; itr < GMQCC_ARRAY_COUNT(opts.werror); ++itr) opts.werror[itr] = 0xFFFFFFFFL; opts_restore_non_Werror_all(); break; } else if (!strcmp(argv[0]+2, "NONE")) { - for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr) + for (itr = 0; itr < GMQCC_ARRAY_COUNT(opts.warn); ++itr) opts.warn[itr] = 0; break; } else if (!strcmp(argv[0]+2, "ALL")) { opts_backup_non_Wall(); - for (itr = 0; itr < sizeof(opts.warn)/sizeof(opts.warn[0]); ++itr) + for (itr = 0; itr < GMQCC_ARRAY_COUNT(opts.warn); ++itr) opts.warn[itr] = 0xFFFFFFFFL; opts_restore_non_Wall(); break; @@ -576,13 +576,13 @@ int main(int argc, char **argv) { /* the standard decides which set of operators to use */ if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_GMQCC) { operators = c_operators; - operator_count = c_operator_count; + operator_count = GMQCC_ARRAY_COUNT(c_operators); } else if (OPTS_OPTION_U32(OPTION_STANDARD) == COMPILER_FTEQCC) { operators = fte_operators; - operator_count = fte_operator_count; + operator_count = GMQCC_ARRAY_COUNT(fte_operators); } else { operators = qcc_operators; - operator_count = qcc_operator_count; + operator_count = GMQCC_ARRAY_COUNT(qcc_operators); } if (operators == fte_operators) { -- 2.39.2