Coverage Report

Created: 2025-07-08 11:15

/src/binutils-gdb/gas/macro.c
Line
Count
Source (jump to first uncovered line)
1
/* macro.c - macro support for gas
2
   Copyright (C) 1994-2025 Free Software Foundation, Inc.
3
4
   Written by Steve and Judy Chamberlain of Cygnus Support,
5
      sac@cygnus.com
6
7
   This file is part of GAS, the GNU Assembler.
8
9
   GAS is free software; you can redistribute it and/or modify
10
   it under the terms of the GNU General Public License as published by
11
   the Free Software Foundation; either version 3, or (at your option)
12
   any later version.
13
14
   GAS is distributed in the hope that it will be useful,
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
   GNU General Public License for more details.
18
19
   You should have received a copy of the GNU General Public License
20
   along with GAS; see the file COPYING.  If not, write to the Free
21
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22
   02110-1301, USA.  */
23
24
#include "as.h"
25
#include "safe-ctype.h"
26
#include "sb.h"
27
#include "macro.h"
28
29
/* The routines in this file handle macro definition and expansion.
30
   They are called by gas.  */
31
32
#define ISSEP(x) \
33
0
 (is_whitespace (x) || (x) == ',' || (x) == '"' || (x) == ';' \
34
0
  || (x) == ')' || (x) == '(' \
35
0
  || ((flag_macro_alternate || flag_mri) && ((x) == '<' || (x) == '>')))
36
37
#define ISBASE(x) \
38
0
  ((x) == 'b' || (x) == 'B' \
39
0
   || (x) == 'q' || (x) == 'Q' \
40
0
   || (x) == 'h' || (x) == 'H' \
41
0
   || (x) == 'd' || (x) == 'D')
42
43
/* The macro hash table.  */
44
45
htab_t macro_hash;
46
47
/* Whether any macros have been defined.  */
48
49
int macro_defined;
50
51
/* Whether we should strip '@' characters.  */
52
53
0
#define macro_strip_at false
54
55
/* Number of macro expansions that have been done.  */
56
57
static unsigned int macro_number;
58
59
static void free_macro (macro_entry *);
60
61
static void
62
macro_del_f (void *ent)
63
0
{
64
0
  string_tuple_t *tuple = ent;
65
0
  free_macro ((macro_entry *) tuple->value);
66
0
}
67
68
/* Initialize macro processing.  */
69
70
void
71
macro_init (void)
72
0
{
73
0
  macro_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
74
0
          macro_del_f, notes_calloc, NULL);
75
0
  macro_defined = 0;
76
0
}
77
78
void
79
macro_end (void)
80
0
{
81
0
  htab_delete (macro_hash);
82
0
}
83
84
/* Read input lines till we get to a TO string.
85
   Increase nesting depth if we get a FROM string.
86
   Put the results into sb at PTR.
87
   FROM may be NULL (or will be ignored) if TO is "ENDR".
88
   Add a new input line to an sb using GET_LINE.
89
   Return 1 on success, 0 on unexpected EOF.  */
90
91
int
92
buffer_and_nest (const char *from, const char *to, sb *ptr,
93
     size_t (*get_line) (sb *))
94
0
{
95
0
  size_t from_len;
96
0
  size_t to_len = strlen (to);
97
0
  int depth = 1;
98
0
  size_t line_start, more;
99
100
0
  if (to_len == 4 && strcasecmp (to, "ENDR") == 0)
101
0
    {
102
0
      from = NULL;
103
0
      from_len = 0;
104
0
    }
105
0
  else
106
0
    from_len = strlen (from);
107
108
  /* Record the present source position, such that diagnostics and debug info
109
     can be properly associated with the respective original lines, rather
110
     than with the line of the ending directive (TO).  */
111
0
  {
112
0
    unsigned int line;
113
0
    char *linefile;
114
115
0
    as_where_top (&line);
116
0
    if (!flag_m68k_mri)
117
0
      linefile = xasprintf ("\t.linefile %u .", line + 1);
118
0
    else
119
0
      linefile = xasprintf ("\tlinefile %u .", line + 1);
120
0
    sb_add_string (ptr, linefile);
121
0
    xfree (linefile);
122
0
  }
123
124
0
  line_start = ptr->len;
125
0
  more = get_line (ptr);
126
0
  while (more)
127
0
    {
128
      /* Try to find the first pseudo op on the line.  */
129
0
      size_t i = line_start;
130
0
      bool had_colon = false;
131
132
      /* With normal syntax we can suck what we want till we get
133
   to the dot.  With the alternate, labels have to start in
134
   the first column, since we can't tell what's a label and
135
   what's a pseudoop.  */
136
137
0
      if (! LABELS_WITHOUT_COLONS)
138
0
  {
139
    /* Skip leading whitespace.  */
140
0
    i = sb_skip_white (i, ptr);
141
0
  }
142
143
0
      for (;;)
144
0
  {
145
    /* Skip over a label, if any.  */
146
0
    if (i >= ptr->len || ! is_name_beginner (ptr->ptr[i]))
147
0
      break;
148
0
    i++;
149
0
    while (i < ptr->len && is_part_of_name (ptr->ptr[i]))
150
0
      i++;
151
0
    if (i < ptr->len && is_name_ender (ptr->ptr[i]))
152
0
      i++;
153
    /* Skip whitespace.  */
154
0
    i = sb_skip_white (i, ptr);
155
    /* Check for the colon.  */
156
0
    if (i >= ptr->len || ptr->ptr[i] != ':')
157
0
      {
158
        /* LABELS_WITHOUT_COLONS doesn't mean we cannot have a
159
     colon after a label.  If we do have a colon on the
160
     first label then handle more than one label on the
161
     line, assuming that each label has a colon.  */
162
0
        if (LABELS_WITHOUT_COLONS && !had_colon)
163
0
    break;
164
0
        i = line_start;
165
0
        break;
166
0
      }
167
0
    i++;
168
0
    line_start = i;
169
0
    had_colon = true;
170
0
  }
171
172
      /* Skip trailing whitespace.  */
173
0
      i = sb_skip_white (i, ptr);
174
175
0
      if (i < ptr->len && (ptr->ptr[i] == '.'
176
0
         || NO_PSEUDO_DOT
177
0
         || flag_mri))
178
0
  {
179
0
    if (! flag_m68k_mri && ptr->ptr[i] == '.')
180
0
      i++;
181
0
    size_t len = ptr->len - i;
182
0
    if (from == NULL)
183
0
      {
184
0
        if (len >= 5 && strncasecmp (ptr->ptr + i, "IREPC", 5) == 0)
185
0
    from_len = 5;
186
0
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IREP", 4) == 0)
187
0
    from_len = 4;
188
0
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "IRPC", 4) == 0)
189
0
    from_len = 4;
190
0
        else if (len >= 4 && strncasecmp (ptr->ptr + i, "REPT", 4) == 0)
191
0
    from_len = 4;
192
0
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "IRP", 3) == 0)
193
0
    from_len = 3;
