1 /* macro.c - macro support for gas and gasp
2 Copyright (C) 1994, 95, 96, 1997 Free Software Foundation, Inc.
4 Written by Steve and Judy Chamberlain of Cygnus Support,
7 This file is part of GAS, the GNU Assembler.
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 2, or (at your option)
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.
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, 59 Temple Place - Suite 330, Boston, MA
26 /* AIX requires this to be the first thing in the file. */
29 extern void *alloca ();
31 extern char *alloca ();
40 # ifndef alloca /* predefined by HP cc +Olibcalls */
41 # if !defined (__STDC__) && !defined (__hpux)
42 extern char *alloca ();
44 extern void *alloca ();
45 # endif /* __STDC__, __hpux */
48 # endif /* HAVE_ALLOCA_H */
61 #include "libiberty.h"
66 /* The routines in this file handle macro definition and expansion.
67 They are called by both gasp and gas. */
69 /* Structures used to store macros.
71 Each macro knows its name and included text. It gets built with a
72 list of formal arguments, and also keeps a hash table which points
73 into the list to speed up formal search. Each formal knows its
74 name and its default value. Each time the macro is expanded, the
75 formals get the actual values attatched to them. */
77 /* describe the formal arguments to a macro */
79 typedef struct formal_struct
81 struct formal_struct
*next
; /* next formal in list */
82 sb name
; /* name of the formal */
83 sb def
; /* the default value */
84 sb actual
; /* the actual argument (changed on each expansion) */
85 int index
; /* the index of the formal 0..formal_count-1 */
89 /* Other values found in the index field of a formal_entry. */
90 #define QUAL_INDEX (-1)
91 #define NARG_INDEX (-2)
92 #define LOCAL_INDEX (-3)
94 /* describe the macro. */
96 typedef struct macro_struct
98 sb sub
; /* substitution text. */
99 int formal_count
; /* number of formal args. */
100 formal_entry
*formals
; /* pointer to list of formal_structs */
101 struct hash_control
*formal_hash
; /* hash table of formals. */
105 /* Internal functions. */
107 static int get_token
PARAMS ((int, sb
*, sb
*));
108 static int getstring
PARAMS ((int, sb
*, sb
*));
109 static int get_any_string
PARAMS ((int, sb
*, sb
*, int, int));
110 static int do_formals
PARAMS ((macro_entry
*, int, sb
*));
111 static int get_apost_token
PARAMS ((int, sb
*, sb
*, int));
112 static int sub_actual
113 PARAMS ((int, sb
*, sb
*, struct hash_control
*, int, sb
*, int));
114 static const char *macro_expand_body
115 PARAMS ((sb
*, sb
*, formal_entry
*, struct hash_control
*, int, int));
116 static const char *macro_expand
PARAMS ((int, sb
*, macro_entry
*, sb
*, int));
118 #define ISWHITE(x) ((x) == ' ' || (x) == '\t')
121 ((x) == ' ' || (x) == '\t' || (x) == ',' || (x) == '"' || (x) == ';' \
122 || (x) == '<' || (x) == '>' || (x) == ')' || (x) == '(')
125 ((x) == 'b' || (x) == 'B' \
126 || (x) == 'q' || (x) == 'Q' \
127 || (x) == 'h' || (x) == 'H' \
128 || (x) == 'd' || (x) == 'D')
130 /* The macro hash table. */
132 static struct hash_control
*macro_hash
;
134 /* Whether any macros have been defined. */
138 /* Whether we are in GASP alternate mode. */
140 static int macro_alternate
;
142 /* Whether we are in MRI mode. */
144 static int macro_mri
;
146 /* Whether we should strip '@' characters. */
148 static int macro_strip_at
;
150 /* Function to use to parse an expression. */
152 static int (*macro_expr
) PARAMS ((const char *, int, sb
*, int *));
154 /* Number of macro expansions that have been done. */
156 static int macro_number
;
158 /* Initialize macro processing. */
161 macro_init (alternate
, mri
, strip_at
, expr
)
165 int (*expr
) PARAMS ((const char *, int, sb
*, int *));
167 macro_hash
= hash_new ();
169 macro_alternate
= alternate
;
171 macro_strip_at
= strip_at
;
175 /* Read input lines till we get to a TO string.
176 Increase nesting depth if we get a FROM string.
177 Put the results into sb at PTR.
178 Add a new input line to an sb using GET_LINE.
179 Return 1 on success, 0 on unexpected EOF. */
182 buffer_and_nest (from
, to
, ptr
, get_line
)
186 int (*get_line
) PARAMS ((sb
*));
188 int from_len
= strlen (from
);
189 int to_len
= strlen (to
);
191 int line_start
= ptr
->len
;
193 int more
= get_line (ptr
);
197 /* Try and find the first pseudo op on the line */
200 if (! macro_alternate
&& ! macro_mri
)
202 /* With normal syntax we can suck what we want till we get
203 to the dot. With the alternate, labels have to start in
204 the first column, since we cant tell what's a label and
207 /* Skip leading whitespace */
208 while (i
< ptr
->len
&& ISWHITE (ptr
->ptr
[i
]))
211 /* Skip over a label */
213 && (isalnum ((unsigned char) ptr
->ptr
[i
])
214 || ptr
->ptr
[i
] == '_'
215 || ptr
->ptr
[i
] == '$'))
220 && ptr
->ptr
[i
] == ':')
224 /* Skip trailing whitespace */
225 while (i
< ptr
->len
&& ISWHITE (ptr
->ptr
[i
]))
228 if (i
< ptr
->len
&& (ptr
->ptr
[i
] == '.'
232 if (ptr
->ptr
[i
] == '.')
234 if (strncasecmp (ptr
->ptr
+ i
, from
, from_len
) == 0)
236 if (strncasecmp (ptr
->ptr
+ i
, to
, to_len
) == 0)
241 /* Reset the string to not include the ending rune */
242 ptr
->len
= line_start
;
248 /* Add a CR to the end and keep running */
249 sb_add_char (ptr
, '\n');
250 line_start
= ptr
->len
;
251 more
= get_line (ptr
);
254 /* Return 1 on success, 0 on unexpected EOF. */
258 /* Pick up a token. */
261 get_token (idx
, in
, name
)
267 && (isalpha ((unsigned char) in
->ptr
[idx
])
268 || in
->ptr
[idx
] == '_'
269 || in
->ptr
[idx
] == '$'))
271 sb_add_char (name
, in
->ptr
[idx
++]);
273 && (isalnum ((unsigned char) in
->ptr
[idx
])
274 || in
->ptr
[idx
] == '_'
275 || in
->ptr
[idx
] == '$'))
277 sb_add_char (name
, in
->ptr
[idx
++]);
280 /* Ignore trailing & */
281 if (macro_alternate
&& idx
< in
->len
&& in
->ptr
[idx
] == '&')
286 /* Pick up a string. */
289 getstring (idx
, in
, acc
)
294 idx
= sb_skip_white (idx
, in
);
297 && (in
->ptr
[idx
] == '"'
298 || in
->ptr
[idx
] == '<'
299 || (in
->ptr
[idx
] == '\'' && macro_alternate
)))
301 if (in
->ptr
[idx
] == '<')
303 if (macro_alternate
|| macro_mri
)
307 while ((in
->ptr
[idx
] != '>' || nest
)
310 if (in
->ptr
[idx
] == '!')
313 sb_add_char (acc
, in
->ptr
[idx
++]);
317 if (in
->ptr
[idx
] == '>')
319 if (in
->ptr
[idx
] == '<')
321 sb_add_char (acc
, in
->ptr
[idx
++]);
331 ("character code in string must be absolute expression",
333 sb_add_char (acc
, code
);
336 if (in
->ptr
[idx
] != '>')
337 ERROR ((stderr
, "Missing > for character code.\n"));
342 else if (in
->ptr
[idx
] == '"' || in
->ptr
[idx
] == '\'')
344 char tchar
= in
->ptr
[idx
];
346 while (idx
< in
->len
)
348 if (macro_alternate
&& in
->ptr
[idx
] == '!')
351 sb_add_char (acc
, in
->ptr
[idx
++]);
355 if (in
->ptr
[idx
] == tchar
)
358 if (idx
>= in
->len
|| in
->ptr
[idx
] != tchar
)
361 sb_add_char (acc
, in
->ptr
[idx
]);
371 /* Fetch string from the input stream,
373 'Bxyx<whitespace> -> return 'Bxyza
374 %<char> -> return string of decimal value of x
375 "<string>" -> return string
376 xyx<whitespace> -> return xyz
380 get_any_string (idx
, in
, out
, expand
, pretend_quoted
)
388 idx
= sb_skip_white (idx
, in
);
392 if (in
->len
> 2 && in
->ptr
[idx
+1] == '\'' && ISBASE (in
->ptr
[idx
]))
394 while (!ISSEP (in
->ptr
[idx
]))
395 sb_add_char (out
, in
->ptr
[idx
++]);
397 else if (in
->ptr
[idx
] == '%'
403 /* Turns the next expression into a string */
404 idx
= (*macro_expr
) ("% operator needs absolute expression",
408 sprintf(buf
, "%d", val
);
409 sb_add_string (out
, buf
);
411 else if (in
->ptr
[idx
] == '"'
412 || in
->ptr
[idx
] == '<'
413 || (macro_alternate
&& in
->ptr
[idx
] == '\''))
419 /* Keep the quotes */
420 sb_add_char (out
, '\"');
422 idx
= getstring (idx
, in
, out
);
423 sb_add_char (out
, '\"');
427 idx
= getstring (idx
, in
, out
);
433 && (in
->ptr
[idx
] == '"'
434 || in
->ptr
[idx
] == '\''
436 || (in
->ptr
[idx
] != ' '
437 && in
->ptr
[idx
] != '\t'
438 && in
->ptr
[idx
] != ','
439 && in
->ptr
[idx
] != '<')))
441 if (in
->ptr
[idx
] == '"'
442 || in
->ptr
[idx
] == '\'')
444 char tchar
= in
->ptr
[idx
];
445 sb_add_char (out
, in
->ptr
[idx
++]);
447 && in
->ptr
[idx
] != tchar
)
448 sb_add_char (out
, in
->ptr
[idx
++]);
452 sb_add_char (out
, in
->ptr
[idx
++]);
460 /* Pick up the formal parameters of a macro definition. */
463 do_formals (macro
, idx
, in
)
468 formal_entry
**p
= ¯o
->formals
;
470 macro
->formal_count
= 0;
471 macro
->formal_hash
= hash_new ();
472 while (idx
< in
->len
)
474 formal_entry
*formal
;
476 formal
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
478 sb_new (&formal
->name
);
479 sb_new (&formal
->def
);
480 sb_new (&formal
->actual
);
482 idx
= sb_skip_white (idx
, in
);
483 idx
= get_token (idx
, in
, &formal
->name
);
484 if (formal
->name
.len
== 0)
486 idx
= sb_skip_white (idx
, in
);
487 if (formal
->name
.len
)
489 /* This is a formal */
490 if (idx
< in
->len
&& in
->ptr
[idx
] == '=')
493 idx
= get_any_string (idx
+ 1, in
, &formal
->def
, 1, 0);
497 /* Add to macro's hash table */
498 hash_jam (macro
->formal_hash
, sb_terminate (&formal
->name
), formal
);
500 formal
->index
= macro
->formal_count
;
501 idx
= sb_skip_comma (idx
, in
);
502 macro
->formal_count
++;
510 formal_entry
*formal
;
513 /* Add a special NARG formal, which macro_expand will set to the
514 number of arguments. */
515 formal
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
517 sb_new (&formal
->name
);
518 sb_new (&formal
->def
);
519 sb_new (&formal
->actual
);
521 /* The same MRI assemblers which treat '@' characters also use
522 the name $NARG. At least until we find an exception. */
528 sb_add_string (&formal
->name
, name
);
530 /* Add to macro's hash table */
531 hash_jam (macro
->formal_hash
, name
, formal
);
533 formal
->index
= NARG_INDEX
;
541 /* Define a new macro. Returns NULL on success, otherwise returns an
542 error message. If NAMEP is not NULL, *NAMEP is set to the name of
543 the macro which was defined. */
546 define_macro (idx
, in
, label
, get_line
, namep
)
550 int (*get_line
) PARAMS ((sb
*));
557 macro
= (macro_entry
*) xmalloc (sizeof (macro_entry
));
558 sb_new (¯o
->sub
);
561 macro
->formal_count
= 0;
564 idx
= sb_skip_white (idx
, in
);
565 if (! buffer_and_nest ("MACRO", "ENDM", ¯o
->sub
, get_line
))
566 return "unexpected end of file in macro definition";
567 if (label
!= NULL
&& label
->len
!= 0)
569 sb_add_sb (&name
, label
);
570 if (idx
< in
->len
&& in
->ptr
[idx
] == '(')
572 /* It's the label: MACRO (formals,...) sort */
573 idx
= do_formals (macro
, idx
+ 1, in
);
574 if (in
->ptr
[idx
] != ')')
575 return "missing ) after formals";
579 /* It's the label: MACRO formals,... sort */
580 idx
= do_formals (macro
, idx
, in
);
585 idx
= get_token (idx
, in
, &name
);
586 idx
= sb_skip_comma (idx
, in
);
587 idx
= do_formals (macro
, idx
, in
);
590 /* and stick it in the macro hash table */
591 for (idx
= 0; idx
< name
.len
; idx
++)
592 if (isupper (name
.ptr
[idx
]))
593 name
.ptr
[idx
] = tolower (name
.ptr
[idx
]);
594 namestr
= sb_terminate (&name
);
595 hash_jam (macro_hash
, namestr
, (PTR
) macro
);
605 /* Scan a token, and then skip KIND. */
608 get_apost_token (idx
, in
, name
, kind
)
614 idx
= get_token (idx
, in
, name
);
616 && in
->ptr
[idx
] == kind
617 && (! macro_mri
|| macro_strip_at
)
618 && (! macro_strip_at
|| kind
== '@'))
623 /* Substitute the actual value for a formal parameter. */
626 sub_actual (start
, in
, t
, formal_hash
, kind
, out
, copyifnotthere
)
630 struct hash_control
*formal_hash
;
638 src
= get_apost_token (start
, in
, t
, kind
);
639 /* See if it's in the macro's hash table, unless this is
640 macro_strip_at and kind is '@' and the token did not end in '@'. */
643 && (src
== start
|| in
->ptr
[src
- 1] != '@'))
646 ptr
= (formal_entry
*) hash_find (formal_hash
, sb_terminate (t
));
651 sb_add_sb (out
, &ptr
->actual
);
655 sb_add_sb (out
, &ptr
->def
);
658 else if (copyifnotthere
)
664 sb_add_char (out
, '\\');
670 /* Expand the body of a macro. */
673 macro_expand_body (in
, out
, formals
, formal_hash
, comment_char
, locals
)
676 formal_entry
*formals
;
677 struct hash_control
*formal_hash
;
684 formal_entry
*loclist
= NULL
;
688 while (src
< in
->len
)
690 if (in
->ptr
[src
] == '&')
695 if (src
+ 1 < in
->len
&& in
->ptr
[src
+ 1] == '&')
696 src
= sub_actual (src
+ 2, in
, &t
, formal_hash
, '\'', out
, 1);
698 sb_add_char (out
, in
->ptr
[src
++]);
702 /* FIXME: Why do we do this? It prevents people from
703 using the & operator in a macro. */
704 src
= sub_actual (src
+ 1, in
, &t
, formal_hash
, '&', out
, 0);
707 else if (in
->ptr
[src
] == '\\')
710 if (in
->ptr
[src
] == comment_char
&& comment_char
!= '\0')
712 /* This is a comment, just drop the rest of the line */
714 && in
->ptr
[src
] != '\n')
717 else if (in
->ptr
[src
] == '(')
719 /* Sub in till the next ')' literally */
721 while (src
< in
->len
&& in
->ptr
[src
] != ')')
723 sb_add_char (out
, in
->ptr
[src
++]);
725 if (in
->ptr
[src
] == ')')
728 return "missplaced )";
730 else if (in
->ptr
[src
] == '@')
732 /* Sub in the macro invocation number */
736 sprintf (buffer
, "%05d", macro_number
);
737 sb_add_string (out
, buffer
);
739 else if (in
->ptr
[src
] == '&')
741 /* This is a preprocessor variable name, we don't do them
743 sb_add_char (out
, '\\');
744 sb_add_char (out
, '&');
748 && isalnum ((unsigned char) in
->ptr
[src
]))
753 if (isdigit ((unsigned char) in
->ptr
[src
]))
754 ind
= in
->ptr
[src
] - '0';
755 else if (isupper ((unsigned char) in
->ptr
[src
]))
756 ind
= in
->ptr
[src
] - 'A' + 10;
758 ind
= in
->ptr
[src
] - 'a' + 10;
760 for (f
= formals
; f
!= NULL
; f
= f
->next
)
762 if (f
->index
== ind
- 1)
764 if (f
->actual
.len
!= 0)
765 sb_add_sb (out
, &f
->actual
);
767 sb_add_sb (out
, &f
->def
);
775 src
= sub_actual (src
, in
, &t
, formal_hash
, '\'', out
, 0);
778 else if ((macro_alternate
|| macro_mri
)
779 && (isalpha ((unsigned char) in
->ptr
[src
])
780 || in
->ptr
[src
] == '_'
781 || in
->ptr
[src
] == '$')
784 || (src
> 0 && in
->ptr
[src
- 1] == '@')))
787 || src
+ 5 >= in
->len
788 || strncasecmp (in
->ptr
+ src
, "LOCAL", 5) != 0
789 || ! ISWHITE (in
->ptr
[src
+ 5]))
792 src
= sub_actual (src
, in
, &t
, formal_hash
,
793 (macro_strip_at
&& inquote
) ? '@' : '\'',
800 src
= sb_skip_white (src
+ 5, in
);
801 while (in
->ptr
[src
] != '\n' && in
->ptr
[src
] != comment_char
)
807 f
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
811 f
->index
= LOCAL_INDEX
;
815 src
= get_token (src
, in
, &f
->name
);
817 sprintf (buf
, "LL%04x", loccnt
);
818 sb_add_string (&f
->actual
, buf
);
820 err
= hash_jam (formal_hash
, sb_terminate (&f
->name
), f
);
824 src
= sb_skip_comma (src
, in
);
828 else if (comment_char
!= '\0'
829 && in
->ptr
[src
] == comment_char
831 && in
->ptr
[src
+ 1] == comment_char
834 /* Two comment chars in a row cause the rest of the line to
836 while (src
< in
->len
&& in
->ptr
[src
] != '\n')
839 else if (in
->ptr
[src
] == '"'
840 || (macro_mri
&& in
->ptr
[src
] == '\''))
843 sb_add_char (out
, in
->ptr
[src
++]);
845 else if (in
->ptr
[src
] == '@' && macro_strip_at
)
849 && in
->ptr
[src
] == '@')
851 sb_add_char (out
, '@');
856 && in
->ptr
[src
] == '='
858 && in
->ptr
[src
+ 1] == '=')
863 src
= get_token (src
+ 2, in
, &t
);
864 ptr
= (formal_entry
*) hash_find (formal_hash
, sb_terminate (&t
));
867 /* FIXME: We should really return a warning string here,
868 but we can't, because the == might be in the MRI
869 comment field, and, since the nature of the MRI
870 comment field depends upon the exact instruction
871 being used, we don't have enough information here to
872 figure out whether it is or not. Instead, we leave
873 the == in place, which should cause a syntax error if
874 it is not in a comment. */
875 sb_add_char (out
, '=');
876 sb_add_char (out
, '=');
883 sb_add_string (out
, "-1");
887 sb_add_char (out
, '0');
893 sb_add_char (out
, in
->ptr
[src
++]);
899 while (loclist
!= NULL
)
904 hash_delete (formal_hash
, sb_terminate (&loclist
->name
));
905 sb_kill (&loclist
->name
);
906 sb_kill (&loclist
->def
);
907 sb_kill (&loclist
->actual
);
915 /* Assign values to the formal parameters of a macro, and expand the
919 macro_expand (idx
, in
, m
, out
, comment_char
)
929 int is_positional
= 0;
936 /* Reset any old value the actuals may have */
937 for (f
= m
->formals
; f
; f
= f
->next
)
938 sb_reset (&f
->actual
);
940 while (f
!= NULL
&& f
->index
< 0)
945 /* The macro may be called with an optional qualifier, which may
946 be referred to in the macro body as \0. */
947 if (idx
< in
->len
&& in
->ptr
[idx
] == '.')
951 n
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
955 n
->index
= QUAL_INDEX
;
957 n
->next
= m
->formals
;
960 idx
= get_any_string (idx
+ 1, in
, &n
->actual
, 1, 0);
964 /* Peel off the actuals and store them away in the hash tables' actuals */
965 idx
= sb_skip_white (idx
, in
);
966 while (idx
< in
->len
&& in
->ptr
[idx
] != comment_char
)
970 /* Look and see if it's a positional or keyword arg */
972 while (scan
< in
->len
973 && !ISSEP (in
->ptr
[scan
])
974 && !(macro_mri
&& in
->ptr
[scan
] == '\'')
975 && (!macro_alternate
&& in
->ptr
[scan
] != '='))
977 if (scan
< in
->len
&& !macro_alternate
&& in
->ptr
[scan
] == '=')
981 return "can't mix positional and keyword arguments";
983 /* This is a keyword arg, fetch the formal name and
984 then the actual stuff */
986 idx
= get_token (idx
, in
, &t
);
987 if (in
->ptr
[idx
] != '=')
988 return "confusion in formal parameters";
990 /* Lookup the formal in the macro's list */
991 ptr
= (formal_entry
*) hash_find (m
->formal_hash
, sb_terminate (&t
));
993 return "macro formal argument does not exist";
996 /* Insert this value into the right place */
997 sb_reset (&ptr
->actual
);
998 idx
= get_any_string (idx
+ 1, in
, &ptr
->actual
, 0, 0);
999 if (ptr
->actual
.len
> 0)
1005 /* This is a positional arg */
1008 return "can't mix positional and keyword arguments";
1016 return "too many positional arguments";
1018 f
= (formal_entry
*) xmalloc (sizeof (formal_entry
));
1021 sb_new (&f
->actual
);
1025 for (pf
= &m
->formals
; *pf
!= NULL
; pf
= &(*pf
)->next
)
1026 if ((*pf
)->index
>= c
)
1027 c
= (*pf
)->index
+ 1;
1034 sb_reset (&f
->actual
);
1035 idx
= get_any_string (idx
, in
, &f
->actual
, 1, 0);
1036 if (f
->actual
.len
> 0)
1042 while (f
!= NULL
&& f
->index
< 0);
1046 idx
= sb_skip_comma (idx
, in
);
1049 if (in
->ptr
[idx
] == ',')
1051 if (ISWHITE (in
->ptr
[idx
]))
1061 sb_add_string (&t
, macro_strip_at
? "$NARG" : "NARG");
1062 ptr
= (formal_entry
*) hash_find (m
->formal_hash
, sb_terminate (&t
));
1063 sb_reset (&ptr
->actual
);
1064 sprintf (buffer
, "%d", narg
);
1065 sb_add_string (&ptr
->actual
, buffer
);
1068 err
= macro_expand_body (&m
->sub
, out
, m
->formals
, m
->formal_hash
,
1073 /* Discard any unnamed formal arguments. */
1081 if ((*pf
)->name
.len
!= 0)
1085 sb_kill (&(*pf
)->name
);
1086 sb_kill (&(*pf
)->def
);
1087 sb_kill (&(*pf
)->actual
);
1101 /* Check for a macro. If one is found, put the expansion into
1102 *EXPAND. COMMENT_CHAR is the comment character--this is used by
1103 gasp. Return 1 if a macro is found, 0 otherwise. */
1106 check_macro (line
, expand
, comment_char
, error
)
1117 if (! isalpha ((unsigned char) *line
)
1120 && (! macro_mri
|| *line
!= '.'))
1124 while (isalnum ((unsigned char) *s
)
1129 copy
= (char *) alloca (s
- line
+ 1);
1130 memcpy (copy
, line
, s
- line
);
1131 copy
[s
- line
] = '\0';
1132 for (cs
= copy
; *cs
!= '\0'; cs
++)
1134 *cs
= tolower (*cs
);
1136 macro
= (macro_entry
*) hash_find (macro_hash
, copy
);
1141 /* Wrap the line up in an sb. */
1143 while (*s
!= '\0' && *s
!= '\n' && *s
!= '\r')
1144 sb_add_char (&line_sb
, *s
++);
1147 *error
= macro_expand (0, &line_sb
, macro
, expand
, comment_char
);
1154 /* Delete a macro. */
1160 hash_delete (macro_hash
, name
);
1163 /* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a
1164 combined macro definition and execution. This returns NULL on
1165 success, or an error message otherwise. */
1168 expand_irp (irpc
, idx
, in
, out
, get_line
, comment_char
)
1173 int (*get_line
) PARAMS ((sb
*));
1179 struct hash_control
*h
;
1187 idx
= sb_skip_white (idx
, in
);
1190 if (! buffer_and_nest (mn
, "ENDR", &sub
, get_line
))
1191 return "unexpected end of file in irp or irpc";
1197 idx
= get_token (idx
, in
, &f
.name
);
1198 if (f
.name
.len
== 0)
1199 return "missing model parameter";
1202 err
= hash_jam (h
, sb_terminate (&f
.name
), &f
);
1211 idx
= sb_skip_comma (idx
, in
);
1212 if (idx
>= in
->len
|| in
->ptr
[idx
] == comment_char
)
1214 /* Expand once with a null string. */
1215 err
= macro_expand_body (&sub
, out
, &f
, h
, comment_char
, 0);
1221 if (irpc
&& in
->ptr
[idx
] == '"')
1223 while (idx
< in
->len
&& in
->ptr
[idx
] != comment_char
)
1226 idx
= get_any_string (idx
, in
, &f
.actual
, 1, 0);
1229 if (in
->ptr
[idx
] == '"')
1233 nxt
= sb_skip_white (idx
+ 1, in
);
1234 if (nxt
>= in
->len
|| in
->ptr
[nxt
] == comment_char
)
1240 sb_reset (&f
.actual
);
1241 sb_add_char (&f
.actual
, in
->ptr
[idx
]);
1244 err
= macro_expand_body (&sub
, out
, &f
, h
, comment_char
, 0);
1248 idx
= sb_skip_comma (idx
, in
);
1250 idx
= sb_skip_white (idx
, in
);
This page took 0.054274 seconds and 4 git commands to generate.