summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-05-07 22:28:08 -0700
committerOri Bernstein <ori@eigenstate.org>2015-05-07 22:28:08 -0700
commit3623ee59e2c80fe5a5334f3e52499295b510f026 (patch)
tree559c759ae35a20b3e4149659dfcfbc595009e297 /parse
parent6a8faed320bdd72e0ca316ee4f780ed25bf141ae (diff)
downloadmc-3623ee59e2c80fe5a5334f3e52499295b510f026.tar.gz
Add 'undef' operator.
Marks values as undefined, useful for reaching defn dummy analysis.
Diffstat (limited to 'parse')
-rw-r--r--parse/infer.c31
-rw-r--r--parse/ops.def3
2 files changed, 19 insertions, 15 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 477c1fb..aa840a0 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -517,19 +517,21 @@ static void settype(Inferstate *st, Node *n, Type *t)
/* Gets the type of a literal value */
static Type *littype(Node *n)
{
- if (n->lit.type)
- return n->lit.type;
- switch (n->lit.littype) {
- case Lchr: return mktype(n->loc, Tychar); break;
- case Lbool: return mktype(n->loc, Tybool); break;
- case Lint: return mktylike(n->loc, Tyint); break;
- case Lflt: return mktylike(n->loc, Tyflt64); break;
- case Lstr: return mktyslice(n->loc, mktype(n->loc, Tybyte)); break;
- case Llbl: return mktyptr(n->loc, mktype(n->loc, Tyvoid)); break;
- case Lfunc: return n->lit.fnval->func.type; break;
- };
- die("Bad lit type %d", n->lit.littype);
- return NULL;
+ Type *t;
+
+ if (!n->lit.type) {
+ switch (n->lit.littype) {
+ case Lchr: t = mktype(n->loc, Tychar); break;
+ case Lbool: t = mktype(n->loc, Tybool); break;
+ case Lint: t = mktylike(n->loc, Tyint); break;
+ case Lflt: t = mktylike(n->loc, Tyflt64); break;
+ case Lstr: t = mktyslice(n->loc, mktype(n->loc, Tybyte)); break;
+ case Llbl: t = mktyptr(n->loc, mktype(n->loc, Tyvoid)); break;
+ case Lfunc: t = n->lit.fnval->func.type; break;
+ }
+ n->lit.type = t;
+ }
+ return n->lit.type;
}
static Type *delayeducon(Inferstate *st, Type *fallback)
@@ -1446,7 +1448,8 @@ static void inferexpr(Inferstate *st, Node **np, Type *ret, int *sawret)
}
settype(st, n, type(st, args[0]));
break;
- case Obad: case Ocjmp: case Ojtab: case Oset: case Odead:
+ 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 fac46a3..9b8de94 100644
--- a/parse/ops.def
+++ b/parse/ops.def
@@ -56,7 +56,8 @@ O(Ostruct, 1, OTmisc, NULL)
O(Oarr, 1, OTmisc, NULL)
/* all below this point are backend-only */
-O(Odead, 0, OTmisc, "DEAD") /* code */
+O(Odead, 0, OTmisc, "DEAD") /* dead code */
+O(Oundef, 0, OTmisc, "UNDEF") /* undefined var */
O(Ocjmp, 1, OTmisc, "CJMP") /* conditional jump */
O(Ojtab, 1, OTmisc, "JTAB") /* jump table */
O(Oset, 1, OTbin, "=") /* store to var */