tree.h (SCOPE_FILE_SCOPE_P): New macro.
2010-09-29 Richard Guenther <rguenther@suse.de> * tree.h (SCOPE_FILE_SCOPE_P): New macro. (DECL_FILE_SCOPE_P): Use it. (TYPE_FILE_SCOPE_P): New macro. cp/ * cp-tree.h (CP_DECL_CONTEXT): Check DECL_FILE_SCOPE_P. (CP_TYPE_CONTEXT): Similar. (FROB_CONTEXT): Frob global_namespace to the global TRANSLATION_UNIT_DECL. * decl.c (cxx_init_decl_processing): Build a TRANSLATION_UNIT_DECL, set DECL_CONTEXT of global_namespace to it. (start_decl): Use CP_DECL_CONTEXT and test TYPE_P instead of zeroing context. (cp_finish_decl): Use DECL_FILE_SCOPE_P. (grokfndecl): Likewise. (start_preparsed_function): Likewise. * name-lookup.c (maybe_push_decl): Use DECL_NAMESPACE_SCOPE_P. (namespace_binding): Use SCOPE_FILE_SCOPE_P. * pt.c (template_class_depth): Use CP_TYPE_CONTEXT. (is_specialization_of_friend): Use CP_DECL_CONTEXT. (push_template_decl_real): Likewise. (tsubst_friend_class): Likewise. Adjust context comparisons. (instantiate_class_template): Use CP_TYPE_CONTEXT. (tsubst): Do not substitute into TRANSLATION_UNIT_DECL. * cxx-pretty-print.c (pp_cxx_nested_name_specifier): Use SCOPE_FILE_SCOPE_P. From-SVN: r164719
This commit is contained in:
parent
085c1b4766
commit
725214ac5e
8 changed files with 60 additions and 34 deletions
|
@ -1,3 +1,9 @@
|
|||
2010-09-29 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* tree.h (SCOPE_FILE_SCOPE_P): New macro.
|
||||
(DECL_FILE_SCOPE_P): Use it.
|
||||
(TYPE_FILE_SCOPE_P): New macro.
|
||||
|
||||
2010-09-29 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* c-parser.c (c_lex_one_token): In Objective-C, when dealing with
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
2010-09-29 Richard Guenther <rguenther@suse.de>
|
||||
|
||||
* cp-tree.h (CP_DECL_CONTEXT): Check DECL_FILE_SCOPE_P.
|
||||
(CP_TYPE_CONTEXT): Similar.
|
||||
(FROB_CONTEXT): Frob global_namespace to the global
|
||||
TRANSLATION_UNIT_DECL.
|
||||
* decl.c (cxx_init_decl_processing): Build a TRANSLATION_UNIT_DECL,
|
||||
set DECL_CONTEXT of global_namespace to it.
|
||||
(start_decl): Use CP_DECL_CONTEXT and test TYPE_P
|
||||
instead of zeroing context.
|
||||
(cp_finish_decl): Use DECL_FILE_SCOPE_P.
|
||||
(grokfndecl): Likewise.
|
||||
(start_preparsed_function): Likewise.
|
||||
* name-lookup.c (maybe_push_decl): Use DECL_NAMESPACE_SCOPE_P.
|
||||
(namespace_binding): Use SCOPE_FILE_SCOPE_P.
|
||||
* pt.c (template_class_depth): Use CP_TYPE_CONTEXT.
|
||||
(is_specialization_of_friend): Use CP_DECL_CONTEXT.
|
||||
(push_template_decl_real): Likewise.
|
||||
(tsubst_friend_class): Likewise. Adjust context comparisons.
|
||||
(instantiate_class_template): Use CP_TYPE_CONTEXT.
|
||||
(tsubst): Do not substitute into TRANSLATION_UNIT_DECL.
|
||||
* cxx-pretty-print.c (pp_cxx_nested_name_specifier): Use
|
||||
SCOPE_FILE_SCOPE_P.
|
||||
|
||||
2010-09-29 Yao Qi <yao@codesourcery.com>
|
||||
|
||||
* decl.c (get_atexit_node): Fix typo.
|
||||
|
|
|
@ -2361,12 +2361,12 @@ struct GTY((variable_size)) lang_decl {
|
|||
#define SET_DECL_FRIEND_CONTEXT(NODE, CONTEXT) \
|
||||
(LANG_DECL_FN_CHECK (NODE)->context = (CONTEXT))
|
||||
|
||||
/* NULL_TREE in DECL_CONTEXT represents the global namespace. */
|
||||
#define CP_DECL_CONTEXT(NODE) \
|
||||
(DECL_CONTEXT (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
|
||||
(!DECL_FILE_SCOPE_P (NODE) ? DECL_CONTEXT (NODE) : global_namespace)
|
||||
#define CP_TYPE_CONTEXT(NODE) \
|
||||
(TYPE_CONTEXT (NODE) ? TYPE_CONTEXT (NODE) : global_namespace)
|
||||
#define FROB_CONTEXT(NODE) ((NODE) == global_namespace ? NULL_TREE : (NODE))
|
||||
(!TYPE_FILE_SCOPE_P (NODE) ? TYPE_CONTEXT (NODE) : global_namespace)
|
||||
#define FROB_CONTEXT(NODE) \
|
||||
((NODE) == global_namespace ? DECL_CONTEXT (NODE) : (NODE))
|
||||
|
||||
/* 1 iff NODE has namespace scope, including the global namespace. */
|
||||
#define DECL_NAMESPACE_SCOPE_P(NODE) \
|
||||
|
|
|
@ -260,7 +260,7 @@ pp_cxx_template_keyword_if_needed (cxx_pretty_printer *pp, tree scope, tree t)
|
|||
static void
|
||||
pp_cxx_nested_name_specifier (cxx_pretty_printer *pp, tree t)
|
||||
{
|
||||
if (t != NULL && t != pp->enclosing_scope)
|
||||
if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
|
||||
{
|
||||
tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
|
||||
pp_cxx_nested_name_specifier (pp, scope);
|
||||
|
|
|
@ -3417,6 +3417,7 @@ cxx_init_decl_processing (void)
|
|||
gcc_assert (global_namespace == NULL_TREE);
|
||||
global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name,
|
||||
void_type_node);
|
||||
DECL_CONTEXT (global_namespace) = build_translation_unit_decl (NULL_TREE);
|
||||
TREE_PUBLIC (global_namespace) = 1;
|
||||
begin_scope (sk_namespace, global_namespace);
|
||||
|
||||
|
@ -4163,16 +4164,9 @@ start_decl (const cp_declarator *declarator,
|
|||
|| decl == error_mark_node)
|
||||
return error_mark_node;
|
||||
|
||||
context = DECL_CONTEXT (decl);
|
||||
|
||||
if (context)
|
||||
{
|
||||
*pushed_scope_p = push_scope (context);
|
||||
|
||||
/* We are only interested in class contexts, later. */
|
||||
if (TREE_CODE (context) == NAMESPACE_DECL)
|
||||
context = NULL_TREE;
|
||||
}
|
||||
context = CP_DECL_CONTEXT (decl);
|
||||
if (context != global_namespace)
|
||||
*pushed_scope_p = push_scope (context);
|
||||
|
||||
if (initialized)
|
||||
/* Is it valid for this decl to have an initializer at all?
|
||||
|
@ -4241,7 +4235,7 @@ start_decl (const cp_declarator *declarator,
|
|||
&& lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
|
||||
warning (0, "inline function %q+D given attribute noinline", decl);
|
||||
|
||||
if (context && COMPLETE_TYPE_P (complete_type (context)))
|
||||
if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
|
||||
{
|
||||
if (TREE_CODE (decl) == VAR_DECL)
|
||||
{
|
||||
|
@ -5802,7 +5796,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
|
|||
&& !COMPLETE_TYPE_P (TREE_TYPE (decl)))
|
||||
TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
|
||||
|
||||
rest_of_decl_compilation (decl, DECL_CONTEXT (decl) == NULL_TREE,
|
||||
rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
|
||||
at_eof);
|
||||
goto finish_end;
|
||||
}
|
||||
|
@ -6888,8 +6882,7 @@ grokfndecl (tree ctype,
|
|||
&& strncmp (IDENTIFIER_POINTER (declarator)+2, "builtin_", 8) == 0))
|
||||
&& current_lang_name == lang_name_cplusplus
|
||||
&& ctype == NULL_TREE
|
||||
/* NULL_TREE means global namespace. */
|
||||
&& DECL_CONTEXT (decl) == NULL_TREE)
|
||||
&& DECL_FILE_SCOPE_P (decl))
|
||||
SET_DECL_LANGUAGE (decl, lang_c);
|
||||
|
||||
/* Should probably propagate const out from type to decl I bet (mrs). */
|
||||
|
@ -12068,7 +12061,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
|
|||
with any previous declarations; if the original declaration
|
||||
has a linkage specification, that specification applies to
|
||||
the definition as well, and may affect the mangled name. */
|
||||
if (!DECL_CONTEXT (decl1))
|
||||
if (DECL_FILE_SCOPE_P (decl1))
|
||||
maybe_apply_pragma_weak (decl1);
|
||||
}
|
||||
|
||||
|
|
|
@ -1169,7 +1169,7 @@ maybe_push_decl (tree decl)
|
|||
&& DECL_CONTEXT (decl) != NULL_TREE
|
||||
/* Definitions of namespace members outside their namespace are
|
||||
possible. */
|
||||
&& TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
|
||||
&& !DECL_NAMESPACE_SCOPE_P (decl))
|
||||
|| (TREE_CODE (decl) == TEMPLATE_DECL && !namespace_bindings_p ())
|
||||
|| type == unknown_type_node
|
||||
/* The declaration of a template specialization does not affect
|
||||
|
@ -3068,7 +3068,7 @@ namespace_binding (tree name, tree scope)
|
|||
{
|
||||
cxx_binding *binding;
|
||||
|
||||
if (scope == NULL)
|
||||
if (SCOPE_FILE_SCOPE_P (scope))
|
||||
scope = global_namespace;
|
||||
else
|
||||
/* Unnecessary for the global namespace because it can't be an alias. */
|
||||
|
|
18
gcc/cp/pt.c
18
gcc/cp/pt.c
|
@ -344,7 +344,7 @@ template_class_depth (tree type)
|
|||
for (depth = 0;
|
||||
type && TREE_CODE (type) != NAMESPACE_DECL;
|
||||
type = (TREE_CODE (type) == FUNCTION_DECL)
|
||||
? CP_DECL_CONTEXT (type) : TYPE_CONTEXT (type))
|
||||
? CP_DECL_CONTEXT (type) : CP_TYPE_CONTEXT (type))
|
||||
{
|
||||
tree tinfo = get_template_info (type);
|
||||
|
||||
|
@ -1130,7 +1130,7 @@ is_specialization_of_friend (tree decl, tree friend_decl)
|
|||
nonzero. To determine if DECL is a friend of FRIEND, we first
|
||||
check if the enclosing class is a specialization of another. */
|
||||
|
||||
template_depth = template_class_depth (DECL_CONTEXT (friend_decl));
|
||||
template_depth = template_class_depth (CP_DECL_CONTEXT (friend_decl));
|
||||
if (template_depth
|
||||
&& DECL_CLASS_SCOPE_P (decl)
|
||||
&& is_specialization_of (TYPE_NAME (DECL_CONTEXT (decl)),
|
||||
|
@ -4346,7 +4346,7 @@ push_template_decl_real (tree decl, bool is_friend)
|
|||
if (is_friend)
|
||||
/* For a friend, we want the context of the friend function, not
|
||||
the type of which it is a friend. */
|
||||
ctx = DECL_CONTEXT (decl);
|
||||
ctx = CP_DECL_CONTEXT (decl);
|
||||
else if (CP_DECL_CONTEXT (decl)
|
||||
&& TREE_CODE (CP_DECL_CONTEXT (decl)) != NAMESPACE_DECL)
|
||||
/* In the case of a virtual function, we want the class in which
|
||||
|
@ -7530,9 +7530,9 @@ tsubst_friend_class (tree friend_tmpl, tree args)
|
|||
tree tmpl;
|
||||
tree context;
|
||||
|
||||
context = DECL_CONTEXT (friend_tmpl);
|
||||
context = CP_DECL_CONTEXT (friend_tmpl);
|
||||
|
||||
if (context)
|
||||
if (context != global_namespace)
|
||||
{
|
||||
if (TREE_CODE (context) == NAMESPACE_DECL)
|
||||
push_nested_namespace (context);
|
||||
|
@ -7621,7 +7621,7 @@ tsubst_friend_class (tree friend_tmpl, tree args)
|
|||
friend_type = TREE_TYPE (pushdecl_top_level_maybe_friend (tmpl, true));
|
||||
}
|
||||
|
||||
if (context)
|
||||
if (context != global_namespace)
|
||||
{
|
||||
if (TREE_CODE (context) == NAMESPACE_DECL)
|
||||
pop_nested_namespace (context);
|
||||
|
@ -7883,14 +7883,13 @@ instantiate_class_template (tree type)
|
|||
if (BINFO_N_BASE_BINFOS (pbinfo))
|
||||
{
|
||||
tree pbase_binfo;
|
||||
tree context = TYPE_CONTEXT (type);
|
||||
tree pushed_scope;
|
||||
int i;
|
||||
|
||||
/* We must enter the scope containing the type, as that is where
|
||||
the accessibility of types named in dependent bases are
|
||||
looked up from. */
|
||||
pushed_scope = push_scope (context ? context : global_namespace);
|
||||
pushed_scope = push_scope (CP_TYPE_CONTEXT (type));
|
||||
|
||||
/* Substitute into each of the bases to determine the actual
|
||||
basetypes. */
|
||||
|
@ -10012,7 +10011,8 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
|
|||
|| t == void_type_node
|
||||
|| t == char_type_node
|
||||
|| t == unknown_type_node
|
||||
|| TREE_CODE (t) == NAMESPACE_DECL)
|
||||
|| TREE_CODE (t) == NAMESPACE_DECL
|
||||
|| TREE_CODE (t) == TRANSLATION_UNIT_DECL)
|
||||
return t;
|
||||
|
||||
if (DECL_P (t))
|
||||
|
|
|
@ -2687,10 +2687,13 @@ struct GTY(()) tree_decl_minimal {
|
|||
#define DECL_LANG_FLAG_8(NODE) \
|
||||
(DECL_COMMON_CHECK (NODE)->decl_common.lang_flag_8)
|
||||
|
||||
/* Nonzero for a scope which is equal to file scope. */
|
||||
#define SCOPE_FILE_SCOPE_P(EXP) \
|
||||
(! (EXP) || TREE_CODE (EXP) == TRANSLATION_UNIT_DECL)
|
||||
/* Nonzero for a decl which is at file scope. */
|
||||
#define DECL_FILE_SCOPE_P(EXP) \
|
||||
(! DECL_CONTEXT (EXP) \
|
||||
|| TREE_CODE (DECL_CONTEXT (EXP)) == TRANSLATION_UNIT_DECL)
|
||||
#define DECL_FILE_SCOPE_P(EXP) SCOPE_FILE_SCOPE_P (DECL_CONTEXT (EXP))
|
||||
/* Nonzero for a type which is at file scope. */
|
||||
#define TYPE_FILE_SCOPE_P(EXP) SCOPE_FILE_SCOPE_P (TYPE_CONTEXT (EXP))
|
||||
|
||||
/* Nonzero for a decl that is decorated using attribute used.
|
||||
This indicates to compiler tools that this decl needs to be preserved. */
|
||||
|
|
Loading…
Add table
Reference in a new issue