aboutsummaryrefslogtreecommitdiff
path: root/contrib/gcclibs
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2011-12-13 17:34:47 +0000
committerEd Schouten <ed@FreeBSD.org>2011-12-13 17:34:47 +0000
commitbdc971eb19f1587a855b446583dee42745f76fb5 (patch)
tree6680d81f129f0782fcd1515b1f4af7ce94045db6 /contrib/gcclibs
parent59340eb8e21aedfba9d715c137acdc668db134fd (diff)
downloadsrc-bdc971eb19f1587a855b446583dee42745f76fb5.tar.gz
src-bdc971eb19f1587a855b446583dee42745f76fb5.zip
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.
Notes
Notes: svn path=/head/; revision=228474
Diffstat (limited to 'contrib/gcclibs')
-rw-r--r--contrib/gcclibs/libcpp/include/cpplib.h3
-rw-r--r--contrib/gcclibs/libcpp/init.c1
-rw-r--r--contrib/gcclibs/libcpp/internal.h2
-rw-r--r--contrib/gcclibs/libcpp/macro.c4
4 files changed, 9 insertions, 1 deletions
diff --git a/contrib/gcclibs/libcpp/include/cpplib.h b/contrib/gcclibs/libcpp/include/cpplib.h
index 5fb80d9e8209..c6a5efc5f1ce 100644
--- a/contrib/gcclibs/libcpp/include/cpplib.h
+++ b/contrib/gcclibs/libcpp/include/cpplib.h
@@ -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))
diff --git a/contrib/gcclibs/libcpp/init.c b/contrib/gcclibs/libcpp/init.c
index 4330f884be72..8280f2fe1b45 100644
--- a/contrib/gcclibs/libcpp/init.c
+++ b/contrib/gcclibs/libcpp/init.c
@@ -308,6 +308,7 @@ static const struct builtin builtin_array[] =
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 --git a/contrib/gcclibs/libcpp/internal.h b/contrib/gcclibs/libcpp/internal.h
index 857bfe1d8c58..addff6120f05 100644
--- a/contrib/gcclibs/libcpp/internal.h
+++ b/contrib/gcclibs/libcpp/internal.h
@@ -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.
diff --git a/contrib/gcclibs/libcpp/macro.c b/contrib/gcclibs/libcpp/macro.c
index be50c111e32e..1eec5788f35b 100644
--- a/contrib/gcclibs/libcpp/macro.c
+++ b/contrib/gcclibs/libcpp/macro.c
@@ -262,6 +262,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
else
result = pfile->time;
break;
+
+ case BT_COUNTER:
+ number = pfile->nextcounter++;
+ break;
}
if (result == NULL)