From 0ed5edac59d8ee8ad66e9a92763257895008eb8c Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 20 Mar 2006 22:19:06 -0500 Subject: re PR c++/21764 (visibility attributes on namespace scope) PR c++/21764 * c-pragma.c (visstack): Move out of handle_pragma_visibility. (push_visibility, pop_visibility): Likewise. * c-pragma.h: Declare them. * cp/name-lookup.h (struct cp_binding_level): Add has_visibility bitfield. * cp/name-lookup.c: Include c-pragma.h. (push_namespace_with_attribs): Split out from push_namespace. Push visibility if appropriate. Set TREE_PUBLIC on namespaces. (leave_scope): Pop visibility if appropriate. * cp/parser.c (cp_parser_declaration, cp_parser_namespace_name): Allow attributes on namespace declarations. PR c++/19238 * cp/decl.c (cp_finish_decl): Call determine_visibility later. (start_preparsed_function): Likewise. * cp/cp-tree.h (CP_TYPE_CONTEXT, TYPE_NAMESPACE_SCOPE_P): New macros. (TYPE_CLASS_SCOPE_P, TYPE_FUNCTION_SCOPE_P): New macros. * cp/decl2.c (determine_visibility_from_class): Split out from... (determine_visibility): ...here. Handle function scope and nested classes. (import_export_decl): Move visibility handling to determine_visibility_from_class. From-SVN: r112239 --- gcc/c-pragma.c | 67 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'gcc/c-pragma.c') diff --git a/gcc/c-pragma.c b/gcc/c-pragma.c index 39c4595..b62352c 100644 --- a/gcc/c-pragma.c +++ b/gcc/c-pragma.c @@ -593,9 +593,42 @@ static void handle_pragma_visibility (cpp_reader *); typedef enum symbol_visibility visibility; DEF_VEC_I (visibility); DEF_VEC_ALLOC_I (visibility, heap); +static VEC (visibility, heap) *visstack; + +/* Push the visibility indicated by STR onto the top of the #pragma + visibility stack. */ + +void +push_visibility (const char *str) +{ + VEC_safe_push (visibility, heap, visstack, + default_visibility); + if (!strcmp (str, "default")) + default_visibility = VISIBILITY_DEFAULT; + else if (!strcmp (str, "internal")) + default_visibility = VISIBILITY_INTERNAL; + else if (!strcmp (str, "hidden")) + default_visibility = VISIBILITY_HIDDEN; + else if (!strcmp (str, "protected")) + default_visibility = VISIBILITY_PROTECTED; + else + GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected"); + visibility_options.inpragma = 1; +} + +/* Pop a level of the #pragma visibility stack. */ + +void +pop_visibility (void) +{ + default_visibility = VEC_pop (visibility, visstack); + visibility_options.inpragma + = VEC_length (visibility, visstack) != 0; +} /* Sets the default visibility for symbols to something other than that specified on the command line. */ + static void handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED) { @@ -603,7 +636,6 @@ handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED) tree x; enum cpp_ttype token; enum { bad, push, pop } action = bad; - static VEC (visibility, heap) *visstack; token = pragma_lex (&x); if (token == CPP_NAME) @@ -621,15 +653,9 @@ handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED) if (pop == action) { if (!VEC_length (visibility, visstack)) - { - GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>"); - } + GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>"); else - { - default_visibility = VEC_pop (visibility, visstack); - visibility_options.inpragma - = VEC_length (visibility, visstack) != 0; - } + pop_visibility (); } else { @@ -637,28 +663,9 @@ handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED) GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); token = pragma_lex (&x); if (token != CPP_NAME) - { - GCC_BAD ("malformed #pragma GCC visibility push"); - } + GCC_BAD ("malformed #pragma GCC visibility push"); else - { - const char *str = IDENTIFIER_POINTER (x); - VEC_safe_push (visibility, heap, visstack, - default_visibility); - if (!strcmp (str, "default")) - default_visibility = VISIBILITY_DEFAULT; - else if (!strcmp (str, "internal")) - default_visibility = VISIBILITY_INTERNAL; - else if (!strcmp (str, "hidden")) - default_visibility = VISIBILITY_HIDDEN; - else if (!strcmp (str, "protected")) - default_visibility = VISIBILITY_PROTECTED; - else - { - GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected"); - } - visibility_options.inpragma = 1; - } + push_visibility (IDENTIFIER_POINTER (x)); if (pragma_lex (&x) != CPP_CLOSE_PAREN) GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored"); } -- cgit v1.1