summaryrefslogtreecommitdiff
path: root/parse/fold.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-07-30 18:34:52 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-30 18:40:02 -0700
commit594223c2959cc116ccc2782ebf7930677b053843 (patch)
tree82781e9646db2e51b0f096753fb49533fa8d7c2c /parse/fold.c
parent093716ff5e2ffe837793ba7c9239c64e22789ec0 (diff)
downloadmc-594223c2959cc116ccc2782ebf7930677b053843.tar.gz
Add hook into frontend for sizeof() folding.
Before, code like: const f = { var buf: byte[sizeof(int)] } would crash us, because `sizeof` would not get folded. A slightly subtle point: muse doens't install a hook here, but since it's already handling processed usefiles, the array sizes should already be prefolded for its viewing pleasure.
Diffstat (limited to 'parse/fold.c')
-rw-r--r--parse/fold.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/parse/fold.c b/parse/fold.c
index d01ff6a..c13b41c 100644
--- a/parse/fold.c
+++ b/parse/fold.c
@@ -13,6 +13,8 @@
#include "util.h"
#include "parse.h"
+size_t (*sizefn)(Node *n);
+
static int
getintlit(Node *n, vlong *v)
{
@@ -250,6 +252,10 @@ fold(Node *n, int foldvar)
case Ocast:
r = foldcast(n);
break;
+ case Osize:
+ if (sizefn)
+ r = val(n->loc, sizefn(n->expr.args[0]), exprtype(n));
+ break;
default:
break;
}