summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-03 17:13:21 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-03 17:13:21 -0500
commit5665bde91427725cf0231cab7e54a6b37b6fba7f (patch)
treef9042cb12a9e07d5b9d8c48caf46d4abe231e5bd /eval.c
parent72b20e0c81144adb60f5f342af4ec1cec8a86e9c (diff)
improved the way #sizeof and #alignof work
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/eval.c b/eval.c
index 4affb26..e1d199e 100644
--- a/eval.c
+++ b/eval.c
@@ -1366,25 +1366,6 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
case EXPR_C:
err_print(e->where, "Cannot run C code at compile time.");
return false;
- case EXPR_DSIZEOF:
- case EXPR_DALIGNOF: {
- Expression *of = e->kind == EXPR_DSIZEOF ? e->dsizeof.of : e->dalignof.of;
- Type *type;
- if (of->type.kind == TYPE_TYPE) {
- /* it's a type, return the size/align of it */
- Value typeval;
- if (!eval_expr(ev, of, &typeval)) return false;
- type = typeval.type;
- if (!type_resolve(ev->typer, type, e->where)) return false;
- } else {
- /* it's an expression, return the size/align of its type */
- type = &of->type;
- }
- if (e->kind == EXPR_DSIZEOF)
- v->i64 = (I64)compiler_sizeof(type);
- else
- v->i64 = (I64)compiler_alignof(type);
- } break;
case EXPR_NEW:
/* it's not strictly necessary to do the if here */
if (e->new.n) {
@@ -1542,6 +1523,10 @@ static bool eval_expr(Evaluator *ev, Expression *e, Value *v) {
case EXPR_VAL:
*v = e->val;
break;
+ case EXPR_DSIZEOF:
+ case EXPR_DALIGNOF:
+ assert(0);
+ return false;
}
return true;
}