]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas/macro: drop ISSEP()
authorJan Beulich <jbeulich@suse.com>
Fri, 12 Dec 2025 07:04:41 +0000 (08:04 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 12 Dec 2025 07:04:41 +0000 (08:04 +0100)
I've been irritated by it more than once: It very obviously doesn't cover
all separators, hence resulting in inconsistent behavior. Nor do both use
sites look to really want the same set of separators. In macro_expand() we
really can pull the get_token() call ahead. If we don't find the expected
'=' we can simply continue parsing from the original position.

The use in get_any_string() is dead code afaict, inherited from gasp. The
sole leftover thereof is handled in the scrubber (see H_TICK_HEX,
LEX_IS_H, and alike there). With that dropped, ISBASE() also can be.

gas/macro.c

index b272800388a4f96b7692baa449feb778de938275..4bb66004f1ba738e6e6c4433f4894cd57ef210ef 100644 (file)
 /* The routines in this file handle macro definition and expansion.
    They are called by gas.  */
 
-#define ISSEP(x) \
- (is_whitespace (x) || (x) == ',' || (x) == '"' || (x) == ';' \
-  || (x) == ')' || (x) == '(' \
-  || ((flag_macro_alternate || flag_mri) && ((x) == '<' || (x) == '>')))
-
-#define ISBASE(x) \
-  ((x) == 'b' || (x) == 'B' \
-   || (x) == 'q' || (x) == 'Q' \
-   || (x) == 'h' || (x) == 'H' \
-   || (x) == 'd' || (x) == 'D')
-
 /* The macro hash table.  */
 
 htab_t macro_hash;
@@ -347,7 +336,6 @@ getstring (size_t idx, sb *in, sb *acc)
 
 /* Fetch string from the input stream,
    rules:
-    'Bxyx<whitespace>          -> return 'Bxyza
     %<expr>            -> return string of decimal value of <expr>
     "string"           -> return string
     (string)           -> return (string-including-whitespaces)
@@ -361,12 +349,7 @@ get_any_string (size_t idx, sb *in, sb *out)
 
   if (idx < in->len)
     {
-      if (in->len > idx + 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
-       {
-         while (idx < in->len && !ISSEP (in->ptr[idx]))
-           sb_add_char (out, in->ptr[idx++]);
-       }
-      else if (in->ptr[idx] == '%' && flag_macro_alternate)
+      if (in->ptr[idx] == '%' && flag_macro_alternate)
        {
          /* Turn the following expression into a string.  */
          expressionS ex;
@@ -1069,31 +1052,18 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
   idx = sb_skip_white (idx, in);
   while (idx < in->len)
     {
+      /* Look and see if it's a positional or keyword arg.  */
       size_t scan;
 
-      /* Look and see if it's a positional or keyword arg.  */
-      scan = idx;
-      while (scan < in->len
-            && !ISSEP (in->ptr[scan])
-            && !(flag_mri && in->ptr[scan] == '\'')
-            && (!flag_macro_alternate && in->ptr[scan] != '='))
-       scan++;
-      if (scan < in->len && !flag_macro_alternate && in->ptr[scan] == '=')
+      sb_reset (&t);
+      scan = !flag_macro_alternate ? get_token (idx, in, &t) : idx;
+
+      if (scan > idx && scan < in->len && in->ptr[scan] == '=')
        {
          is_keyword = 1;
 
          /* It's OK to go from positional to keyword.  */
 
-         /* This is a keyword arg, fetch the formal name and
-            then the actual stuff.  */
-         sb_reset (&t);
-         idx = get_token (idx, in, &t);
-         if (idx >= in->len || in->ptr[idx] != '=')
-           {
-             err = _("confusion in formal parameters");
-             break;
-           }
-
          /* Lookup the formal in the macro's list.  */
          ptr = str_hash_find (m->formal_hash, sb_terminate (&t));
          if (!ptr)
@@ -1102,7 +1072,8 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
                      t.ptr,
                      m->name);
              sb_reset (&t);
-             idx = get_any_string (idx + 1, in, &t);
+             /* Skip what would be the actual stuff.  */
+             idx = get_any_string (scan + 1, in, &t);
            }
          else
            {
@@ -1114,7 +1085,8 @@ macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
                           m->name);
                  sb_reset (&ptr->actual);
                }
-             idx = get_any_string (idx + 1, in, &ptr->actual);
+             /* Fetch the actual stuff.  */
+             idx = get_any_string (scan + 1, in, &ptr->actual);
              if (ptr->actual.len > 0)
                ++narg;
            }