tests for __func__ and friends
[cparser] / parser.c
index 95810ad..32a2a9d 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -297,6 +297,8 @@ static size_t get_expression_struct_size(expression_kind_t kind)
                [EXPR_CLASSIFY_TYPE]           = sizeof(classify_type_expression_t),
                [EXPR_FUNCTION]                = sizeof(string_literal_expression_t),
                [EXPR_PRETTY_FUNCTION]         = sizeof(string_literal_expression_t),
+               [EXPR_FUNCSIG]                 = sizeof(string_literal_expression_t),
+               [EXPR_FUNCDNAME]               = sizeof(string_literal_expression_t),
                [EXPR_BUILTIN_SYMBOL]          = sizeof(builtin_symbol_expression_t),
                [EXPR_BUILTIN_CONSTANT_P]      = sizeof(builtin_constant_expression_t),
                [EXPR_BUILTIN_PREFETCH]        = sizeof(builtin_prefetch_expression_t),
@@ -951,7 +953,9 @@ static void parse_gnu_attribute(void)
        while(true) {
                if(token.type != T_IDENTIFIER)
                        break;
-               symbol_t *symbol = token.v.symbol;
+               symbol_t *sym = token.v.symbol;
+               if(sym == sym_deprecated) {
+               }
                next_token();
                if(token.type == '(')
                        eat_until_matching_token('(');
@@ -1225,7 +1229,7 @@ static __attribute__((unused)) void debug_print_type_path(
                        }
                        fprintf(stderr, ".%s", entry->v.compound_entry->symbol->string);
                } else if(is_type_array(type)) {
-                       fprintf(stderr, "[%u]", entry->v.index);
+                       fprintf(stderr, "[%zd]", entry->v.index);
                } else {
                        fprintf(stderr, "-INVALID-");
                }
@@ -4456,7 +4460,6 @@ static expression_t *parse_function_keyword(void)
 static expression_t *parse_pretty_function_keyword(void)
 {
        eat(T___PRETTY_FUNCTION__);
-       /* TODO */
 
        if (current_function == NULL) {
                errorf(HERE, "'__PRETTY_FUNCTION__' used outside of a function");
@@ -4468,6 +4471,34 @@ static expression_t *parse_pretty_function_keyword(void)
        return expression;
 }
 
+static expression_t *parse_funcsig_keyword(void)
+{
+       next_token();
+
+       if (current_function == NULL) {
+               errorf(HERE, "'__FUNCSIG__' used outside of a function");
+       }
+
+       expression_t *expression = allocate_expression_zero(EXPR_FUNCSIG);
+       expression->base.type    = type_char_ptr;
+
+       return expression;
+}
+
+static expression_t *parse_funcdname_keyword(void)
+{
+       next_token();
+
+       if (current_function == NULL) {
+               errorf(HERE, "'__FUNCDNAME__' used outside of a function");
+       }
+
+       expression_t *expression = allocate_expression_zero(EXPR_FUNCDNAME);
+       expression->base.type    = type_char_ptr;
+
+       return expression;
+}
+
 static designator_t *parse_designator(void)
 {
        designator_t *result    = allocate_ast_zero(sizeof(result[0]));
@@ -4799,6 +4830,8 @@ static expression_t *parse_primary_expression(void)
                case T___FUNCTION__:
                case T___func__:                 return parse_function_keyword();
                case T___PRETTY_FUNCTION__:      return parse_pretty_function_keyword();
+               case T___FUNCSIG__:              return parse_funcsig_keyword();
+               case T___FUNCDNAME__:            return parse_funcdname_keyword();
                case T___builtin_offsetof:       return parse_offsetof();
                case T___builtin_va_start:       return parse_va_start();
                case T___builtin_va_arg:         return parse_va_arg();
@@ -5793,6 +5826,8 @@ static bool expression_has_effect(const expression_t *const expr)
 
                case EXPR_FUNCTION:                  return false;
                case EXPR_PRETTY_FUNCTION:           return false;
+               case EXPR_FUNCSIG:                   return false;
+               case EXPR_FUNCDNAME:                 return false;
                case EXPR_BUILTIN_SYMBOL:            break; /* handled in EXPR_CALL */
                case EXPR_BUILTIN_CONSTANT_P:        return false;
                case EXPR_BUILTIN_PREFETCH:          return true;