194
0
        else if (len >= 3 && strncasecmp (ptr->ptr + i, "REP", 3) == 0)
195
0
    from_len = 3;
196
0
        else
197
0
    from_len = 0;
198
0
      }
199
0
    if ((from != NULL
200
0
         ? (len >= from_len
201
0
      && strncasecmp (ptr->ptr + i, from, from_len) == 0)
202
0
         : from_len > 0)
203
0
        && (len == from_len
204
0
      || ! (is_part_of_name (ptr->ptr[i + from_len])
205
0
      || is_name_ender (ptr->ptr[i + from_len]))))
206
0
      depth++;
207
0
    if (len >= to_len
208
0
        && strncasecmp (ptr->ptr + i, to, to_len) == 0
209
0
        && (len == to_len
210
0
      || ! (is_part_of_name (ptr->ptr[i + to_len])
211
0
      || is_name_ender (ptr->ptr[i + to_len]))))
212
0
      {
213
0
        depth--;
214
0
        if (depth == 0)
215
0
    {
216
      /* Reset the string to not include the ending rune.  */
217
0
      ptr->len = line_start;
218
219
      /* With the ending directive consumed here, announce the
220
         line for macro-expanded listings. */
221
0
      if (listing & LISTING_MACEXP)
222
0
        listing_newline (NULL);
223
0
      break;
224
0
    }
225
0
      }
226
227
    /* PR gas/16908
228
       Apply .linefile directives that appear within the macro, alongside
229
       keeping them for later expansion of the macro.  */
230
0
    if (from != NULL && strcasecmp (from, "MACRO") == 0
231
0
        && len >= 8 && strncasecmp (ptr->ptr + i, "linefile", 8) == 0)
232
0
      {
233
0
        sb_add_char (ptr, more);
234
0
        temp_ilp (sb_terminate (ptr) + i + 8);
235
0
        s_linefile (0);
236
0
        restore_ilp ();
237
0
        line_start = ptr->len;
238
0
        more = get_line (ptr);
239
0
        continue;
240
0
      }
241
0
  }
242
243
      /* Add the original end-of-line char to the end and keep running.  */
244
0
      sb_add_char (ptr, more);
245
0
      line_start = ptr->len;
246
0
      more = get_line (ptr);
247
0
    }
248
249
  /* Return 1 on success, 0 on unexpected EOF.  */
250
0
  return depth == 0;
251
0
}
252
253
/* Pick up a token.  */
254
255
static size_t
256
get_token (size_t idx, sb *in, sb *name)
257
0
{
258
0
  if (idx < in->len
259
0
      && is_name_beginner (in->ptr[idx]))
260
0
    {
261
0
      sb_add_char (name, in->ptr[idx++]);
262
0
      while (idx < in->len
263
0
       && is_part_of_name (in->ptr[idx]))
264
0
  {
265
0
    sb_add_char (name, in->ptr[idx++]);
266
0
  }
267
0
      if (idx < in->len
268
0
       && is_name_ender (in->ptr[idx]))
269
0
  {
270
0
    sb_add_char (name, in->ptr[idx++]);
271
0
  }
272
0
    }
273
  /* Ignore trailing &.  */
274
0
  if (flag_macro_alternate && idx < in->len && in->ptr[idx] == '&')
275
0
    idx++;
276
0
  return idx;
277
0
}
278
279
/* Pick up a string.  */
280
281
static size_t
282
getstring (size_t idx, sb *in, sb *acc)
283
0
{
284
0
  while (idx < in->len
285
0
   && (in->ptr[idx] == '"'
286
0
       || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
287
0
       || (in->ptr[idx] == '\'' && flag_macro_alternate)))
288
0
    {
289
0
      if (in->ptr[idx] == '<')
290
0
  {
291
0
    int nest = 0;
292
0
    idx++;
293
0
    while (idx < in->len
294
0
     && (in->ptr[idx] != '>' || nest))
295
0
      {
296
0
        if (in->ptr[idx] == '!')
297
0
    {
298
0
      idx++;
299
0
      sb_add_char (acc, in->ptr[idx++]);
300
0
    }
301
0
        else
302
0
    {
303
0
      if (in->ptr[idx] == '>')
304
0
        nest--;
305
0
      if (in->ptr[idx] == '<')
306
0
        nest++;
307
0
      sb_add_char (acc, in->ptr[idx++]);
308
0
    }
309
0
      }
310
0
    idx++;
311
0
  }
312
0
      else if (in->ptr[idx] == '"' || in->ptr[idx] == '\'')
313
0
  {
314
0
    char tchar = in->ptr[idx];
315
0
    int escaped = 0;
316
317
0
    idx++;
318
319
0
    while (idx < in->len)
320
0
      {
321
0
        if (in->ptr[idx - 1] == '\\')
322
0
    escaped ^= 1;
323
0
        else
324
0
    escaped = 0;
325
326
0
        if (flag_macro_alternate && in->ptr[idx] == '!')
327
0
    {
328
0
      idx ++;
329
330
0
      sb_add_char (acc, in->ptr[idx]);
331
332
0
      idx ++;
333
0
    }
334
0
        else if (escaped && in->ptr[idx] == tchar)
335
0
    {
336
0
      sb_add_char (acc, tchar);
337
0
      idx ++;
338
0
    }
339
0
        else
340
0
    {
341
0
      if (in->ptr[idx] == tchar)
342
0
        {
343
0
          idx ++;
344
345
0
          if (idx >= in->len || in->ptr[idx] != tchar)
346
0
      break;
347
0
        }
348
349
0
      sb_add_char (acc, in->ptr[idx]);
350
0
      idx ++;
351
0
    }
352
0
      }
353
0
  }
354
0
    }
355
356
0
  return idx;
357
0
}
358
359
/* Fetch string from the input stream,
360
   rules:
361
    'Bxyx<whitespace>   -> return 'Bxyza
362
    %<expr>   -> return string of decimal value of <expr>
363
    "string"    -> return string
364
    (string)    -> return (string-including-whitespaces)
365
    xyx<whitespace>     -> return xyz.  */
