1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

- store builtin name as definition for builtin macros.

this removes the need for code->name conversion, in exchange for
systematically testing the definition type, since we can no longer
rely on the defn being NULL.

- commonnalize the builtin-detection code, so that we can use it for pushdef
as well with define, so that pushdef handles builtins correctly as well.

okay fries@, millert@.
This commit is contained in:
espie 2003-06-18 21:08:07 +00:00
parent 2b335b5e71
commit 5ddad5cc6c
3 changed files with 35 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $ */
/* $OpenBSD: eval.c,v 1.48 2003/06/18 21:08:07 espie Exp $ */
/* $NetBSD: eval.c,v 1.7 1996/11/10 21:21:29 pk Exp $ */
/*
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.2 (Berkeley) 4/27/95";
#else
static char rcsid[] = "$OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $";
static char rcsid[] = "$OpenBSD: eval.c,v 1.48 2003/06/18 21:08:07 espie Exp $";
#endif
#endif /* not lint */
@ -63,6 +63,7 @@ static char rcsid[] = "$OpenBSD: eval.c,v 1.47 2003/06/03 02:56:10 millert Exp $
#define BUILTIN_MARKER "__builtin_"
static void setup_definition(ndptr, const char *);
static void dodefn(const char *);
static void dopushdef(const char *, const char *);
static void dodump(const char *[], int);
@ -560,29 +561,22 @@ expand_macro(const char *argv[], int argc)
PUTBACK(*p);
}
/*
* dodefine - install definition in the table
* common part to dodefine and dopushdef
*/
void
dodefine(const char *name, const char *defn)
static void
setup_definition(ndptr p, const char *defn)
{
ndptr p;
int n;
if (!*name)
errx(1, "%s at line %lu: null definition.", CURRENT_NAME,
CURRENT_LINE);
if ((p = lookup(name)) == nil)
p = addent(name);
else if (p->defn != null)
free((char *) p->defn);
if (strncmp(defn, BUILTIN_MARKER, sizeof(BUILTIN_MARKER)-1) == 0) {
n = builtin_type(defn+sizeof(BUILTIN_MARKER)-1);
if (n != -1) {
p->type = n & TYPEMASK;
if ((n & NOARGS) == 0)
p->type |= NEEDARGS;
p->defn = null;
p->defn = xstrdup(defn+sizeof(BUILTIN_MARKER)-1);
return;
}
}
@ -591,6 +585,24 @@ dodefine(const char *name, const char *defn)
else
p->defn = xstrdup(defn);
p->type = MACRTYPE;
}
/*
* dodefine - install definition in the table
*/
void
dodefine(const char *name, const char *defn)
{
ndptr p;
if (!*name)
errx(1, "%s at line %lu: null definition.", CURRENT_NAME,
CURRENT_LINE);
if ((p = lookup(name)) == nil)
p = addent(name);
else if (p->defn != null)
free((char *) p->defn);
setup_definition(p, defn);
if (STREQ(name, defn))
p->type |= RECDEF;
}
@ -606,12 +618,12 @@ dodefn(const char *name)
char *real;
if ((p = lookup(name)) != nil) {
if (p->defn != null) {
if ((p->type & TYPEMASK) == MACRTYPE) {
pbstr(rquote);
pbstr(p->defn);
pbstr(lquote);
} else if ((real = builtin_realname(p->type)) != NULL) {
pbstr(real);
} else {
pbstr(p->defn);
pbstr(BUILTIN_MARKER);
}
}
@ -633,11 +645,7 @@ dopushdef(const char *name, const char *defn)
errx(1, "%s at line %lu: null definition", CURRENT_NAME,
CURRENT_LINE);
p = addent(name);
if (!*defn)
p->defn = null;
else
p->defn = xstrdup(defn);
p->type = MACRTYPE;
setup_definition(p, defn);
if (STREQ(name, defn))
p->type |= RECDEF;
}
@ -648,16 +656,11 @@ dopushdef(const char *name, const char *defn)
static void
dump_one_def(ndptr p)
{
char *real;
if (mimic_gnu) {
if ((p->type & TYPEMASK) == MACRTYPE)
fprintf(traceout, "%s:\t%s\n", p->name, p->defn);
else {
real = builtin_realname(p->type);
if (real == NULL)
real = null;
fprintf(traceout, "%s:\t<%s>\n", p->name, real);
fprintf(traceout, "%s:\t<%s>\n", p->name, p->defn);
}
} else
fprintf(traceout, "`%s'\t`%s'\n", p->name, p->defn);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.32 2003/06/12 14:36:43 espie Exp $ */
/* $OpenBSD: extern.h,v 1.33 2003/06/18 21:08:07 espie Exp $ */
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
/*-
@ -66,7 +66,6 @@ extern void remhash(const char *, int);
/* main.c */
extern void outputstr(const char *);
extern int builtin_type(const char *);
extern char *builtin_realname(int);
extern void do_emit_synchline(void);
#define emit_synchline() do { if (synch_lines) do_emit_synchline(); } while(0)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main.c,v 1.57 2003/06/12 14:36:43 espie Exp $ */
/* $OpenBSD: main.c,v 1.58 2003/06/18 21:08:07 espie Exp $ */
/* $NetBSD: main.c,v 1.12 1997/02/08 23:54:49 cgd Exp $ */
/*-
@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$OpenBSD: main.c,v 1.57 2003/06/12 14:36:43 espie Exp $";
static char rcsid[] = "$OpenBSD: main.c,v 1.58 2003/06/18 21:08:07 espie Exp $";
#endif
#endif /* not lint */
@ -586,7 +586,7 @@ initkwds(void)
p->nxtptr = hashtab[h % HASHSIZE];
hashtab[h % HASHSIZE] = p;
p->name = xstrdup(keywrds[i].knam);
p->defn = null;
p->defn = xstrdup(keywrds[i].knam);
p->hv = h;
p->type = keywrds[i].ktyp & TYPEMASK;
if ((keywrds[i].ktyp & NOARGS) == 0)
@ -606,17 +606,6 @@ builtin_type(const char *key)
return -1;
}
char *
builtin_realname(int n)
{
int i;
for (i = 0; i != MAXKEYS; i++)
if (((keywrds[i].ktyp ^ n) & TYPEMASK) == 0)
return keywrds[i].knam;
return NULL;
}
static void
record(struct position *t, int lev)
{