]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
internal.h (_cpp_save_parameter): Take parm no, not macro.
authorNathan Sidwell <nathan@acm.org>
Fri, 13 Jul 2018 15:37:31 +0000 (15:37 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 13 Jul 2018 15:37:31 +0000 (15:37 +0000)
libcpp/
* internal.h (_cpp_save_parameter): Take parm no, not macro.
* macro,c (_cpp_save_parameter): Adjust.  Invert sense of return value.
(parse_params): Adjust.
* traditional.c (scan_parameters): Likewise.

From-SVN: r262638

ChangeLog.name-lookup
libcpp/internal.h
libcpp/macro.c
libcpp/traditional.c

index f3537036cf673c634dee8f3340520e066624a9cb..f954e4508fec659763c4343451d03e5f16db28c7 100644 (file)
@@ -1,3 +1,11 @@
+2018-07-13  Nathan Sidwell  <nathan@acm.org>
+
+       libcpp/
+       * internal.h (_cpp_save_parameter): Take parm no, not macro.
+       * macro,c (_cpp_save_parameter): Adjust.  Invert sense of return value.
+       (parse_params): Adjust.
+       * traditional.c (scan_parameters): Likewise.
+
 2018-07-12  Nathan Sidwell  <nathan@acm.org>
 
        assert body is indirect.
index 782d8e6349f90a890dba97c6e9431b81aff3c50f..e4db3c3ae54070b7921e2d6588ce8a1715c3a8d1 100644 (file)
@@ -627,7 +627,7 @@ extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
 extern void _cpp_pop_context (cpp_reader *);
 extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
                                    const unsigned char *, size_t);
-extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *,
+extern bool _cpp_save_parameter (cpp_reader *, unsigned, cpp_hashnode *,
                                 cpp_hashnode *);
 extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
                               unsigned int);
index 0d798fdc4ca294a75ae6b91260895dc51b699152..d4a5a7794684039d2782c6613b9ce483da3812dd 100644 (file)
@@ -3060,42 +3060,43 @@ _cpp_free_definition (cpp_hashnode *h)
 }
 
 /* Save parameter NODE (spelling SPELLING) to the parameter list of
-   macro MACRO.  Returns zero on success, nonzero if the parameter is
-   a duplicate.  */
+   macro MACRO.  Returns true on success, false on failure.   */
+
 bool
-_cpp_save_parameter (cpp_reader *pfile, cpp_macro *macro, cpp_hashnode *node,
+_cpp_save_parameter (cpp_reader *pfile, unsigned n, cpp_hashnode *node,
                     cpp_hashnode *spelling)
 {
-  unsigned int len;
   /* Constraint 6.10.3.6 - duplicate parameter names.  */
   if (node->flags & NODE_MACRO_ARG)
     {
       cpp_error (pfile, CPP_DL_ERROR, "duplicate macro parameter \"%s\"",
                 NODE_NAME (node));
-      return true;
+      return false;
     }
 
-  if (BUFF_ROOM (pfile->a_buff)
-      < (macro->paramc + 1) * sizeof (cpp_hashnode *))
-    _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_hashnode *));
-
-  ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[macro->paramc++] = spelling;
-  node->flags |= NODE_MACRO_ARG;
-  len = macro->paramc * sizeof (struct macro_arg_saved_data);
+  unsigned len = (n + 1) * sizeof (struct macro_arg_saved_data);
   if (len > pfile->macro_buffer_len)
     {
-      pfile->macro_buffer = XRESIZEVEC (unsigned char, pfile->macro_buffer,
-                                        len);
+      pfile->macro_buffer
+       = XRESIZEVEC (unsigned char, pfile->macro_buffer, len);
       pfile->macro_buffer_len = len;
     }
-  struct macro_arg_saved_data save;
-  save.value = node->value;
-  save.canonical_node = node;
-  ((struct macro_arg_saved_data *) pfile->macro_buffer)[macro->paramc - 1]
-    = save;
   