366
367
static size_t
368
get_any_string (size_t idx, sb *in, sb *out)
369
0
{
370
0
  sb_reset (out);
371
0
  idx = sb_skip_white (idx, in);
372
373
0
  if (idx < in->len)
374
0
    {
375
0
      if (in->len > idx + 2 && in->ptr[idx + 1] == '\'' && ISBASE (in->ptr[idx]))
376
0
  {
377
0
    while (idx < in->len && !ISSEP (in->ptr[idx]))
378
0
      sb_add_char (out, in->ptr[idx++]);
379
0
  }
380
0
      else if (in->ptr[idx] == '%' && flag_macro_alternate)
381
0
  {
382
    /* Turn the following expression into a string.  */
383
0
    expressionS ex;
384
0
    char buf[64];
385
386
0
    sb_terminate (in);
387
388
0
    temp_ilp (in->ptr + idx + 1);
389
0
    expression_and_evaluate (&ex);
390
0
    idx = input_line_pointer - in->ptr;
391
0
    restore_ilp ();
392
393
0
    if (ex.X_op != O_constant)
394
0
      as_bad (_("%% operator needs absolute expression"));
395
396
0
    sprintf (buf, "%" PRId64, (int64_t) ex.X_add_number);
397
0
    sb_add_string (out, buf);
398
0
  }
399
0
      else if (in->ptr[idx] == '"'
400
0
         || (in->ptr[idx] == '<' && (flag_macro_alternate || flag_mri))
401
0
         || (flag_macro_alternate && in->ptr[idx] == '\''))
402
0
  {
403
0
    if (flag_macro_alternate && ! macro_strip_at && in->ptr[idx] != '<')
404
0
      {
405
        /* Keep the quotes.  */
406
0
        sb_add_char (out, '"');
407
0
        idx = getstring (idx, in, out);
408
0
        sb_add_char (out, '"');
409
0
      }
410
0
    else
411
0
      {
412
0
        idx = getstring (idx, in, out);
413
0
      }
414
0
  }
415
0
      else
416
0
  {
417
0
    char *br_buf = XNEWVEC (char, 1);
418
0
    char *in_br = br_buf;
419
420
0
    *in_br = '\0';
421
0
    while (idx < in->len
422
0
     && (*in_br || !is_whitespace (in->ptr[idx]))
423
0
     && in->ptr[idx] != ','
424
0
     && (in->ptr[idx] != '<'
425
0
         || (! flag_macro_alternate && ! flag_mri)))
426
0
      {
427
0
        char tchar = in->ptr[idx];
428
429
0
        switch (tchar)
430
0
    {
431
0
    case '"':
432
0
    case '\'':
433
0
      sb_add_char (out, in->ptr[idx++]);
434
0
      while (idx < in->len
435
0
       && in->ptr[idx] != tchar)
436
0
        sb_add_char (out, in->ptr[idx++]);
437
0
      if (idx == in->len)
438
0
        {
439
0
          free (br_buf);
440
0
          return idx;
441
0
        }
442
0
      break;
443
0
    case '(':
444
0
    case '[':
445
0
      if (in_br > br_buf)
446
0
        --in_br;
447
0
      else
448
0
        {
449
0
          br_buf = XNEWVEC (char, strlen (in_br) + 2);
450
0
          strcpy (br_buf + 1, in_br);
451
0
          free (in_br);
452
0
          in_br = br_buf;
453
0
        }
454
0
      *in_br = tchar;
455
0
      break;
456
0
    case ')':
457
0
      if (*in_br == '(')
458
0
        ++in_br;
459
0
      break;
460
0
    case ']':
461
0
      if (*in_br == '[')
462
0
        ++in_br;
463
0
      break;
464
0
    }
465
0
        sb_add_char (out, tchar);
466
0
        ++idx;
467
0
      }
468
0
    free (br_buf);
469
0
  }
470
0
    }
471
472
0
  return idx;
473
0
}
474
475
/* Allocate a new formal.  */
476
477
static formal_entry *
478
new_formal (void)
479
0
{
480
0
  formal_entry *formal;
481
482
0
  formal = XNEW (formal_entry);
483
484
0
  sb_new (&formal->name);
485
0
  sb_new (&formal->def);
486
0
  sb_new (&formal->actual);
487
0
  formal->next = NULL;
488
0
  formal->type = FORMAL_OPTIONAL;
489
0
  return formal;
490
0
}
491
492
/* Free a formal.  */
493
494
static void
495
del_formal (formal_entry *formal)
496
0
{
497
0
  sb_kill (&formal->actual);
498
0
  sb_kill (&formal->def);
499
0
  sb_kill (&formal->name);
500
0
  free (formal);
501
0
}
502
503
/* Pick up the formal parameters of a macro definition.  */
504
505
static size_t
506
do_formals (macro_entry *macro, size_t idx, sb *in)
507
0
{
508
0
  formal_entry **p = &macro->formals;
509
0
  const char *name;
510
511
0
  idx = sb_skip_white (idx, in);
512
0
  while (idx < in->len)
513
0
    {
514
0
      formal_entry *formal = new_formal ();
515
0
      size_t cidx;
516
517
0
      idx = get_token (idx, in, &formal->name);
518
0
      if (formal->name.len == 0)
519
0
  {
520
0
    if (macro->formal_count)
521
0
      --idx;
522
0
    del_formal (formal);  /* 'formal' goes out of scope.  */
523
0
    break;
524
0
  }
525
0
      idx = sb_skip_white (idx, in);
526
      /* This is a formal.  */
527
0
      name = sb_terminate (&formal->name);
528
0
      if (! flag_mri
529
0
    && idx < in->len
530
0
    && in->ptr[idx] == ':'
531
0
    && (! is_name_beginner (':')
532
0
        || idx + 1 >= in->len
533
0
        || ! is_part_of_name (in->ptr[idx + 1])))
534
0
  {
535
    /* Got a qualifier.  */
536
0
    sb qual;
537
538
0
    sb_new (&qual);
539
0
    idx = get_token (sb_skip_white (idx + 1, in), in, &qual);
540
0
    sb_terminate (&qual);
541
0
    if (qual.len == 0)
542
0
      as_bad_where (macro->file,
543
0
        macro->line,
544
0
        _("Missing parameter qualifier for `%s' in macro `%s'"),
545
0
        name,
546
0
        macro->name);
547
0
    else if (strcmp (qual.ptr, "req") == 0)
548
0
      formal->type = FORMAL_REQUIRED;
549
0
    else if (strcmp (qual.ptr, "vararg") == 0)
550
0
      formal->type = FORMAL_VARARG;
551
0
    else
552
0
      as_bad_where (macro->file,
553
0
        macro->line,
554
0
        _("`%s' is not a valid parameter qualifier for `%s' in macro `%s'"),
555
0
        qual.ptr,
556
0
        name,
557
0
        macro->name);
558
0
    sb_kill (&qual);
559
0
    idx = sb_skip_white (idx, in);
560
0
  }
561
0
      if (idx < in->len && in->ptr[idx] == '=')
562
0
  {
563
    /* Got a default.  */
564
0
    idx = get_any_string (idx + 1, in, &formal->def);
565
0
    idx = sb_skip_white (idx, in);
566
0
    if (formal->type == FORMAL_REQUIRED)
567
0
      {
568
0
        sb_reset (&formal->def);
569
0
        as_warn_where (macro->file,
570
0
          macro->line,
571
0
          _("Pointless default value for required parameter `%s' in macro `%s'"),
572
0
          name,
573
0
          macro->name);
574
0
      }
575
0
  }
576
577
      /* Add to macro's hash table.  */
578
0
      if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL)
579
0
  {
580
0
    as_bad_where (macro->file, macro->line,
581
0
      _("A parameter named `%s' "
582
0
        "already exists for macro `%s'"),
583
0
      name, macro->name);
584
0
  }
585
586
0
      formal->index = macro->formal_count++;
587
0
      *p = formal;
588
0
      p = &formal->next;
589
0
      if (formal->type == FORMAL_VARARG)
590
0
  break;
591
0
      cidx = idx;
592
0
      idx = sb_skip_comma (idx, in);
593
0
      if (idx != cidx && idx >= in->len)
594
0
  {
595
0
    idx = cidx;
596
0
    break;
597
0
  }
598
0
    }
