ref: 41e2a4f9b568b784c97b285c908409d8879a42a4
parent: 9d11b6dbcecb0ed2013043bbff1dea9ac0355c7b
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Feb 14 17:55:11 EST 2017
Fold Utags on union literals.
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -121,6 +121,7 @@
Node **args, *r;
Type *t;
vlong a, b;
+ Ucon *uc;
size_t i;
if (!n)
@@ -135,6 +136,12 @@
for (i = 0; i < n->expr.nargs; i++)
args[i] = fold(args[i], foldvar);
switch (exprop(n)) {
+ case Outag:
+ if (exprop(args[0]) != Oucon)
+ break;
+ uc = finducon(tybase(exprtype(args[0])), args[0]->expr.args[0]);
+ r = val(n->loc, uc->id, exprtype(n));
+ break;
case Ovar:
if (foldvar && issmallconst(decls[n->expr.did]))
r = fold(decls[n->expr.did]->decl.init, foldvar);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -148,7 +148,7 @@
struct Ucon {
Srcloc loc;
- size_t id; /* unique id */
+ size_t id; /* tag id */
int synth; /* is it generated? */
Node *name; /* ucon name */
Type *utype; /* type of the union this is an element of */