declaration->type = type;
}
+static bool first_err = true;
+
+/**
+ * When called with first_err set, prints the name of the current function,
+ * else does noting.
+ */
+static void print_in_function(void) {
+ if (first_err) {
+ first_err = false;
+ diagnosticf("%s: In function '%Y':\n",
+ current_function->source_position.input_name,
+ current_function->symbol);
+ }
+}
+
/**
* Check if all labels are defined in the current function.
* Check if all labels are used in the current function.
*/
static void check_labels(void)
{
- bool first_err = true;
for (const goto_statement_t *goto_statement = goto_first;
goto_statement != NULL;
goto_statement = goto_statement->next) {
label->used = true;
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);
- }
+ print_in_function();
errorf(goto_statement->statement.source_position,
"label '%Y' used but not defined", label->symbol);
}
const declaration_t *label = label_statement->label;
if (! label->used) {
- if (first_err) {
- first_err = false;
- diagnosticf("%s: In function '%Y':\n",
- current_function->source_position.input_name,
- current_function->symbol);
- }
+ print_in_function();
warningf(label_statement->statement.source_position,
"label '%Y' defined but not used", label->symbol);
}
const declaration_t *parameter = scope->declarations;
for (; parameter != NULL; parameter = parameter->next) {
if (! parameter->used) {
+ print_in_function();
warningf(parameter->source_position,
"unused parameter '%Y'", parameter->symbol);
}
current_function = declaration;
declaration->init.statement = parse_compound_statement();
+ first_err = true;
check_labels();
check_declarations();
.implicit_function_declaration = true,
.implicit_int = true,
.main = true,
- .missing_declarations = true,
- .missing_prototypes = true,
+ .missing_declarations = false,
+ .missing_prototypes = false,
.redundant_decls = true,
.s_are_errors = false,
.strict_prototypes = true,