diff options
author | Neil Booth <neilb@earthling.net> | 2000-10-31 23:34:59 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2000-10-31 23:34:59 +0000 |
commit | 86368122e68f2b697cf898523d408bea831fa6e7 (patch) | |
tree | e504a7a4e2c4a7bde207adaf17b32b6b047226da /gcc/cpplib.c | |
parent | e199824280b56df47f390fbbdc727f9219d4408f (diff) | |
download | gcc-86368122e68f2b697cf898523d408bea831fa6e7.zip gcc-86368122e68f2b697cf898523d408bea831fa6e7.tar.gz gcc-86368122e68f2b697cf898523d408bea831fa6e7.tar.bz2 |
cpp.texi: Update for new command line assertion syntax.
* cpp.texi: Update for new command line assertion syntax.
* cpplib.c (cpp_define): Simplify a bit.
(cpp_assert, cpp_unassert): Use handle_assertion.
(handle_assertion): New function; accept new command line
syntax with '='.
* testsuite/gcc.dg/cpp/assert3.c: New tests.
From-SVN: r37171
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 58 |
1 files changed, 40 insertions, 18 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 12fa982..cd14ba4 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -107,6 +107,7 @@ static cpp_hashnode *parse_assertion PARAMS ((cpp_reader *, struct answer **, int)); static struct answer ** find_answer PARAMS ((cpp_hashnode *, const struct answer *)); +static void handle_assertion PARAMS ((cpp_reader *, const char *, int)); /* This is the table of directive handlers. It is ordered by frequency of occurrence; the numbers at the end are directive @@ -1608,29 +1609,25 @@ cpp_define (pfile, str) char *buf, *p; size_t count; - p = strchr (str, '='); /* Copy the entire option so we can modify it. Change the first "=" in the string to a space. If there is none, - tack " 1" on the end. Then add a newline and a NUL. */ - + tack " 1" on the end. */ + + /* Length including the null. */ + count = strlen (str); + buf = (char *) alloca (count + 2); + memcpy (buf, str, count); + + p = strchr (str, '='); if (p) - { - count = strlen (str) + 2; - buf = (char *) alloca (count); - memcpy (buf, str, count - 2); - buf[p - str] = ' '; - buf[count - 2] = '\n'; - buf[count - 1] = '\0'; - } + buf[p - str] = ' '; else { - count = strlen (str) + 4; - buf = (char *) alloca (count); - memcpy (buf, str, count - 4); - strcpy (&buf[count-4], " 1\n"); + buf[count++] = ' '; + buf[count++] = '1'; } - run_directive (pfile, T_DEFINE, buf, count - 1, 0); + run_directive (pfile, T_DEFINE, buf, count, 0); } /* Slight variant of the above for use by initialize_builtins, which (a) @@ -1659,7 +1656,7 @@ cpp_assert (pfile, str) cpp_reader *pfile; const char *str; { - run_directive (pfile, T_ASSERT, str, strlen (str), 0); + handle_assertion (pfile, str, T_ASSERT); } /* Process STR as if it appeared as the body of an #unassert. */ @@ -1668,9 +1665,34 @@ cpp_unassert (pfile, str) cpp_reader *pfile; const char *str; { - run_directive (pfile, T_UNASSERT, str, strlen (str), 0); + handle_assertion (pfile, str, T_UNASSERT); } +/* Common code for cpp_assert (-A) and cpp_unassert (-A-). */ +static void +handle_assertion (pfile, str, type) + cpp_reader *pfile; + const char *str; + int type; +{ + size_t count = strlen (str); + const char *p = strchr (str, '='); + + if (p) + { + /* Copy the entire option so we can modify it. Change the first + "=" in the string to a '(', and tack a ')' on the end. */ + char *buf = (char *) alloca (count + 1); + + memcpy (buf, str, count); + buf[p - str] = '('; + buf[count++] = ')'; + str = buf; + } + + run_directive (pfile, type, str, count, 0); +} + /* Determine whether the identifier ID, of length LEN, is a defined macro. */ int cpp_defined (pfile, id, len) |