Commit 9cd51ef6 by Zack Weinberg Committed by Zack Weinberg

c-decl.c (pushdecl_function_level): Make static, return nothing.

	* c-decl.c (pushdecl_function_level): Make static, return nothing.
	(kept_level_p): Fold into poplevel.
	(undeclared_variable): Moved here from c-typeck.c.  Export.
	* c-tree.h (KEEP_YES, KEEP_NO, KEEP_MAYBE): New #defines.
	(undeclared_variable): Prototype here.  Don't prototype
	kept_level_p nor pushdecl_function_level.
	* c-parse.in: Change first argument to poplevel from
	"kept_level_p()" to "KEEP_MAYBE".
	* c-typeck.c (undeclared_variable): Moved to c-decl.c.

From-SVN: r69540
parent cf6bcbd0
2003-07-17 Zack Weinberg <zack@codesourcery.com>
* c-decl.c (pushdecl_function_level): Make static, return nothing.
(kept_level_p): Fold into poplevel.
(undeclared_variable): Moved here from c-typeck.c. Export.
* c-tree.h (KEEP_YES, KEEP_NO, KEEP_MAYBE): New #defines.
(undeclared_variable): Prototype here. Don't prototype
kept_level_p nor pushdecl_function_level.
* c-parse.in: Change first argument to poplevel from
"kept_level_p()" to "KEEP_MAYBE".
* c-typeck.c (undeclared_variable): Moved to c-decl.c.
2003-07-17 Roger Sayle <roger@eyesopen.com> 2003-07-17 Roger Sayle <roger@eyesopen.com>
* simplify-rtx.c (simplify_rtx): Use simplify_gen_binary to swap * simplify-rtx.c (simplify_rtx): Use simplify_gen_binary to swap
......
...@@ -291,6 +291,7 @@ static tree any_external_decl (tree); ...@@ -291,6 +291,7 @@ static tree any_external_decl (tree);
static void record_external_decl (tree); static void record_external_decl (tree);
static void warn_if_shadowing (tree, tree); static void warn_if_shadowing (tree, tree);
static void clone_underlying_type (tree); static void clone_underlying_type (tree);
static void pushdecl_function_level (tree, tree);
static bool flexible_array_type_p (tree); static bool flexible_array_type_p (tree);
static hashval_t link_hash_hash (const void *); static hashval_t link_hash_hash (const void *);
static int link_hash_eq (const void *, const void *); static int link_hash_eq (const void *, const void *);
...@@ -391,18 +392,6 @@ keep_next_level (void) ...@@ -391,18 +392,6 @@ keep_next_level (void)
keep_next_level_flag = 1; keep_next_level_flag = 1;
} }
/* Nonzero if the current level needs to have a BLOCK made. */
int
kept_level_p (void)
{
return ((current_binding_level->keep_if_subblocks
&& current_binding_level->blocks != 0)
|| current_binding_level->keep
|| current_binding_level->names != 0
|| current_binding_level->tags != 0);
}
/* Identify this binding level as a level of parameters. */ /* Identify this binding level as a level of parameters. */
void void
...@@ -485,8 +474,12 @@ poplevel (int keep, int reverse, int functionbody) ...@@ -485,8 +474,12 @@ poplevel (int keep, int reverse, int functionbody)
tree subblocks = current_binding_level->blocks; tree subblocks = current_binding_level->blocks;
functionbody |= current_binding_level->function_body; functionbody |= current_binding_level->function_body;
if (keep == KEEP_MAYBE)
keep = (current_binding_level->names || current_binding_level->tags);
keep |= (current_binding_level->keep || functionbody keep |= (current_binding_level->keep || functionbody
|| (current_binding_level->keep_if_subblocks && subblocks != 0)); || (subblocks && current_binding_level->keep_if_subblocks));
/* We used to warn about unused variables in expand_end_bindings, /* We used to warn about unused variables in expand_end_bindings,
i.e. while generating RTL. But in function-at-a-time mode we may i.e. while generating RTL. But in function-at-a-time mode we may
...@@ -1830,12 +1823,12 @@ pushdecl_top_level (tree x) ...@@ -1830,12 +1823,12 @@ pushdecl_top_level (tree x)
/* Record X as belonging to the outermost scope of the current /* Record X as belonging to the outermost scope of the current
function. This is used only internally, by c_make_fname_decl and function. This is used only internally, by c_make_fname_decl and
build_external_ref, and is limited to their needs. The NAME is undeclared_variable, and is limited to their needs. The NAME is
provided as a separate argument because build_external_ref wants to provided as a separate argument because undeclared_variable wants to
use error_mark_node for X. For VAR_DECLs, duplicate_decls is not use error_mark_node for X. For VAR_DECLs, duplicate_decls is not
called; if there is any preexisting decl for this identifier, it is called; if there is any preexisting decl for this identifier, it is
an ICE. */ an ICE. */
tree static void
pushdecl_function_level (tree x, tree name) pushdecl_function_level (tree x, tree name)
{ {
struct binding_level *scope; struct binding_level *scope;
...@@ -1862,7 +1855,6 @@ pushdecl_function_level (tree x, tree name) ...@@ -1862,7 +1855,6 @@ pushdecl_function_level (tree x, tree name)
} }
IDENTIFIER_SYMBOL_VALUE (name) = x; IDENTIFIER_SYMBOL_VALUE (name) = x;
return x;
} }
/* Generate an implicit declaration for identifier FUNCTIONID as a /* Generate an implicit declaration for identifier FUNCTIONID as a
...@@ -1993,6 +1985,38 @@ redeclaration_error_message (tree newdecl, tree olddecl) ...@@ -1993,6 +1985,38 @@ redeclaration_error_message (tree newdecl, tree olddecl)
} }
} }
/* Issue an error message for a reference to an undeclared variable
ID, including a reference to a builtin outside of function-call
context. Establish a binding of the identifier to error_mark_node
in an appropriate scope, which will suppress further errors for the
same identifier. */
void
undeclared_variable (tree id)
{
static bool already = false;
if (current_function_decl == 0)
{
error ("`%s' undeclared here (not in a function)",
IDENTIFIER_POINTER (id));
IDENTIFIER_SYMBOL_VALUE (id) = error_mark_node;
}
else
{
error ("`%s' undeclared (first use in this function)",
IDENTIFIER_POINTER (id));
if (! already)
{
error ("(Each undeclared identifier is reported only once");
error ("for each function it appears in.)");
already = true;
}
pushdecl_function_level (error_mark_node, id);
}
}
/* Get the LABEL_DECL corresponding to identifier ID as a label. /* Get the LABEL_DECL corresponding to identifier ID as a label.
Create one if none exists so far for the current function. Create one if none exists so far for the current function.
This function is called for both label definitions and label references. */ This function is called for both label definitions and label references. */
......
...@@ -2087,7 +2087,7 @@ c99_block_end: /* empty */ ...@@ -2087,7 +2087,7 @@ c99_block_end: /* empty */
{ if (flag_isoc99) { if (flag_isoc99)
{ {
tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0); tree scope_stmt = add_scope_stmt (/*begin_p=*/0, /*partial_p=*/0);
$$ = poplevel (kept_level_p (), 0, 0); $$ = poplevel (KEEP_MAYBE, 0, 0);
SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt)) SCOPE_STMT_BLOCK (TREE_PURPOSE (scope_stmt))
= SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt)) = SCOPE_STMT_BLOCK (TREE_VALUE (scope_stmt))
= $$; = $$;
...@@ -2137,7 +2137,7 @@ compstmt_start: '{' { compstmt_count++; ...@@ -2137,7 +2137,7 @@ compstmt_start: '{' { compstmt_count++;
compstmt_nostart: '}' compstmt_nostart: '}'
{ $$ = convert (void_type_node, integer_zero_node); } { $$ = convert (void_type_node, integer_zero_node); }
| pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel | pushlevel maybe_label_decls compstmt_contents_nonempty '}' poplevel
{ $$ = poplevel (kept_level_p (), 1, 0); { $$ = poplevel (KEEP_MAYBE, 1, 0);
SCOPE_STMT_BLOCK (TREE_PURPOSE ($5)) SCOPE_STMT_BLOCK (TREE_PURPOSE ($5))
= SCOPE_STMT_BLOCK (TREE_VALUE ($5)) = SCOPE_STMT_BLOCK (TREE_VALUE ($5))
= $$; } = $$; }
......
...@@ -155,6 +155,11 @@ struct lang_type GTY(()) ...@@ -155,6 +155,11 @@ struct lang_type GTY(())
without prototypes. */ without prototypes. */
#define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_BINFO (NODE) #define TYPE_ACTUAL_ARG_TYPES(NODE) TYPE_BINFO (NODE)
/* Values for the first parameter to poplevel. */
#define KEEP_NO 0
#define KEEP_YES 1
#define KEEP_MAYBE 2
/* in c-lang.c and objc-act.c */ /* in c-lang.c and objc-act.c */
extern tree lookup_interface (tree); extern tree lookup_interface (tree);
...@@ -175,7 +180,6 @@ extern void gen_aux_info_record (tree, int, int, int); ...@@ -175,7 +180,6 @@ extern void gen_aux_info_record (tree, int, int, int);
/* in c-decl.c */ /* in c-decl.c */
extern int global_bindings_p (void); extern int global_bindings_p (void);
extern int kept_level_p (void);
extern tree getdecls (void); extern tree getdecls (void);
extern void pushlevel (int); extern void pushlevel (int);
extern void insert_block (tree); extern void insert_block (tree);
...@@ -192,6 +196,7 @@ extern void check_for_loop_decls (void); ...@@ -192,6 +196,7 @@ extern void check_for_loop_decls (void);
extern void clear_parm_order (void); extern void clear_parm_order (void);
extern int complete_array_type (tree, tree, int); extern int complete_array_type (tree, tree, int);
extern void declare_parm_level (void); extern void declare_parm_level (void);
extern void undeclared_variable (tree);
extern tree define_label (location_t, tree); extern tree define_label (location_t, tree);
extern void finish_decl (tree, tree, tree); extern void finish_decl (tree, tree, tree);
extern tree finish_enum (tree, tree, tree); extern tree finish_enum (tree, tree, tree);
...@@ -213,7 +218,6 @@ extern void pop_label_level (void); ...@@ -213,7 +218,6 @@ extern void pop_label_level (void);
extern void push_label_level (void); extern void push_label_level (void);
extern void push_parm_decl (tree); extern void push_parm_decl (tree);
extern tree pushdecl_top_level (tree); extern tree pushdecl_top_level (tree);
extern tree pushdecl_function_level (tree, tree);
extern void pushtag (tree, tree); extern void pushtag (tree, tree);
extern tree set_array_declarator_type (tree, tree, int); extern tree set_array_declarator_type (tree, tree, int);
extern tree shadow_label (tree); extern tree shadow_label (tree);
......
...@@ -49,9 +49,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -49,9 +49,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
message within this initializer. */ message within this initializer. */
static int missing_braces_mentioned; static int missing_braces_mentioned;
/* 1 if we explained undeclared var errors. */
static int undeclared_variable_notice;
static tree qualify_type (tree, tree); static tree qualify_type (tree, tree);
static int tagged_types_tu_compatible_p (tree, tree, int); static int tagged_types_tu_compatible_p (tree, tree, int);
static int comp_target_types (tree, tree, int); static int comp_target_types (tree, tree, int);
...@@ -60,7 +57,6 @@ static int type_lists_compatible_p (tree, tree, int); ...@@ -60,7 +57,6 @@ static int type_lists_compatible_p (tree, tree, int);
static tree decl_constant_value_for_broken_optimization (tree); static tree decl_constant_value_for_broken_optimization (tree);
static tree default_function_array_conversion (tree); static tree default_function_array_conversion (tree);
static tree lookup_field (tree, tree); static tree lookup_field (tree, tree);
static void undeclared_variable (tree);
static tree convert_arguments (tree, tree, tree, tree); static tree convert_arguments (tree, tree, tree, tree);
static tree pointer_diff (tree, tree); static tree pointer_diff (tree, tree);
static tree unary_complex_lvalue (enum tree_code, tree, int); static tree unary_complex_lvalue (enum tree_code, tree, int);
...@@ -1531,37 +1527,6 @@ build_array_ref (tree array, tree index) ...@@ -1531,37 +1527,6 @@ build_array_ref (tree array, tree index)
} }
} }
/* Issue an error message for a reference to an undeclared variable ID,
including a reference to a builtin outside of function-call context.
Arrange to suppress further errors for the same identifier. */
static void
undeclared_variable (tree id)
{
if (current_function_decl == 0)
{
error ("`%s' undeclared here (not in a function)",
IDENTIFIER_POINTER (id));
IDENTIFIER_SYMBOL_VALUE (id) = error_mark_node;
}
else
{
error ("`%s' undeclared (first use in this function)",
IDENTIFIER_POINTER (id));
if (! undeclared_variable_notice)
{
error ("(Each undeclared identifier is reported only once");
error ("for each function it appears in.)");
undeclared_variable_notice = 1;
}
/* Set IDENTIFIER_SYMBOL_VALUE (id) to error_mark_node
at function scope. This suppresses further warnings
about this undeclared identifier in this function. */
pushdecl_function_level (error_mark_node, id);
}
}
/* Build an external reference to identifier ID. FUN indicates /* Build an external reference to identifier ID. FUN indicates
whether this will be used for a function call. */ whether this will be used for a function call. */
tree tree
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment