aboutsummaryrefslogtreecommitdiff
path: root/gas/macro.c
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@novell.com>2005-01-31 14:26:13 +0000
committerJan Beulich <jbeulich@novell.com>2005-01-31 14:26:13 +0000
commit057f53c1ad39b24d7833c2eb23aec562c8c3a002 (patch)
tree26ad7ac7ca6bb3f17d7783ea997decae5fdd9aac /gas/macro.c
parente87b2913a34b6a601214f3b3634e9c8949276526 (diff)
downloadgdb-057f53c1ad39b24d7833c2eb23aec562c8c3a002.zip
gdb-057f53c1ad39b24d7833c2eb23aec562c8c3a002.tar.gz
gdb-057f53c1ad39b24d7833c2eb23aec562c8c3a002.tar.bz2
gas/
2005-01-31 Jan Beulich <jbeulich@novell.com> * macro.c (do_formals): Adjust to no longer accept empty parameter names. (define_macro): Adjust to no longer accept empty macro name, garbage following the parameters, or macros that were previously defined. * read.c (s_bad_end): Declare. (potable): Add endm. Handler for endr and endm is s_bad_end. (s_bad_end): Rename from s_bad_endr. Adjust to handle both .endm and .endr. * read.h (s_bad_endr): Remove. gas/testsuite/ 2005-01-31 Jan Beulich <jbeulich@novell.com> * gas/macros/badarg.[ls]: New. * gas/macros/end.[ls]: New. * gas/macros/redef.[ls]: New. * gas/macros/macros.exp (run_list_test): Copy from elsewhere. Run new tests.
Diffstat (limited to 'gas/macro.c')
-rw-r--r--gas/macro.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/gas/macro.c b/gas/macro.c
index edadcc9..2173d00 100644
--- a/gas/macro.c
+++ b/gas/macro.c
@@ -435,9 +435,11 @@ do_formals (macro_entry *macro, int idx, sb *in)
macro->formal_count = 0;
macro->formal_hash = hash_new ();
+ idx = sb_skip_white (idx, in);
while (idx < in->len)
{
formal_entry *formal;
+ int cidx;
formal = (formal_entry *) xmalloc (sizeof (formal_entry));
@@ -445,27 +447,33 @@ do_formals (macro_entry *macro, int idx, sb *in)
sb_new (&formal->def);
sb_new (&formal->actual);
- idx = sb_skip_white (idx, in);
idx = get_token (idx, in, &formal->name);
if (formal->name.len == 0)
- break;
+ {
+ if (macro->formal_count)
+ --idx;
+ break;
+ }
idx = sb_skip_white (idx, in);
- if (formal->name.len)
+ /* This is a formal. */
+ if (idx < in->len && in->ptr[idx] == '=')
{
- /* This is a formal. */
- if (idx < in->len && in->ptr[idx] == '=')
- {
- /* Got a default. */
- idx = get_any_string (idx + 1, in, &formal->def, 1, 0);
- }
+ /* Got a default. */
+ idx = get_any_string (idx + 1, in, &formal->def, 1, 0);
+ idx = sb_skip_white (idx, in);
}
/* Add to macro's hash table. */
hash_jam (macro->formal_hash, sb_terminate (&formal->name), formal);
- formal->index = macro->formal_count;
+ formal->index = macro->formal_count++;
+ cidx = idx;
idx = sb_skip_comma (idx, in);
- macro->formal_count++;
+ if (idx != cidx && idx >= in->len)
+ {
+ idx = cidx;
+ break;
+ }
*p = formal;
p = &formal->next;
*p = NULL;
@@ -533,8 +541,9 @@ define_macro (int idx, sb *in, sb *label,
{
/* It's the label: MACRO (formals,...) sort */
idx = do_formals (macro, idx + 1, in);
- if (in->ptr[idx] != ')')
+ if (idx >= in->len || in->ptr[idx] != ')')
return _("missing ) after formals");
+ idx = sb_skip_white (idx + 1, in);
}
else
{
@@ -544,15 +553,27 @@ define_macro (int idx, sb *in, sb *label,
}
else
{
+ int cidx;
+
idx = get_token (idx, in, &name);
- idx = sb_skip_comma (idx, in);
- idx = do_formals (macro, idx, in);
+ if (name.len == 0)
+ return _("Missing macro name");
+ cidx = sb_skip_white (idx, in);
+ idx = sb_skip_comma (cidx, in);
+ if (idx == cidx || idx < in->len)
+ idx = do_formals (macro, idx, in);
+ else
+ idx = cidx;
}
+ if (idx < in->len)
+ return _("Bad macro parameter list");
/* And stick it in the macro hash table. */
for (idx = 0; idx < name.len; idx++)
name.ptr[idx] = TOLOWER (name.ptr[idx]);
namestr = sb_terminate (&name);
+ if (hash_find (macro_hash, namestr))
+ return _("Macro with this name was already defined");
hash_jam (macro_hash, namestr, (PTR) macro);
macro_defined = 1;