finished implementation of __func__ and _PRETTY_FUNC__
[cparser] / parser.c
index a92c7e7..beedd11 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -592,8 +592,11 @@ static declaration_t *stack_push(stack_entry_t **stack_ptr,
                        print_type_quoted(previous_declaration->type);
                        fputc('\n', stderr);
                } else {
-                       unsigned old_storage_class = previous_declaration->storage_class;
-                       unsigned new_storage_class = declaration->storage_class;
+                       unsigned  old_storage_class = previous_declaration->storage_class;
+                       unsigned  new_storage_class = declaration->storage_class;
+                       type_t   *type              = previous_declaration->type;
+                       type = skip_typeref(type);
+
                        if (current_function == NULL) {
                                if (old_storage_class != STORAGE_CLASS_STATIC &&
                                    new_storage_class == STORAGE_CLASS_STATIC) {
@@ -609,7 +612,7 @@ static declaration_t *stack_push(stack_entry_t **stack_ptr,
                                                if (new_storage_class == STORAGE_CLASS_NONE) {
                                                        previous_declaration->storage_class = STORAGE_CLASS_NONE;
                                                }
-                                       } else {
+                                       } else if(!is_type_function(type)) {
                                                parser_print_warning_prefix_pos(declaration->source_position);
                                                fprintf(stderr, "redundant declaration for '%s'\n",
                                                                                symbol->string);
@@ -2593,7 +2596,8 @@ static void parse_declaration(parsed_declaration_func finished_declaration)
 static void parse_kr_declaration_list(declaration_t *declaration)
 {
        type_t *type = skip_typeref(declaration->type);
-       assert(is_type_function(type));
+       if(!is_type_function(type))
+               return;
 
        if(!type->function.kr_style_parameters)
                return;
@@ -3193,7 +3197,7 @@ static expression_t *parse_function_keyword(void)
 
        expression->expression.type     = EXPR_FUNCTION;
        expression->expression.datatype = type_string;
-       expression->value               = "TODO: FUNCTION";
+       expression->value               = current_function->symbol->string;
 
        return (expression_t*) expression;
 }
@@ -3203,12 +3207,16 @@ static expression_t *parse_pretty_function_keyword(void)
        eat(T___PRETTY_FUNCTION__);
        /* TODO */
 
+       if (current_function == NULL) {
+               parse_error("'__PRETTY_FUNCTION__' used outside of a function");
+       }
+
        string_literal_expression_t *expression
                = allocate_ast_zero(sizeof(expression[0]));
 
        expression->expression.type     = EXPR_PRETTY_FUNCTION;
        expression->expression.datatype = type_string;
-       expression->value               = "TODO: PRETTY FUNCTION";
+       expression->value               = current_function->symbol->string;
 
        return (expression_t*) expression;
 }
@@ -4924,6 +4932,8 @@ static statement_t *parse_return(void)
 
        if(return_type == NULL)
                return (statement_t*) statement;
+       if(return_value != NULL && return_value->base.datatype == NULL)
+               return (statement_t*) statement;
 
        return_type = skip_typeref(return_type);