From: Wolfgang (Blub) Bumiller Date: Sun, 25 Nov 2012 21:57:11 +0000 (+0100) Subject: __builtin_debug_printtype directive... helped me down tracking a bug: parsing typedef... X-Git-Tag: 0.1.9~220 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2f5a26a4de1b8fdb8876f5b1efc34ec52127cdec;p=xonotic%2Fgmqcc.git __builtin_debug_printtype directive... helped me down tracking a bug: parsing typedeffed types in parameter lists properly now --- diff --git a/lexer.c b/lexer.c index 6fbe41d..662e7e7 100644 --- a/lexer.c +++ b/lexer.c @@ -48,7 +48,9 @@ static const char *keywords_fg[] = { "struct", "union", "break", "continue", "typedef", - "goto" + "goto", + + "__builtin_debug_printtype" }; static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]); diff --git a/parser.c b/parser.c index 753f184..fb4f867 100644 --- a/parser.c +++ b/parser.c @@ -2326,6 +2326,39 @@ ident_var: *out = NULL; return true; } + else if (!strcmp(parser_tokval(parser), "__builtin_debug_printtype")) + { + char ty[1024]; + ast_value *tdef; + + if (!parser_next(parser)) { + parseerror(parser, "parse error after __builtin_debug_printtype"); + return false; + } + + if (parser->tok == TOKEN_IDENT && (tdef = parser_find_typedef(parser, parser_tokval(parser), 0))) + { + ast_type_to_string((ast_expression*)tdef, ty, sizeof(ty)); + con_out("__builtin_debug_printtype: `%s`=`%s`\n", tdef->name, ty); + if (!parser_next(parser)) { + parseerror(parser, "parse error after __builtin_debug_printtype typename argument"); + return false; + } + } + else + { + if (!parse_statement(parser, block, out, allow_cases)) + return false; + if (!*out) + con_out("__builtin_debug_printtype: got no output node\n"); + else + { + ast_type_to_string(*out, ty, sizeof(ty)); + con_out("__builtin_debug_printtype: `%s`\n", ty); + } + } + return true; + } else if (!strcmp(parser_tokval(parser), "return")) { return parse_return(parser, block, out); @@ -3390,13 +3423,12 @@ static ast_value *parse_typename(parser_t *parser, ast_value **storebase, ast_va return NULL; } } - - if (parser->tok == TOKEN_IDENT) - cached_typedef = parser_find_typedef(parser, parser_tokval(parser), 0); - if (!cached_typedef && parser->tok != TOKEN_TYPENAME) { - parseerror(parser, "expected typename"); - return NULL; - } + } + if (parser->tok == TOKEN_IDENT) + cached_typedef = parser_find_typedef(parser, parser_tokval(parser), 0); + if (!cached_typedef && parser->tok != TOKEN_TYPENAME) { + parseerror(parser, "expected typename"); + return NULL; } /* generate the basic type value */