From 082a9724f12d2beda1002081b2ed16611e04e12f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Techet?= Date: Sun, 7 Aug 2016 00:49:51 +0200 Subject: [PATCH] Use ARRAY_SIZE() in parsers --- ctags/parsers/c.c | 14 +++++++------- ctags/parsers/perl.c | 2 +- ctags/parsers/php.c | 4 ++-- ctags/parsers/powershell.c | 4 +--- ctags/parsers/ruby.c | 2 +- ctags/parsers/verilog.c | 3 +-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ctags/parsers/c.c b/ctags/parsers/c.c index 696ba2147..056a25e20 100644 --- a/ctags/parsers/c.c +++ b/ctags/parsers/c.c @@ -668,7 +668,7 @@ static const char *accessString (const accessType laccess) static const char *const names [] = { "?", "private", "protected", "public", "default" }; - Assert (sizeof (names) / sizeof (names [0]) == ACCESS_COUNT); + Assert (ARRAY_SIZE (names) == ACCESS_COUNT); Assert ((int) laccess < ACCESS_COUNT); return names[(int) laccess]; } @@ -678,7 +678,7 @@ static const char *implementationString (const impType imp) static const char *const names [] = { "?", "abstract", "virtual", "pure virtual" }; - Assert (sizeof (names) / sizeof (names [0]) == IMP_COUNT); + Assert (ARRAY_SIZE (names) == IMP_COUNT); Assert ((int) imp < IMP_COUNT); return names [(int) imp]; } @@ -697,7 +697,7 @@ static const char *tokenString (const tokenType type) "none", "args", "}", "{", "comma", "double colon", "keyword", "name", "package", "paren-name", "semicolon", "specifier", "*", "[]" }; - Assert (sizeof (names) / sizeof (names [0]) == TOKEN_COUNT); + Assert (ARRAY_SIZE (names) == TOKEN_COUNT); Assert ((int) type < TOKEN_COUNT); return names [(int) type]; } @@ -707,7 +707,7 @@ static const char *scopeString (const tagScope scope) static const char *const names [] = { "global", "static", "extern", "friend", "typedef" }; - Assert (sizeof (names) / sizeof (names [0]) == SCOPE_COUNT); + Assert (ARRAY_SIZE (names) == SCOPE_COUNT); Assert ((int) scope < SCOPE_COUNT); return names [(int) scope]; } @@ -719,14 +719,14 @@ static const char *declString (const declType declaration) "function template", "ignore", "interface", "module", "namespace", "no mangle", "package", "struct", "union", }; - Assert (sizeof (names) / sizeof (names [0]) == DECL_COUNT); + Assert (ARRAY_SIZE (names) == DECL_COUNT); Assert ((int) declaration < DECL_COUNT); return names [(int) declaration]; } static const char *keywordString (const keywordId keyword) { - const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]); + const size_t count = ARRAY_SIZE (KeywordTable); const char *name = "none"; size_t i; for (i = 0 ; i < count ; ++i) @@ -3172,7 +3172,7 @@ static boolean findCTags (const unsigned int passCount) static void buildKeywordHash (const langType language, unsigned int idx) { - const size_t count = sizeof (KeywordTable) / sizeof (KeywordTable [0]); + const size_t count = ARRAY_SIZE (KeywordTable); size_t i; for (i = 0 ; i < count ; ++i) { diff --git a/ctags/parsers/perl.c b/ctags/parsers/perl.c index 36b9aa90e..eaefcb0b4 100644 --- a/ctags/parsers/perl.c +++ b/ctags/parsers/perl.c @@ -71,7 +71,7 @@ static boolean isPodWord (const char *word) "head1", "head2", "head3", "head4", "over", "item", "back", "pod", "begin", "end", "for" }; - const size_t count = sizeof (pods) / sizeof (pods [0]); + const size_t count = ARRAY_SIZE (pods); const char *white = strpbrk (word, " \t"); const size_t len = (white!=NULL) ? (size_t)(white-word) : strlen (word); char *const id = (char*) eMalloc (len + 1); diff --git a/ctags/parsers/php.c b/ctags/parsers/php.c index 0394ffea4..5383b254d 100644 --- a/ctags/parsers/php.c +++ b/ctags/parsers/php.c @@ -449,7 +449,7 @@ static void printToken (const tokenInfo *const token) case TOKEN_KEYWORD: { - size_t n = sizeof PhpKeywordTable / sizeof PhpKeywordTable[0]; + size_t n = ARRAY_SIZE (PhpKeywordTable); size_t i; fprintf (stderr, "\tkeyword:\t"); @@ -548,7 +548,7 @@ static void parseHeredoc (vString *const string) quote = c; c = getcFromInputFile (); } - for (len = 0; len < (sizeof delimiter / sizeof delimiter[0]) - 1; len++) + for (len = 0; len < ARRAY_SIZE (delimiter) - 1; len++) { if (! isIdentChar (c)) break; diff --git a/ctags/parsers/powershell.c b/ctags/parsers/powershell.c index 7297d8180..ec0170a66 100644 --- a/ctags/parsers/powershell.c +++ b/ctags/parsers/powershell.c @@ -26,8 +26,6 @@ #define SCOPE_SEPARATOR "::" -#define ARRAY_LENGTH(array) (sizeof array / sizeof array[0]) - #define ACCESS_UNDEFINED NULL static const char *const accessTypes[] = { ACCESS_UNDEFINED, @@ -85,7 +83,7 @@ static const char *findValidAccessType (const char *const access) unsigned int i; if (access == ACCESS_UNDEFINED) return ACCESS_UNDEFINED; /* early out to save the for-loop if possible */ - for (i = 0; i < ARRAY_LENGTH(accessTypes); i++) + for (i = 0; i < ARRAY_SIZE(accessTypes); i++) { if (accessTypes[i] == ACCESS_UNDEFINED) continue; diff --git a/ctags/parsers/ruby.c b/ctags/parsers/ruby.c index f516a1402..7acabb82c 100644 --- a/ctags/parsers/ruby.c +++ b/ctags/parsers/ruby.c @@ -216,7 +216,7 @@ static void emitRubyTag (vString* name, rubyKind kind) initTagEntry (&tag, unqualified_name, &(RubyKinds [kind])); if (vStringLength (scope) > 0) { Assert (0 <= parent_kind && - (size_t) parent_kind < (sizeof RubyKinds / sizeof RubyKinds[0])); + (size_t) parent_kind < (ARRAY_SIZE (RubyKinds))); tag.extensionFields.scopeKind = &(RubyKinds [parent_kind]); tag.extensionFields.scopeName = vStringValue (scope); diff --git a/ctags/parsers/verilog.c b/ctags/parsers/verilog.c index e7f3ba339..46cb10756 100644 --- a/ctags/parsers/verilog.c +++ b/ctags/parsers/verilog.c @@ -102,8 +102,7 @@ static keywordTable VerilogKeywordTable [] = { static void initialize (const langType language) { size_t i; - const size_t count = - sizeof (VerilogKeywordTable) / sizeof (VerilogKeywordTable [0]); + const size_t count = ARRAY_SIZE (VerilogKeywordTable); Lang_verilog = language; for (i = 0 ; i < count ; ++i) { -- 2.11.4.GIT