Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu/dist/gcc4/libcpp Teach gcc4.1's cpp about the magic __CO...



details:   https://anonhg.NetBSD.org/src/rev/def4819f19ab
branches:  trunk
changeset: 782866:def4819f19ab
user:      apb <apb%NetBSD.org@localhost>
date:      Sat Nov 24 09:07:44 2012 +0000

description:
Teach gcc4.1's cpp about the magic __COUNTER__ macro,
which returns a unique integer each time it is expanded.
This code was written without reference to any other
implementation of the same feature.

diffstat:

 gnu/dist/gcc4/libcpp/include/cpplib.h |  1 +
 gnu/dist/gcc4/libcpp/init.c           |  1 +
 gnu/dist/gcc4/libcpp/macro.c          |  8 ++++++++
 3 files changed, 10 insertions(+), 0 deletions(-)

diffs (40 lines):

diff -r 56ad005c4d87 -r def4819f19ab gnu/dist/gcc4/libcpp/include/cpplib.h
--- a/gnu/dist/gcc4/libcpp/include/cpplib.h     Sat Nov 24 07:16:04 2012 +0000
+++ b/gnu/dist/gcc4/libcpp/include/cpplib.h     Sat Nov 24 09:07:44 2012 +0000
@@ -551,6 +551,7 @@
   BT_BASE_FILE,                        /* `__BASE_FILE__' */
   BT_INCLUDE_LEVEL,            /* `__INCLUDE_LEVEL__' */
   BT_TIME,                     /* `__TIME__' */
+  BT_COUNTER,                  /* `__COUNTER__' */
   BT_STDC,                     /* `__STDC__' */
   BT_PRAGMA                    /* `_Pragma' operator */
 };
diff -r 56ad005c4d87 -r def4819f19ab gnu/dist/gcc4/libcpp/init.c
--- a/gnu/dist/gcc4/libcpp/init.c       Sat Nov 24 07:16:04 2012 +0000
+++ b/gnu/dist/gcc4/libcpp/init.c       Sat Nov 24 09:07:44 2012 +0000
@@ -309,6 +309,7 @@
   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),
diff -r 56ad005c4d87 -r def4819f19ab gnu/dist/gcc4/libcpp/macro.c
--- a/gnu/dist/gcc4/libcpp/macro.c      Sat Nov 24 07:16:04 2012 +0000
+++ b/gnu/dist/gcc4/libcpp/macro.c      Sat Nov 24 09:07:44 2012 +0000
@@ -284,6 +284,14 @@
       else
        result = pfile->time;
       break;
+
+    case BT_COUNTER:
+      {
+       static unsigned int counter = 0;
+
+       number = counter++;
+      }
+      break;
     }
 
   if (result == NULL)



Home | Main Index | Thread Index | Old Index