This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: remove ObjC-related globals from C FE


This patch moves the global variables objc_pq_context and
objc_need_raw_identifier into the c_parser struct.

This relies on my earlier patch which adds a parser argument to
c_lex_one_token.  However, that part of the earlier patch could easily
be extracted and put into this patch, if that would help this one go
in more quickly.

I think I'm almost done with all the easy globals.  The remaining ones
(and there are lots and lots of them) require more intrusive patches.

Bootstrapped and regression tested (including ObjC) on x86 FC 6.
Ok?

Tom

:ADDPATCH C:

2007-06-14  Tom Tromey  <tromey@redhat.com>

	* c-parser.c (objc_pq_context): Removed.
	(objc_need_raw_identifier): Likewise.
	(c_parser) <objc_pq_context>: New field.
	<objc_need_raw_identifier>: Likewise.
	(OBJC_NEED_RAW_IDENTIFIER): Added parser argument.
	(c_lex_one_token): Update.
	(c_parser_objc_protocol_definition): Update.
	(c_parser_objc_method_definition): Update.
	(c_parser_objc_methodproto): Update.
	(c_parser_declspecs): Update.

Index: c-parser.c
===================================================================
--- c-parser.c	(revision 125720)
+++ c-parser.c	(working copy)
@@ -59,19 +59,10 @@
 #include "cgraph.h"
 
 
-/* Objective-C specific parser/lexer information.  */
-
-static int objc_pq_context = 0;
-
-/* The following flag is needed to contextualize Objective-C lexical
-   analysis.  In some cases (e.g., 'int NSObject;'), it is undesirable
-   to bind an identifier to an Objective-C class, even if a class with
-   that name exists.  */
-static int objc_need_raw_identifier = 0;
-#define OBJC_NEED_RAW_IDENTIFIER(VAL)		\
+#define OBJC_NEED_RAW_IDENTIFIER(PARSER, VAL)	\
   do {						\
     if (c_dialect_objc ())			\
-      objc_need_raw_identifier = VAL;		\
+      parser->objc_need_raw_identifier = VAL;	\
   } while (0)
 
 /* The reserved keyword table.  */
@@ -293,6 +284,13 @@
   /* True if we're processing a pragma, and shouldn't automatically
      consume CPP_PRAGMA_EOL.  */
   BOOL_BITFIELD in_pragma : 1;
+  /* Objective-C specific parser/lexer information.  */
+  BOOL_BITFIELD objc_pq_context : 1;
+  /* The following flag is needed to contextualize Objective-C lexical
+     analysis.  In some cases (e.g., 'int NSObject;'), it is
+     undesirable to bind an identifier to an Objective-C class, even
+     if a class with that name exists.  */
+  BOOL_BITFIELD objc_need_raw_identifier : 1;
 } c_parser;
 
 
@@ -321,8 +319,8 @@
       {
 	tree decl;
 
-	int objc_force_identifier = objc_need_raw_identifier;
-	OBJC_NEED_RAW_IDENTIFIER (0);
+	bool objc_force_identifier = parser->objc_need_raw_identifier;
+	OBJC_NEED_RAW_IDENTIFIER (parser, false);
 
 	if (C_IS_RESERVED_WORD (token->value))
 	  {
@@ -331,7 +329,8 @@
 	    if (c_dialect_objc ())
 	      {
 		if (!OBJC_IS_AT_KEYWORD (rid_code)
-		    && (!OBJC_IS_PQ_KEYWORD (rid_code) || objc_pq_context))
+		    && (!OBJC_IS_PQ_KEYWORD (rid_code)
+			|| parser->objc_pq_context))
 		  {
 		    /* Return the canonical spelling for this keyword.  */
 		    token->value = ridpointers[(int) rid_code];
@@ -388,7 +387,7 @@
     case CPP_SEMICOLON:
       /* These tokens may affect the interpretation of any identifiers
 	 following, if doing Objective-C.  */
-      OBJC_NEED_RAW_IDENTIFIER (0);
+      OBJC_NEED_RAW_IDENTIFIER (parser, false);
       break;
     case CPP_PRAGMA:
       /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST.  */
@@ -1605,7 +1604,7 @@
 	    goto out;
 	  attrs_ok = true;
 	  seen_type = true;
-	  OBJC_NEED_RAW_IDENTIFIER (1);
+	  OBJC_NEED_RAW_IDENTIFIER (parser, true);
 	  t.kind = ctsk_resword;
 	  t.spec = c_parser_peek_token (parser)->value;
 	  declspecs_add_type (specs, t);
@@ -5908,11 +5907,11 @@
       c_parser_consume_token (parser);
       if (c_parser_next_token_is (parser, CPP_LESS))
 	proto = c_parser_objc_protocol_refs (parser);
-      objc_pq_context = 1;
+      parser->objc_pq_context = true;
       objc_start_protocol (id, proto);
       c_parser_objc_methodprotolist (parser);
       c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>");
-      objc_pq_context = 0;
+      parser->objc_pq_context = false;
       objc_finish_interface ();
     }
 }
@@ -5952,7 +5951,7 @@
   enum tree_code type = c_parser_objc_method_type (parser);
   tree decl;
   objc_set_method_type (type);
-  objc_pq_context = 1;
+  parser->objc_pq_context = true;
   decl = c_parser_objc_method_decl (parser);
   if (c_parser_next_token_is (parser, CPP_SEMICOLON))
     {
@@ -5965,7 +5964,7 @@
       c_parser_error (parser, "expected %<{%>");
       return;
     }
-  objc_pq_context = 0;
+  parser->objc_pq_context = false;
   objc_start_method_definition (decl);
   add_stmt (c_parser_compound_statement (parser));
   objc_finish_method_definition (current_function_decl);
@@ -6029,10 +6028,10 @@
   tree decl;
   objc_set_method_type (type);
   /* Remember protocol qualifiers in prototypes.  */
-  objc_pq_context = 1;
+  parser->objc_pq_context = true;
   decl = c_parser_objc_method_decl (parser);
   /* Forget protocol qualifiers here.  */
-  objc_pq_context = 0;
+  parser->objc_pq_context = false;
   objc_add_method_declaration (decl);
   c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]