599
600
0
  if (flag_mri)
601
0
    {
602
0
      formal_entry *formal = new_formal ();
603
604
      /* Add a special NARG formal, which macro_expand will set to the
605
   number of arguments.  */
606
      /* The same MRI assemblers which treat '@' characters also use
607
   the name $NARG.  At least until we find an exception.  */
608
0
      if (macro_strip_at)
609
0
  name = "$NARG";
610
0
      else
611
0
  name = "NARG";
612
613
0
      sb_add_string (&formal->name, name);
614
615
      /* Add to macro's hash table.  */
616
0
      if (str_hash_insert (macro->formal_hash, name, formal, 0) != NULL)
617
0
  {
618
0
    as_bad_where (macro->file, macro->line,
619
0
      _("Reserved word `%s' used as parameter in macro `%s'"),
620
0
      name, macro->name);
621
0
  }
622
623
0
      formal->index = NARG_INDEX;
624
0
      *p = formal;
625
0
    }
626
627
0
  return idx;
628
0
}
629
630
/* Free the memory allocated to a macro.  */
631
632
static void
633
free_macro (macro_entry *macro)
634
0
{
635
0
  formal_entry *formal;
636
637
0
  for (formal = macro->formals; formal; )
638
0
    {
639
0
      formal_entry *f;
640
641
0
      f = formal;
642
0
      formal = formal->next;
643
0
      del_formal (f);
644
0
    }
645
0
  htab_delete (macro->formal_hash);
646
0
  sb_kill (&macro->sub);
647
0
  free ((char *) macro->name);
648
0
  free (macro);
649
0
}
650
651
/* Define a new macro.  */
652
653
macro_entry *
654
define_macro (sb *in, sb *label, size_t (*get_line) (sb *))
655
0
{
656
0
  macro_entry *macro;
657
0
  sb name;
658
0
  size_t idx;
659
0
  const char *error = NULL;
660
661
0
  macro = XNEW (macro_entry);
662
0
  sb_new (&macro->sub);
663
0
  sb_new (&name);
664
0
  macro->file = as_where (&macro->line);
665
666
0
  macro->formal_count = 0;
667
0
  macro->formals = 0;
668
0
  macro->formal_hash = str_htab_create ();
669
0
  macro->count = 0;
670
671
0
  idx = sb_skip_white (0, in);
672
0
  if (! buffer_and_nest ("MACRO", "ENDM", &macro->sub, get_line))
673
0
    error = _("unexpected end of file in macro `%s' definition");
674
0
  if (label != NULL && label->len != 0)
675
0
    {
676
0
      sb_add_sb (&name, label);
677
0
      macro->name = sb_terminate (&name);
678
0
      if (idx < in->len && in->ptr[idx] == '(')
679
0
  {
680
    /* It's the label: MACRO (formals,...)  sort  */
681
0
    idx = do_formals (macro, idx + 1, in);
682
0
    if (idx < in->len && in->ptr[idx] == ')')
683
0
      idx = sb_skip_white (idx + 1, in);
684
0
    else if (!error)
685
0
      error = _("missing `)' after formals in macro definition `%s'");
686
0
  }
687
0
      else
688
0
  {
689
    /* It's the label: MACRO formals,...  sort  */
690
0
    idx = do_formals (macro, idx, in);
691
0
  }
692
0
    }
693
0
  else
694
0
    {
695
0
      size_t cidx;
696
697
0
      idx = get_token (idx, in, &name);
698
0
      macro->name = sb_terminate (&name);
699
0
      if (name.len == 0)
700
0
  error = _("Missing macro name");
701
0
      cidx = sb_skip_white (idx, in);
702
0
      idx = sb_skip_comma (cidx, in);
703
0
      if (idx == cidx || idx < in->len)
704
0
  idx = do_formals (macro, idx, in);
705
0
      else
706
0
  idx = cidx;
707
0
    }
708
0
  if (!error && idx < in->len)
709
0
    error = _("Bad parameter list for macro `%s'");
710
711
  /* And stick it in the macro hash table.  */
712
0
  for (idx = 0; idx < name.len; idx++)
713
0
    name.ptr[idx] = TOLOWER (name.ptr[idx]);
714
0
  if (!error)
715
0
    {
716
0
      if (str_hash_insert (macro_hash, macro->name, macro, 0) != NULL)
717
0
  error = _("Macro `%s' was already defined");
718
0
    }
719
720
0
  if (!error)
721
0
    macro_defined = 1;
722
0
  else
723
0
    {
724
0
      as_bad_where (macro->file, macro->line, error, macro->name);
725
0
      free_macro (macro);
726
0
      macro = NULL;
727
0
    }
728
729
0
  return macro;
730
0
}
731
732
/* Scan a token, and then skip KIND.  */
733
734
static size_t
735
get_apost_token (size_t idx, sb *in, sb *name, int kind)
736
0
{
737
0
  idx = get_token (idx, in, name);
738
0
  if (idx < in->len
739
0
      && in->ptr[idx] == kind
740
0
      && (! flag_mri || macro_strip_at)
741
0
      && (! macro_strip_at || kind == '@'))
742
0
    idx++;
743
0
  return idx;
744
0
}
745
746
/* Substitute the actual value for a formal parameter.  */
747
748
static size_t
749
sub_actual (size_t start, sb *in, sb *t, struct htab *formal_hash,
750
      int kind, sb *out, int copyifnotthere)
