aboutsummaryrefslogtreecommitdiff
path: root/decl.c
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2024-04-12 00:46:22 -0700
committerMichael Forney <mforney@mforney.org>2024-04-12 00:46:22 -0700
commit7d6efdd8626fd3a654a8f231fc1ddc481352af6a (patch)
treeedc6352a07ffd5e23af2f9ffcbc4c0d0be6c38e9 /decl.c
parentaefce92bd54033c49ba007fde4904dfc6ca740ff (diff)
decl: Add name field to decl struct
Diffstat (limited to 'decl.c')
-rw-r--r--decl.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/decl.c b/decl.c
index eb9217b..a2b689e 100644
--- a/decl.c
+++ b/decl.c
@@ -60,12 +60,13 @@ struct structbuilder {
};
struct decl *
-mkdecl(enum declkind k, struct type *t, enum typequal tq, enum linkage linkage)
+mkdecl(char *name, enum declkind k, struct type *t, enum typequal tq, enum linkage linkage)
{
struct decl *d;
d = xmalloc(sizeof(*d));
memset(d, 0, sizeof(*d));
+ d->name = name;
d->kind = k;
d->linkage = linkage;
d->type = t;
@@ -271,7 +272,7 @@ tagspec(struct scope *s)
}
assert(i < LEN(inttypes));
}
- d = mkdecl(DECLCONST, et, QUALNONE, LINKNONE);
+ d = mkdecl(name, DECLCONST, et, QUALNONE, LINKNONE);
d->value = mkintconst(value);
d->next = enumconsts;
enumconsts = d;
@@ -281,7 +282,7 @@ tagspec(struct scope *s)
} else if (value > max) {
max = value;
}
- scopeputdecl(s, name, d);
+ scopeputdecl(s, d);
if (!consume(TCOMMA))
break;
}
@@ -979,8 +980,8 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc
t = typecomposite(t, prior->type);
}
}
- d = mkdecl(kind, t, tq, linkage);
- scopeputdecl(s, name, d);
+ d = mkdecl(name, kind, t, tq, linkage);
+ scopeputdecl(s, d);
if (kind == DECLFUNC || linkage != LINKNONE || sc & SCSTATIC) {
if (asmname)
name = asmname;
@@ -1053,7 +1054,7 @@ decl(struct scope *s, struct func *f)
if (asmname)
error(&tok.loc, "typedef '%s' declared with assembler label", name);
if (!prior)
- scopeputdecl(s, name, mkdecl(DECLTYPE, t, tq, LINKNONE));
+ scopeputdecl(s, mkdecl(name, DECLTYPE, t, tq, LINKNONE));
else if (!typesame(prior->type, t) || prior->qual != tq)
error(&tok.loc, "typedef '%s' redefined with different type", name);
break;
@@ -1147,7 +1148,7 @@ stringdecl(struct expr *expr)
entry = mapput(&strings, &key);
d = *entry;
if (!d) {
- d = mkdecl(DECLOBJECT, expr->type, QUALNONE, LINKNONE);
+ d = mkdecl(NULL, DECLOBJECT, expr->type, QUALNONE, LINKNONE);
d->value = mkglobal("string", true);
emitdata(d, mkinit(0, expr->type->size, (struct bitfield){0}, expr));
*entry = d;