diff options
-rw-r--r-- | src/parse.c | 66 | ||||
-rw-r--r-- | src/parse.h | 50 |
2 files changed, 74 insertions, 42 deletions
diff --git a/src/parse.c b/src/parse.c index 16f6355..2b298d0 100644 --- a/src/parse.c +++ b/src/parse.c @@ -60,48 +60,41 @@ static enum parse_type_e sub_parse_type(void) ERR_AT(l, c, "invalid type `%s`", t.val); } - if (!strcmp(t.val, "bool") || !strcmp(t.val, "boolean")) + if (!strcmp(t.val, "bool")) return type; if (!strcmp(t.val, "string")) return type + PARSE_TYPE_STRING; - if (!strcmp(t.val, "char")) { - t = tok_get(); - - ERR_END(t); + if (!strcmp(t.val, "id")) + return type + PARSE_TYPE_ID; - if (t.type != TOK_ASTERISK) { - if (type >= PARSE_TYPE_HASH_BOOL) - ERR_AT(l, c, "invalid type `hash char %s`", t.val); - else if (type >= PARSE_TYPE_ARRAY_BOOL) - ERR_AT(l, c, "invalid type `array char %s`", t.val); - else - ERR_AT(l, c, "invalid type `char %s`", t.val); - } + if (!strcmp(t.val, "int")) + return type + PARSE_TYPE_INT; - return type + PARSE_TYPE_STRING; - } + if (!strcmp(t.val, "intl")) + return type + PARSE_TYPE_INTL; - if (!strcmp(t.val, "int") || !strcmp(t.val, "integer")) - return type + PARSE_TYPE_INT; + if (!strcmp(t.val, "intll")) + return type + PARSE_TYPE_INTLL; if (!strcmp(t.val, "uint")) return type + PARSE_TYPE_UINT; - if (!strcmp(t.val, "unsigned")) { - l = t.line; - c = t.col; - t = tok_get(); + if (!strcmp(t.val, "uintl")) + return type + PARSE_TYPE_UINTL; - if (t.type != TOK_ID - || (strcmp(t.val, "int") && strcmp(t.val, "integer")) - ) { - tok_unget(t); - } + if (!strcmp(t.val, "uintll")) + return type + PARSE_TYPE_UINTLL; - return type + PARSE_TYPE_UINT; - } + if (!strcmp(t.val, "float")) + return type + PARSE_TYPE_FLOAT; + + if (!strcmp(t.val, "double")) + return type + PARSE_TYPE_DOUBLE; + + if (!strcmp(t.val, "doublel")) + return type + PARSE_TYPE_DOUBLEL; tok_unget(t); @@ -128,6 +121,21 @@ static void sub_parse_deftype(size_t line, size_t col, bool is_union) t.val, (dt.is_union ? "union" : "struct")); } + if ( + !strcmp(t.val, "hash") || !strcmp(t.val, "array") || + !strcmp(t.val, "bool") || + !strcmp(t.val, "string") || !strcmp(t.val, "id") || + !strcmp(t.val, "int") || !strcmp(t.val, "intl") || + !strcmp(t.val, "intll") || + !strcmp(t.val, "uint") || !strcmp(t.val, "uintl") || + !strcmp(t.val, "uintll") || + !strcmp(t.val, "float") || !strcmp(t.val, "double") || + !strcmp(t.val, "doublell") + ) { + ERR_AT(dt.line, dt.col, + "defined type conflicts with builtin type `%s`", t.val); + } + HASH_FIND_STR(r.deftypes, t.val, dtp); if (dtp != NULL) { ERR_AT(dt.line, dt.col, @@ -358,7 +366,7 @@ struct parse_result_s parse(FILE *f, const char *fname) struct parse_deftype_s *d; r.hkey_size = 16; - strcpy(r.hkey_name, "id"); + strcpy(r.hkey_name, "key"); r.hkey_name_seen = false; r.hkey_size_seen = false; r.fun_suf_seen = false; diff --git a/src/parse.h b/src/parse.h index 1bc6710..09eed9f 100644 --- a/src/parse.h +++ b/src/parse.h @@ -12,21 +12,45 @@ enum parse_type_e { PARSE_TYPE_BOOL = 0, PARSE_TYPE_STRING = 1, - PARSE_TYPE_INT = 2, - PARSE_TYPE_UINT = 3, - PARSE_TYPE_DEFTYPE = 4, + PARSE_TYPE_ID = 2, + PARSE_TYPE_INT = 3, + PARSE_TYPE_INTL = 4, + PARSE_TYPE_INTLL = 5, + PARSE_TYPE_UINT = 6, + PARSE_TYPE_UINTL = 7, + PARSE_TYPE_UINTLL = 8, + PARSE_TYPE_FLOAT = 9, + PARSE_TYPE_DOUBLE = 10, + PARSE_TYPE_DOUBLEL = 11, + PARSE_TYPE_DEFTYPE = 12, - PARSE_TYPE_ARRAY_BOOL = 5, - PARSE_TYPE_ARRAY_STRING = 6, - PARSE_TYPE_ARRAY_INT = 7, - PARSE_TYPE_ARRAY_UINT = 8, - PARSE_TYPE_ARRAY_DEFTYPE = 9, + PARSE_TYPE_ARRAY_BOOL = 13, + PARSE_TYPE_ARRAY_STRING = 14, + PARSE_TYPE_ARRAY_ID = 15, + PARSE_TYPE_ARRAY_INT = 16, + PARSE_TYPE_ARRAY_INTL = 17, + PARSE_TYPE_ARRAY_INTLL = 18, + PARSE_TYPE_ARRAY_UINT = 19, + PARSE_TYPE_ARRAY_UINTL = 20, + PARSE_TYPE_ARRAY_UINTLL = 21, + PARSE_TYPE_ARRAY_FLOAT = 22, + PARSE_TYPE_ARRAY_DOUBLE = 23, + PARSE_TYPE_ARRAY_DOUBLEL = 24, + PARSE_TYPE_ARRAY_DEFTYPE = 25, - PARSE_TYPE_HASH_BOOL = 10, - PARSE_TYPE_HASH_STRING = 11, - PARSE_TYPE_HASH_INT = 12, - PARSE_TYPE_HASH_UINT = 13, - PARSE_TYPE_HASH_DEFTYPE = 14, + PARSE_TYPE_HASH_BOOL = 26, + PARSE_TYPE_HASH_STRING = 27, + PARSE_TYPE_HASH_ID = 28, + PARSE_TYPE_HASH_INT = 29, + PARSE_TYPE_HASH_INTL = 30, + PARSE_TYPE_HASH_INTLL = 31, + PARSE_TYPE_HASH_UINT = 32, + PARSE_TYPE_HASH_UINTL = 33, + PARSE_TYPE_HASH_UINTLL = 34, + PARSE_TYPE_HASH_FLOAT = 35, + PARSE_TYPE_HASH_DOUBLE = 36, + PARSE_TYPE_HASH_DOUBLEL = 37, + PARSE_TYPE_HASH_DEFTYPE = 38, }; struct parse_deftype_s { |