summaryrefslogtreecommitdiff
path: root/parse/stab.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-20 22:02:21 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-20 22:26:18 -0800
commitc694d9a9c3f8c78837cf3bcbbe11fb19d04c204d (patch)
tree0f3c4d88df4e929d9c9fba5ff7646ec3fb056518 /parse/stab.c
parentd91d1e446ded81fba2452731ed40fec6e9a3be30 (diff)
downloadmc-c694d9a9c3f8c78837cf3bcbbe11fb19d04c204d.tar.gz
Put labels into scopes.
Diffstat (limited to 'parse/stab.c')
-rw-r--r--parse/stab.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/parse/stab.c b/parse/stab.c
index 5b5512d..9da49dc 100644
--- a/parse/stab.c
+++ b/parse/stab.c
@@ -109,8 +109,10 @@ Stab *mkstab(int isfunc)
st->ty = mkht(nsnamehash, nsnameeq);
st->tr = mkht(nsnamehash, nsnameeq);
st->uc = mkht(nsnamehash, nsnameeq);
- if (isfunc)
+ if (isfunc) {
st->env = mkht(nsnamehash, nsnameeq);
+ st->lbl = mkht(strhash, streq);
+ }
st->impl = mkht(implhash, impleq);
return st;
}
@@ -178,6 +180,26 @@ Node *getdcl(Stab *st, Node *n)
return NULL;
}
+void putlbl(Stab *st, char *name, Node *lbl)
+{
+ while (!st->isfunc && st->super)
+ st = st->super;
+ if (!st)
+ fatal(lbl, "label %s defined outside function\n", name);
+ if (hthas(st->lbl, name))
+ fatal(lbl, "duplicate label %s, first defined on line %d\n", name, lbl->loc.line);
+ htput(st->lbl, name, lbl);
+}
+
+Node *getlbl(Stab *st, Srcloc loc, char *name)
+{
+ while (!st->isfunc && st->super)
+ st = st->super;
+ if (!st || !hthas(st->lbl, name))
+ lfatal(loc, "unable to find label %s in function scope\n", name);
+ return htget(st->lbl, name);
+}
+
Type *gettype_l(Stab *st, Node *n)
{
Tydefn *t;