]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Remove that idiom, and use GMQCC_ARRAY_COUNT.
authorDale Weiler <killfieldengine@gmail.com>
Sat, 17 Aug 2013 23:39:06 +0000 (23:39 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 17 Aug 2013 23:39:06 +0000 (23:39 +0000)
exec.c
ftepp.c
lexer.c
lexer.h
main.c

diff --git a/exec.c b/exec.c
index 81c23610abb5d9f2729690cb2ed5c31b618b9ed8..1856248bcab4a88ed50725ea9df53b82766580d4 100644 (file)
--- 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 8edb644f8c44019eeee11f43ee8b6e2f20d39d07..e79dcd751c46db36506665524966b623f588b89b 100644 (file)
--- 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 541104127393fb9ba393f64f9f49edd62214d97d..feea8a2eb49cf5ce14873df7067d25cb4526e274 100644 (file)
--- 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 d0ca190d38915d7f41f42ca25bb6e9e6464d5ab3..2d67f3967e605ad9fd87dd5181919a03c07d5a72 100644 (file)
--- 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 48ff96e237c644b24f430cf5b3d9ee69f9de12e1..652ee616c9e3d0faa6e0d2877ab46cd268d81789 100644 (file)
--- 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) {