Aria

A low-level systems programming language
git clone git://git.m21c.me/Aria.git
Log | Files | Refs | README | LICENSE

commit 5d413b5820ea2b42ae1815de06aae650351a44bc
parent c9f8394bf9fc27527b208657d6d9fc7ef625b59c
Author: m21c <ho*******@gmail.com>
Date:   Tue, 23 Jun 2026 17:36:26 +0200

refactor: use isrecordenv()

Diffstat:
Mcompiler.c | 32+++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/compiler.c b/compiler.c @@ -2325,6 +2325,13 @@ deleteenv(Env *env) /* @todo delete env */ } +static bool +isrecordenv(Env *env) +{ + assert(env); + return env->kind == SSTRUCT || env->kind == SUNION; +} + // }}} @@ -2961,11 +2968,10 @@ redodeclaration: if (getkind(source) == IDENT) { int key = source->tok.u.key; SrcLoc loc = source->tok.loc; - EnvKind envkind = env->kind; gettok(source); - if (tryreadtype && (envkind == SSTRUCT || envkind == SUNION)) { + if (tryreadtype && isrecordenv(env)) { if (!isbasicdelimiter(getkind(source)) && getkind(source) != LPARDELIM) @@ -3118,7 +3124,7 @@ redodeclaration: body = stmtlist(source, source->lastindent, SFUNCTION, decl, !!functionenv); - if (env->kind != SSTRUCT && env->kind != SUNION) { + if (!isrecordenv(env)) { assert(body && body->kind == ASCOPE); functionenv = body->u.env; } @@ -3171,7 +3177,7 @@ redodeclaration: } finish: - if (env->kind == SSTRUCT || env->kind == SUNION) + if (isrecordenv(env)) decl->flags |= MRECORDMEMBER; result = tokennode(source, decl->u.content); @@ -3195,14 +3201,10 @@ readident(Source *source, int flags) SrcLoc loc = source->tok.loc; int key = source->tok.u.key; - EnvKind envkind = source->currenv - ? source->currenv->kind - : STOPLEVEL; - decl = finddeclaration(source, source->currenv, source->tok.u.key); gettok(source); - if (!decl && (envkind == SSTRUCT || envkind == SUNION)) { + if (!decl && isrecordenv(source->currenv)) { if (!isbasicdelimiter(getkind(source))) { decl = defertypedeclaration(source, key); decl->loc = loc; @@ -6399,9 +6401,7 @@ cgtype(CodeGen *cg, Type *type, Decl *decl) Type *post[64]; int top = 0, pcount = 0; - if ((cg->env->kind == SSTRUCT - || cg->env->kind == SUNION) - && type->kind == TFUNCTION) { + if (isrecordenv(cg->env) && type->kind == TFUNCTION) { assert(top < lengthof(stack)); stack[top++] = maketype( cg->env->arenas, &decl->loc, @@ -6448,7 +6448,7 @@ decorate: } if (decl) { - if (cg->env->kind == SSTRUCT || cg->env->kind == SUNION) + if (isrecordenv(cg->env)) cgprintf(cg, "%s", getstring(idents, decl->key)); else cgdeclname(cg, decl); @@ -6599,8 +6599,7 @@ cgdeclaration(CodeGen *cg, Node *expr) cgprintf(cg, "}\n"); cg->hasclause = true; } else if (decl->kind == DPARAM || decl->kind == DVAR) { - if (decl->parentenv->kind == SUNION - || decl->parentenv->kind == SSTRUCT) + if (isrecordenv(decl->parentenv)) return; cgprintf(cg, " = "); @@ -7994,8 +7993,7 @@ printexpr(FILE *out, Node *expr, int indent) if (expr->lhs && expr->lhs->kind == ASTMT && expr->u.env && - expr->u.env->kind != SFUNCTION && - expr->u.env->kind != SSTRUCT) + !isrecordenv(expr->u.env)) { Node *stmt = expr->lhs;