Allow symbolic references not just to symbol tables:

(xunsymbol1): Use ef_elt_byname().
(setsym): Accept any table reference, not just to symbol table.
(symval): New.
(setsym, add2symset): Use it.
(mtsymset): Last remaining user of getsymtab(); inline and simplify.
(getsymtab): Remove.

(xunsymbol1, xunsymbol): Rename.
This commit is contained in:
Markus Armbruster 2006-06-01 19:15:30 +00:00
parent a1546476bf
commit 568b9d6639

View file

@ -80,11 +80,10 @@ static int defellipsis(int fldno);
static int chkflds(void); static int chkflds(void);
static int setnum(int, double); static int setnum(int, double);
static int setstr(int, char *); static int setstr(int, char *);
static int xunsymbol1(char *, struct symbol *, struct castr *, int); static int xunsymbol(char *, struct castr *, int);
static int setsym(int, char *); static int setsym(int, char *);
static int mtsymset(int, long *); static int mtsymset(int, long *);
static int add2symset(int, long *, char *); static int add2symset(int, long *, char *);
static struct symbol *get_symtab(struct castr *);
static int xundump1(FILE *, int, struct castr *); static int xundump1(FILE *, int, struct castr *);
static int xundump2(FILE *, int, struct castr *); static int xundump2(FILE *, int, struct castr *);
@ -445,6 +444,7 @@ setnum(int fldno, double dbl)
return -1; return -1;
memb_ptr += ca->ca_off; memb_ptr += ca->ca_off;
/* FIXME check assignment preserves value */
switch (ca->ca_type) { switch (ca->ca_type) {
case NSC_CHAR: case NSC_CHAR:
old = ((signed char *)memb_ptr)[idx]; old = ((signed char *)memb_ptr)[idx];
@ -561,10 +561,9 @@ setstr(int fldno, char *str)
} }
static int static int
xunsymbol1(char *id, struct symbol *symtab, struct castr *ca, int n) xunsymbol(char *id, struct castr *ca, int n)
{ {
int i = stmtch(id, symtab, offsetof(struct symbol, name), int i = ef_elt_byname(ca->ca_table, id);
sizeof(struct symbol));
if (i < 0) if (i < 0)
return gripe("%s %s symbol `%s' in field %d", return gripe("%s %s symbol `%s' in field %d",
i == M_NOTUNIQUE ? "Ambiguous" : "Unknown", i == M_NOTUNIQUE ? "Ambiguous" : "Unknown",
@ -572,25 +571,37 @@ xunsymbol1(char *id, struct symbol *symtab, struct castr *ca, int n)
return i; return i;
} }
static int
symval(struct castr *ca, int i)
{
int type = ca->ca_table;
if (ef_check(type) < 0)
return -1;
if (ef_cadef(type) == symbol_ca)
/* symbol table, value is in the table */
return ((struct symbol *)ef_ptr(type, i))->value;
/* value is the table index */
return i;
}
static int static int
setsym(int fldno, char *sym) setsym(int fldno, char *sym)
{ {
struct castr *ca; struct castr *ca;
struct symbol *symtab;
int i; int i;
ca = getfld(fldno, NULL); ca = getfld(fldno, NULL);
if (!ca) if (!ca)
return -1; return -1;
symtab = get_symtab(ca); if (ca->ca_table == EF_BAD || (ca->ca_flags & NSC_BITS))
if (!symtab || (ca->ca_flags & NSC_BITS))
return gripe("Field %d doesn't take symbols", fldno + 1); return gripe("Field %d doesn't take symbols", fldno + 1);
i = xunsymbol1(sym, symtab, ca, fldno); i = xunsymbol(sym, ca, fldno);
if (i < 0) if (i < 0)
return -1; return -1;
return setnum(fldno, symtab[i].value); return setnum(fldno, symval(ca, i));
} }
static int static int
@ -603,10 +614,9 @@ mtsymset(int fldno, long *set)
if (!ca) if (!ca)
return -1; return -1;
symtab = get_symtab(ca); if (ca->ca_table == EF_BAD || ef_cadef(ca->ca_table) != symbol_ca
if (!symtab || !(ca->ca_flags & NSC_BITS)) { || !(ca->ca_flags & NSC_BITS))
return gripe("Field %d doesn't take symbol sets", fldno + 1); return gripe("Field %d doesn't take symbol sets", fldno + 1);
}
*set = 0; *set = 0;
return 0; return 0;
} }
@ -622,28 +632,13 @@ add2symset(int fldno, long *set, char *sym)
if (!ca) if (!ca)
return -1; return -1;
symtab = get_symtab(ca); i = xunsymbol(sym, ca, fldno);
i = xunsymbol1(sym, symtab, ca, fldno);
if (i < 0) if (i < 0)
return -1; return -1;
*set |= symtab[i].value; *set |= symval(ca, i);
return 0; return 0;
} }
static struct symbol *
get_symtab(struct castr *ca)
{
int symtype = ca->ca_table;
struct symbol *symtab;
if (symtype == EF_BAD || ef_cadef(symtype) != symbol_ca)
return NULL;
symtab = ef_ptr(symtype, 0);
CANT_HAPPEN(!symtab);
return symtab;
}
static int static int
xuheader(FILE *fp, int expected_table) xuheader(FILE *fp, int expected_table)
{ {