+ /* parse declaration list */
+ while(is_declaration_specifier(&token, false)) {
+ parse_declaration(finished_kr_declaration);
+ }
+
+ /* pop function parameters */
+ assert(context == &declaration->context);
+ set_context(last_context);
+ environment_pop_to(top);
+
+ /* update function type */
+ type_t *new_type = duplicate_type(type);
+ new_type->function.kr_style_parameters = false;
+
+ function_parameter_t *parameters = NULL;
+ function_parameter_t *last_parameter = NULL;
+
+ declaration_t *parameter_declaration = declaration->context.declarations;
+ for( ; parameter_declaration != NULL;
+ parameter_declaration = parameter_declaration->next) {
+ type_t *parameter_type = parameter_declaration->type;
+ if(parameter_type == NULL) {
+ if (strict_mode) {
+ errorf(HERE, "no type specified for function parameter '%Y'",
+ parameter_declaration->symbol);
+ } else {
+ warningf(HERE, "no type specified for function parameter '%Y', using int",
+ parameter_declaration->symbol);
+ parameter_type = type_int;
+ parameter_declaration->type = parameter_type;
+ }
+ }
+
+ semantic_parameter(parameter_declaration);
+ parameter_type = parameter_declaration->type;
+
+ function_parameter_t *function_parameter
+ = obstack_alloc(type_obst, sizeof(function_parameter[0]));
+ memset(function_parameter, 0, sizeof(function_parameter[0]));
+
+ function_parameter->type = parameter_type;
+ if(last_parameter != NULL) {
+ last_parameter->next = function_parameter;
+ } else {
+ parameters = function_parameter;
+ }
+ last_parameter = function_parameter;
+ }
+ new_type->function.parameters = parameters;
+
+ type = typehash_insert(new_type);
+ if(type != new_type) {
+ obstack_free(type_obst, new_type);
+ }
+
+ declaration->type = type;
+}
+
+/**
+ * Check if all labels are defined in the current function.
+ */
+static void check_for_missing_labels(void)
+{
+ bool first_err = true;
+ for (const goto_statement_t *goto_statement = goto_first;
+ goto_statement != NULL;
+ goto_statement = goto_statement->next) {
+ const declaration_t *label = goto_statement->label;
+
+ if (label->source_position.input_name == NULL) {
+ if (first_err) {
+ first_err = false;
+ diagnosticf("%s: In function '%Y':\n",
+ current_function->source_position.input_name,
+ current_function->symbol);
+ }
+ errorf(goto_statement->statement.source_position,
+ "label '%Y' used but not defined", label->symbol);
+ }
+ }
+ goto_first = goto_last = NULL;
+}
+
+static void parse_external_declaration(void)
+{
+ /* function-definitions and declarations both start with declaration
+ * specifiers */
+ declaration_specifiers_t specifiers;
+ memset(&specifiers, 0, sizeof(specifiers));
+ parse_declaration_specifiers(&specifiers);
+
+ /* must be a declaration */
+ if(token.type == ';') {
+ parse_anonymous_declaration_rest(&specifiers, append_declaration);
+ return;
+ }
+
+ /* declarator is common to both function-definitions and declarations */
+ declaration_t *ndeclaration = parse_declarator(&specifiers, /*may_be_abstract=*/false);
+
+ /* must be a declaration */
+ if(token.type == ',' || token.type == '=' || token.type == ';') {
+ parse_declaration_rest(ndeclaration, &specifiers, record_declaration);
+ return;
+ }
+
+ /* must be a function definition */
+ parse_kr_declaration_list(ndeclaration);
+
+ if(token.type != '{') {
+ parse_error_expected("while parsing function definition", '{', 0);
+ eat_statement();
+ return;
+ }
+
+ type_t *type = ndeclaration->type;
+ if(type == NULL) {
+ eat_block();
+ return;
+ }
+
+ /* note that we don't skip typerefs: the standard doesn't allow them here
+ * (so we can't use is_type_function here) */
+ if(type->kind != TYPE_FUNCTION) {
+ errorf(HERE, "declarator '%#T' has a body but is not a function type",
+ type, ndeclaration->symbol);
+ eat_block();