Aria

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

commit d1492be55b71589353369899c04fbe1661ae9e29
parent 810119b44fdb4cff269d676d4bd5ca4061b94c28
Author: m21c  <ho*******@gmail.com>
Date:   Thu, 15 Jul 2021 15:14:21 +0200

worked on SrcLoc for Env, Decl and Type

Diffstat:
Maria.c | 37+++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/aria.c b/aria.c @@ -1379,8 +1379,14 @@ Type typebuf[4096]; int typetop; Type * -maketype(void) { - return typebuf + typetop++; +maketype(SrcLoc *loc, Type *orig, Type *target) { + Type *ty = typebuf + typetop++; + + *ty = *orig; + ty->loc = *loc; + ty->target = target; + + return ty; } @@ -1448,6 +1454,10 @@ setheadenv(Source *source, EnvKind kind) { Env *env = envbuf + envtop++; env->kind = kind; + + /* TODO(m21c): make sure that source->tok.loc is the correct + * source-location. */ + env->loc = source->tok.loc; env->below = source->currenv; assert(source->headenv == NULL); @@ -1469,6 +1479,9 @@ pushenv(Source *source, EnvKind kind) { Env *env = envbuf + envtop++; env->kind = kind; + /* TODO(m21c): make sure that source->tok.loc is the correct + * source-location. */ + env->loc = source->tok.loc; env->below = source->currenv; source->currenv = env; @@ -1516,6 +1529,8 @@ makedecl(Source *source, int key, DeclKind kind) { Decl *probe, *decl = declbuf + decltop++; decl->kind = kind; + /* TODO(m21c): make sure that source->tok.loc is the correct + * source-location. */ decl->loc = source->tok.loc; decl->key = key; decl->type = prim + TVOID; @@ -1526,6 +1541,8 @@ makedecl(Source *source, int key, DeclKind kind) { probe = finddeclinenv(key, currenv); if (probe) { + /* TODO(m21c): make sure that source->tok.loc is the correct + * source-location. */ error( &source->tok.loc, "'%s' already declared", @@ -1669,11 +1686,10 @@ advance: flags = qualifiers(source, QTYPE); if (getkind(source) == '[') { - Type *tmp = maketype(); - tmp->kind = TARRAY; - tmp->target = basetype, basetype = tmp; - gettok(source, false); + Type *tmp = maketype(getloc(source), prim + TARRAY, basetype); + basetype = tmp; + gettok(source, false); if (source->tok.kind != ']') basetype->u.val = expr(source, PSTART); @@ -1682,9 +1698,8 @@ advance: } if (getkind(source) == OLPTR) { - Type *tmp = maketype(); - tmp->kind = TPTR; - tmp->target = basetype, basetype = tmp; + Type *tmp = maketype(getloc(source), prim + TPTR, basetype); + basetype = tmp; gettok(source, false); goto advance; @@ -2532,9 +2547,7 @@ autoref(Type *ty, Node *node) } if (numderefs == -1) { - t = maketype(); - *t = prim[TPTR]; - t->target = node->type; + t = maketype(&node->loc, prim + TPTR, node->type); n = makenode(node, node); n->type = t;