Use ARRAY_SIZE() in parsers

This commit is contained in:
Jiří Techet 2016-08-07 00:49:51 +02:00
parent 9745d470c6
commit 082a9724f1
6 changed files with 13 additions and 16 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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)
{