751
0
{
752
0
  size_t src;
753
0
  formal_entry *ptr;
754
755
0
  src = get_apost_token (start, in, t, kind);
756
  /* See if it's in the macro's hash table, unless this is
757
     macro_strip_at and kind is '@' and the token did not end in '@'.  */
758
0
  if (macro_strip_at
759
0
      && kind == '@'
760
0
      && (src == start || in->ptr[src - 1] != '@'))
761
0
    ptr = NULL;
762
0
  else
763
0
    ptr = str_hash_find (formal_hash, sb_terminate (t));
764
0
  if (ptr)
765
0
    {
766
0
      if (ptr->actual.len)
767
0
  {
768
0
    sb_add_sb (out, &ptr->actual);
769
0
  }
770
0
      else
771
0
  {
772
0
    sb_add_sb (out, &ptr->def);
773
0
  }
774
0
    }
775
0
  else if (kind == '&')
776
0
    {
777
      /* Doing this permits people to use & in macro bodies.  */
778
0
      sb_add_char (out, '&');
779
0
      sb_add_sb (out, t);
780
0
      if (src != start && in->ptr[src - 1] == '&')
781
0
  sb_add_char (out, '&');
782
0
    }
783
0
  else if (copyifnotthere)
784
0
    {
785
0
      sb_add_sb (out, t);
786
0
    }
787
0
  else
788
0
    {
789
0
      sb_add_char (out, '\\');
790
0
      sb_add_sb (out, t);
791
0
    }
792
0
  return src;
793
0
}
794
795
/* Expand the body of a macro.  */
796
797
static const char *
798
macro_expand_body (sb *in, sb *out, formal_entry *formals,
799
       struct htab *formal_hash, const macro_entry *macro,
800
       unsigned int instance)
