cpp.texi: Update for new command line assertion syntax.
authorNeil Booth <neilb@earthling.net>
Tue, 31 Oct 2000 23:34:59 +0000 (23:34 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Tue, 31 Oct 2000 23:34:59 +0000 (23:34 +0000)
* 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

gcc/ChangeLog
gcc/cpp.texi
gcc/cpplib.c
gcc/testsuite/gcc.dg/cpp/assert3.c [new file with mode: 0644]

index b76c51e5be7e72cb524a50125858fa20070b5e40..b27a49a110ea60e64d56634b2984e499b9dcbd2e 100644 (file)
@@ -1,3 +1,12 @@
+2000-10-31  Neil Booth  <neilb@earthling.net>
+
+       * 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.
+
 2000-10-31  Neil Booth  <neilb@earthling.net>
 
        * cppmacro.c (STDC_0_IN_SYSTEM_HEADERS): Define to 0 if
index ffbd323ebad7c8f4a6890ba86b916add3201975f..457cbf2d9b61c0c735fd4877f6f21f4e921c4af7 100644 (file)
@@ -3364,12 +3364,14 @@ Define the macros @var{__GNUC__}, @var{__GNUC_MINOR__} and
 @var{__GNUC_PATCHLEVEL__}. These are defined automatically when you use
 @samp{gcc -E}; you can turn them off in that case with @samp{-no-gcc}.
 
-@item -A @var{predicate}(@var{answer})
+@item -A @var{predicate}=@var{answer}
 @findex -A
 Make an assertion with the predicate @var{predicate} and answer
-@var{answer}.  @xref{Assertions}.
+@var{answer}.  This form is preferred to the older form @samp{-A
+@var{predicate}(@var{answer})}, which is still supported, because
+it does not use shell special characters.  @xref{Assertions}.
 
-@item -A -@var{predicate}(@var{answer})
+@item -A -@var{predicate}=@var{answer}
 Disable an assertion with the predicate @var{predicate} and answer
 @var{answer}.  Specifying no predicate, by @samp{-A-} or @samp{-A -},
 disables all predefined assertions and all assertions preceding it on
index 12fa982885639c1cf64206043b4b92a8bad706fa..cd14ba4e83a21cea036ffc2a2649bd48c90a1fd2 100644 (file)
@@ -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)
diff --git a/gcc/testsuite/gcc.dg/cpp/assert3.c b/gcc/testsuite/gcc.dg/cpp/assert3.c
new file mode 100644 (file)
index 0000000..df9b19f
--- /dev/null
@@ -0,0 +1,10 @@
+/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+
+/* { dg-do preprocess } */
+/* { dg-options "-A abc=def -A abc\(ghi\) \"-Aabc = jkl\" -A abc=mno -A -abc=mno" } */
+
+/* Test -A command line syntax.  Source Neil Booth.  31 Oct 2000.  */
+
+#if !#abc (def) || !#abc (ghi) || !#abc (jkl) || #abc(mno)
+#error Command line -A assertions
+#endif