summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-05-08 20:22:21 -0700
committerOri Bernstein <ori@eigenstate.org>2015-05-08 20:22:21 -0700
commit8c8335a2471a99d29e26ca60788ec7dc6dd5e768 (patch)
tree5be5286364828f7ae0fef88437aa941db39d45e9 /parse
parentae3b82a3fa5ee691c7f25bdb80be2b9c62a2b3cc (diff)
downloadmc-8c8335a2471a99d29e26ca60788ec7dc6dd5e768.tar.gz
Use before def checking is closer to working.
Reduce spurious errors.
Diffstat (limited to 'parse')
-rw-r--r--parse/gram.y13
-rw-r--r--parse/infer.c9
-rw-r--r--parse/ops.def1
3 files changed, 20 insertions, 3 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 47f3f0a..c241951 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -876,10 +876,19 @@ block : blkbody Tendblk
blkbody : decl {
size_t i;
+ Node *n, *d, *u;
+
$$ = mkblock($1.loc, mkstab());
for (i = 0; i < $1.nn; i++) {
- putdcl($$->block.scope, $1.nl[i]);
- lappend(&$$->block.stmts, &$$->block.nstmts, $1.nl[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);
}
}
| stmt {
diff --git a/parse/infer.c b/parse/infer.c
index aa840a0..937f116 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1448,8 +1448,15 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
}
settype(st, n, type(st, args[0]));
break;
+ case Oundef:
+ infersub(st, n, ret, sawret, &isconst);
+ settype(st, n, mktype(n->loc, Tyvoid));
+ break;
+ case Odef:
+ case Odead:
+ n->expr.type = mktype(n->loc, Tyvoid);
+ break;
case Obad: case Ocjmp: case Ojtab: case Oset:
- case Odead: case Oundef:
case Oslbase: case Osllen: case Outag:
case Oblit: case Oclear: case Oudata:
case Otrunc: case Oswiden: case Ozwiden:
diff --git a/parse/ops.def b/parse/ops.def
index 9b8de94..c5c3643 100644
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -58,6 +58,7 @@ O(Oarr, 1, OTmisc, NULL)
/* all below this point are backend-only */
O(Odead, 0, OTmisc, "DEAD") /* dead code */
O(Oundef, 0, OTmisc, "UNDEF") /* undefined var */
+O(Odef, 0, OTmisc, "DEF") /* defined var */
O(Ocjmp, 1, OTmisc, "CJMP") /* conditional jump */
O(Ojtab, 1, OTmisc, "JTAB") /* jump table */
O(Oset, 1, OTbin, "=") /* store to var */