]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
macro.c (create_iso_definition): Create macro after saving parms.
authorNathan Sidwell <nathan@acm.org>
Tue, 17 Jul 2018 18:31:15 +0000 (18:31 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 17 Jul 2018 18:31:15 +0000 (18:31 +0000)
libcpp/
* macro.c (create_iso_definition): Create macro after saving
parms.
* traditional.c (_cpp_create_trad_definition): Likewise.

From-SVN: r262834

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

index 3127271a3ec790a8f99279aa92bcba7c571be439..bb9b5a745cefb22767ab3f531fa95b81446256cf 100644 (file)
@@ -1,3 +1,10 @@
+2018-07-17  Nathan Sidwell  <nathan@acm.org>
+
+       libcpp/
+       * macro.c (create_iso_definition): Create macro after saving
+       parms.
+       * traditional.c (_cpp_create_trad_definition): Likewise.
+
 2018-07-16  Nathan Sidwell  <nathan@acm.org>
 
        libcpp/
index 52ae6ce5a9b9bbc3f1ceb93a59c8de66f6cb991f..23edff7695e06183da4c38045823df5bdde1a04f 100644 (file)
@@ -3266,35 +3266,34 @@ lex_expansion_token (cpp_reader *pfile, cpp_macro *macro)
 static cpp_macro *
 create_iso_definition (cpp_reader *pfile)
 {
-  cpp_macro *macro = _cpp_new_macro (pfile, cmk_macro);
   bool following_paste_op = false;
   const char *paste_op_error_msg =
     N_("'##' cannot appear at either end of a macro expansion");
   unsigned int num_extra_tokens = 0;
   unsigned nparms = 0;
+  cpp_hashnode **params = NULL;
+  bool varadic = false;
   bool ok = false;
+  cpp_macro *macro = NULL;
 
   /* Look at the first token, to see if this is a function-like
      macro.   */
-  cpp_token *token = lex_expansion_token (pfile, macro);
+  cpp_token first;
+  cpp_token *saved_cur_token = pfile->cur_token;
+  pfile->cur_token = &first;
+  cpp_token *token = _cpp_lex_direct (pfile);
+  pfile->cur_token = saved_cur_token;
+
   if (token->flags & PREV_WHITE)
     /* Preceeded by space, must be part of expansion.  */;
   else if (token->type == CPP_OPEN_PAREN)
     {
       /* An open-paren, get a parameter list.  */
-      bool varadic = false;
-
-      /* Drop the '(' token.  */
-      macro->count = 0;
       if (!parse_params (pfile, &nparms, &varadic))
        goto out;
 
-      macro->parm.params = (cpp_hashnode **)_cpp_commit_buff
+      params = (cpp_hashnode **)_cpp_commit_buff
        (pfile, sizeof (cpp_hashnode *) * nparms);
-      macro->variadic = varadic;
-      macro->paramc = nparms;
-      macro->fun_like = 1;
-
       token = NULL;
     }
   else if (token->type != CPP_EOF
@@ -3336,6 +3335,23 @@ create_iso_definition (cpp_reader *pfile)
        }
     }
 
+  macro = _cpp_new_macro (pfile, cmk_macro);
+  if (!token)
+    {
+      macro->variadic = varadic;
+      macro->paramc = nparms;
+      macro->parm.params = params;
+      macro->fun_like = true;
+    }
+  else
+    {
+      /* Preserve the token we peeked.  */
+      void *base = _cpp_reserve_room (pfile, 0, sizeof (cpp_token));
+      *(cpp_token *)base = *token;
+      token = (cpp_token *)base;
+      macro->count = 1;
+    }
+
   for (vaopt_state vaopt_tracker (pfile, macro->variadic, true);; token = NULL)
     {
       if (!token)
index 17e4ef22dfacaad1019c448f94a6ebfba1d40b58..7166f2544a143926fe38376fbb32684dcd93f80a 100644 (file)
@@ -1180,11 +1180,12 @@ save_replacement_text (cpp_reader *pfile, cpp_macro *macro,
 cpp_macro *
 _cpp_create_trad_definition (cpp_reader *pfile)
 {
-  cpp_macro *macro = _cpp_new_macro (pfile, cmk_traditional);
   const uchar *cur;
   uchar *limit;
   cpp_context *context = pfile->context;
   unsigned nparms = 0;
+  int fun_like = 0;
+  cpp_hashnode **params = NULL;
 
   /* The context has not been set up for command line defines, and CUR
      has not been updated for the macro name for in-file defines.  */
@@ -1196,16 +1197,22 @@ _cpp_create_trad_definition (cpp_reader *pfile)
   /* Is this a function-like macro?  */
   if (* CUR (context) == '(')
     {
+      fun_like = +1;
       if (scan_parameters (pfile, &nparms))
-       {
-         macro->paramc = nparms;
-         macro->parm.params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff);
-         BUFF_FRONT (pfile->a_buff)
-           = (uchar *) &macro->parm.params[macro->paramc];
-         macro->fun_like = 1;
-       }
+       params = (cpp_hashnode **)_cpp_commit_buff
+         (pfile, sizeof (cpp_hashnode *) * nparms);
       else
-       macro = NULL;
+       fun_like = -1;
+    }
+
+  cpp_macro *macro = NULL;
+
+  if (fun_like >= 0)
+    {
+      macro = _cpp_new_macro (pfile, cmk_traditional);
+      macro->parm.params = params;
+      macro->paramc = nparms;
+      macro->fun_like = fun_like != 0;
     }
 
   /* Skip leading whitespace in the replacement text.  */