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]

Re: cpplib: Clean up language initialisation


Unfortunately, we cannot move lang handling until after option
handling because that wipes any record of command line options
like trigraphs (Doh and Ugh!).

So, the best I can do is to move the builtins.  At least this
stops the wrong macro definitions being made.

Neil.
 	* cppinit.c (set_lang):	 Move builtin handling to...
	(init_builtins): ...here.
	(_cpp_create_reader): Move call to set_lang.
	(_cpp_handle_option): Similarly.

Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.147
diff -u -p -r1.147 cppinit.c
--- cppinit.c	2001/02/07 18:32:41	1.147
+++ cppinit.c	2001/02/20 22:45:58
@@ -371,8 +371,6 @@ set_lang (pfile, lang)
      cpp_reader *pfile;
      enum c_lang lang;
 {
-  struct cpp_pending *pend = CPP_OPTION (pfile, pending);
-
   /* Defaults.  */
   CPP_OPTION (pfile, lang) = lang;
   CPP_OPTION (pfile, objc) = 0;
@@ -388,7 +386,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, cplusplus_comments) = 1;
       CPP_OPTION (pfile, digraphs) = 1;
       CPP_OPTION (pfile, c99) = 1;
-      new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
       break;
     case CLK_GNUC89:
       CPP_OPTION (pfile, trigraphs) = 0;
@@ -400,7 +397,6 @@ set_lang (pfile, lang)
 
       /* ISO C.  */
     case CLK_STDC94:
-      new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
     case CLK_STDC89:
       CPP_OPTION (pfile, trigraphs) = 1;
       CPP_OPTION (pfile, dollars_in_ident) = 0;
@@ -408,7 +404,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, digraphs) = lang == CLK_STDC94;
       CPP_OPTION (pfile, c99) = 0;
       CPP_OPTION (pfile, extended_numbers) = 0;
-      new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
       break;
     case CLK_STDC99:
       CPP_OPTION (pfile, trigraphs) = 1;
@@ -416,13 +411,10 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, cplusplus_comments) = 1;
       CPP_OPTION (pfile, digraphs) = 1;
       CPP_OPTION (pfile, c99) = 1;
-      new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
-      new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
       break;
 
       /* Objective C.  */
     case CLK_OBJCXX:
-      new_pending_directive (pend, "__cplusplus", cpp_define);
       CPP_OPTION (pfile, cplusplus) = 1;
     case CLK_OBJC:
       CPP_OPTION (pfile, trigraphs) = 0;
@@ -431,7 +423,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, digraphs) = 1;
       CPP_OPTION (pfile, c99) = 0;
       CPP_OPTION (pfile, objc) = 1;
-      new_pending_directive (pend, "__OBJC__", cpp_define);
       break;
 
       /* C++.  */
@@ -443,7 +434,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, cplusplus_comments) = 1;
       CPP_OPTION (pfile, digraphs) = 1;
       CPP_OPTION (pfile, c99) = 0;
-      new_pending_directive (pend, "__cplusplus", cpp_define);
       break;
 
       /* Assembler.  */
@@ -453,7 +443,6 @@ set_lang (pfile, lang)
       CPP_OPTION (pfile, cplusplus_comments) = 1;
       CPP_OPTION (pfile, digraphs) = 0; 
       CPP_OPTION (pfile, c99) = 0;
-      new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
       break;
     }
 }
@@ -509,6 +498,7 @@ cpp_create_reader (lang)
 
   pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
 
+  set_lang (pfile, lang);
   CPP_OPTION (pfile, warn_import) = 1;
   CPP_OPTION (pfile, discard_comments) = 1;
   CPP_OPTION (pfile, show_column) = 1;
@@ -518,9 +508,6 @@ cpp_create_reader (lang)
   CPP_OPTION (pfile, pending) =
     (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
 
-  /* After creating pfile->pending.  */
-  set_lang (pfile, lang);
-
   /* It's simplest to just create this struct whether or not it will
      be needed.  */
   pfile->deps = deps_init ();
@@ -757,6 +744,23 @@ init_builtins (pfile)
 	  _cpp_define_builtin (pfile, str);
 	}
     }
+
+  if (CPP_OPTION (pfile, cplusplus))
+    _cpp_define_builtin (pfile, "__cplusplus 1");
+  if (CPP_OPTION (pfile, objc))
+    _cpp_define_builtin (pfile, "__OBJC__ 1");
+
+  if (CPP_OPTION (pfile, lang) == CLK_STDC94)
+    _cpp_define_builtin (pfile, "__STDC_VERSION__ 199409L");
+  else if (CPP_OPTION (pfile, c99))
+    _cpp_define_builtin (pfile, "__STDC_VERSION__ 199901L");
+
+  if (CPP_OPTION (pfile, lang) == CLK_STDC89
+      || CPP_OPTION (pfile, lang) == CLK_STDC94
+      || CPP_OPTION (pfile, lang) == CLK_STDC99)
+    _cpp_define_builtin (pfile, "__STRICT_ANSI__ 1");
+  else if (CPP_OPTION (pfile, lang) == CLK_ASM)
+    _cpp_define_builtin (pfile, "__ASSEMBLER__ 1");
 }
 #undef BUILTIN
 #undef OPERATOR


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