summaryrefslogtreecommitdiff
path: root/parse/gram.y
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2018-06-09 13:47:28 -0700
committerOri Bernstein <ori@eigenstate.org>2018-06-09 13:47:28 -0700
commit84393ead97a2e189b6057420ad7d94170b9aa00f (patch)
tree0356c0bc422713adde510745645d652aa867944f /parse/gram.y
parent92840bc1ade4d670ce1b6cd3dc7be48b16148a5e (diff)
downloadmc-84393ead97a2e189b6057420ad7d94170b9aa00f.tar.gz
Consistently and corretly add Oundef.
Diffstat (limited to 'parse/gram.y')
-rw-r--r--parse/gram.y28
1 files changed, 17 insertions, 11 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 9d9ddef..146c842 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -35,6 +35,7 @@ static void installucons(Stab *st, Type *t);
static void setattrs(Node *dcl, char **attrs, size_t nattrs);
static void setwith(Type *ty, Traitspec **spec, size_t nspec);
static void setupinit(Node *n);
+static void addinit(Node *blk, Node *dcl);
%}
@@ -1064,19 +1065,11 @@ block : blkbody Tendblk
blkbody : decl {
size_t i;
- Node *n, *d, *u;
$$ = mkblock($1.loc, mkstab(0));
for (i = 0; i < $1.nn; i++) {
- d = $1.nl[i];
- putdcl($$->block.scope, d);
- if (!d->decl.init) {
- n = mkexpr(d->loc, Ovar, d->decl.name, NULL);
- u = mkexpr(n->loc, Oundef, n, NULL);
- n->expr.did = d->decl.did;
- lappend(&$$->block.stmts, &$$->block.nstmts, u);
- }
- lappend(&$$->block.stmts, &$$->block.nstmts, d);
+ putdcl($$->block.scope, $1.nl[i]);
+ addinit($$, $1.nl[i]);
}
}
| stmt {
@@ -1098,7 +1091,7 @@ blkbody : decl {
size_t i;
for (i = 0; i < $3.nn; i++){
putdcl($$->block.scope, $3.nl[i]);
- lappend(&$1->block.stmts, &$1->block.nstmts, $3.nl[i]);
+ addinit($$, $3.nl[i]);
}
}
| blkbody Tendln tydef {
@@ -1119,6 +1112,19 @@ label : Tcolon Tident {
%%
static void
+addinit(Node *blk, Node *dcl)
+{
+ Node *n, *u;
+ if (!dcl->decl.init) {
+ n = mkexpr(dcl->loc, Ovar, dcl->decl.name, NULL);
+ u = mkexpr(n->loc, Oundef, n, NULL);
+ n->expr.did = dcl->decl.did;
+ lappend(&blk->block.stmts, &blk->block.nstmts, u);
+ }
+ lappend(&blk->block.stmts, &blk->block.nstmts, dcl);
+}
+
+static void
setupinit(Node *n)
{
char name[1024];