mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-22 03:31:34 +00:00
Allow same-type re-declarations of uninitialized variables.
This is especially important for declaring variables that were previously declared external.
This commit is contained in:
parent
b3d5789377
commit
f1fccb19dd
2 changed files with 13 additions and 9 deletions
|
@ -182,33 +182,33 @@ void
|
||||||
initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space,
|
initialize_def (symbol_t *sym, type_t *type, expr_t *init, defspace_t *space,
|
||||||
storage_class_t storage)
|
storage_class_t storage)
|
||||||
{
|
{
|
||||||
|
symbol_t *check = symtab_lookup (current_symtab, sym->name);
|
||||||
if (!type) {
|
if (!type) {
|
||||||
warning (0, "type for %s defaults to %s", sym->name,
|
warning (0, "type for %s defaults to %s", sym->name,
|
||||||
type_default->name);
|
type_default->name);
|
||||||
type = type_default;
|
type = type_default;
|
||||||
}
|
}
|
||||||
if (sym->table == current_symtab) {
|
if (check && check->table == current_symtab) {
|
||||||
if (sym->sy_type != sy_var || sym->type != type) {
|
if (check->sy_type != sy_var || check->type != type) {
|
||||||
error (0, "%s redefined", sym->name);
|
error (0, "%s redefined", sym->name);
|
||||||
sym = new_symbol (sym->name);
|
|
||||||
} else {
|
} else {
|
||||||
// is var and same type
|
// is var and same type
|
||||||
if (!sym->s.def)
|
if (!check->s.def)
|
||||||
internal_error (0, "half defined var");
|
internal_error (0, "half defined var");
|
||||||
if (storage == st_extern) {
|
if (storage == st_extern) {
|
||||||
if (init)
|
if (init)
|
||||||
warning (0, "initializing external variable");
|
warning (0, "initializing external variable");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (init && sym->s.def->initialized) {
|
if (init && check->s.def->initialized) {
|
||||||
error (0, "%s redefined", sym->name);
|
error (0, "%s redefined", sym->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
sym = check;
|
||||||
}
|
}
|
||||||
} else if (sym->table) {
|
|
||||||
sym = new_symbol (sym->name);
|
|
||||||
}
|
}
|
||||||
sym->type = type;
|
sym->type = type;
|
||||||
|
if (!sym->table)
|
||||||
symtab_addsymbol (current_symtab, sym);
|
symtab_addsymbol (current_symtab, sym);
|
||||||
if (storage == st_global && init) {
|
if (storage == st_global && init) {
|
||||||
sym->sy_type = sy_const;
|
sym->sy_type = sy_const;
|
||||||
|
|
|
@ -568,7 +568,11 @@ struct_decl
|
||||||
var_decl
|
var_decl
|
||||||
: NAME %prec COMMA
|
: NAME %prec COMMA
|
||||||
{
|
{
|
||||||
$$ = check_redefined ($1);
|
$$ = $1;
|
||||||
|
// due to the way declarations work, we need a new symbol at all
|
||||||
|
// times. redelcarations will be checked later
|
||||||
|
if ($$->table)
|
||||||
|
$$ = new_symbol ($1->name);
|
||||||
$$->type = 0;
|
$$->type = 0;
|
||||||
}
|
}
|
||||||
| var_decl function_params
|
| var_decl function_params
|
||||||
|
|
Loading…
Reference in a new issue