801
0
{
802
0
  sb t;
803
0
  size_t src = 0;
804
0
  int inquote = 0, macro_line = 0;
805
0
  formal_entry *loclist = NULL;
806
0
  const char *err = NULL;
807
808
0
  sb_new (&t);
809
810
0
  while (src < in->len && !err)
811
0
    {
812
0
      if (in->ptr[src] == '&')
813
0
  {
814
0
    sb_reset (&t);
815
0
    if (flag_mri)
816
0
      {
817
0
        if (src + 1 < in->len && in->ptr[src + 1] == '&')
818
0
    src = sub_actual (src + 2, in, &t, formal_hash, '\'', out, 1);
819
0
        else
820
0
    sb_add_char (out, in->ptr[src++]);
821
0
      }
822
0
    else
823
0
      {
824
        /* Permit macro parameter substitution delineated with
825
     an '&' prefix and optional '&' suffix.  */
826
0
        src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
827
0
      }
828
0
  }
829
0
      else if (in->ptr[src] == '\\')
830
0
  {
831
0
    src++;
832
0
    if (src < in->len && in->ptr[src] == '(')
833
0
      {
834
        /* Sub in till the next ')' literally.  */
835
0
        src++;
836
0
        while (src < in->len && in->ptr[src] != ')')
837
0
    {
838
0
      sb_add_char (out, in->ptr[src++]);
839
0
    }
840
0
        if (src < in->len)
841
0
    src++;
842
0
        else if (!macro)
843
0
    err = _("missing `)'");
844
0
        else
845
0
    as_bad_where (macro->file, macro->line + macro_line, _("missing `)'"));
846
0
      }
847
0
    else if (src < in->len && in->ptr[src] == '@')
848
0
      {
849
        /* Sub in the total macro invocation number.  */
850
851
0
        char buffer[12];
852
0
        src++;
853
0
        sprintf (buffer, "%u", macro_number);
854
0
        sb_add_string (out, buffer);
855
0
      }
856
0
    else if (src < in->len && in->ptr[src] == '+')
857
0
      {
858
        /* Sub in the current macro invocation number.  */
859
860
0
        char buffer[12];
861
0
        src++;
862
0
        sprintf (buffer, "%d", instance);
863
0
        sb_add_string (out, buffer);
864
0
      }
865
0
    else if (src < in->len && in->ptr[src] == '&')
866
0
      {
867
        /* This is a preprocessor variable name, we don't do them
868
     here.  */
869
0
        sb_add_char (out, '\\');
870
0
        sb_add_char (out, '&');
871
0
        src++;
872
0
      }
873
0
    else if (flag_mri && src < in->len && ISALNUM (in->ptr[src]))
874
0
      {
875
0
        int ind;
876
0
        formal_entry *f;
877
878
0
        if (ISDIGIT (in->ptr[src]))
879
0
    ind = in->ptr[src] - '0';
880
0
        else if (ISUPPER (in->ptr[src]))
881
0
    ind = in->ptr[src] - 'A' + 10;
882
0
        else
883
0
    ind = in->ptr[src] - 'a' + 10;
884
0
        ++src;
885
0
        for (f = formals; f != NULL; f = f->next)
886
0
    {
887
0
      if (f->index == ind - 1)
888
0
        {
889
0
          if (f->actual.len != 0)
890
0
      sb_add_sb (out, &f->actual);
891
0
          else
892
0
      sb_add_sb (out, &f->def);
893
0
          break;
894
0
        }
895
0
    }
896
0
      }
897
0
    else
898
0
      {
899
0
        sb_reset (&t);
900
0
        src = sub_actual (src, in, &t, formal_hash, '\'', out, 0);
901
0
      }
902
0
  }
903
0
      else if ((flag_macro_alternate || flag_mri)
904
0
         && is_name_beginner (in->ptr[src])
905
0
         && (! inquote
906
0
       || ! macro_strip_at
907
0
       || (src > 0 && in->ptr[src - 1] == '@')))
908
0
  {
909
0
    if (! macro
910
0
        || src + 5 >= in->len
911
0
        || strncasecmp (in->ptr + src, "LOCAL", 5) != 0
912
0
        || ! is_whitespace (in->ptr[src + 5])
913
        /* PR 11507: Skip keyword LOCAL if it is found inside a quoted string.  */
914
0
        || inquote)
915
0
      {
916
0
        sb_reset (&t);
917
0
        src = sub_actual (src, in, &t, formal_hash,
918
0
        (macro_strip_at && inquote) ? '@' : '\'',
919
0
        out, 1);
920
0
      }
921
0
    else
922
0
      {
923
0
        src = sb_skip_white (src + 5, in);
924
0
        while (in->ptr[src] != '\n')
925
0
    {
926
0
      const char *name;
927
0
      formal_entry *f = new_formal ();
928
929
0
      src = get_token (src, in, &f->name);
930
0
      name = sb_terminate (&f->name);
931
0
      if (str_hash_insert (formal_hash, name, f, 0) != NULL)
932
0
        {
933
0
          as_bad_where (macro->file, macro->line + macro_line,
934
0
            _("`%s' was already used as parameter "
935
0
              "(or another local) name"), name);
936
0
          del_formal (f);
937
0
        }
938
0
      else
939
0
        {
940
0
          static int loccnt;
941
0
          char buf[20];
942
943
0
          f->index = LOCAL_INDEX;
944
0
          f->next = loclist;
945
0
          loclist = f;
946
947
0
          sprintf (buf, IS_ELF ? ".LL%04x" : "LL%04x", ++loccnt);
948
0
          sb_add_string (&f->actual, buf);
949
0
        }
950
951
0
      src = sb_skip_comma (src, in);
952
0
    }
953
0
      }
954
0
  }
955
0
      else if (in->ptr[src] == '"'
956
0
         || (flag_mri && in->ptr[src] == '\''))
957
0
  {
958
0
    inquote = !inquote;
959
0
    sb_add_char (out, in->ptr[src++]);
960
0
  }
961
0
      else if (in->ptr[src] == '@' && macro_strip_at)
962
0
  {
963
0
    ++src;
964
0
    if (src < in->len
965
0
        && in->ptr[src] == '@')
966
0
      {
967
0
        sb_add_char (out, '@');
968
0
        ++src;
969
0
      }
970
0
  }
971
0
      else if (flag_mri
972
0
         && in->ptr[src] == '='
973
0
         && src + 1 < in->len
974
0
         && in->ptr[src + 1] == '=')
975
0
  {
976
0
    formal_entry *ptr;
977
978
0
    sb_reset (&t);
979
0
    src = get_token (src + 2, in, &t);
980
0
    ptr = str_hash_find (formal_hash, sb_terminate (&t));
981
0
    if (ptr == NULL)
982
0
      {
983
        /* FIXME: We should really return a warning string here,
984
     but we can't, because the == might be in the MRI
985
     comment field, and, since the nature of the MRI
986
     comment field depends upon the exact instruction
987
     being used, we don't have enough information here to
988
     figure out whether it is or not.  Instead, we leave
989
     the == in place, which should cause a syntax error if
990
     it is not in a comment.  */
991
0
        sb_add_char (out, '=');
992
0
        sb_add_char (out, '=');
993
0
        sb_add_sb (out, &t);
994
0
      }
995
0
    else
996
0
      {
997
0
        if (ptr->actual.len)
998
0
    {
999
0
      sb_add_string (out, "-1");
1000
0
    }
1001
0
        else
1002
0
    {
1003
0
      sb_add_char (out, '0');
1004
0
    }
1005
0
      }
1006
0
  }
1007
0
      else
1008
0
  {
1009
0
    if (in->ptr[src] == '\n')
1010
0
      ++macro_line;
1011
0
    sb_add_char (out, in->ptr[src++]);
1012
0
  }
1013
0
    }
1014
1015
0
  sb_kill (&t);
1016
1017
0
  while (loclist != NULL)
1018
0
    {
1019
0
      formal_entry *f;
1020
0
      const char *name;
1021
1022
0
      f = loclist->next;
1023
0
      name = sb_terminate (&loclist->name);
1024
0
      str_hash_delete (formal_hash, name);
1025
0
      del_formal (loclist);
1026
0
      loclist = f;
1027
0
    }
1028
1029
0
  if (!err && (out->len == 0 || out->ptr[out->len - 1] != '\n'))
1030
0
    sb_add_char (out, '\n');
1031
0
  return err;
1032
0
}
1033
1034
/* Assign values to the formal parameters of a macro, and expand the
1035
   body.  */
