svn commit: r228474 - in head/contrib/gcclibs/libcpp: . include

Ed Schouten ed at FreeBSD.org
Tue Dec 13 17:34:48 UTC 2011


Author: ed
Date: Tue Dec 13 17:34:47 2011
New Revision: 228474
URL: http://svn.freebsd.org/changeset/base/228474

Log:
  Add support for __COUNTER__.
  
  __COUNTER__ allows one to obtain incrementing (read: unique) numbers
  from the C preprocesor. This is useful when implementing things like a
  robust implementation of CTASSERT(), which currently fails when using
  it more than once on a single line of code. Probably not likely to cause
  any breakage, but still.
  
  __COUNTER__ was also added to GCC 4.3, but since that implementation is
  GPLv3 licensed, I took the liberty of implementing it without looking at
  any upstream sources. Therefore, this version is licensed under the same
  license as the rest of the code; GPLv2.

Modified:
  head/contrib/gcclibs/libcpp/include/cpplib.h
  head/contrib/gcclibs/libcpp/init.c
  head/contrib/gcclibs/libcpp/internal.h
  head/contrib/gcclibs/libcpp/macro.c

Modified: head/contrib/gcclibs/libcpp/include/cpplib.h
==============================================================================
--- head/contrib/gcclibs/libcpp/include/cpplib.h	Tue Dec 13 14:53:26 2011	(r228473)
+++ head/contrib/gcclibs/libcpp/include/cpplib.h	Tue Dec 13 17:34:47 2011	(r228474)
@@ -555,7 +555,8 @@ enum builtin_type
   BT_TIME,			/* `__TIME__' */
   BT_STDC,			/* `__STDC__' */
   BT_PRAGMA,			/* `_Pragma' operator */
-  BT_TIMESTAMP			/* `__TIMESTAMP__' */
+  BT_TIMESTAMP,			/* `__TIMESTAMP__' */
+  BT_COUNTER			/* `__COUNTER__' */
 };
 
 #define CPP_HASHNODE(HNODE)	((cpp_hashnode *) (HNODE))

Modified: head/contrib/gcclibs/libcpp/init.c
==============================================================================
--- head/contrib/gcclibs/libcpp/init.c	Tue Dec 13 14:53:26 2011	(r228473)
+++ head/contrib/gcclibs/libcpp/init.c	Tue Dec 13 17:34:47 2011	(r228474)
@@ -308,6 +308,7 @@ static const struct builtin builtin_arra
   B("__BASE_FILE__",	 BT_BASE_FILE),
   B("__LINE__",		 BT_SPECLINE),
   B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
+  B("__COUNTER__",	 BT_COUNTER),
   /* Keep builtins not used for -traditional-cpp at the end, and
      update init_builtins() if any more are added.  */
   B("_Pragma",		 BT_PRAGMA),

Modified: head/contrib/gcclibs/libcpp/internal.h
==============================================================================
--- head/contrib/gcclibs/libcpp/internal.h	Tue Dec 13 14:53:26 2011	(r228473)
+++ head/contrib/gcclibs/libcpp/internal.h	Tue Dec 13 17:34:47 2011	(r228474)
@@ -448,6 +448,8 @@ struct cpp_reader
   /* A saved list of the defined macros, for dependency checking
      of precompiled headers.  */
   struct cpp_savedstate *savedstate;
+
+  unsigned int nextcounter;
 };
 
 /* Character classes.  Based on the more primitive macros in safe-ctype.h.

Modified: head/contrib/gcclibs/libcpp/macro.c
==============================================================================
--- head/contrib/gcclibs/libcpp/macro.c	Tue Dec 13 14:53:26 2011	(r228473)
+++ head/contrib/gcclibs/libcpp/macro.c	Tue Dec 13 17:34:47 2011	(r228474)
@@ -262,6 +262,10 @@ _cpp_builtin_macro_text (cpp_reader *pfi
       else
 	result = pfile->time;
       break;
+
+    case BT_COUNTER:
+      number = pfile->nextcounter++;
+      break;
     }
 
   if (result == NULL)


More information about the svn-src-head mailing list