This is the mail archive of the gcc@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]

ISO C 9X changes for cpp


Hi,

I've implemented a switch for ISO C 9X, corrected the recognition
of FP numbers in hex notatino and implemented the ISO C 9X version
of macro varargs.

[The patch also contains the -remap option handling and changed
the default of reading headers.gcc.]


If somebody (Jim?) says it is ok I'll also provide a similar patch
for cpplib.c.

Oh, an example of ISO C 9X macro varargs:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define bar(a, ...) a -> #__VA_ARGS__
bar(3)
bar(3,4)
bar(3,4,5)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

produces

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 1 "r.c"

 3  -> "" 
 3  -> "4" 
 3  -> "4,5" 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- Uli
---------------.      drepper at gnu.org  ,-.   Rubensstrasse 5
Ulrich Drepper  \    ,-------------------'   \  76149 Karlsruhe/Germany
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: cccp.c
===================================================================
RCS file: /cvs/cvsfiles/egcs/gcc/cccp.c,v
retrieving revision 1.6
diff -u -w -r1.6 cccp.c
--- cccp.c	1997/11/17 23:41:05	1.6
+++ cccp.c	1997/11/21 01:51:52
@@ -438,6 +438,10 @@
    so it's not worth testing for them.  */
 static int no_precomp = 1;
 
+/* Nonzero if we want to use the `header.gcc' remapping files since we
+   use a reasonable OS.  */
+static int do_remap;
+
 /* Nonzero means give all the error messages the ANSI standard requires.  */
 
 int pedantic;
@@ -484,6 +488,10 @@
 
 int c89;
 
+/* Nonzero for the 199X C Standard, including ISO C 1998.  */
+
+int c9x;
+
 /* Nonzero causes output not to be done,
    but directives such as #define that have side effects
    are still obeyed.  */
@@ -1535,6 +1543,7 @@
 	if (!strcmp (argv[i], "-traditional")) {
 	  traditional = 1;
 	  cplusplus_comments = 0;
+	  c9x = 0;
 	} else if (!strcmp (argv[i], "-trigraphs")) {
 	  no_trigraphs = 0;
 	}
@@ -1542,15 +1551,17 @@
 
       case 'l':
 	if (! strcmp (argv[i], "-lang-c"))
-	  cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 0;
+	  cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 1, objc = 0;
 	if (! strcmp (argv[i], "-lang-c89"))
-	  cplusplus = 0, cplusplus_comments = 0, c89 = 1, objc = 0;
+	  cplusplus = 0, cplusplus_comments = 0, c89 = 1, c9x = 0, objc = 0;
+	if (! strcmp (argv[i], "-lang-c9x"))
+	  cplusplus = 0, cplusplus_comments = 1, c89 = 1, c9x = 1, objc = 0;
 	if (! strcmp (argv[i], "-lang-c++"))
-	  cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 0;
+	  cplusplus = 1, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 0;
 	if (! strcmp (argv[i], "-lang-objc"))
-	  cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 1;
+	  cplusplus = 0, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 1;
 	if (! strcmp (argv[i], "-lang-objc++"))
-	  cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 1;
+	  cplusplus = 1, cplusplus_comments = 1, c89 = 0, c9x = 0, objc = 1;
  	if (! strcmp (argv[i], "-lang-asm"))
  	  lang_asm = 1;
  	if (! strcmp (argv[i], "-lint"))
@@ -1775,6 +1786,11 @@
 	  no_precomp = 1;
 	break;
 
+      case 'r':
+	if (!strcmp (argv[i], "-remap"))
+	  do_remap = 1;
+	break;
+
       case 'u':
 	/* Sun compiler passes undocumented switch "-undef".
 	   Let's assume it means to inhibit the predefined symbols.  */
@@ -3107,16 +3123,16 @@
 	  *obp++ = c;
 	  /* A sign can be part of a preprocessing number
 	     if it follows an `e' or `p'.  */
-	  if (c == 'e' || c == 'E' || c == 'p' || c == 'P') {
+	  if (c == 'e' || c == 'E'
+	      || (!traditional && !c89 && (c == 'p' || c == 'P'))) {
 	    while (ibp[0] == '\\' && ibp[1] == '\n') {
 	      ++ip->lineno;
 	      ibp += 2;
 	    }
 	    if (*ibp == '+' || *ibp == '-') {
 	      *obp++ = *ibp++;
-	      /* But traditional C does not let the token go past the sign,
-		 and C89 does not allow `p'.  */
-	      if (traditional || (c89 && (c == 'p' || c == 'P')))
+	      /* But traditional C does not let the token go past the sign.  */
+	      if (traditional)
 		break;
 	    }
 	  }
@@ -4926,7 +4942,7 @@
      U_CHAR *importing;
      struct include_file **pinc;
 {
-  char *fname = remap_include_file (filename, searchptr);
+  char *fname = do_remap ? remap_include_file (filename, searchptr) : filename;
   int fd = -2;
 
   /* Look up FNAME in include_hashtab.  */
@@ -5587,23 +5603,37 @@
 	pedwarn ("another parameter follows `%s'",
 		 rest_extension);
 
-      if (!is_idstart[*bp])
+      if (!is_idstart[*bp] && (!c9x || *bp != rest_extension[0]))
 	pedwarn ("invalid character in macro parameter name");
       
       /* Find the end of the arg name.  */
-      while (is_idchar[*bp]) {
+      while (is_idchar[*bp])
 	bp++;
+
 	/* do we have a "special" rest-args extension here? */
 	if (limit - bp > REST_EXTENSION_LENGTH
-	    && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
+	  && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0)
+	{
 	  rest_args = 1;
 	  temp->rest_args = 1;
-	  break;
-	}
       }
+
       temp->length = bp - temp->name;
       if (rest_args == 1)
+	{
+	  if (temp->length == 0 && c9x)
+	    {
+	      /* ISO C 9X specifies a different syntax for variable argument
+		 macros.  The ellipsis is used without a prior identifier
+		 and the replacement text is implicitly assigned to an
+		 Identifier named `__VA_ARGS__'.  We emulate this by
+		 setting the name to this value and everything can be
+		 processed as for GNU C macro varargs.  */
+	      temp->name = "__VA_ARGS__";
+	      temp->length = sizeof ("__VA_ARGS__") - 1;
+	    }
 	bp += REST_EXTENSION_LENGTH;
+	}
       arglengths += temp->length + 2;
       SKIP_WHITE_SPACE (bp);
       if (temp->length == 0 || (*bp != ',' && *bp != ')')) {
@@ -5613,8 +5643,9 @@
       if (*bp == ',') {
 	bp++;
 	SKIP_WHITE_SPACE (bp);
-	/* A comma at this point can only be followed by an identifier.  */
-	if (!is_idstart[*bp]) {
+	/* A comma at this point can only be followed by an identifier
+	   or an ellipsis if we handle ISO C 9X.  */
+	if (!is_idstart[*bp] && (!c9x || *bp != rest_extension[0])) {
 	  error ("badly punctuated parameter list in `#define'");
 	  goto nope;
 	}
@@ -9554,6 +9585,9 @@
   install ((U_CHAR *) "__TIME__", -1, T_TIME, NULL_PTR, -1);
   if (!traditional) {
     install ((U_CHAR *) "__STDC__", -1, T_CONST, "1", -1);
+    if (c9x)
+      install ((U_CHAR *) "__STDC_VERSION__", -1, T_CONST, "199901L", -1);
+    else
     install ((U_CHAR *) "__STDC_VERSION__", -1, T_CONST, "199409L", -1);
   }
   if (objc)


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