1036
1037
static const char *
1038
macro_expand (size_t idx, sb *in, macro_entry *m, sb *out)
1039
0
{
1040
0
  sb t;
1041
0
  formal_entry *ptr;
1042
0
  formal_entry *f;
1043
0
  int is_keyword = 0;
1044
0
  int narg = 0;
1045
0
  const char *err = NULL;
1046
1047
0
  sb_new (&t);
1048
1049
  /* Reset any old value the actuals may have.  */
1050
0
  for (f = m->formals; f; f = f->next)
1051
0
    sb_reset (&f->actual);
1052
0
  f = m->formals;
1053
0
  while (f != NULL && f->index < 0)
1054
0
    f = f->next;
1055
1056
0
  if (flag_mri)
1057
0
    {
1058
      /* The macro may be called with an optional qualifier, which may
1059
   be referred to in the macro body as \0.  */
1060
0
      if (idx < in->len && in->ptr[idx] == '.')
1061
0
  {
1062
    /* The Microtec assembler ignores this if followed by a white space.
1063
       (Macro invocation with empty extension) */
1064
0
    idx++;
1065
0
    if (idx < in->len && !is_whitespace (in->ptr[idx]))
1066
0
      {
1067
0
        formal_entry *n = new_formal ();
1068
1069
0
        n->index = QUAL_INDEX;
1070
1071
0
        n->next = m->formals;
1072
0
        m->formals = n;
1073
1074
0
        idx = get_any_string (idx, in, &n->actual);
1075
0
      }
1076
0
  }
1077
0
    }
1078
1079
  /* Peel off the actuals and store them away in the hash tables' actuals.  */
1080
0
  idx = sb_skip_white (idx, in);
1081
0
  while (idx < in->len)
1082
0
    {
1083
0
      size_t scan;
1084
1085
      /* Look and see if it's a positional or keyword arg.  */
1086
0
      scan = idx;
1087
0
      while (scan < in->len
1088
0
       && !ISSEP (in->ptr[scan])
1089
0
       && !(flag_mri && in->ptr[scan] == '\'')
1090
0
       && (!flag_macro_alternate && in->ptr[scan] != '='))
1091
0
  scan++;
1092
0
      if (scan < in->len && !flag_macro_alternate && in->ptr[scan] == '=')
1093
0
  {
1094
0
    is_keyword = 1;
1095
1096
    /* It's OK to go from positional to keyword.  */
1097
1098
    /* This is a keyword arg, fetch the formal name and
1099
       then the actual stuff.  */
1100
0
    sb_reset (&t);
1101
0
    idx = get_token (idx, in, &t);
1102
0
    if (idx >= in->len || in->ptr[idx] != '=')
1103
0
      {
1104
0
        err = _("confusion in formal parameters");
1105
0
        break;
1106
0
      }
1107
1108
    /* Lookup the formal in the macro's list.  */
1109
0
    ptr = str_hash_find (m->formal_hash, sb_terminate (&t));
1110
0
    if (!ptr)
1111
0
      {
1112
0
        as_bad (_("Parameter named `%s' does not exist for macro `%s'"),
1113
0
          t.ptr,
1114
0
          m->name);
1115
0
        sb_reset (&t);
1116
0
        idx = get_any_string (idx + 1, in, &t);
1117
0
      }
1118
0
    else
1119
0
      {
1120
        /* Insert this value into the right place.  */
1121
0
        if (ptr->actual.len)
1122
0
    {
1123
0
      as_warn (_("Value for parameter `%s' of macro `%s' was already specified"),
1124
0
         ptr->name.ptr,
1125
0
         m->name);
1126
0
      sb_reset (&ptr->actual);
1127
0
    }
1128
0
        idx = get_any_string (idx + 1, in, &ptr->actual);
1129
0
        if (ptr->actual.len > 0)
1130
0
    ++narg;
1131
0
      }
1132
0
  }
1133
0
      else
1134
0
  {
1135
0
    if (is_keyword)
1136
0
      {
1137
0
        err = _("can't mix positional and keyword arguments");
1138
0
        break;
1139
0
      }
1140
1141
0
    if (!f)
1142
0
      {
1143
0
        formal_entry **pf;
1144
0
        int c;
1145
1146
0
        if (!flag_mri)
1147
0
    {
1148
0
      err = _("too many positional arguments");
1149
0
      break;
1150
0
    }
1151
1152
0
        f = new_formal ();
1153
1154
0
        c = -1;
1155
0
        for (pf = &m->formals; *pf != NULL; pf = &(*pf)->next)
1156
0
    if ((*pf)->index >= c)
1157
0
      c = (*pf)->index + 1;
1158
0
        if (c == -1)
1159
0
    c = 0;
1160
0
        *pf = f;
1161
0
        f->index = c;
1162
0
      }
1163
1164
0
    if (f->type != FORMAL_VARARG)
1165
0
      idx = get_any_string (idx, in, &f->actual);
1166
0
    else if (idx < in->len)
1167
0
      {
1168
0
        sb_add_buffer (&f->actual, in->ptr + idx, in->len - idx);
1169
0
        idx = in->len;
1170
0
      }
1171
0
    if (f->actual.len > 0)
1172
0
      ++narg;
1173
0
    do
1174
0
      {
1175
0
        f = f->next;
1176
0
      }
1177
0
    while (f != NULL && f->index < 0);
1178
0
  }
1179
1180
0
      if (! flag_mri)
1181
0
  idx = sb_skip_comma (idx, in);
1182
0
      else
1183
0
  {
1184
0
    if (idx < in->len && in->ptr[idx] == ',')
1185
0
      ++idx;
1186
0
    if (idx < in->len && is_whitespace (in->ptr[idx]))
1187
0
      break;
1188
0
  }
1189
0
    }
1190
1191
0
  if (! err)
1192
0
    {
1193
0
      for (ptr = m->formals; ptr; ptr = ptr->next)
1194
0
  {
1195
0
    if (ptr->type == FORMAL_REQUIRED && ptr->actual.len == 0)
1196
0
      as_bad (_("Missing value for required parameter `%s' of macro `%s'"),
1197
0
        ptr->name.ptr,
1198
0
        m->name);
1199
0
  }
1200
1201
0
      if (flag_mri)
1202
0
  {
1203
0
    ptr = str_hash_find (m->formal_hash,
1204
0
             macro_strip_at ? "$NARG" : "NARG");
1205
0
    if (ptr)
1206
0
      {
1207
0
        char buffer[20];
1208
0
        sprintf (buffer, "%d", narg);
1209
0
        sb_add_string (&ptr->actual, buffer);
1210
0
      }
1211
0
  }
1212
1213
0
      err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m,
1214
0
             m->count);
1215
0
    }
1216
1217
  /* Discard any unnamed formal arguments.  */
1218
0
  if (flag_mri)
1219
0
    {
1220
0
      formal_entry **pf;
1221
1222
0
      pf = &m->formals;
1223
0
      while (*pf != NULL)
1224
0
  {
1225
0
    if ((*pf)->name.len != 0)
1226
0
      pf = &(*pf)->next;
1227
0
    else
1228
0
      {
1229
0
        f = (*pf)->next;
1230
0
        del_formal (*pf);
1231
0
        *pf = f;
1232
0
      }
1233
0
  }
1234
0
    }
