diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-03 17:13:21 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-01-03 17:13:21 -0500 |
commit | 5665bde91427725cf0231cab7e54a6b37b6fba7f (patch) | |
tree | f9042cb12a9e07d5b9d8c48caf46d4abe231e5bd /eval.c | |
parent | 72b20e0c81144adb60f5f342af4ec1cec8a86e9c (diff) |
improved the way #sizeof and #alignof work
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 23 |
1 files changed, 4 insertions, 19 deletions
@@ -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; } |