* sb.c, macro.c: Include string.h.

This commit is contained in:
Ken Raeburn 1995-10-06 01:37:30 +00:00
parent 6b0a6eaa68
commit 2c5eb48d3a
3 changed files with 75 additions and 10 deletions

View file

@ -1,5 +1,7 @@
Thu Oct 5 20:17:30 1995 Ken Raeburn <raeburn@cygnus.com> Thu Oct 5 20:17:30 1995 Ken Raeburn <raeburn@cygnus.com>
* sb.c, macro.c: Include string.h.
* Makefile.in (comparison): Only check *.o; we don't care if * Makefile.in (comparison): Only check *.o; we don't care if
timestamps inserted by the native linker differ. timestamps inserted by the native linker differ.

View file

@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
@ -112,6 +113,10 @@ static int macro_alternate;
static int macro_mri; static int macro_mri;
/* Whether we should strip '@' characters. */
static int macro_strip_at;
/* Function to use to parse an expression. */ /* Function to use to parse an expression. */
static int (*macro_expr) PARAMS ((const char *, int, sb *, int *)); static int (*macro_expr) PARAMS ((const char *, int, sb *, int *));
@ -123,15 +128,17 @@ static int macro_number;
/* Initialize macro processing. */ /* Initialize macro processing. */
void void
macro_init (alternate, mri, expr) macro_init (alternate, mri, strip_at, expr)
int alternate; int alternate;
int mri; int mri;
int strip_at;
int (*expr) PARAMS ((const char *, int, sb *, int *)); int (*expr) PARAMS ((const char *, int, sb *, int *));
{ {
macro_hash = hash_new (); macro_hash = hash_new ();
macro_defined = 0; macro_defined = 0;
macro_alternate = alternate; macro_alternate = alternate;
macro_mri = mri; macro_mri = mri;
macro_strip_at = strip_at;
macro_expr = expr; macro_expr = expr;
} }
@ -469,6 +476,7 @@ do_formals (macro, idx, in)
if (macro_mri) if (macro_mri)
{ {
formal_entry *formal; formal_entry *formal;
const char *name;
/* Add a special NARG formal, which macro_expand will set to the /* Add a special NARG formal, which macro_expand will set to the
number of arguments. */ number of arguments. */
@ -478,10 +486,17 @@ do_formals (macro, idx, in)
sb_new (&formal->def); sb_new (&formal->def);
sb_new (&formal->actual); sb_new (&formal->actual);
sb_add_string (&formal->name, "NARG"); /* The same MRI assemblers which treat '@' characters also use
the name $NARG. At least until we find an exception. */
if (macro_strip_at)
name = "$NARG";
else
name = "NARG";
sb_add_string (&formal->name, name);
/* Add to macro's hash table */ /* Add to macro's hash table */
hash_jam (macro->formal_hash, "NARG", formal); hash_jam (macro->formal_hash, name, formal);
formal->index = NARG_INDEX; formal->index = NARG_INDEX;
*p = formal; *p = formal;
@ -533,7 +548,7 @@ define_macro (idx, in, label, get_line)
else else
{ {
idx = get_token (idx, in, &name); idx = get_token (idx, in, &name);
idx = sb_skip_white (idx, in); idx = sb_skip_comma (idx, in);
idx = do_formals (macro, idx, in); idx = do_formals (macro, idx, in);
} }
@ -558,7 +573,8 @@ get_apost_token (idx, in, name, kind)
int kind; int kind;
{ {
idx = get_token (idx, in, name); idx = get_token (idx, in, name);
if (idx < in->len && in->ptr[idx] == kind && ! macro_mri) if (idx < in->len && in->ptr[idx] == kind
&& (! macro_mri || macro_strip_at))
idx++; idx++;
return idx; return idx;
} }
@ -709,7 +725,10 @@ macro_expand_body (in, out, formals, formal_hash, comment_char, locals)
else if ((macro_alternate || macro_mri) else if ((macro_alternate || macro_mri)
&& (isalpha ((unsigned char) in->ptr[src]) && (isalpha ((unsigned char) in->ptr[src])
|| in->ptr[src] == '_' || in->ptr[src] == '_'
|| in->ptr[src] == '$')) || in->ptr[src] == '$')
&& (! inquote
|| ! macro_strip_at
|| (src > 0 && in->ptr[src - 1] == '@')))
{ {
if (! locals if (! locals
|| src + 5 >= in->len || src + 5 >= in->len
@ -717,7 +736,9 @@ macro_expand_body (in, out, formals, formal_hash, comment_char, locals)
|| ! ISWHITE (in->ptr[src + 5])) || ! ISWHITE (in->ptr[src + 5]))
{ {
sb_reset (&t); sb_reset (&t);
src = sub_actual (src, in, &t, formal_hash, '\'', out, 1); src = sub_actual (src, in, &t, formal_hash,
(macro_strip_at && inquote) ? '@' : '\'',
out, 1);
} }
else else
{ {
@ -768,6 +789,16 @@ macro_expand_body (in, out, formals, formal_hash, comment_char, locals)
inquote = !inquote; inquote = !inquote;
sb_add_char (out, in->ptr[src++]); sb_add_char (out, in->ptr[src++]);
} }
else if (in->ptr[src] == '@' && macro_strip_at)
{
++src;
if (src < in->len
&& in->ptr[src] == '@')
{
sb_add_char (out, '@');
++src;
}
}
else if (macro_mri else if (macro_mri
&& in->ptr[src] == '=' && in->ptr[src] == '='
&& src + 1 < in->len && src + 1 < in->len
@ -805,6 +836,7 @@ macro_expand_body (in, out, formals, formal_hash, comment_char, locals)
formal_entry *f; formal_entry *f;
f = loclist->next; f = loclist->next;
hash_delete (formal_hash, sb_terminate (&loclist->name));
sb_kill (&loclist->name); sb_kill (&loclist->name);
sb_kill (&loclist->def); sb_kill (&loclist->def);
sb_kill (&loclist->actual); sb_kill (&loclist->actual);
@ -944,7 +976,15 @@ macro_expand (idx, in, m, out, comment_char)
while (f != NULL && f->index < 0); while (f != NULL && f->index < 0);
} }
idx = sb_skip_comma (idx, in); if (! macro_mri)
idx = sb_skip_comma (idx, in);
else
{
if (in->ptr[idx] == ',')
++idx;
if (ISWHITE (in->ptr[idx]))
break;
}
} }
if (macro_mri) if (macro_mri)
@ -952,7 +992,7 @@ macro_expand (idx, in, m, out, comment_char)
char buffer[20]; char buffer[20];
sb_reset (&t); sb_reset (&t);
sb_add_string (&t, "NARG"); sb_add_string (&t, macro_strip_at ? "$NARG" : "NARG");
ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate (&t)); ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate (&t));
sb_reset (&ptr->actual); sb_reset (&ptr->actual);
sprintf (buffer, "%d", narg); sprintf (buffer, "%d", narg);
@ -1045,6 +1085,15 @@ check_macro (line, expand, comment_char, error)
return 1; return 1;
} }
/* Delete a macro. */
void
delete_macro (name)
const char *name;
{
hash_delete (macro_hash, name);
}
/* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a /* Handle the MRI IRP and IRPC pseudo-ops. These are handled as a
combined macro definition and execution. This returns NULL on combined macro definition and execution. This returns NULL on
success, or an error message otherwise. */ success, or an error message otherwise. */
@ -1103,12 +1152,25 @@ expand_irp (irpc, idx, in, out, get_line, comment_char)
} }
else else
{ {
if (irpc && in->ptr[idx] == '"')
++idx;
while (idx < in->len && in->ptr[idx] != comment_char) while (idx < in->len && in->ptr[idx] != comment_char)
{ {
if (!irpc) if (!irpc)
idx = get_any_string (idx, in, &f.actual, 1, 0); idx = get_any_string (idx, in, &f.actual, 1, 0);
else else
{ {
if (in->ptr[idx] == '"')
{
int nxt;
nxt = sb_skip_white (idx + 1, in);
if (nxt >= in->len || in->ptr[nxt] == comment_char)
{
idx = nxt;
break;
}
}
sb_reset (&f.actual); sb_reset (&f.actual);
sb_add_char (&f.actual, in->ptr[idx]); sb_add_char (&f.actual, in->ptr[idx]);
++idx; ++idx;

View file

@ -23,6 +23,8 @@
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "libiberty.h"
#include "sb.h" #include "sb.h"
/* These routines are about manipulating strings. /* These routines are about manipulating strings.
@ -63,7 +65,6 @@ sb_build (ptr, size)
/* see if we can find one to allocate */ /* see if we can find one to allocate */
sb_element *e; sb_element *e;
#undef abort
if (size > sb_max_power_two) if (size > sb_max_power_two)
abort (); abort ();