commit f386bec34579235f8c4e6928ed3374f393979d2f
parent 6aa84a53d8330534396129492073f269321e822a
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 19 Dec 2020 13:16:07 -0500
check: populate identifier for checked decls
Diffstat:
3 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/include/identifier.h b/include/identifier.h
@@ -10,5 +10,6 @@ struct identifier {
char *identifier_unparse(const struct identifier *ident);
int identifier_unparse_static(const struct identifier *ident,
char *buf, size_t len);
+void identifier_dup(struct identifier *new, const struct identifier *ident);
#endif
diff --git a/src/check.c b/src/check.c
@@ -133,6 +133,7 @@ check_function(struct context *ctx,
assert(fntype); // Invariant
decl->type = DECL_FUNC;
decl->func.type = fntype;
+ identifier_dup(&decl->ident, &afndecl->ident);
decl->func.flags = afndecl->flags;
struct expression *body = calloc(1, sizeof(struct expression));
diff --git a/src/identifier.c b/src/identifier.c
@@ -62,3 +62,14 @@ identifier_unparse_static(const struct identifier *ident, char *buf, size_t len)
}
return n;
}
+
+void
+identifier_dup(struct identifier *new, const struct identifier *ident)
+{
+ assert(ident && new);
+ new->name = strdup(ident->name);
+ if (ident->ns) {
+ new->ns = calloc(1, sizeof(struct identifier));
+ identifier_dup(new->ns, ident->ns);
+ }
+}