OSDN Git Service

Fix implicit extern "C" breakage introduced by tokenization patch.
authoraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Sep 2004 22:24:35 +0000 (22:24 +0000)
committeraustern <austern@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Sep 2004 22:24:35 +0000 (22:24 +0000)
* cp/parser.c (struct cp_token): new one-bit field , implicit_extern_c
(cp_lexer_get_preprocessor_token): Set implicit_extern_c for
tokens that come from headers that are implicitly extern "C".
(struct cp_parser): new one-bit field, implicit_extern_c.
(cp_parser_new): Set parser's implicit_extern_c to false.
(cp_parser_translation_unit): Pop lang context if we were in a
header that was implicitly extern "C".
(cp_parser_declaration_seq_opt): Push/pop lang context as
required by the token's and parser's implicit_extern_c.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@88203 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/parser.c

index 028e0e1..6da00c4 100644 (file)
@@ -1,3 +1,49 @@
+2004-09-27  Matt Austern  <austern@apple.com>
+
+       * cp/parser.c (struct cp_token): new one-bit field , implicit_extern_c
+       (cp_lexer_get_preprocessor_token): Set implicit_extern_c for
+       tokens that come from headers that are implicitly extern "C".
+       (struct cp_parser): new one-bit field, implicit_extern_c.
+       (cp_parser_new): Set parser's implicit_extern_c to false.
+       (cp_parser_translation_unit): Pop lang context if we were in a
+       header that was implicitly extern "C".
+       (cp_parser_declaration_seq_opt): Push/pop lang context as
+       required by the token's and parser's implicit_extern_c.
+       
+2004-09-27  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/17585
+       * cp-tree.h (shared_member_p): Declare.
+       * search.c (shared_member_p): Give it external linkage.
+       * semantics.c (finish_qualified_id_expr): Use it.
+       (finish_id_expression): Likewise.
+
+       PR c++/17585
+       * semantics.c (finish_id_expression): Do not add "this->" to
+       static member functions.
+
+2004-09-27  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/17681
+       * error.c (dump_type): Change TREE_VEC case into TREE_BINFO.
+
+       * class.c (struct count_depth_data): Remove.
+       (dfs_depth_post, dfs_depth_q): Remove.
+       (find_final_overrider): Use number of vbase classes as depth
+       bound.
+       
+       * cp-tree.h (types_overlap_p): Remove.
+       * search.c (struct overlap_info): Remove.
+       (dfs_check_overlap, dfs_no_overlap_yet, types_overlap_p): Remove.
+       
+       * pt.c (GTB_VIA_VIRTUAL, GTB_IGNORE_TYPE): Remove.
+       (get_template_base_recursive): Remove. Replace with ...
+       (get_template_base_r): ... this.
+       (struct get_template_base_data_s): New.
+       (get_template_base): Use get_template_base_r via dfs_walk.  Always
+       return NULL on failure.
+       (unify): Remove error_mark_node check from get_template_base result.
+
 2004-09-27  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/17585
index 89a9601..184ae54 100644 (file)
@@ -55,6 +55,8 @@ typedef struct cp_token GTY (())
   unsigned char flags;
   /* True if this token is from a system header. */
   BOOL_BITFIELD in_system_header : 1;
+  /* True if this token is from a context where it is implicitly extern "C" */
+  BOOL_BITFIELD implicit_extern_c : 1;
   /* The value associated with this token, if any.  */
   tree value;
   /* The location at which this token was found.  */
@@ -418,6 +420,7 @@ static void
 cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED ,
                                  cp_token *token)
 {
+  static int is_extern_c = 0;
   bool done;
 
   done = false;
@@ -445,6 +448,13 @@ cp_lexer_get_preprocessor_token (cp_lexer *lexer ATTRIBUTE_UNUSED ,
   token->location = input_location;
   token->in_system_header = in_system_header;
 
+  /* On some systems, some header files are surrounded by an 
+     implicit extern "C" block.  Set a flag in the token if it
+     comes from such a header. */
+  is_extern_c += pending_lang_change;
+  pending_lang_change = 0;
+  token->implicit_extern_c = is_extern_c > 0;
+
   /* Check to see if this token is a keyword.  */
   if (token->type == CPP_NAME
       && C_IS_RESERVED_WORD (token->value))
@@ -1317,6 +1327,10 @@ typedef struct cp_parser GTY(())
      alternatives.  */
   bool in_type_id_in_expr_p;
 
+  /* TRUE if we are currently in a header file where declarations are
+     implicitly extern "C". */
+  bool implicit_extern_c;
+
   /* TRUE if strings in expressions should be translated to the execution
      character set.  */
   bool translate_strings_p;
@@ -2425,6 +2439,9 @@ cp_parser_new (void)
   /* We are not parsing a type-id inside an expression.  */
   parser->in_type_id_in_expr_p = false;
 
+  /* Declarations aren't implicitly extern "C". */
+  parser->implicit_extern_c = false;
+
   /* String literals should be translated to the execution character set.  */
   parser->translate_strings_p = true;
 
@@ -2625,6 +2642,14 @@ cp_parser_translation_unit (cp_parser* parser)
          cp_lexer_destroy (parser->lexer);
          parser->lexer = NULL;
 
+         /* This file might have been a context that's implicitly extern
+            "C".  If so, pop the lang context.  (Only relevant for PCH.) */
+         if (parser->implicit_extern_c)
+           {
+             pop_lang_context ();
+             parser->implicit_extern_c = false;
+           }
+
          /* Finish up.  */
          finish_translation_unit ();
 
@@ -6634,6 +6659,19 @@ cp_parser_declaration_seq_opt (cp_parser* parser)
          continue;
        }
 
+      /* If we're entering or exiting a region that's implicitly
+        extern "C", modify the lang context appropriately. */
+      if (!parser->implicit_extern_c && token->implicit_extern_c)
+       {
+         push_lang_context (lang_name_c);
+         parser->implicit_extern_c = true;
+       }
+      else if (parser->implicit_extern_c && !token->implicit_extern_c)
+       {
+         pop_lang_context ();
+         parser->implicit_extern_c = false;
+       }
+
       if (token->type == CPP_PRAGMA)
        {
          /* A top-level declaration can consist solely of a #pragma.
@@ -6644,19 +6682,6 @@ cp_parser_declaration_seq_opt (cp_parser* parser)
          continue;
        }
 
-      /* The C lexer modifies PENDING_LANG_CHANGE when it wants the
-        parser to enter or exit implicit `extern "C"' blocks.  */
-      while (pending_lang_change > 0)
-       {
-         push_lang_context (lang_name_c);
-         --pending_lang_change;
-       }
-      while (pending_lang_change < 0)
-       {
-         pop_lang_context ();
-         ++pending_lang_change;
-       }
-
       /* Parse the declaration itself.  */
       cp_parser_declaration (parser);
     }