related fix about unspecified parameters -> () on function defintion means no parameters
authorMatthias Braun <matze@braunis.de>
Thu, 29 Nov 2007 21:35:03 +0000 (21:35 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 29 Nov 2007 21:35:03 +0000 (21:35 +0000)
[r18572]

Makefile
parser.c
parsetest/cp_error001.c
parsetest/shouldfail/cp_error002.c [new file with mode: 0644]

index e078b3a..c84ffbc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 GOAL = cparser
 
-FIRM_HOME = $(HOME)/jambuild/
+FIRM_HOME = $(HOME)/projects/firm
 FIRM_BUILD = $(FIRM_HOME)/build/i686-pc-linux-gnu/debug/
 FIRM_CFLAGS = -I$(FIRM_HOME)/libfirm/include -I$(FIRM_HOME)/obstack -I$(FIRM_HOME)/libcore -I$(FIRM_HOME)/libcore/libcore -I$(FIRM_HOME)
 FIRM_LIBS = -L$(FIRM_BUILD) -lfirm -llpp -lcore -lm -lz -ldl
index 9b52ea7..fcc30ea 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2624,46 +2624,26 @@ static void parse_external_declaration(void)
        /* must be a function definition */
        parse_kr_declaration_list(ndeclaration);
 
-       declaration_t *declaration = record_declaration(ndeclaration);
-       if(ndeclaration != declaration) {
-               memcpy(&declaration->context, &ndeclaration->context,
-                               sizeof(declaration->context));
-       }
-
-       /* push function parameters and switch context */
-       int         top          = environment_top();
-       context_t  *last_context = context;
-       set_context(&declaration->context);
-
-       declaration_t *parameter = declaration->context.declarations;
-       for( ; parameter != NULL; parameter = parameter->next) {
-               environment_push(parameter);
-       }
-
-       type_t *orig_type;
-       type_t *type;
-
        if(token.type != '{') {
                parse_error_expected("while parsing function definition", '{', 0);
                eat_statement();
-               goto end_of_parse_external_declaration;
+               return;
        }
 
-       orig_type = declaration->type;
+       type_t *orig_type = ndeclaration->type;
        if(orig_type == NULL) {
                eat_block();
-               goto end_of_parse_external_declaration;
+               return;
        }
 
-       type = skip_typeref(orig_type);
-
+       type_t *type = skip_typeref(orig_type);
        if(type->type != TYPE_FUNCTION) {
                parser_print_error_prefix();
                fprintf(stderr, "declarator '");
-               print_type_ext(orig_type, declaration->symbol, NULL);
+               print_type_ext(orig_type, ndeclaration->symbol, NULL);
                fprintf(stderr, "' has a body but is not a function type.\n");
                eat_block();
-               goto end_of_parse_external_declaration;
+               return;
        }
 
        /* ยง 6.7.5.3 (14) a function definition with () means no
@@ -2676,17 +2656,32 @@ static void parse_external_declaration(void)
                if(type != duplicate) {
                        obstack_free(type_obst, duplicate);
                }
-               declaration->type = type;
+               ndeclaration->type = type;
+       }
+
+       declaration_t *declaration = record_declaration(ndeclaration);
+       if(ndeclaration != declaration) {
+               memcpy(&declaration->context, &ndeclaration->context,
+                               sizeof(declaration->context));
+       }
+       type = skip_typeref(declaration->type);
+
+       /* push function parameters and switch context */
+       int         top          = environment_top();
+       context_t  *last_context = context;
+       set_context(&declaration->context);
+
+       declaration_t *parameter = declaration->context.declarations;
+       for( ; parameter != NULL; parameter = parameter->next) {
+               environment_push(parameter);
        }
 
        if(declaration->init.statement != NULL) {
                parser_error_multiple_definition(declaration, token.source_position);
                eat_block();
                goto end_of_parse_external_declaration;
-       }
-
-       /* parse function body */
-       {
+       } else {
+               /* parse function body */
                int            label_stack_top      = label_top();
                declaration_t *old_current_function = current_function;
                current_function                    = declaration;
index 6973841..06c54fe 100644 (file)
@@ -1,5 +1,7 @@
 void bi_windup(void);
 
+void bi_windup();
+
 void bi_windup() {
 }
 
diff --git a/parsetest/shouldfail/cp_error002.c b/parsetest/shouldfail/cp_error002.c
new file mode 100644 (file)
index 0000000..afcc79e
--- /dev/null
@@ -0,0 +1,11 @@
+void bi_windup(int k);
+
+void bi_windup();
+
+void bi_windup() {
+}
+
+int main(void)
+{
+       return 0;
+}