From 2bf46034b225252d462431b066e33505e61b5410 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Mon, 21 Sep 2015 15:26:41 +0100 Subject: [PATCH] eolian: split tokens/keywords for cleaner indexing --- src/lib/eolian/eo_lexer.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/eolian/eo_lexer.c b/src/lib/eolian/eo_lexer.c index 8b0d79c..456f0b1 100644 --- a/src/lib/eolian/eo_lexer.c +++ b/src/lib/eolian/eo_lexer.c @@ -49,12 +49,11 @@ next_char(Eo_Lexer *ls) static const char * const tokens[] = { "==", "!=", ">=", "<=", "&&", "||", "<<", ">>", - - "", "", "", "", "", - - KEYWORDS + "", "", "", "", "" }; +static const char * const keywords[] = { KEYWORDS }; + static const char * const ctypes[] = { "signed char", "unsigned char", "char", "short", "unsigned short", "int", @@ -112,13 +111,11 @@ throw(Eo_Lexer *ls, const char *fmt, ...) static void init_hash(void) { - unsigned int i, u; + unsigned int i; if (keyword_map) return; keyword_map = eina_hash_string_superfast_new(NULL); - for (i = u = 13; i < (sizeof(tokens) / sizeof(const char*)); ++i) - { - eina_hash_add(keyword_map, tokens[i], (void*)(size_t)(i - u + 1)); - } + for (i = 0; i < (sizeof(keywords) / sizeof(keywords[0])); ++i) + eina_hash_add(keyword_map, keywords[i], (void *)(size_t)(i + 1)); } static void @@ -1086,7 +1083,12 @@ eo_lexer_token_to_str(int token, char *buf) } else { - const char *v = tokens[token - START_CUSTOM]; + const char *v; + size_t idx = token - START_CUSTOM; + if (idx >= sizeof(tokens)) + v = keywords[idx - sizeof(tokens)]; + else + v = tokens[idx]; memcpy(buf, v, strlen(v) + 1); } } @@ -1094,7 +1096,7 @@ eo_lexer_token_to_str(int token, char *buf) const char * eo_lexer_keyword_str_get(int kw) { - return tokens[kw + 12]; + return keywords[kw - 1]; } Eina_Bool -- 2.7.4