-  node->value.arg_index  = macro->paramc;
-  return false;
+  macro_arg_saved_data *saved = (macro_arg_saved_data *)pfile->macro_buffer;
+  saved[n].value = node->value;
+  saved[n].canonical_node = node;
+
+  if (BUFF_ROOM (pfile->a_buff) < (n + 1) * sizeof (cpp_hashnode *))
+    _cpp_extend_buff (pfile, &pfile->a_buff, sizeof (cpp_hashnode *));
+
+  ((cpp_hashnode **) BUFF_FRONT (pfile->a_buff))[n++] = spelling;
+
+  /* Morph into a macro arg.  */
+  node->flags |= NODE_MACRO_ARG;
+  /* Index is 1 based.  */
+  node->value.arg_index = n;
+
+  return true;
 }
 
 /* Check the syntax of the parameters in a MACRO definition.  Returns
@@ -3104,6 +3105,8 @@ static bool
 parse_params (cpp_reader *pfile, cpp_macro *macro)
 {
   unsigned int prev_ident = 0;
+  unsigned nparms = 0;
+  bool ok = false;
 
   for (;;)
     {
@@ -3121,25 +3124,29 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
          cpp_error (pfile, CPP_DL_ERROR,
                     "\"%s\" may not appear in macro parameter list",
                     cpp_token_as_text (pfile, token));
-         return false;
+         goto out;
 
        case CPP_NAME:
          if (prev_ident)
            {
              cpp_error (pfile, CPP_DL_ERROR,
                         "macro parameters must be comma-separated");
-             return false;
+             goto out;
            }
          prev_ident = 1;
 
-         if (_cpp_save_parameter (pfile, macro, token->val.node.node,
-                                  token->val.node.spelling))
-           return false;
+         if (!_cpp_save_parameter (pfile, nparms, token->val.node.node,
+                                   token->val.node.spelling))
+           goto out;
+         nparms++;
          continue;
 
        case CPP_CLOSE_PAREN:
-         if (prev_ident || macro->paramc == 0)
-           return true;
+         if (prev_ident || !nparms)
+           {
+             ok = true;
+             goto out;
+           }
 
          /* Fall through to pick up the error.  */
          /* FALLTHRU */
@@ -3147,7 +3154,7 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
          if (!prev_ident)
            {
              cpp_error (pfile, CPP_DL_ERROR, "parameter name missing");
-             return false;
+             goto out;
            }
          prev_ident = 0;
          continue;
@@ -3156,9 +3163,10 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
          macro->variadic = 1;
          if (!prev_ident)
            {
-             _cpp_save_parameter (pfile, macro,
+             _cpp_save_parameter (pfile, nparms,
                                   pfile->spec_nodes.n__VA_ARGS__,
                                   pfile->spec_nodes.n__VA_ARGS__);
+             nparms++;
              pfile->state.va_args_ok = 1;
              if (! CPP_OPTION (pfile, c99)
                  && CPP_OPTION (pfile, cpp_pedantic)
@@ -3192,14 +3200,22 @@ parse_params (cpp_reader *pfile, cpp_macro *macro)
          /* We're at the end, and just expect a closing parenthesis.  */
          token = _cpp_lex_token (pfile);
          if (token->type == CPP_CLOSE_PAREN)
-           return true;
+           {
+             ok = true;
+             goto out;
+           }
+
          /* Fall through.  */
 
        case CPP_EOF:
          cpp_error (pfile, CPP_DL_ERROR, "missing ')' in macro parameter list");
-         return false;
+         goto out;
        }
     }
+
+ out:
+  macro->paramc = nparms;
+  return ok;
 }
 
 /* Allocate room for a token from a macro's replacement list.  */
index 795fb277ac479fe8bdac7cb263c30d34d4e7c180..1e0b0a82d1aacbd760e245005d4d9051363935a3 100644 (file)
@@ -1087,6 +1087,7 @@ scan_parameters (cpp_reader *pfile, cpp_macro *macro)
   const uchar *cur = CUR (pfile->context) + 1;
   bool ok;
 
+  unsigned nparms = 0;
   for (;;)
     {
       cur = skip_whitespace (pfile, cur, true /* skip_comments */);
@@ -1095,8 +1096,9 @@ scan_parameters (cpp_reader *pfile, cpp_macro *macro)
        {
          struct cpp_hashnode *id = lex_identifier (pfile, cur);
          ok = false;
-         if (_cpp_save_parameter (pfile, macro, id, id))
+         if (!_cpp_save_parameter (pfile, nparms, id, id))
            break;
+         nparms++;
          cur = skip_whitespace (pfile, CUR (pfile->context),
                                 true /* skip_comments */);
          if (*cur == ',')
@@ -1108,10 +1110,12 @@ scan_parameters (cpp_reader *pfile, cpp_macro *macro)
          break;
        }
 
-      ok = (*cur == ')' && macro->paramc == 0);
+      ok = (*cur == ')' && !nparms);
       break;
     }
 
+  macro->paramc = nparms;
+
   if (!ok)
     cpp_error (pfile, CPP_DL_ERROR, "syntax error in macro parameter list");