harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4e9d60660d0f026bbb29a9339d29662e1eb5e24f
parent bdc04644989c6aeae0539d463019ed2633149238
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  4 Feb 2021 14:21:53 -0500

check, gen: allow tests to have name conflicts

Diffstat:
Msrc/check.c | 18++++++++++--------
Msrc/gen.c | 7++++++-
2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/check.c b/src/check.c @@ -1805,15 +1805,17 @@ scan_function(struct context *ctx, const struct ast_function_decl *decl) ctx->store, &fn_atype); assert(fntype); // TODO: Forward references - struct identifier ident = {0}; - if (decl->symbol) { - ident.name = strdup(decl->symbol); - } else if (!decl->ident.ns) { - mkident(ctx, &ident, &decl->ident); - } else { - ident = decl->ident; + if (!(decl->flags & FN_TEST)) { + struct identifier ident = {0}; + if (decl->symbol) { + ident.name = strdup(decl->symbol); + } else if (!decl->ident.ns) { + mkident(ctx, &ident, &decl->ident); + } else { + ident = decl->ident; + } + scope_insert(ctx->unit, O_DECL, &ident, &decl->ident, fntype, NULL); } - scope_insert(ctx->unit, O_DECL, &ident, &decl->ident, fntype, NULL); char buf[1024]; identifier_unparse_static(&decl->ident, buf, sizeof(buf)); diff --git a/src/gen.c b/src/gen.c @@ -2324,7 +2324,12 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl) struct qbe_def *qdef = xcalloc(1, sizeof(struct qbe_def)); qdef->kind = Q_FUNC; qdef->exported = decl->exported; - qdef->name = decl->symbol ? strdup(decl->symbol) : ident_to_sym(&decl->ident); + if (func->flags & FN_TEST) { + qdef->name = gen_name(ctx, "testfunc.%d"); + } else { + qdef->name = decl->symbol ? strdup(decl->symbol) + : ident_to_sym(&decl->ident); + } qdef->func.returns = qtype_for_type(ctx, fntype->func.result, false); ctx->current = &qdef->func;