summaryrefslogtreecommitdiff
path: root/parse
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-01-20 00:32:35 -0800
committerOri Bernstein <ori@eigenstate.org>2015-01-20 00:32:35 -0800
commitb9b0d1222d90c30ea7921a175cd9653c84dd06b7 (patch)
treec4cc093fdebe225c9542086dcfba06c41d049087 /parse
parent9d31324cc831023057ffc287e5450de181d08e60 (diff)
downloadmc-b9b0d1222d90c30ea7921a175cd9653c84dd06b7.tar.gz
Add support for constant union initializers.
Oops, that was broked.
Diffstat (limited to 'parse')
-rw-r--r--parse/infer.c3
-rw-r--r--parse/parse.h1
-rw-r--r--parse/type.c11
3 files changed, 14 insertions, 1 deletions
diff --git a/parse/infer.c b/parse/infer.c
index 83dcc1e..d447b76 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -1051,14 +1051,15 @@ static void inferucon(Inferstate *st, Node *n, int *isconst)
Ucon *uc;
Type *t;
+ *isconst = 1;
uc = uconresolve(st, n);
t = tyfreshen(st, tf(st, uc->utype));
uc = tybase(t)->udecls[uc->id];
if (uc->etype) {
inferexpr(st, &n->expr.args[1], NULL, NULL);
unify(st, n, uc->etype, type(st, n->expr.args[1]));
+ *isconst = n->expr.args[1]->expr.isconst;
}
- *isconst = n->expr.args[0]->expr.isconst;
settype(st, n, delayeducon(st, t));
}
diff --git a/parse/parse.h b/parse/parse.h
index 7f9c98c..638391e 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -495,6 +495,7 @@ Type *mktystruct(Srcloc l, Node **decls, size_t ndecls);
Type *mktyunion(Srcloc l, Ucon **decls, size_t ndecls);
Trait *mktrait(Srcloc l, Node *name, Type *param, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs, int isproto);
Type *mktylike(Srcloc l, Ty ty); /* constrains tyvar t like it was builtin ty */
+Ucon *finducon(Type *t, Node *name);
int istysigned(Type *t);
int istyunsigned(Type *t);
int istyfloat(Type *t);
diff --git a/parse/type.c b/parse/type.c
index 6d1b7ef..ec282e6 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -273,6 +273,17 @@ Type *mktyunion(Srcloc loc, Ucon **decls, size_t ndecls)
return t;
}
+Ucon *finducon(Type *ty, Node *name)
+{
+ size_t i;
+
+ ty = tybase(ty);
+ for (i = 0; i < ty->nmemb; i++)
+ if (!strcmp(namestr(ty->udecls[i]->name), namestr(name)))
+ return ty->udecls[i];
+ return NULL;
+}
+
int istyunsigned(Type *t)
{
switch (tybase(t)->type) {