]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - parser.c
__builtin_debug_printtype directive... helped me down tracking a bug: parsing typedef...
[xonotic/gmqcc.git] / parser.c
index e8fddc91b5c21d64d2faf1649a200a54625a6567..fb4f8671f3534cbe658ba13e3bbc8e4e04cb96fc 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -600,6 +600,9 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
             vec_push(sy->out, syblock(ctx, blocks[0]));
             return true;
 
+        case opid2('+','P'):
+            out = exprs[0];
+            break;
         case opid2('-','P'):
             switch (exprs[0]->expression.vtype) {
                 case TYPE_FLOAT:
@@ -2159,7 +2162,7 @@ static bool parse_switch(parser_t *parser, ast_block *block, ast_expression **ou
             }
             if (!OPTS_FLAG(RELAXED_SWITCH)) {
                 opval = (ast_value*)swcase.value;
-                if (!ast_istype(swcase.value, ast_value) || !opval->constant) {
+                if (!ast_istype(swcase.value, ast_value)) { /* || !opval->constant) { */
                     parseerror(parser, "case on non-constant values need to be explicitly enabled via -frelaxed-switch");
                     ast_unref(operand);
                     return false;
@@ -2323,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);
@@ -3387,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 */