include/opcode/
[deliverable/binutils-gdb.git] / gas / macro.c
index 76e3664b22ef47eafad4f035e70f6da273031385..e6e9d05ba2728814140a2cfefc7e7add80497610 100644 (file)
@@ -70,7 +70,7 @@ extern void *alloca ();
 
 static int get_token (int, sb *, sb *);
 static int getstring (int, sb *, sb *);
-static int get_any_string (int, sb *, sb *, int, int);
+static int get_any_string (int, sb *, sb *);
 static formal_entry *new_formal (void);
 static void del_formal (formal_entry *);
 static int do_formals (macro_entry *, int, sb *);
@@ -180,49 +180,46 @@ buffer_and_nest (const char *from, const char *to, sb *ptr,
 
   while (more)
     {
-      /* Try and find the first pseudo op on the line.  */
+      /* Try to find the first pseudo op on the line.  */
       int i = line_start;
 
-      if (! NO_PSEUDO_DOT && ! flag_m68k_mri)
-       {
-         /* With normal syntax we can suck what we want till we get
-            to the dot.  With the alternate, labels have to start in
-            the first column, since we can't tell what's a label and
-            whats a pseudoop.  */
+      /* With normal syntax we can suck what we want till we get
+        to the dot.  With the alternate, labels have to start in
+        the first column, since we can't tell what's a label and
+        what's a pseudoop.  */
 
-         if (! LABELS_WITHOUT_COLONS)
-           {
-             /* Skip leading whitespace.  */
-             while (i < ptr->len && ISWHITE (ptr->ptr[i]))
-               i++;
-           }
+      if (! LABELS_WITHOUT_COLONS)
+       {
+         /* Skip leading whitespace.  */
+         while (i < ptr->len && ISWHITE (ptr->ptr[i]))
+           i++;
+       }
 
-         for (;;)
+      for (;;)
+       {
+         /* Skip over a label, if any.  */
+         if (i >= ptr->len || ! is_name_beginner (ptr->ptr[i]))
+           break;
+         i++;
+         while (i < ptr->len && is_part_of_name (ptr->ptr[i]))
+           i++;
+         if (i < ptr->len && is_name_ender (ptr->ptr[i]))
+           i++;
+         if (LABELS_WITHOUT_COLONS)
+           break;
+         /* Skip whitespace.  */
+         while (i < ptr->len && ISWHITE (ptr->ptr[i]))
+           i++;
+         /* Check for the colon.  */
+         if (i >= ptr->len || ptr->ptr[i] != ':')
            {
-             /* Skip over a label, if any.  */
-             if (i >= ptr->len || ! is_name_beginner (ptr->ptr[i]))
-               break;
-             i++;
-             while (i < ptr->len && is_part_of_name (ptr->ptr[i]))
-               i++;
-             if (i < ptr->len && is_name_ender (ptr->ptr[i]))
-               i++;
-             if (LABELS_WITHOUT_COLONS)
-               break;
-             /* Skip whitespace.  */
-             while (i < ptr->len && ISWHITE (ptr->ptr[i]))
-               i++;
-             /* Check for the colon.  */
-             if (i >= ptr->len || ptr->ptr[i] != ':')
-               {
-                 i = line_start;
-                 break;
-               }
-             i++;
-             line_start = i;
+             i = line_start;
+             break;
            }
-
+         i++;
+         line_start = i;
        }
+
       /* Skip trailing whitespace.  */
       while (i < ptr->len && ISWHITE (ptr->ptr[i]))
        i++;
@@ -304,8 +301,6 @@ get_token (int idx, sb *in, sb *name)
 static int
 getstring (int idx, sb *in, sb *acc)
 {
-  idx = sb_skip_white (idx, in);
-
   while (idx < in->len
         && (in->ptr[idx] == '"'
             || (in->ptr[idx] == '<' && (macro_alternate || macro_mri))
@@ -384,13 +379,13 @@ getstring (int idx, sb *in, sb *acc)
 /* Fetch string from the input stream,
    rules:
     'Bxyx<whitespace>          -> return 'Bxyza
-    %<char>            -> return string of decimal value of x
-    "<string>"         -> return string
-    xyx<whitespace>     -> return xyz
-*/
+    %<expr>            -> return string of decimal value of <expr>
+    "string"           -> return string
+    (string)           -> return (string-including-whitespaces)
+    xyx<whitespace>     -> return xyz.  */
 
 static int
-get_any_string (int idx, sb *in, sb *out, int expand, int pretend_quoted)
+get_any_string (int idx, sb *in, sb *out)
 {
   sb_reset (out);
   idx = sb_skip_white (idx, in);
@@ -402,12 +397,11 @@ get_any_string (int idx, sb *in, sb *out, int expand, int pretend_quoted)
          while (!ISSEP (in->ptr[idx]))
            sb_add_char (out, in->ptr[idx++]);
        }
-      else if (in->ptr[idx] == '%'
-              && macro_alternate
-              && expand)
+      else if (in->ptr[idx] == '%' && macro_alternate)
        {
          int val;
          char buf[20];
+
          /* Turns the next expression into a string.  */
          /* xgettext: no-c-format */
          idx = (*macro_expr) (_("% operator needs absolute expression"),
@@ -421,15 +415,12 @@ get_any_string (int idx, sb *in, sb *out, int expand, int pretend_quoted)
               || (in->ptr[idx] == '<' && (macro_alternate || macro_mri))
               || (macro_alternate && in->ptr[idx] == '\''))
        {
-         if (macro_alternate
-             && ! macro_strip_at
-             && expand)
+         if (macro_alternate && ! macro_strip_at && in->ptr[idx] != '<')
            {
              /* Keep the quotes.  */
-             sb_add_char (out, '\"');
-
+             sb_add_char (out, '"');
              idx = getstring (idx, in, out);
-             sb_add_char (out, '\"');
+             sb_add_char (out, '"');
            }
          else
            {
@@ -438,29 +429,57 @@ get_any_string (int idx, sb *in, sb *out, int expand, int pretend_quoted)
        }
       else
        {
+         char *br_buf = xmalloc(1);
+         char *in_br = br_buf;
+
+         *in_br = '\0';
          while (idx < in->len
-                && (in->ptr[idx] == '"'
-                    || in->ptr[idx] == '\''
-                    || pretend_quoted
+                && (*in_br
                     || (in->ptr[idx] != ' '
-                        && in->ptr[idx] != '\t'
-                        && in->ptr[idx] != ','
-                        && (in->ptr[idx] != '<'
-                            || (! macro_alternate && ! macro_mri)))))
+                        && in->ptr[idx] != '\t'))
+                && in->ptr[idx] != ','
+                && (in->ptr[idx] != '<'
+                    || (! macro_alternate && ! macro_mri)))
            {
-             if (in->ptr[idx] == '"'
-                 || in->ptr[idx] == '\'')
+             char tchar = in->ptr[idx];
+
+             switch (tchar)
                {
-                 char tchar = in->ptr[idx];
+               case '"':
+               case '\'':
                  sb_add_char (out, in->ptr[idx++]);
                  while (idx < in->len
                         && in->ptr[idx] != tchar)
                    sb_add_char (out, in->ptr[idx++]);
                  if (idx == in->len)
                    return idx;
+                 break;
+               case '(':
+               case '[':
+                 if (in_br > br_buf)
+                   --in_br;
+                 else
+                   {
+                     br_buf = xmalloc(strlen(in_br) + 2);
+                     strcpy(br_buf + 1, in_br);
+                     free(in_br);
+                     in_br = br_buf;
+                   }
+                 *in_br = tchar;
+                 break;
+               case ')':
+                 if (*in_br == '(')
+                   ++in_br;
+                 break;
+               case ']':
+                 if (*in_br == '[')
+                   ++in_br;
+                 break;
                }
-             sb_add_char (out, in->ptr[idx++]);
+             sb_add_char (out, tchar);
+             ++idx;
            }
+         free(br_buf);
        }
     }
 
@@ -555,7 +574,7 @@ do_formals (macro_entry *macro, int idx, sb *in)
       if (idx < in->len && in->ptr[idx] == '=')
        {
          /* Got a default.  */
-         idx = get_any_string (idx + 1, in, &formal->def, 1, 0);
+         idx = get_any_string (idx + 1, in, &formal->def);
          idx = sb_skip_white (idx, in);
          if (formal->type == FORMAL_REQUIRED)
            {
@@ -1006,7 +1025,6 @@ macro_expand (int idx, sb *in, macro_entry *m, sb *out)
   sb t;
   formal_entry *ptr;
   formal_entry *f;
-  int is_positional = 0;
   int is_keyword = 0;
   int narg = 0;
   const char *err = NULL;
@@ -1040,7 +1058,7 @@ macro_expand (int idx, sb *in, macro_entry *m, sb *out)
              n->next = m->formals;
              m->formals = n;
 
-             idx = get_any_string (idx, in, &n->actual, 1, 0);
+             idx = get_any_string (idx, in, &n->actual);
            }
        }
     }
@@ -1090,15 +1108,13 @@ macro_expand (int idx, sb *in, macro_entry *m, sb *out)
                           m->name);
                  sb_reset (&ptr->actual);
                }
-             idx = get_any_string (idx + 1, in, &ptr->actual, 0, 0);
+             idx = get_any_string (idx + 1, in, &ptr->actual);
              if (ptr->actual.len > 0)
                ++narg;
            }
        }
       else
        {
-         /* This is a positional arg.  */
-         is_positional = 1;
          if (is_keyword)
            {
              err = _("can't mix positional and keyword arguments");
@@ -1129,7 +1145,7 @@ macro_expand (int idx, sb *in, macro_entry *m, sb *out)
            }
 
          if (f->type != FORMAL_VARARG)
-           idx = get_any_string (idx, in, &f->actual, 1, 0);
+           idx = get_any_string (idx, in, &f->actual);
          else
            {
              sb_add_buffer (&f->actual, in->ptr + idx, in->len - idx);
@@ -1350,7 +1366,7 @@ expand_irp (int irpc, int idx, sb *in, sb *out, int (*get_line) (sb *))
       while (idx < in->len)
        {
          if (!irpc)
-           idx = get_any_string (idx, in, &f.actual, 1, 0);
+           idx = get_any_string (idx, in, &f.actual);
          else
            {
              if (in->ptr[idx] == '"')
This page took 0.028912 seconds and 4 git commands to generate.