1235
1236
0
  sb_kill (&t);
1237
0
  if (!err)
1238
0
    {
1239
0
      macro_number++;
1240
0
      m->count++;
1241
0
    }
1242
1243
0
  return err;
1244
0
}
1245
1246
/* Check for a macro.  If one is found, put the expansion into
1247
   *EXPAND.  Return 1 if a macro is found, 0 otherwise.  */
1248
1249
int
1250
check_macro (const char *line, sb *expand,
1251
       const char **error, macro_entry **info)
1252
0
{
1253
0
  const char *s;
1254
0
  char *copy, *cls;
1255
0
  macro_entry *macro;
1256
0
  sb line_sb;
1257
1258
0
  if (! is_name_beginner (*line)
1259
0
      && (! flag_mri || *line != '.'))
1260
0
    return 0;
1261
1262
0
  s = line + 1;
1263
0
  while (is_part_of_name (*s))
1264
0
    ++s;
1265
0
  if (is_name_ender (*s))
1266
0
    ++s;
1267
1268
0
  copy = xmemdup0 (line, s - line);
1269
0
  for (cls = copy; *cls != '\0'; cls ++)
1270
0
    *cls = TOLOWER (*cls);
1271
1272
0
  macro = str_hash_find (macro_hash, copy);
1273
0
  free (copy);
1274
1275
0
  if (macro == NULL)
1276
0
    return 0;
1277
1278
  /* Wrap the line up in an sb.  */
1279
0
  sb_new (&line_sb);
1280
0
  while (*s != '\0' && *s != '\n' && *s != '\r')
1281
0
    sb_add_char (&line_sb, *s++);
1282
1283
0
  sb_new (expand);
1284
0
  *error = macro_expand (0, &line_sb, macro, expand);
1285
1286
0
  sb_kill (&line_sb);
1287
1288
  /* Export the macro information if requested.  */
1289
0
  if (info)
1290
0
    *info = macro;
1291
1292
0
  return 1;
1293
0
}
1294
1295
/* Delete a macro.  */
1296
1297
void
1298
delete_macro (const char *name)
1299
0
{
1300
0
  char *copy;
1301
0
  size_t i, len;
1302
0
  macro_entry *macro;
1303
1304
0
  len = strlen (name);
1305
0
  copy = XNEWVEC (char, len + 1);
1306
0
  for (i = 0; i < len; ++i)
1307
0
    copy[i] = TOLOWER (name[i]);
1308
0
  copy[i] = '\0';
1309
1310
0
  macro = str_hash_find (macro_hash, copy);
1311
0
  if (macro != NULL)
1312
0
    str_hash_delete (macro_hash, copy);
1313
0
  else
1314
0
    as_warn (_("Attempt to purge non-existing macro `%s'"), copy);
1315
0
  free (copy);
1316
0
}
1317
1318
/* Handle the MRI IRP and IRPC pseudo-ops.  These are handled as a
1319
   combined macro definition and execution.  This returns NULL on
1320
   success, or an error message otherwise.  */
1321
1322
const char *
1323
expand_irp (int irpc, size_t idx, sb *in, sb *out, size_t (*get_line) (sb *))
1324
0
{
1325
0
  sb sub;
1326
0
  formal_entry f;
1327
0
  struct htab *h;
1328
0
  const char *err = NULL;
1329
1330
0
  idx = sb_skip_white (idx, in);
1331
1332
0
  sb_new (&sub);
1333
0
  if (! buffer_and_nest (NULL, "ENDR", &sub, get_line))
1334
0
    {
1335
0
      err = _("unexpected end of file in irp or irpc");
1336
0
      goto out2;
1337
0
    }
1338
1339
0
  sb_new (&f.name);
1340
0
  sb_new (&f.def);
1341
0
  sb_new (&f.actual);
1342
1343
0
  idx = get_token (idx, in, &f.name);
1344
0
  if (f.name.len == 0)
1345
0
    {
1346
0
      err = _("missing model parameter");
1347
0
      goto out1;
1348
0
    }
1349
1350
0
  h = str_htab_create ();
1351
1352
0
  str_hash_insert (h, sb_terminate (&f.name), &f, 0);
1353
1354
0
  f.index = 1;
1355
0
  f.next = NULL;
1356
0
  f.type = FORMAL_OPTIONAL;
1357
1358
0
  sb_reset (out);
1359
1360
0
  idx = sb_skip_comma (idx, in);
1361
0
  if (idx >= in->len)
1362
0
    {
1363
      /* Expand once with a null string.  */
1364
0
      err = macro_expand_body (&sub, out, &f, h, NULL, 0);
1365
0
    }
1366
0
  else
1367
0
    {
1368
0
      bool in_quotes = false;
1369
0
      unsigned int instance = 0;
1370
1371
0
      while (idx < in->len)
1372
0
  {
1373
0
    if (!irpc)
1374
0
      idx = get_any_string (idx, in, &f.actual);
1375
0
    else
1376
0
      {
1377
0
        if (in->ptr[idx] == '"')
1378
0
    {
1379
0
      in_quotes = ! in_quotes;
1380
0
      ++idx;
1381
1382
0
      if (! in_quotes)
1383
0
        {
1384
0
          idx = sb_skip_white (idx, in);
1385
0
          if (idx >= in->len)
1386
0
      break;
1387
0
        }
1388
0
      continue;
1389
0
    }
1390
0
        sb_reset (&f.actual);
1391
0
        sb_add_char (&f.actual, in->ptr[idx]);
1392
0
        ++idx;
1393
0
      }
1394
1395
0
    err = macro_expand_body (&sub, out, &f, h, NULL, instance);
1396
0
    ++instance;
1397
0
    if (err != NULL)
1398
0
      break;
1399
0
    if (!irpc)
1400
0
      idx = sb_skip_comma (idx, in);
1401
0
    else if (! in_quotes)
1402
0
      idx = sb_skip_white (idx, in);
1403
0
  }
1404
0
    }
1405
1406
0
  htab_delete (h);
1407
0
 out1:
1408
0
  sb_kill (&f.actual);
1409
0
  sb_kill (&f.def);
1410
0
  sb_kill (&f.name);
1411
0
 out2:
1412
0
  sb_kill (&sub);
1413
1414
0
  return err;
1415
0
}