commit 3bc1e40cc68c0f1fe0d983db146021b6b43df431
parent 482cfc29c42414dfafe22898926e10e8c2250f37
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 20 Feb 2021 19:42:33 -0500
all: s/TYPE_STORAGE_/STORAGE_/g
Diffstat:
M | include/types.h | | | 64 | ++++++++++++++++++++++++++++++++-------------------------------- |
M | src/check.c | | | 264 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/dump.c | | | 158 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/eval.c | | | 278 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/gen.c | | | 236 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/lex.c | | | 134 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/parse.c | | | 120 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/qtype.c | | | 322 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/type_store.c | | | 166 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/typedef.c | | | 162 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
M | src/types.c | | | 688 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
11 files changed, 1296 insertions(+), 1296 deletions(-)
diff --git a/include/types.h b/include/types.h
@@ -6,39 +6,39 @@
enum type_storage {
// Scalar types
- TYPE_STORAGE_BOOL,
- TYPE_STORAGE_CHAR,
- TYPE_STORAGE_ENUM,
- TYPE_STORAGE_F32,
- TYPE_STORAGE_F64,
- TYPE_STORAGE_FCONST,
- TYPE_STORAGE_I16,
- TYPE_STORAGE_I32,
- TYPE_STORAGE_I64,
- TYPE_STORAGE_I8,
- TYPE_STORAGE_ICONST,
- TYPE_STORAGE_INT,
- TYPE_STORAGE_NULL,
- TYPE_STORAGE_RUNE,
- TYPE_STORAGE_SIZE,
- TYPE_STORAGE_U16,
- TYPE_STORAGE_U32,
- TYPE_STORAGE_U64,
- TYPE_STORAGE_U8,
- TYPE_STORAGE_UINT,
- TYPE_STORAGE_UINTPTR,
- TYPE_STORAGE_VOID,
+ STORAGE_BOOL,
+ STORAGE_CHAR,
+ STORAGE_ENUM,
+ STORAGE_F32,
+ STORAGE_F64,
+ STORAGE_FCONST,
+ STORAGE_I16,
+ STORAGE_I32,
+ STORAGE_I64,
+ STORAGE_I8,
+ STORAGE_ICONST,
+ STORAGE_INT,
+ STORAGE_NULL,
+ STORAGE_RUNE,
+ STORAGE_SIZE,
+ STORAGE_U16,
+ STORAGE_U32,
+ STORAGE_U64,
+ STORAGE_U8,
+ STORAGE_UINT,
+ STORAGE_UINTPTR,
+ STORAGE_VOID,
// Aggregate types
- TYPE_STORAGE_ALIAS,
- TYPE_STORAGE_ARRAY,
- TYPE_STORAGE_FUNCTION,
- TYPE_STORAGE_POINTER,
- TYPE_STORAGE_SLICE,
- TYPE_STORAGE_STRING,
- TYPE_STORAGE_STRUCT,
- TYPE_STORAGE_TAGGED,
- TYPE_STORAGE_TUPLE,
- TYPE_STORAGE_UNION,
+ STORAGE_ALIAS,
+ STORAGE_ARRAY,
+ STORAGE_FUNCTION,
+ STORAGE_POINTER,
+ STORAGE_SLICE,
+ STORAGE_STRING,
+ STORAGE_STRUCT,
+ STORAGE_TAGGED,
+ STORAGE_TUPLE,
+ STORAGE_UNION,
};
struct type;
diff --git a/src/check.c b/src/check.c
@@ -47,7 +47,7 @@ lower_implicit_cast(const struct type *to, struct expression *expr)
return expr;
}
- if (type_dealias(to)->storage == TYPE_STORAGE_TAGGED) {
+ if (type_dealias(to)->storage == STORAGE_TAGGED) {
const struct type *interim =
tagged_select_subtype(to, expr->result);
if (interim) {
@@ -98,7 +98,7 @@ check_expr_access(struct context *ctx,
break;
case O_TYPE:
expect(&aexpr->loc,
- type_dealias(obj->type)->storage == TYPE_STORAGE_VOID,
+ type_dealias(obj->type)->storage == STORAGE_VOID,
"Cannot use non-void type alias '%s' as constant",
identifier_unparse(&obj->type->alias.ident));
expr->type = EXPR_CONSTANT;
@@ -120,7 +120,7 @@ check_expr_access(struct context *ctx,
const struct type *itype =
type_dealias(expr->access.index->result);
expect(&aexpr->access.array->loc,
- atype->storage == TYPE_STORAGE_ARRAY || atype->storage == TYPE_STORAGE_SLICE,
+ atype->storage == STORAGE_ARRAY || atype->storage == STORAGE_SLICE,
"Cannot index non-array, non-slice %s object",
type_storage_unparse(atype->storage));
expect(&aexpr->access.index->loc, type_is_integer(itype),
@@ -140,7 +140,7 @@ check_expr_access(struct context *ctx,
expect(&aexpr->access._struct->loc, stype,
"Cannot dereference nullable pointer for field selection");
expect(&aexpr->access._struct->loc,
- stype->storage == TYPE_STORAGE_STRUCT || stype->storage == TYPE_STORAGE_UNION,
+ stype->storage == STORAGE_STRUCT || stype->storage == STORAGE_UNION,
"Cannot select field from non-struct, non-union object");
expr->access.field = type_get_field(stype, aexpr->access.field);
expect(&aexpr->access._struct->loc, expr->access.field,
@@ -161,7 +161,7 @@ check_expr_access(struct context *ctx,
expect(&aexpr->access.tuple->loc, ttype,
"Cannot dereference nullable pointer for value selection");
expect(&aexpr->access.tuple->loc,
- ttype->storage == TYPE_STORAGE_TUPLE,
+ ttype->storage == STORAGE_TUPLE,
"Cannot select value from non-tuple object");
expect(&aexpr->access.tuple->loc,
type_is_integer(expr->access.value->result),
@@ -192,7 +192,7 @@ check_expr_alloc(struct context *ctx,
type_store_lookup_atype(ctx->store, aexpr->alloc.type);
enum type_storage storage = type_dealias(expr->result)->storage;
switch (storage) {
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
check_expression(ctx, aexpr->alloc.expr, expr->alloc.expr,
expr->result->pointer.referent);
if (aexpr->alloc.cap != NULL) {
@@ -203,7 +203,7 @@ check_expr_alloc(struct context *ctx,
type_storage_unparse(storage));
}
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
check_expression(ctx, aexpr->alloc.expr, expr->alloc.expr,
expr->result);
if (aexpr->alloc.cap != NULL) {
@@ -236,7 +236,7 @@ check_expr_append(struct context *ctx,
expr->append.expr = xcalloc(sizeof(struct expression), 1);
check_expression(ctx, aexpr->append.expr, expr->append.expr, NULL);
expect(&aexpr->append.expr->loc,
- expr->append.expr->result->storage == TYPE_STORAGE_SLICE,
+ expr->append.expr->result->storage == STORAGE_SLICE,
"append must operate on a slice");
expect(&aexpr->append.expr->loc,
!(expr->append.expr->result->flags & TYPE_CONST),
@@ -290,7 +290,7 @@ check_expr_assert(struct context *ctx,
check_expression(ctx, aexpr->assert.cond,
expr->assert.cond, &builtin_type_bool);
expect(&aexpr->assert.cond->loc,
- expr->assert.cond->result->storage == TYPE_STORAGE_BOOL,
+ expr->assert.cond->result->storage == STORAGE_BOOL,
"Assertion condition must be boolean");
} else {
expr->terminates = true;
@@ -301,7 +301,7 @@ check_expr_assert(struct context *ctx,
check_expression(ctx, aexpr->assert.message,
expr->assert.message, &builtin_type_str);
expect(&aexpr->assert.message->loc,
- expr->assert.message->result->storage == TYPE_STORAGE_STRING,
+ expr->assert.message->result->storage == STORAGE_STRING,
"Assertion message must be string");
} else {
int n = snprintf(NULL, 0, "Assertion failed: %s:%d:%d",
@@ -324,7 +324,7 @@ check_expr_assert(struct context *ctx,
eval_expr(ctx, expr->assert.cond, &out);
expect(&aexpr->assert.cond->loc, r == EVAL_OK,
"Unable to evaluate static assertion at compile time");
- assert(out.result->storage == TYPE_STORAGE_BOOL);
+ assert(out.result->storage == STORAGE_BOOL);
cond = out.constant.bval;
} else {
cond = false;
@@ -358,7 +358,7 @@ check_expr_assign(struct context *ctx,
if (aexpr->assign.indirect) {
expect(&aexpr->loc,
- object->result->storage == TYPE_STORAGE_POINTER,
+ object->result->storage == STORAGE_POINTER,
"Cannot dereference non-pointer type for assignment");
expect(&aexpr->loc,
!(object->result->pointer.flags & PTR_NULLABLE),
@@ -402,17 +402,17 @@ type_promote(struct type_store *store,
const struct type *b =
type_store_lookup_with_flags(store, _b, _b->flags & ~TYPE_CONST);
- if (a->storage == TYPE_STORAGE_ALIAS) {
+ if (a->storage == STORAGE_ALIAS) {
return a == b || a->alias.type == b ? _b : NULL;
}
- if (b->storage == TYPE_STORAGE_ALIAS) {
+ if (b->storage == STORAGE_ALIAS) {
return a == b || a == b->alias.type ? _a : NULL;
}
const struct type *base = a == b ? a : NULL;
switch (a->storage) {
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
if (a->array.length == SIZE_UNDEFINED && a->array.members) {
base = b;
break;
@@ -422,43 +422,43 @@ type_promote(struct type_store *store,
break;
}
break;
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_INT:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_INT:
if (!type_is_integer(b) || !type_is_signed(b)
|| b->size == a->size) {
break;
}
base = a->size > b->size ? a : b;
break;
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_CHAR:
+ case STORAGE_U32:
+ case STORAGE_U16:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_CHAR:
if (!type_is_integer(b) || type_is_signed(b)
|| b->size == a->size) {
break;
}
base = a->size > b->size ? a : b;
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
+ case STORAGE_F32:
+ case STORAGE_F64:
if (!type_is_float(b) || b->size == a->size) {
break;
}
base = a->size > b->size ? a : b;
break;
- case TYPE_STORAGE_POINTER:
- if (b->storage == TYPE_STORAGE_NULL) {
+ case STORAGE_POINTER:
+ if (b->storage == STORAGE_NULL) {
base = a;
break;
}
- if (b->storage != TYPE_STORAGE_POINTER) {
+ if (b->storage != STORAGE_POINTER) {
break;
}
base = type_promote(store, a->pointer.referent,
@@ -468,32 +468,32 @@ type_promote(struct type_store *store,
a->pointer.flags | b->pointer.flags);
}
break;
- case TYPE_STORAGE_NULL:
- if (b->storage == TYPE_STORAGE_POINTER
- || b->storage == TYPE_STORAGE_NULL) {
+ case STORAGE_NULL:
+ if (b->storage == STORAGE_POINTER
+ || b->storage == STORAGE_NULL) {
base = b;
}
break;
// Cannot be promoted
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_VOID:
+ case STORAGE_BOOL:
+ case STORAGE_ENUM:
+ case STORAGE_FUNCTION:
+ case STORAGE_RUNE:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UINTPTR:
+ case STORAGE_UNION:
+ case STORAGE_VOID:
break;
// Handled above
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
break;
// Invariant
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0);
}
@@ -563,32 +563,32 @@ check_expr_binarithm(struct context *ctx,
intmax_t l = aexpr->binarithm.lvalue->constant.ival,
r = aexpr->binarithm.rvalue->constant.ival,
max = l > r ? l : r, min = l < r ? l : r;
- enum type_storage storage = TYPE_STORAGE_ICONST;
+ enum type_storage storage = STORAGE_ICONST;
if (min < 0) {
if (max < ((intmax_t)1 << 7) - 1
&& min > -((intmax_t)1 << 8)) {
- storage = TYPE_STORAGE_I8;
+ storage = STORAGE_I8;
} else if (max < ((intmax_t)1 << 15) - 1
&& min > -((intmax_t)1 << 16)) {
- storage = TYPE_STORAGE_I16;
+ storage = STORAGE_I16;
} else if (max < ((intmax_t)1 << 31) - 1
&& min > -((intmax_t)1 << 32)) {
- storage = TYPE_STORAGE_I32;
+ storage = STORAGE_I32;
} else {
- storage = TYPE_STORAGE_I64;
+ storage = STORAGE_I64;
}
} else {
if (max < ((intmax_t)1 << 8)) {
- storage = TYPE_STORAGE_U8;
+ storage = STORAGE_U8;
} else if (max < ((intmax_t)1 << 16)) {
- storage = TYPE_STORAGE_U16;
+ storage = STORAGE_U16;
} else if (max < ((intmax_t)1 << 32)) {
- storage = TYPE_STORAGE_U32;
+ storage = STORAGE_U32;
} else {
- storage = TYPE_STORAGE_U64;
+ storage = STORAGE_U64;
}
}
- assert(storage != TYPE_STORAGE_ICONST);
+ assert(storage != STORAGE_ICONST);
check_expression(ctx, aexpr->binarithm.lvalue, lvalue,
builtin_type_for_storage(storage, false));
check_expression(ctx, aexpr->binarithm.rvalue, rvalue,
@@ -660,7 +660,7 @@ check_expr_binding(struct context *ctx,
}
bool context = abinding->type
- && abinding->type->storage == TYPE_STORAGE_ARRAY
+ && abinding->type->storage == STORAGE_ARRAY
&& abinding->type->array.contextual;
if (type && !context) {
// If the type is defined in advance, we can insert the
@@ -679,7 +679,7 @@ check_expr_binding(struct context *ctx,
if (context) {
expect(&aexpr->loc,
- initializer->result->storage == TYPE_STORAGE_ARRAY,
+ initializer->result->storage == STORAGE_ARRAY,
"Cannot infer array length from non-array type");
expect(&aexpr->loc,
initializer->result->array.members == type->array.members,
@@ -741,7 +741,7 @@ lower_vaargs(struct context *ctx,
struct ast_expression val = {
.type = EXPR_CONSTANT,
.constant = {
- .storage = TYPE_STORAGE_ARRAY,
+ .storage = STORAGE_ARRAY,
},
};
// TODO: Provide location some other way
@@ -761,7 +761,7 @@ lower_vaargs(struct context *ctx,
const struct type *hint = type_store_lookup_array(
ctx->store, type, SIZE_UNDEFINED);
check_expression(ctx, &val, vaargs, hint);
- assert(vaargs->result->storage == TYPE_STORAGE_ARRAY);
+ assert(vaargs->result->storage == STORAGE_ARRAY);
expect(&val.loc, vaargs->result->array.members == type,
"Argument is not assignable to variadic parameter type");
@@ -790,7 +790,7 @@ check_expr_call(struct context *ctx,
expect(&aexpr->loc, fntype,
"Cannot dereference nullable pointer type for function call");
expect(&aexpr->loc,
- fntype->storage == TYPE_STORAGE_FUNCTION,
+ fntype->storage == STORAGE_FUNCTION,
"Cannot call non-function type");
expr->result = fntype->func.result;
if (fntype->func.flags & FN_NORETURN) {
@@ -862,7 +862,7 @@ check_expr_cast(struct context *ctx,
if (aexpr->cast.kind == C_ASSERTION || aexpr->cast.kind == C_TEST) {
const struct type *primary = type_dealias(expr->cast.value->result);
expect(&aexpr->cast.value->loc,
- primary->storage == TYPE_STORAGE_TAGGED,
+ primary->storage == STORAGE_TAGGED,
"Expected a tagged union type");
expect(&aexpr->cast.type->loc,
type_is_castable(value->result, secondary),
@@ -907,16 +907,16 @@ check_expr_array(struct context *ctx,
const struct type *type = NULL;
if (hint) {
hint = type_dealias(hint);
- if (hint->storage == TYPE_STORAGE_ARRAY
- || hint->storage == TYPE_STORAGE_SLICE) {
+ if (hint->storage == STORAGE_ARRAY
+ || hint->storage == STORAGE_SLICE) {
type = hint->array.members;
- } else if (hint->storage == TYPE_STORAGE_TAGGED) {
+ } else if (hint->storage == STORAGE_TAGGED) {
size_t narray = 0;
for (const struct type_tagged_union *tu = &hint->tagged;
tu; tu = tu->next) {
const struct type *t = type_dealias(tu->type);
- if (t->storage == TYPE_STORAGE_ARRAY
- || t->storage == TYPE_STORAGE_SLICE) {
+ if (t->storage == STORAGE_ARRAY
+ || t->storage == STORAGE_SLICE) {
hint = t;
type = hint->array.members;
++narray;
@@ -959,7 +959,7 @@ check_expr_array(struct context *ctx,
if (expandable) {
expect(&aexpr->loc, hint != NULL,
"Cannot expand array for inferred type");
- expect(&aexpr->loc, hint->storage == TYPE_STORAGE_ARRAY
+ expect(&aexpr->loc, hint->storage == STORAGE_ARRAY
&& hint->array.length != SIZE_UNDEFINED
&& hint->array.length >= len,
"Cannot expand array into destination type");
@@ -980,7 +980,7 @@ lower_constant(const struct type *type, struct expression *expr)
if (type_is_float(type)) {
assert(0); // TODO
}
- if (type->storage == TYPE_STORAGE_TAGGED) {
+ if (type->storage == STORAGE_TAGGED) {
const struct type *tag = NULL;
for (const struct type_tagged_union *tu = &type->tagged; tu;
tu = tu->next) {
@@ -1057,9 +1057,9 @@ check_expr_constant(struct context *ctx,
expr->type = EXPR_CONSTANT;
expr->result = builtin_type_for_storage(aexpr->constant.storage, false);
- if (expr->result && expr->result->storage == TYPE_STORAGE_ICONST) {
+ if (expr->result && expr->result->storage == STORAGE_ICONST) {
if (hint == NULL) {
- hint = builtin_type_for_storage(TYPE_STORAGE_INT, false);
+ hint = builtin_type_for_storage(STORAGE_INT, false);
}
expr->constant.ival = aexpr->constant.ival;
const struct type *type = lower_constant(hint, expr);
@@ -1069,56 +1069,56 @@ check_expr_constant(struct context *ctx,
}
switch (aexpr->constant.storage) {
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
expr->constant.ival = aexpr->constant.ival;
break;
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_SIZE:
expr->constant.uval = aexpr->constant.uval;
break;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
expr->constant.rune = aexpr->constant.rune;
break;
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
expr->constant.bval = aexpr->constant.bval;
break;
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_VOID:
+ case STORAGE_NULL:
+ case STORAGE_VOID:
// No storage
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
check_expr_array(ctx, aexpr, expr, hint);
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
expr->constant.string.len = aexpr->constant.string.len;
expr->constant.string.value = xcalloc(1, aexpr->constant.string.len);
memcpy(expr->constant.string.value, aexpr->constant.string.value,
aexpr->constant.string.len);
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
assert(0); // TODO
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_UINTPTR:
+ case STORAGE_ALIAS:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_SLICE:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
assert(0); // Invariant
}
}
@@ -1210,7 +1210,7 @@ check_expr_for(struct context *ctx,
check_expression(ctx, aexpr->_for.cond, cond, &builtin_type_bool);
expr->_for.cond = cond;
expect(&aexpr->_for.cond->loc,
- cond->result->storage == TYPE_STORAGE_BOOL,
+ cond->result->storage == STORAGE_BOOL,
"Expected for condition to be boolean");
if (aexpr->_for.afterthought) {
@@ -1241,8 +1241,8 @@ check_expr_free(struct context *ctx,
check_expression(ctx, aexpr->free.expr, expr->free.expr, NULL);
enum type_storage storage = type_dealias(expr->free.expr->result)->storage;
expect(&aexpr->free.expr->loc,
- storage == TYPE_STORAGE_SLICE || storage == TYPE_STORAGE_STRING
- || storage == TYPE_STORAGE_POINTER,
+ storage == STORAGE_SLICE || storage == STORAGE_STRING
+ || storage == STORAGE_POINTER,
"free must operate on slice, string, or pointer");
expr->result = &builtin_type_void;
}
@@ -1300,7 +1300,7 @@ check_expr_if(struct context *ctx,
}
expect(&aexpr->_if.cond->loc,
- cond->result->storage == TYPE_STORAGE_BOOL,
+ cond->result->storage == STORAGE_BOOL,
"Expected if condition to be boolean");
expr->_if.cond = cond;
@@ -1361,10 +1361,10 @@ check_expr_match(struct context *ctx,
expr->match.value = value;
const struct type *type = type_dealias(value->result);
- bool is_ptr = type->storage == TYPE_STORAGE_POINTER
+ bool is_ptr = type->storage == STORAGE_POINTER
&& type->pointer.flags & PTR_NULLABLE;
expect(&aexpr->match.value->loc,
- type->storage == TYPE_STORAGE_TAGGED || is_ptr,
+ type->storage == STORAGE_TAGGED || is_ptr,
"match value must be tagged union or nullable pointer type");
struct type_tagged_union result_type = {0};
@@ -1382,9 +1382,9 @@ check_expr_match(struct context *ctx,
ctype = type_store_lookup_atype(ctx->store, acase->type);
if (is_ptr) {
switch (ctype->storage) {
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
expect(&acase->type->loc,
type->pointer.referent == ctype->pointer.referent,
"Match case on incompatible pointer type");
@@ -1491,9 +1491,9 @@ check_expr_measure(struct context *ctx,
expr->measure.value, NULL);
enum type_storage vstor = expr->measure.value->result->storage;
expect(&aexpr->measure.value->loc,
- vstor == TYPE_STORAGE_ARRAY
- || vstor == TYPE_STORAGE_SLICE
- || vstor == TYPE_STORAGE_STRING,
+ vstor == STORAGE_ARRAY
+ || vstor == STORAGE_SLICE
+ || vstor == STORAGE_STRING,
"len argument must be of an array, slice, or str type");
expect(&aexpr->measure.value->loc,
expr->measure.value->result->size != SIZE_UNDEFINED,
@@ -1556,8 +1556,8 @@ check_expr_slice(struct context *ctx,
expect(&aexpr->slice.object->loc, atype,
"Cannot dereference nullable pointer for slicing");
expect(&aexpr->slice.object->loc,
- atype->storage == TYPE_STORAGE_SLICE
- || atype->storage == TYPE_STORAGE_ARRAY,
+ atype->storage == STORAGE_SLICE
+ || atype->storage == STORAGE_ARRAY,
"Cannot slice non-array, non-slice object");
const struct type *itype;
@@ -1608,12 +1608,12 @@ check_expr_struct(struct context *ctx,
"Name does not refer to a type");
stype = obj->type;
expect(&aexpr->loc,
- type_dealias(stype)->storage == TYPE_STORAGE_STRUCT,
+ type_dealias(stype)->storage == STORAGE_STRUCT,
"Object named is not a struct type");
}
struct ast_type satype = {
- .storage = TYPE_STORAGE_STRUCT,
+ .storage = STORAGE_STRUCT,
.flags = TYPE_CONST,
};
struct ast_struct_union_type *tfield = &satype.struct_union;
@@ -1815,7 +1815,7 @@ check_expr_tuple(struct context *ctx,
expr->type = EXPR_TUPLE;
const struct type_tuple *ttuple = NULL;
- if (hint && type_dealias(hint)->storage == TYPE_STORAGE_TUPLE) {
+ if (hint && type_dealias(hint)->storage == STORAGE_TUPLE) {
ttuple = &type_dealias(hint)->tuple;
}
@@ -1842,7 +1842,7 @@ check_expr_tuple(struct context *ctx,
}
}
- if (hint && type_dealias(hint)->storage == TYPE_STORAGE_TUPLE) {
+ if (hint && type_dealias(hint)->storage == STORAGE_TUPLE) {
expr->result = hint;
} else {
expr->result = type_store_lookup_tuple(ctx->store, &result);
@@ -1883,7 +1883,7 @@ check_expr_unarithm(struct context *ctx,
switch (expr->unarithm.op) {
case UN_LNOT:
expect(&aexpr->unarithm.operand->loc,
- operand->result->storage == TYPE_STORAGE_BOOL,
+ operand->result->storage == STORAGE_BOOL,
"Cannot perform logical NOT (!) on non-boolean type");
expr->result = &builtin_type_bool;
break;
@@ -1912,7 +1912,7 @@ check_expr_unarithm(struct context *ctx,
break;
case UN_DEREF:
expect(&aexpr->unarithm.operand->loc,
- operand->result->storage == TYPE_STORAGE_POINTER,
+ operand->result->storage == STORAGE_POINTER,
"Cannot de-reference non-pointer type");
expect(&aexpr->unarithm.operand->loc,
!(operand->result->pointer.flags & PTR_NULLABLE),
@@ -2044,7 +2044,7 @@ check_function(struct context *ctx,
trenter(TR_CHECK, "function");
const struct ast_type fn_atype = {
- .storage = TYPE_STORAGE_FUNCTION,
+ .storage = STORAGE_FUNCTION,
.flags = TYPE_CONST,
.func = afndecl->prototype,
};
@@ -2125,7 +2125,7 @@ check_global(struct context *ctx,
const struct type *type = type_store_lookup_atype(
ctx->store, agdecl->type);
- bool context = agdecl->type->storage == TYPE_STORAGE_ARRAY
+ bool context = agdecl->type->storage == STORAGE_ARRAY
&& agdecl->type->array.contextual;
// TODO: Free initialier
@@ -2135,7 +2135,7 @@ check_global(struct context *ctx,
if (context) {
expect(&agdecl->init->loc,
- initializer->result->storage == TYPE_STORAGE_ARRAY,
+ initializer->result->storage == STORAGE_ARRAY,
"Cannot infer array length from non-array type");
expect(&agdecl->init->loc,
initializer->result->array.members == type->array.members,
@@ -2266,7 +2266,7 @@ scan_function(struct context *ctx, const struct ast_function_decl *decl)
}
trenter(TR_SCAN, "function");
const struct ast_type fn_atype = {
- .storage = TYPE_STORAGE_FUNCTION,
+ .storage = STORAGE_FUNCTION,
.flags = TYPE_CONST,
.func = decl->prototype,
};
@@ -2325,12 +2325,12 @@ scan_type(struct context *ctx, const struct ast_type_decl *decl)
type_store_lookup_alias(ctx->store, &ident, type);
scope_insert(ctx->unit, O_TYPE, &ident, &decl->ident, alias, NULL);
- if (type->storage == TYPE_STORAGE_ENUM) {
+ if (type->storage == STORAGE_ENUM) {
for (struct type_enum_value *value = type->_enum.values; value;
value = value->next) {
struct ast_type atype = {
.loc = decl->type->loc,
- .storage = TYPE_STORAGE_ALIAS,
+ .storage = STORAGE_ALIAS,
.flags = 0,
.unwrap = false,
.alias = decl->ident,
diff --git a/src/dump.c b/src/dump.c
@@ -21,33 +21,33 @@ static const char *
storage_to_suffix(enum type_storage storage)
{
switch (storage) {
- case TYPE_STORAGE_F32:
+ case STORAGE_F32:
return "f32";
- case TYPE_STORAGE_F64:
+ case STORAGE_F64:
return "f64";
- case TYPE_STORAGE_I16:
+ case STORAGE_I16:
return "i16";
- case TYPE_STORAGE_I32:
+ case STORAGE_I32:
return "i32";
- case TYPE_STORAGE_I64:
+ case STORAGE_I64:
return "i64";
- case TYPE_STORAGE_I8:
+ case STORAGE_I8:
return "i8";
- case TYPE_STORAGE_INT:
+ case STORAGE_INT:
return "i";
- case TYPE_STORAGE_SIZE:
+ case STORAGE_SIZE:
return "z";
- case TYPE_STORAGE_U16:
+ case STORAGE_U16:
return "u16";
- case TYPE_STORAGE_U32:
+ case STORAGE_U32:
return "u32";
- case TYPE_STORAGE_U64:
+ case STORAGE_U64:
return "u64";
- case TYPE_STORAGE_U8:
+ case STORAGE_U8:
return "u8";
- case TYPE_STORAGE_UINT:
+ case STORAGE_UINT:
return "u";
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
return "u64: uintptr";
default:
assert(0);
@@ -60,58 +60,58 @@ dump_const(const struct expression *expr)
assert(expr->type == EXPR_CONSTANT);
const union expression_constant *val = &expr->constant;
switch (expr->result->storage) {
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
fprintf(stderr, "%s", val->bval ? "false" : "true");
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
fprintf(stderr, "%lf%s", val->fval,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
fprintf(stderr, "%ld%s", val->ival,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
fprintf(stderr, "null");
break;
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
fprintf(stderr, "%lu%s", val->uval,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
fprintf(stderr, "void");
break;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
assert(0); // TODO
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
fprintf(stderr, "(const) %s",
identifier_unparse(&expr->result->alias.ident));
break;
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_ARRAY:
+ case STORAGE_ENUM:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
assert(0); // TODO
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_CHAR:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_TAGGED:
assert(0); // Invariant
}
}
@@ -125,37 +125,37 @@ dump_type(const struct type *type)
char *ident;
switch (type->storage) {
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_STRING:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
+ case STORAGE_STRING:
fprintf(stderr, "%s", type_storage_unparse(type->storage));
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
fprintf(stderr, "%s*", type->pointer.flags & PTR_NULLABLE
? "nullable " : "");
dump_type(type->pointer.referent);
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
if (type->array.length == SIZE_UNDEFINED) {
fprintf(stderr, "[*]");
} else {
@@ -163,16 +163,16 @@ dump_type(const struct type *type)
}
dump_type(type->array.members);
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
fprintf(stderr, "[]");
dump_type(type->array.members);
break;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
ident = identifier_unparse(&type->alias.ident);
fprintf(stderr, "%s", ident);
free(ident);
break;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
fprintf(stderr, "(");
for (const struct type_tagged_union *tu = &type->tagged;
tu; tu = tu->next) {
@@ -183,10 +183,10 @@ dump_type(const struct type *type)
}
fprintf(stderr, ")");
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
assert(type->struct_union.c_compat); // TODO
- fprintf(stderr, "%s { ", type->storage == TYPE_STORAGE_STRUCT
+ fprintf(stderr, "%s { ", type->storage == STORAGE_STRUCT
? "struct" : "union");
for (const struct struct_field *f = type->struct_union.fields;
f; f = f->next) {
@@ -196,7 +196,7 @@ dump_type(const struct type *type)
}
fprintf(stderr, "}");
break;
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
if (type->func.flags & FN_NORETURN) {
fprintf(stderr, "@noreturn ");
}
@@ -217,7 +217,7 @@ dump_type(const struct type *type)
fprintf(stderr, ") ");
dump_type(type->func.result);
break;
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
assert(0); // TODO
}
}
diff --git a/src/eval.c b/src/eval.c
@@ -13,53 +13,53 @@ static uintmax_t
itrunc(const struct type *type, uintmax_t val)
{
switch (type->storage) {
- case TYPE_STORAGE_U8:
+ case STORAGE_U8:
return (uint8_t)val;
- case TYPE_STORAGE_U16:
+ case STORAGE_U16:
return (uint16_t)val;
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_RUNE:
+ case STORAGE_U32:
+ case STORAGE_RUNE:
return (uint32_t)val;
- case TYPE_STORAGE_U64:
+ case STORAGE_U64:
return (uint64_t)val;
- case TYPE_STORAGE_I8:
+ case STORAGE_I8:
return (int8_t)((val >> 24) | (val & 0x7F));
- case TYPE_STORAGE_I16:
+ case STORAGE_I16:
return (int16_t)((val >> 16) | (val & 0x7FF));
- case TYPE_STORAGE_I32:
+ case STORAGE_I32:
return (int32_t)((val >> 8) | (val & 0x7FFFF));
- case TYPE_STORAGE_I64:
+ case STORAGE_I64:
return (int64_t)val;
- case TYPE_STORAGE_INT:
+ case STORAGE_INT:
return (int)val;
- case TYPE_STORAGE_UINT:
+ case STORAGE_UINT:
return (unsigned int)val;
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_ARRAY:
+ case STORAGE_ICONST:
+ case STORAGE_POINTER:
+ case STORAGE_SIZE:
+ case STORAGE_UINTPTR:
return val;
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
return (bool)val;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
return (uintptr_t)NULL;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return itrunc(type_dealias(type), val);
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
return itrunc(builtin_type_for_storage(type->_enum.storage, false), val);
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_VOID:
+ case STORAGE_CHAR:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_FUNCTION:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_VOID:
assert(0);
}
assert(0);
@@ -166,8 +166,8 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou
}
break;
case BIN_LAND:
- assert(type_dealias(lvalue.result)->storage == TYPE_STORAGE_BOOL
- && type_dealias(rvalue.result)->storage == TYPE_STORAGE_BOOL);
+ assert(type_dealias(lvalue.result)->storage == STORAGE_BOOL
+ && type_dealias(rvalue.result)->storage == STORAGE_BOOL);
bval = blval || brval;
break;
case BIN_LEQUAL:
@@ -192,13 +192,13 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou
}
break;
case BIN_LOR:
- assert(type_dealias(lvalue.result)->storage == TYPE_STORAGE_BOOL
- && type_dealias(rvalue.result)->storage == TYPE_STORAGE_BOOL);
+ assert(type_dealias(lvalue.result)->storage == STORAGE_BOOL
+ && type_dealias(rvalue.result)->storage == STORAGE_BOOL);
bval = blval || brval;
break;
case BIN_LXOR:
- assert(type_dealias(lvalue.result)->storage == TYPE_STORAGE_BOOL
- && type_dealias(rvalue.result)->storage == TYPE_STORAGE_BOOL);
+ assert(type_dealias(lvalue.result)->storage == STORAGE_BOOL
+ && type_dealias(rvalue.result)->storage == STORAGE_BOOL);
bval = blval != brval;
break;
case BIN_NEQUAL:
@@ -215,7 +215,7 @@ eval_binarithm(struct context *ctx, struct expression *in, struct expression *ou
out->result = in->result;
if (type_is_signed(in->result)) {
out->constant.ival = ival;
- } else if (type_dealias(in->result)->storage == TYPE_STORAGE_BOOL) {
+ } else if (type_dealias(in->result)->storage == STORAGE_BOOL) {
out->constant.bval = bval;
} else {
out->constant.uval = uval;
@@ -229,15 +229,15 @@ eval_const(struct context *ctx, struct expression *in, struct expression *out)
out->type = EXPR_CONSTANT;
out->result = in->result;
enum type_storage storage = type_dealias(out->result)->storage;
- if (storage == TYPE_STORAGE_ENUM) {
+ if (storage == STORAGE_ENUM) {
storage = type_dealias(out->result)->_enum.storage;
}
struct array_constant **next;
switch (storage) {
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ALIAS:
+ case STORAGE_ENUM:
assert(0); // Handled above
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
next = &out->constant.array;
for (struct array_constant *arr = in->constant.array; arr;
arr = arr->next) {
@@ -249,43 +249,43 @@ eval_const(struct context *ctx, struct expression *in, struct expression *out)
next = &aconst->next;
}
break;
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_SLICE:
+ case STORAGE_FUNCTION:
+ case STORAGE_SLICE:
assert(0); // TODO
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
out->constant.string.len = in->constant.string.len;
out->constant.string.value = xcalloc(1, in->constant.string.len);
memcpy(out->constant.string.value,
in->constant.string.value,
in->constant.string.len);
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
assert(0); // TODO
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_POINTER:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
out->constant = in->constant;
break;
}
@@ -314,51 +314,51 @@ eval_cast(struct context *ctx, struct expression *in, struct expression *out)
out->result = to;
switch (to->storage) {
- case TYPE_STORAGE_POINTER:
- if (from->storage == TYPE_STORAGE_NULL) {
+ case STORAGE_POINTER:
+ if (from->storage == STORAGE_NULL) {
out->constant.uval = 0;
return EVAL_OK;
}
assert(0); // TODO
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_RUNE:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_SIZE:
+ case STORAGE_RUNE:
out->constant.uval = itrunc(to, val.constant.uval);
return EVAL_OK;
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_SLICE:
- assert(val.result->storage == TYPE_STORAGE_ARRAY);
+ case STORAGE_ARRAY:
+ case STORAGE_SLICE:
+ assert(val.result->storage == STORAGE_ARRAY);
out->constant = val.constant;
return EVAL_OK;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_NULL:
+ case STORAGE_TAGGED:
assert(0); // TODO
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
assert(0); // Handled above
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_BOOL:
+ case STORAGE_FUNCTION:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
assert(0); // Invariant
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
break; // no-op
}
@@ -388,42 +388,42 @@ constant_default(struct context *ctx, struct expression *v)
{
struct expression b = {0};
switch (type_dealias(v->result)->storage) {
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_BOOL:
+ case STORAGE_POINTER:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_SIZE:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_BOOL:
break; // calloc does this for us
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
b.type = EXPR_STRUCT;
b.result = v->result;
b._struct.autofill = true;
enum eval_result r = eval_expr(ctx, &b, v);
assert(r == EVAL_OK);
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
v->constant.string.value = strdup("");
v->constant.string.len = 0;
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
v->constant.array = xcalloc(1, sizeof(struct array_constant));
v->constant.array->expand = true;
v->constant.array->value = xcalloc(1, sizeof(struct expression));
@@ -432,14 +432,14 @@ constant_default(struct context *ctx, struct expression *v)
type_dealias(v->result)->array.members;
constant_default(ctx, v->constant.array->value);
break;
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TAGGED:
+ case STORAGE_SLICE:
+ case STORAGE_TUPLE:
assert(0); // TODO
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_ALIAS:
+ case STORAGE_FUNCTION:
assert(0); // Invariant
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
break; // no-op
}
}
@@ -456,7 +456,7 @@ enum eval_result
eval_struct(struct context *ctx, struct expression *in, struct expression *out)
{
assert(in->type == EXPR_STRUCT);
- assert(type_dealias(in->result)->storage != TYPE_STORAGE_UNION); // TODO
+ assert(type_dealias(in->result)->storage != STORAGE_UNION); // TODO
const struct type *type = type_dealias(in->result);
out->type = EXPR_CONSTANT;
diff --git a/src/gen.c b/src/gen.c
@@ -314,11 +314,11 @@ address_index(struct gen_context *ctx,
gen_expression(ctx, expr->access.array, out);
const struct type *atype = type_dealias(expr->access.array->result);
- if (atype->storage == TYPE_STORAGE_POINTER) {
+ if (atype->storage == STORAGE_POINTER) {
// We get one dereference for free for aggregate types
atype = type_dealias(atype->pointer.referent);
}
- while (atype->storage == TYPE_STORAGE_POINTER) {
+ while (atype->storage == STORAGE_POINTER) {
pushi(ctx->current, out, Q_LOADL, out, NULL);
atype = type_dealias(atype->pointer.referent);
}
@@ -329,9 +329,9 @@ address_index(struct gen_context *ctx,
// XXX: ARCH
struct qbe_value length = {0};
- if (atype->storage == TYPE_STORAGE_ARRAY) {
+ if (atype->storage == STORAGE_ARRAY) {
constl(&length, atype->array.length);
- } else if (atype->storage == TYPE_STORAGE_SLICE) {
+ } else if (atype->storage == STORAGE_SLICE) {
struct qbe_value ptr = {0};
gen_temp(ctx, &ptr, &qbe_long, "ptr.%d");
constl(&length, 8);
@@ -340,7 +340,7 @@ address_index(struct gen_context *ctx,
pushi(ctx->current, &length, Q_LOADL, &ptr, NULL);
}
- if (atype->storage != TYPE_STORAGE_ARRAY
+ if (atype->storage != STORAGE_ARRAY
|| atype->array.length != SIZE_UNDEFINED) {
struct qbe_statement validl = {0}, invalidl = {0};
struct qbe_value bvalid = {0}, binvalid = {0};
@@ -365,7 +365,7 @@ address_index(struct gen_context *ctx,
push(&ctx->current->body, &validl);
}
- if (atype->storage == TYPE_STORAGE_SLICE) {
+ if (atype->storage == STORAGE_SLICE) {
pushi(ctx->current, out, Q_LOADL, out, NULL);
}
@@ -388,11 +388,11 @@ address_field(struct gen_context *ctx,
gen_expression(ctx, expr->access._struct, out);
const struct type *stype = type_dealias(expr->access._struct->result);
- if (stype->storage == TYPE_STORAGE_POINTER) {
+ if (stype->storage == STORAGE_POINTER) {
// We get one dereference for free for aggregate types
stype = type_dealias(stype->pointer.referent);
}
- while (stype->storage == TYPE_STORAGE_POINTER) {
+ while (stype->storage == STORAGE_POINTER) {
pushi(ctx->current, out, Q_LOADL, out, NULL);
stype = type_dealias(stype->pointer.referent);
}
@@ -417,11 +417,11 @@ address_value(struct gen_context *ctx,
gen_expression(ctx, expr->access.tuple, out);
const struct type *ttype = type_dealias(expr->access.tuple->result);
- if (ttype->storage == TYPE_STORAGE_POINTER) {
+ if (ttype->storage == STORAGE_POINTER) {
// We get one dereference for free for aggregate types
ttype = type_dealias(ttype->pointer.referent);
}
- while (ttype->storage == TYPE_STORAGE_POINTER) {
+ while (ttype->storage == STORAGE_POINTER) {
pushi(ctx->current, out, Q_LOADL, out, NULL);
ttype = type_dealias(ttype->pointer.referent);
}
@@ -498,7 +498,7 @@ gen_slice_alloc(struct gen_context *ctx,
"slice.size.%d");
const struct expression *initializer = expr->alloc.expr;
- if (initializer->result->storage == TYPE_STORAGE_ARRAY) {
+ if (initializer->result->storage == STORAGE_ARRAY) {
assert(initializer->result->array.length != SIZE_UNDEFINED);
constl(&len, initializer->result->array.length);
} else {
@@ -534,7 +534,7 @@ gen_slice_alloc(struct gen_context *ctx,
pushi(ctx->current, &ptr, Q_ADD, &ptr, &temp, NULL);
pushi(ctx->current, NULL, Q_STOREL, &cap, &ptr, NULL);
- if (initializer->result->storage == TYPE_STORAGE_ARRAY) {
+ if (initializer->result->storage == STORAGE_ARRAY) {
gen_expression(ctx, initializer, &ret);
} else {
// TODO: I think this will have to be a separate branch once
@@ -548,7 +548,7 @@ gen_expr_alloc(struct gen_context *ctx,
const struct qbe_value *out)
{
assert(expr->type == EXPR_ALLOC);
- if (type_dealias(expr->result)->storage == TYPE_STORAGE_SLICE) {
+ if (type_dealias(expr->result)->storage == STORAGE_SLICE) {
gen_slice_alloc(ctx, expr, out);
return;
}
@@ -984,7 +984,7 @@ gen_expr_binarithm(struct gen_context *ctx,
}
if (type_dealias(expr->binarithm.lvalue->result)->storage
- == TYPE_STORAGE_STRING) {
+ == STORAGE_STRING) {
struct qbe_value rtfunc = {0};
rtfunc.kind = QV_GLOBAL;
rtfunc.name = strdup("rt.strcmp");
@@ -1027,15 +1027,15 @@ gen_expr_call(struct gen_context *ctx,
next = &arg->next;
const struct type *ftype = type_dealias(expr->call.lvalue->result);
- if (ftype->storage == TYPE_STORAGE_POINTER) {
+ if (ftype->storage == STORAGE_POINTER) {
// We get one dereference for free for aggregate types
ftype = type_dealias(ftype->pointer.referent);
}
- while (ftype->storage == TYPE_STORAGE_POINTER) {
+ while (ftype->storage == STORAGE_POINTER) {
pushi(ctx->current, &arg->value, Q_LOADL, &arg->value, NULL);
ftype = type_dealias(ftype->pointer.referent);
}
- assert(ftype->storage == TYPE_STORAGE_FUNCTION);
+ assert(ftype->storage == STORAGE_FUNCTION);
if (ftype->func.result != &builtin_type_void) {
gen_temp(ctx, &result, qtype_for_type(ctx,
ftype->func.result, true), "returns.%d");
@@ -1138,7 +1138,7 @@ gen_cast_to_tagged(struct gen_context *ctx,
struct qbe_value tag = {0}, ptr = {0}, offs = {0};
constl(&offs, expr->result->align);
- if (!subtype && type_dealias(from)->storage == TYPE_STORAGE_TAGGED
+ if (!subtype && type_dealias(from)->storage == STORAGE_TAGGED
&& from->align != tagged->align
&& type_dealias(tagged)->size != builtin_type_uint.size
&& type_dealias(from)->size != builtin_type_uint.size) {
@@ -1209,13 +1209,13 @@ gen_cast_from_tagged(struct gen_context *ctx,
const struct qbe_value *out,
const struct type *to)
{
- if (type_dealias(to)->storage == TYPE_STORAGE_VOID) {
+ if (type_dealias(to)->storage == STORAGE_VOID) {
// TODO: generate type assertion if appropriate
gen_expression(ctx, expr->cast.value, NULL);
return;
}
- if (type_dealias(to)->storage == TYPE_STORAGE_TAGGED) {
+ if (type_dealias(to)->storage == STORAGE_TAGGED) {
assert(0); // TODO
}
@@ -1264,10 +1264,10 @@ gen_expr_cast(struct gen_context *ctx,
}
const struct type *to = expr->result, *from = expr->cast.value->result;
- if (type_dealias(to)->storage == TYPE_STORAGE_TAGGED) {
+ if (type_dealias(to)->storage == STORAGE_TAGGED) {
gen_cast_to_tagged(ctx, expr, out, from);
return;
- } else if (type_dealias(from)->storage == TYPE_STORAGE_TAGGED) {
+ } else if (type_dealias(from)->storage == STORAGE_TAGGED) {
gen_cast_from_tagged(ctx, expr, out, to);
return;
}
@@ -1284,11 +1284,11 @@ gen_expr_cast(struct gen_context *ctx,
gen_temp(ctx, &result, qtype_for_type(ctx, to, false), "cast.out.%d");
// Special case: str -> *const char; slice -> ptr
- if ((to->storage == TYPE_STORAGE_POINTER
- && to->pointer.referent->storage == TYPE_STORAGE_CHAR
- && from->storage == TYPE_STORAGE_STRING)
- || (to->storage == TYPE_STORAGE_POINTER
- && from->storage == TYPE_STORAGE_SLICE)) {
+ if ((to->storage == STORAGE_POINTER
+ && to->pointer.referent->storage == STORAGE_CHAR
+ && from->storage == STORAGE_STRING)
+ || (to->storage == STORAGE_POINTER
+ && from->storage == STORAGE_SLICE)) {
alloc_temp(ctx, &in, from, "cast.in.%d");
in.indirect = false;
gen_expression(ctx, expr->cast.value, &in);
@@ -1299,7 +1299,7 @@ gen_expr_cast(struct gen_context *ctx,
return;
}
- if (to->storage == TYPE_STORAGE_VOID) {
+ if (to->storage == STORAGE_VOID) {
gen_expression(ctx, expr->cast.value, NULL);
return;
}
@@ -1323,21 +1323,21 @@ gen_expr_cast(struct gen_context *ctx,
struct qbe_value ptr = {0}, offs = {0}, len = {0};
switch (to->storage) {
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_INT: // XXX: ARCH
- case TYPE_STORAGE_UINT: // XXX: ARCH
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINTPTR: // XXX: ARCH
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE: // XXX: ARCH
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_U8:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_U16:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_INT: // XXX: ARCH
+ case STORAGE_UINT: // XXX: ARCH
+ case STORAGE_I64:
+ case STORAGE_U64:
+ case STORAGE_UINTPTR: // XXX: ARCH
+ case STORAGE_RUNE:
+ case STORAGE_SIZE: // XXX: ARCH
if (type_is_integer(from) && to->size <= from->size) {
op = Q_COPY;
} else if (type_is_integer(from) && to->size > from->size) {
@@ -1354,27 +1354,27 @@ gen_expr_cast(struct gen_context *ctx,
default:
assert(0); // Invariant
}
- } else if (from->storage == TYPE_STORAGE_POINTER
- || from->storage == TYPE_STORAGE_NULL) {
- assert(to->storage == TYPE_STORAGE_UINTPTR);
+ } else if (from->storage == STORAGE_POINTER
+ || from->storage == STORAGE_NULL) {
+ assert(to->storage == STORAGE_UINTPTR);
op = Q_COPY;
- } else if (from->storage == TYPE_STORAGE_RUNE) {
- assert(to->storage == TYPE_STORAGE_U32);
+ } else if (from->storage == STORAGE_RUNE) {
+ assert(to->storage == STORAGE_U32);
op = Q_COPY;
} else {
assert(0); // Invariant
}
pushi(ctx->current, &result, op, &in, NULL);
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
+ case STORAGE_F32:
+ case STORAGE_F64:
assert(0); // TODO
- case TYPE_STORAGE_ARRAY:
- assert(from->storage == TYPE_STORAGE_ARRAY);
+ case STORAGE_ARRAY:
+ assert(from->storage == STORAGE_ARRAY);
pushi(ctx->current, &result, Q_COPY, &in, NULL);
break;
- case TYPE_STORAGE_SLICE:
- if (from->storage == TYPE_STORAGE_SLICE) {
+ case STORAGE_SLICE:
+ if (from->storage == STORAGE_SLICE) {
pushi(ctx->current, &result, Q_COPY, &in, NULL);
break;
}
@@ -1396,23 +1396,23 @@ gen_expr_cast(struct gen_context *ctx,
pushi(ctx->current, NULL, Q_STOREL, &len, &ptr, NULL);
return;
// Can be implemented with a copy
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_POINTER:
+ case STORAGE_NULL:
+ case STORAGE_POINTER:
pushi(ctx->current, &result, Q_COPY, &in, NULL);
break;
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_ALIAS:
+ case STORAGE_TAGGED:
assert(0); // Handled above
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_BOOL:
+ case STORAGE_FCONST:
+ case STORAGE_FUNCTION:
+ case STORAGE_ICONST:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
assert(0); // Invariant
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return; // no-op
}
@@ -1531,22 +1531,22 @@ gen_expr_constant(struct gen_context *ctx,
// Special cases
switch (expr->result->storage) {
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
constw(&val, expr->constant.bval ? 1 : 0);
gen_store(ctx, out, &val);
return;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
const_void(&val);
gen_store(ctx, out, &val);
return;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
constl(&val, 0);
gen_store(ctx, out, &val);
return;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
gen_array(ctx, expr, out);
return;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
gen_string(ctx, expr, out);
return;
default:
@@ -1672,8 +1672,8 @@ gen_expr_free(struct gen_context *ctx,
{
struct qbe_value val = {0}, rtfunc = {0};
const struct type *type = type_dealias(expr->alloc.expr->result);
- if (type->storage == TYPE_STORAGE_SLICE
- || type->storage == TYPE_STORAGE_STRING) {
+ if (type->storage == STORAGE_SLICE
+ || type->storage == STORAGE_STRING) {
alloc_temp(ctx, &val, type, "free.%d");
val.type = &qbe_long;
gen_expression(ctx, expr->alloc.expr, &val);
@@ -1874,7 +1874,7 @@ gen_match_tagged(struct gen_context *ctx,
} interpretation = MEMBER;
if (tagged_select_subtype(mtype, _case->type) == NULL) {
- assert(type_dealias(_case->type)->storage == TYPE_STORAGE_TAGGED);
+ assert(type_dealias(_case->type)->storage == STORAGE_TAGGED);
assert(tagged_subset_compat(mtype, _case->type));
// Our match value can be "re-interpreted" as this case
// type because it is a subset-compatible tagged union.
@@ -1997,7 +1997,7 @@ gen_match_nullable(struct gen_context *ctx,
constl(&zero, 0);
pushi(ctx->current, &temp, Q_CEQL, &mval, &zero, NULL);
- if (_case->type->storage == TYPE_STORAGE_NULL) {
+ if (_case->type->storage == STORAGE_NULL) {
pushi(ctx->current, NULL, Q_JNZ,
&temp, &tbranch, &fbranch, NULL);
} else {
@@ -2042,10 +2042,10 @@ gen_expr_match(struct gen_context *ctx,
{
const struct type *mtype = type_dealias(expr->match.value->result);
switch (mtype->storage) {
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
gen_match_tagged(ctx, expr, out);
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
gen_match_nullable(ctx, expr, out);
break;
default:
@@ -2062,15 +2062,15 @@ gen_expr_measure(struct gen_context *ctx,
switch (expr->measure.op) {
case M_LEN:
switch (expr->measure.value->result->storage) {
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
gen_temp(ctx, &temp,
qtype_for_type(ctx, expr->result, false),
"len.%d");
constl(&temp, expr->measure.value->result->array.length);
gen_store(ctx, out, &temp);
break;
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
// My god this is a fucking mess
alloc_temp(ctx, &src,
expr->measure.value->result,
@@ -2135,7 +2135,7 @@ gen_expr_slice(struct gen_context *ctx,
gen_temp(ctx, &object, object.type, "object.%d");
object.type = temp.type;
pushi(ctx->current, &object, Q_COPY, &temp, NULL);
- while (otype->storage == TYPE_STORAGE_POINTER) {
+ while (otype->storage == STORAGE_POINTER) {
pushi(ctx->current, &object, Q_LOADL, &object, NULL);
otype = type_dereference(otype->pointer.referent);
}
@@ -2155,7 +2155,7 @@ gen_expr_slice(struct gen_context *ctx,
if (expr->slice.end) {
gen_expression(ctx, expr->slice.end, &end);
- } else if (otype->storage == TYPE_STORAGE_ARRAY) {
+ } else if (otype->storage == STORAGE_ARRAY) {
constl(&end, otype->array.length);
} else {
pushc(ctx->current, "load length");
@@ -2166,7 +2166,7 @@ gen_expr_slice(struct gen_context *ctx,
// TODO: Bounds check
pushi(ctx->current, &dest, Q_COPY, out, NULL);
- if (otype->storage == TYPE_STORAGE_SLICE) {
+ if (otype->storage == STORAGE_SLICE) {
pushc(ctx->current, "load array");
gen_temp(ctx, &src, &qbe_long, "src.%d");
@@ -2498,47 +2498,47 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
const union expression_constant *constant = &expr->constant;
const struct type *type = type_dealias(expr->result);
switch (type->storage) {
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_U8:
+ case STORAGE_I8:
+ case STORAGE_U8:
item->type = QD_VALUE;
constw(&item->value, (uint8_t)constant->uval);
item->value.type = &qbe_byte;
break;
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
+ case STORAGE_I16:
+ case STORAGE_U16:
item->type = QD_VALUE;
constw(&item->value, (uint16_t)constant->uval);
item->value.type = &qbe_half;
break;
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
item->type = QD_VALUE;
constw(&item->value, constant->bval ? 1 : 0);
break;
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_RUNE:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_INT:
+ case STORAGE_UINT:
+ case STORAGE_RUNE:
item->type = QD_VALUE;
constw(&item->value, (uint32_t)constant->uval);
break;
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_SIZE:
+ case STORAGE_U64:
+ case STORAGE_I64:
+ case STORAGE_SIZE:
item->type = QD_VALUE;
constl(&item->value, (uint32_t)constant->uval);
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
+ case STORAGE_F32:
+ case STORAGE_F64:
assert(0); // TODO
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
assert(0); // TODO: What are the semantics for this?
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
assert(expr->type == EXPR_CONSTANT); // TODO?
item->type = QD_VALUE;
constl(&item->value, (uint64_t)constant->uval); // XXX: ARCH
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
assert(type->array.length != SIZE_UNDEFINED);
size_t n = type->array.length;
for (struct array_constant *c = constant->array;
@@ -2551,7 +2551,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
}
}
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
def = xcalloc(1, sizeof(struct qbe_def));
def->name = gen_name(ctx, "strdata.%d");
def->kind = Q_DATA;
@@ -2579,7 +2579,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
item->type = QD_VALUE;
constl(&item->value, expr->constant.string.len);
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
def = xcalloc(1, sizeof(struct qbe_def));
def->name = gen_name(ctx, "sldata.%d");
def->kind = Q_DATA;
@@ -2617,7 +2617,7 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
item->type = QD_VALUE;
constl(&item->value, len);
break;
- case TYPE_STORAGE_STRUCT:
+ case STORAGE_STRUCT:
for (struct struct_constant *f = constant->_struct;
f; f = f->next) {
item = gen_data_item(ctx, f->value, item);
@@ -2639,18 +2639,18 @@ gen_data_item(struct gen_context *ctx, struct expression *expr,
}
}
break;
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_ENUM:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
assert(0); // TODO
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_VOID:
+ case STORAGE_ALIAS:
+ case STORAGE_CHAR:
+ case STORAGE_FCONST:
+ case STORAGE_FUNCTION:
+ case STORAGE_ICONST:
+ case STORAGE_NULL:
+ case STORAGE_VOID:
assert(0); // Invariant
}
@@ -2719,7 +2719,7 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl)
ctx->end_label = &end_label_v;
struct qbe_value rval = {0};
- if (fntype->func.result->storage != TYPE_STORAGE_VOID) {
+ if (fntype->func.result->storage != STORAGE_VOID) {
alloc_temp(ctx, &rval, fntype->func.result, "ret.%d");
if (type_is_aggregate(fntype->func.result)) {
rval.indirect = false;
@@ -2736,7 +2736,7 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl)
push(&qdef->func.body, &end_label);
pop_scope(ctx);
- if (fntype->func.result->storage != TYPE_STORAGE_VOID) {
+ if (fntype->func.result->storage != STORAGE_VOID) {
if (type_is_aggregate(fntype->func.result)) {
pushi(&qdef->func, NULL, Q_RET, ctx->return_value, NULL);
} else {
diff --git a/src/lex.c b/src/lex.c
@@ -344,26 +344,26 @@ lex_literal(struct lexer *lexer, struct token *out)
finalize:
out->token = T_LITERAL;
if (isfloat) {
- out->storage = TYPE_STORAGE_FCONST;
+ out->storage = STORAGE_FCONST;
} else {
- out->storage = TYPE_STORAGE_ICONST;
+ out->storage = STORAGE_ICONST;
}
if (suff) {
const char *suffs[] = {
- [TYPE_STORAGE_U8] = "u8",
- [TYPE_STORAGE_U16] = "u16",
- [TYPE_STORAGE_U32] = "u32",
- [TYPE_STORAGE_U64] = "u64",
- [TYPE_STORAGE_I8] = "i8",
- [TYPE_STORAGE_I16] = "i16",
- [TYPE_STORAGE_I32] = "i32",
- [TYPE_STORAGE_I64] = "i64",
+ [STORAGE_U8] = "u8",
+ [STORAGE_U16] = "u16",
+ [STORAGE_U32] = "u32",
+ [STORAGE_U64] = "u64",
+ [STORAGE_I8] = "i8",
+ [STORAGE_I16] = "i16",
+ [STORAGE_I32] = "i32",
+ [STORAGE_I64] = "i64",
- [TYPE_STORAGE_UINT] = "u",
- [TYPE_STORAGE_INT] = "i",
- [TYPE_STORAGE_SIZE] = "z",
- [TYPE_STORAGE_F32] = "f32",
- [TYPE_STORAGE_F64] = "f64",
+ [STORAGE_UINT] = "u",
+ [STORAGE_INT] = "i",
+ [STORAGE_SIZE] = "z",
+ [STORAGE_F32] = "f32",
+ [STORAGE_F64] = "f64",
};
bool isvalid = false;
for (enum type_storage i = 0;
@@ -394,43 +394,43 @@ finalize:
errno = 0;
switch (out->storage) {
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_UINT:
+ case STORAGE_U64:
+ case STORAGE_SIZE:
out->uval = strtoumax(lexer->buf, NULL, base);
for (uintmax_t i = 0; i < exponent; i++) {
out->uval *= 10;
}
break;
- case TYPE_STORAGE_ICONST:
+ case STORAGE_ICONST:
if (lexer->buf[0] != '-') {
uintmax_t uval = strtoumax(lexer->buf, NULL, base);
for (uintmax_t i = 0; i < exponent; i++) {
uval *= 10;
}
if (uval > (uintmax_t)INT64_MAX) {
- out->storage = TYPE_STORAGE_U64;
+ out->storage = STORAGE_U64;
out->uval = uval;
break;
}
}
// Fallthrough
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_INT:
+ case STORAGE_I64:
out->ival = strtoimax(lexer->buf, NULL, base);
for (uintmax_t i = 0; i < exponent; i++) {
out->ival *= 10;
}
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
out->fval = strtod(lexer->buf, NULL);
break;
default:
@@ -530,7 +530,7 @@ lex_string(struct lexer *lexer, struct token *out)
char *buf = xcalloc(lexer->buflen, lexer->buflen);
memcpy(buf, lexer->buf, lexer->buflen);
out->token = T_LITERAL;
- out->storage = TYPE_STORAGE_STRING;
+ out->storage = STORAGE_STRING;
out->string.len = lexer->buflen;
out->string.value = buf;
consume(lexer, -1);
@@ -557,7 +557,7 @@ lex_string(struct lexer *lexer, struct token *out)
c = next(lexer, NULL, false);
assert(c == '\'');
out->token = T_LITERAL;
- out->storage = TYPE_STORAGE_RUNE;
+ out->storage = STORAGE_RUNE;
return out->token;
default:
assert(0); // Invariant
@@ -923,7 +923,7 @@ token_finish(struct token *tok)
break;
case T_LITERAL:
switch (tok->storage) {
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
free(tok->string.value);
break;
default:
@@ -1016,7 +1016,7 @@ static const char *
string_unparse(const struct token *tok)
{
static char buf[1024];
- assert(tok->token == T_LITERAL && tok->storage == TYPE_STORAGE_STRING);
+ assert(tok->token == T_LITERAL && tok->storage == STORAGE_STRING);
int bytes = 0;
memset(buf, 0, sizeof(buf));
bytes += snprintf(&buf[bytes], sizeof(buf) - bytes, "\"");
@@ -1045,50 +1045,50 @@ token_str(const struct token *tok)
return buf;
case T_LITERAL:
switch (tok->storage) {
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_SIZE:
snprintf(buf, sizeof(buf), "%ju", tok->uval);
break;
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
snprintf(buf, sizeof(buf), "%jd", tok->ival);
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
snprintf(buf, sizeof(buf), "%lf", tok->fval);
break;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
bytes += snprintf(&buf[bytes], sizeof(buf) - bytes, "'");
bytes += snprintf(&buf[bytes], sizeof(buf) - bytes, "%s",
rune_unparse(tok->rune));
bytes += snprintf(&buf[bytes], sizeof(buf) - bytes, "'");
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
return string_unparse(tok);
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_VOID:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_NULL:
+ case STORAGE_SLICE:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_VOID:
assert(0);
}
return buf;
diff --git a/src/parse.c b/src/parse.c
@@ -202,7 +202,7 @@ parse_parameter_list(struct lexer *lexer, struct ast_function_type *type)
break;
case T_DOUBLE_COLON:
next->type = parse_type(lexer);
- synassert(next->type->storage == TYPE_STORAGE_ALIAS,
+ synassert(next->type->storage == STORAGE_ALIAS,
&tok, T_NAME, T_EOF);
struct identifier *ident =
xcalloc(1, sizeof(struct identifier));
@@ -290,43 +290,43 @@ parse_integer_type(struct lexer *lexer)
struct token tok = {0};
switch (lex(lexer, &tok)) {
case T_I8:
- storage = TYPE_STORAGE_I8;
+ storage = STORAGE_I8;
break;
case T_I16:
- storage = TYPE_STORAGE_I16;
+ storage = STORAGE_I16;
break;
case T_I32:
- storage = TYPE_STORAGE_I32;
+ storage = STORAGE_I32;
break;
case T_I64:
- storage = TYPE_STORAGE_I64;
+ storage = STORAGE_I64;
break;
case T_U8:
- storage = TYPE_STORAGE_U8;
+ storage = STORAGE_U8;
break;
case T_U16:
- storage = TYPE_STORAGE_U16;
+ storage = STORAGE_U16;
break;
case T_U32:
- storage = TYPE_STORAGE_U32;
+ storage = STORAGE_U32;
break;
case T_U64:
- storage = TYPE_STORAGE_U64;
+ storage = STORAGE_U64;
break;
case T_INT:
- storage = TYPE_STORAGE_INT;
+ storage = STORAGE_INT;
break;
case T_UINT:
- storage = TYPE_STORAGE_UINT;
+ storage = STORAGE_UINT;
break;
case T_SIZE:
- storage = TYPE_STORAGE_SIZE;
+ storage = STORAGE_SIZE;
break;
case T_UINTPTR:
- storage = TYPE_STORAGE_UINTPTR;
+ storage = STORAGE_UINTPTR;
break;
case T_CHAR:
- storage = TYPE_STORAGE_CHAR;
+ storage = STORAGE_CHAR;
break;
default:
assert(0);
@@ -359,25 +359,25 @@ parse_primitive_type(struct lexer *lexer)
type->storage = parse_integer_type(lexer);
break;
case T_RUNE:
- type->storage = TYPE_STORAGE_RUNE;
+ type->storage = STORAGE_RUNE;
break;
case T_STR:
- type->storage = TYPE_STORAGE_STRING;
+ type->storage = STORAGE_STRING;
break;
case T_F32:
- type->storage = TYPE_STORAGE_F32;
+ type->storage = STORAGE_F32;
break;
case T_F64:
- type->storage = TYPE_STORAGE_F64;
+ type->storage = STORAGE_F64;
break;
case T_BOOL:
- type->storage = TYPE_STORAGE_BOOL;
+ type->storage = STORAGE_BOOL;
break;
case T_VOID:
- type->storage = TYPE_STORAGE_VOID;
+ type->storage = STORAGE_VOID;
break;
case T_NULL:
- type->storage = TYPE_STORAGE_NULL;
+ type->storage = STORAGE_NULL;
break;
default:
assert(0);
@@ -401,11 +401,11 @@ parse_enum_type(struct lexer *lexer)
trenter(TR_PARSE, "enum");
struct token tok = {0};
struct ast_type *type = mktype(&lexer->loc);
- type->storage = TYPE_STORAGE_ENUM;
+ type->storage = STORAGE_ENUM;
struct ast_enum_field **next = &type->_enum.values;
switch (lex(lexer, &tok)) {
case T_LBRACE:
- type->_enum.storage = TYPE_STORAGE_INT;
+ type->_enum.storage = STORAGE_INT;
unlex(lexer, &tok);
break;
default:
@@ -451,11 +451,11 @@ parse_struct_union_type(struct lexer *lexer)
switch (lex(lexer, &tok)) {
case T_STRUCT:
trenter(TR_PARSE, "struct");
- type->storage = TYPE_STORAGE_STRUCT;
+ type->storage = STORAGE_STRUCT;
break;
case T_UNION:
trenter(TR_PARSE, "union");
- type->storage = TYPE_STORAGE_UNION;
+ type->storage = STORAGE_UNION;
break;
default:
synassert(false, &tok, T_STRUCT, T_UNION, T_EOF);
@@ -537,7 +537,7 @@ parse_tagged_type(struct lexer *lexer, struct ast_type *first)
{
trenter(TR_PARSE, "tagged union");
struct ast_type *type = mktype(&first->loc);
- type->storage = TYPE_STORAGE_TAGGED;
+ type->storage = STORAGE_TAGGED;
struct ast_tagged_union_type *next = &type->tagged_union;
next->type = first;
struct token tok = {0};
@@ -566,7 +566,7 @@ parse_tuple_type(struct lexer *lexer, struct ast_type *first)
{
trenter(TR_PARSE, "tuple");
struct ast_type *type = mktype(&first->loc);
- type->storage = TYPE_STORAGE_TUPLE;
+ type->storage = STORAGE_TUPLE;
struct ast_tuple_type *next = &type->tuple;
next->type = first;
struct token tok = {0};
@@ -656,7 +656,7 @@ parse_type(struct lexer *lexer)
/* fallthrough */
case T_TIMES:
type = mktype(&lexer->loc);
- type->storage = TYPE_STORAGE_POINTER;
+ type->storage = STORAGE_POINTER;
type->pointer.referent = parse_type(lexer);
if (nullable) {
type->pointer.flags |= PTR_NULLABLE;
@@ -674,24 +674,24 @@ parse_type(struct lexer *lexer)
type = mktype(&lexer->loc);
switch (lex(lexer, &tok)) {
case T_RBRACKET:
- type->storage = TYPE_STORAGE_SLICE;
+ type->storage = STORAGE_SLICE;
type->slice.members = parse_type(lexer);
break;
case T_TIMES:
- type->storage = TYPE_STORAGE_ARRAY;
+ type->storage = STORAGE_ARRAY;
type->array.length = NULL;
want(lexer, T_RBRACKET, NULL);
type->array.members = parse_type(lexer);
break;
case T_UNDERSCORE:
- type->storage = TYPE_STORAGE_ARRAY;
+ type->storage = STORAGE_ARRAY;
type->array.length = NULL;
type->array.contextual = true;
want(lexer, T_RBRACKET, NULL);
type->array.members = parse_type(lexer);
break;
default:
- type->storage = TYPE_STORAGE_ARRAY;
+ type->storage = STORAGE_ARRAY;
unlex(lexer, &tok);
type->array.length = parse_simple_expression(lexer);
want(lexer, T_RBRACKET, NULL);
@@ -705,7 +705,7 @@ parse_type(struct lexer *lexer)
// fallthrough
case T_FN:
type = mktype(&lexer->loc);
- type->storage = TYPE_STORAGE_FUNCTION;
+ type->storage = STORAGE_FUNCTION;
parse_prototype(lexer, &type->func);
if (noreturn) {
type->func.flags |= FN_NORETURN;
@@ -718,7 +718,7 @@ parse_type(struct lexer *lexer)
case T_NAME:
unlex(lexer, &tok);
type = mktype(&lexer->loc);
- type->storage = TYPE_STORAGE_ALIAS;
+ type->storage = STORAGE_ALIAS;
type->unwrap = unwrap;
parse_identifier(lexer, &type->alias);
break;
@@ -754,18 +754,18 @@ parse_constant(struct lexer *lexer)
struct token tok = {0};
switch (lex(lexer, &tok)) {
case T_TRUE:
- exp->constant.storage = TYPE_STORAGE_BOOL;
+ exp->constant.storage = STORAGE_BOOL;
exp->constant.bval = true;
return exp;
case T_FALSE:
- exp->constant.storage = TYPE_STORAGE_BOOL;
+ exp->constant.storage = STORAGE_BOOL;
exp->constant.bval = false;
return exp;
case T_NULL:
- exp->constant.storage = TYPE_STORAGE_NULL;
+ exp->constant.storage = STORAGE_NULL;
return exp;
case T_VOID:
- exp->constant.storage = TYPE_STORAGE_VOID;
+ exp->constant.storage = STORAGE_VOID;
return exp;
case T_LITERAL:
exp->constant.storage = tok.storage;
@@ -777,32 +777,32 @@ parse_constant(struct lexer *lexer)
}
switch (tok.storage) {
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_SIZE:
+ case STORAGE_CHAR:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_SIZE:
exp->constant.uval = (uintmax_t)tok.uval;
break;
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
exp->constant.ival = (intmax_t)tok.ival;
break;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
exp->constant.rune = tok.rune;
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
exp->constant.string.len = tok.string.len;
exp->constant.string.value = tok.string.value;
while (lex(lexer, &tok) == T_LITERAL
- && tok.storage == TYPE_STORAGE_STRING) {
+ && tok.storage == STORAGE_STRING) {
size_t len = exp->constant.string.len;
exp->constant.string.value = xrealloc(
exp->constant.string.value,
@@ -831,7 +831,7 @@ parse_array_literal(struct lexer *lexer)
struct ast_expression *exp = mkexpr(&lexer->loc);
exp->type = EXPR_CONSTANT;
- exp->constant.storage = TYPE_STORAGE_ARRAY;
+ exp->constant.storage = STORAGE_ARRAY;
struct ast_array_constant *item, **next = &exp->constant.array;
@@ -1852,13 +1852,13 @@ parse_match_expression(struct lexer *lexer)
ident.ns->name = tok.name; // Assumes ownership
parse_identifier(lexer, &ident);
_case->type = mktype(&tok.loc);
- _case->type->storage = TYPE_STORAGE_ALIAS;
+ _case->type->storage = STORAGE_ALIAS;
_case->type->alias = ident;
break;
case T_CASE:
unlex(lexer, &tok2);
_case->type = mktype(&tok.loc);
- _case->type->storage = TYPE_STORAGE_ALIAS;
+ _case->type->storage = STORAGE_ALIAS;
_case->type->alias.name = tok.name;
break;
default:
@@ -1876,7 +1876,7 @@ parse_match_expression(struct lexer *lexer)
unlex(lexer, &tok2);
_case->type = parse_type(lexer);
struct ast_type *ptr = mktype(&tok.loc);
- ptr->storage = TYPE_STORAGE_POINTER;
+ ptr->storage = STORAGE_POINTER;
ptr->pointer.referent = _case->type;
_case->type = ptr;
break;
@@ -2249,7 +2249,7 @@ parse_attr_symbol(struct lexer *lexer)
struct token tok = {0};
want(lexer, T_LPAREN, NULL);
want(lexer, T_LITERAL, &tok);
- synassert_msg(tok.storage == TYPE_STORAGE_STRING,
+ synassert_msg(tok.storage == STORAGE_STRING,
"expected string literal", &tok);
for (size_t i = 0; i < tok.string.len; i++) {
uint32_t c = tok.string.value[i];
diff --git a/src/qtype.c b/src/qtype.c
@@ -12,46 +12,46 @@ enum qbe_stype
qstype_for_type(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_U8:
+ case STORAGE_CHAR:
+ case STORAGE_I8:
+ case STORAGE_U8:
// Implemented as Q_WORD
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
+ case STORAGE_I16:
+ case STORAGE_U16:
// Implemented as Q_WORD
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_INT: // XXX: Architecture dependent
- case TYPE_STORAGE_UINT: // XXX: Architecture dependent
+ case STORAGE_BOOL:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_RUNE:
+ case STORAGE_INT: // XXX: Architecture dependent
+ case STORAGE_UINT: // XXX: Architecture dependent
return Q_WORD;
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_UINTPTR: // XXX: Architecture dependent
- case TYPE_STORAGE_POINTER: // XXX: Architecture dependent
- case TYPE_STORAGE_NULL: // XXX: Architecture dependent
+ case STORAGE_I64:
+ case STORAGE_U64:
+ case STORAGE_SIZE:
+ case STORAGE_UINTPTR: // XXX: Architecture dependent
+ case STORAGE_POINTER: // XXX: Architecture dependent
+ case STORAGE_NULL: // XXX: Architecture dependent
return Q_LONG;
- case TYPE_STORAGE_F32:
+ case STORAGE_F32:
return Q_SINGLE;
- case TYPE_STORAGE_F64:
+ case STORAGE_F64:
return Q_DOUBLE;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return Q__VOID;
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ALIAS:
+ case STORAGE_ENUM:
return qstype_for_type(builtin_type_for_storage(type->_enum.storage, true));
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_ARRAY:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_FUNCTION:
assert(0); // Invariant
}
assert(0);
@@ -61,42 +61,42 @@ enum qbe_stype
qxtype_for_type(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_U8:
+ case STORAGE_CHAR:
+ case STORAGE_I8:
+ case STORAGE_U8:
return Q_BYTE;
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
+ case STORAGE_I16:
+ case STORAGE_U16:
return Q_HALF;
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_INT: // XXX: Architecture dependent
- case TYPE_STORAGE_UINT: // XXX: Architecture dependent
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_UINTPTR: // XXX: Architecture dependent
- case TYPE_STORAGE_POINTER: // XXX: Architecture dependent
- case TYPE_STORAGE_NULL: // XXX: Architecture dependent
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_BOOL:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_RUNE:
+ case STORAGE_INT: // XXX: Architecture dependent
+ case STORAGE_UINT: // XXX: Architecture dependent
+ case STORAGE_I64:
+ case STORAGE_U64:
+ case STORAGE_SIZE:
+ case STORAGE_UINTPTR: // XXX: Architecture dependent
+ case STORAGE_POINTER: // XXX: Architecture dependent
+ case STORAGE_NULL: // XXX: Architecture dependent
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_VOID:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_FUNCTION:
return qstype_for_type(type);
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
return qxtype_for_type(builtin_type_for_storage(type->_enum.storage, true));
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0); // Lowered in check
}
assert(0);
@@ -156,7 +156,7 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type)
switch (type->storage) {
// Special cases
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
return &qbe_long;
default:
break;
@@ -178,12 +178,12 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type)
struct qbe_field *field = &def->type.fields;
switch (type->storage) {
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
field->type = &qbe_long; // XXX: ARCH
field->count = 3;
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
if (!type->struct_union.c_compat) {
def->type.align = type->align;
field->type = NULL;
@@ -201,11 +201,11 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type)
}
}
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
field->type = &qbe_long; // XXX: ARCH
field->count = 3;
break;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
def->type.align = type->align;
field->type = &qbe_word; // XXX: ARCH
field->count = 1;
@@ -216,7 +216,7 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type)
field->count = 1;
}
break;
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
def->type.align = type->align;
for (const struct type_tuple *tuple = &type->tuple;
tuple; tuple = tuple->next) {
@@ -229,32 +229,32 @@ lookup_aggregate(struct gen_context *ctx, const struct type *type)
}
}
break;
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_ENUM:
+ case STORAGE_ARRAY:
+ case STORAGE_ALIAS:
+ case STORAGE_CHAR:
+ case STORAGE_I8:
+ case STORAGE_U8:
+ case STORAGE_I16:
+ case STORAGE_U16:
+ case STORAGE_BOOL:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_RUNE:
+ case STORAGE_INT:
+ case STORAGE_UINT:
+ case STORAGE_I64:
+ case STORAGE_U64:
+ case STORAGE_ICONST:
+ case STORAGE_SIZE:
+ case STORAGE_UINTPTR:
+ case STORAGE_POINTER:
+ case STORAGE_NULL:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_VOID:
+ case STORAGE_FUNCTION:
assert(0); // Invariant
}
@@ -266,48 +266,48 @@ const struct qbe_type *
qtype_for_type(struct gen_context *ctx, const struct type *type, bool extended)
{
switch (type->storage) {
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_U16:
+ case STORAGE_CHAR:
+ case STORAGE_I8:
+ case STORAGE_U8:
+ case STORAGE_I16:
+ case STORAGE_U16:
if (extended) {
return qtype_for_xtype(
qxtype_for_type(type),
type_is_signed(type));
}
// Fallthrough
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_VOID:
+ case STORAGE_BOOL:
+ case STORAGE_ENUM:
+ case STORAGE_I32:
+ case STORAGE_U32:
+ case STORAGE_RUNE:
+ case STORAGE_INT:
+ case STORAGE_UINT:
+ case STORAGE_I64:
+ case STORAGE_U64:
+ case STORAGE_SIZE:
+ case STORAGE_UINTPTR:
+ case STORAGE_POINTER:
+ case STORAGE_NULL:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_VOID:
return qtype_for_xtype(qstype_for_type(type), false);
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_ARRAY:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
return lookup_aggregate(ctx, type);
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
return qtype_for_xtype(Q__AGGREGATE, false);
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return qtype_for_type(ctx, type->alias.type, extended);
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0); // Lowered in check
}
assert(0); // Unreachable
@@ -317,41 +317,41 @@ bool
type_is_aggregate(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_INT:
+ case STORAGE_POINTER:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
return false;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return type_is_aggregate(type->alias.type);
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_ARRAY:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_FUNCTION:
return true;
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0); // Lowered in check
}
assert(0); // Unreachable
diff --git a/src/type_store.c b/src/type_store.c
@@ -30,60 +30,60 @@ const struct type *
builtin_type_for_storage(enum type_storage storage, bool is_const)
{
switch (storage) {
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
return is_const ? &builtin_type_const_bool : &builtin_type_bool;
- case TYPE_STORAGE_CHAR:
+ case STORAGE_CHAR:
return is_const ? &builtin_type_const_char : &builtin_type_char;
- case TYPE_STORAGE_F32:
+ case STORAGE_F32:
return is_const ? &builtin_type_const_f32 : &builtin_type_f32;
- case TYPE_STORAGE_F64:
+ case STORAGE_F64:
return is_const ? &builtin_type_const_f64 : &builtin_type_f64;
- case TYPE_STORAGE_FCONST:
+ case STORAGE_FCONST:
return is_const ? &builtin_type_const_fconst : &builtin_type_fconst;
- case TYPE_STORAGE_I8:
+ case STORAGE_I8:
return is_const ? &builtin_type_const_i8 : &builtin_type_i8;
- case TYPE_STORAGE_I16:
+ case STORAGE_I16:
return is_const ? &builtin_type_const_i16 : &builtin_type_i16;
- case TYPE_STORAGE_I32:
+ case STORAGE_I32:
return is_const ? &builtin_type_const_i32 : &builtin_type_i32;
- case TYPE_STORAGE_I64:
+ case STORAGE_I64:
return is_const ? &builtin_type_const_i64 : &builtin_type_i64;
- case TYPE_STORAGE_ICONST:
+ case STORAGE_ICONST:
return is_const ? &builtin_type_const_iconst : &builtin_type_iconst;
- case TYPE_STORAGE_INT:
+ case STORAGE_INT:
return is_const ? &builtin_type_const_int : &builtin_type_int;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
return is_const ? &builtin_type_const_rune : &builtin_type_rune;
- case TYPE_STORAGE_SIZE:
+ case STORAGE_SIZE:
return is_const ? &builtin_type_const_size : &builtin_type_size;
- case TYPE_STORAGE_U8:
+ case STORAGE_U8:
return is_const ? &builtin_type_const_u8 : &builtin_type_u8;
- case TYPE_STORAGE_U16:
+ case STORAGE_U16:
return is_const ? &builtin_type_const_u16 : &builtin_type_u16;
- case TYPE_STORAGE_U32:
+ case STORAGE_U32:
return is_const ? &builtin_type_const_u32 : &builtin_type_u32;
- case TYPE_STORAGE_U64:
+ case STORAGE_U64:
return is_const ? &builtin_type_const_u64 : &builtin_type_u64;
- case TYPE_STORAGE_UINT:
+ case STORAGE_UINT:
return is_const ? &builtin_type_const_uint : &builtin_type_uint;
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
return is_const ? &builtin_type_const_uintptr : &builtin_type_uintptr;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return is_const ? &builtin_type_const_void : &builtin_type_void;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
return &builtin_type_null; // const null and null are the same type
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
return is_const ? &builtin_type_const_str : &builtin_type_str;
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_SLICE:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_ENUM:
return NULL;
}
assert(0); // Unreachable
@@ -129,7 +129,7 @@ struct_insert_field(struct type_store *store, struct struct_field **fields,
if (atype->offset) {
*ccompat = false;
- assert(storage == TYPE_STORAGE_STRUCT); // TODO: Bubble up
+ assert(storage == STORAGE_STRUCT); // TODO: Bubble up
struct expression in, out;
check_expression(store->check_context, atype->offset, &in, NULL);
enum eval_result r = eval_expr(store->check_context, &in, &out);
@@ -147,7 +147,7 @@ struct_insert_field(struct type_store *store, struct struct_field **fields,
field->offset = *size;
}
- if (storage == TYPE_STORAGE_STRUCT) {
+ if (storage == STORAGE_STRUCT) {
*size += field->type->size;
} else {
*usize = field->type->size > *usize ? field->type->size : *usize;
@@ -162,7 +162,7 @@ struct_init_from_atype(struct type_store *store, enum type_storage storage,
{
// TODO: fields with size SIZE_UNDEFINED
size_t usize = 0;
- assert(storage == TYPE_STORAGE_STRUCT || storage == TYPE_STORAGE_UNION);
+ assert(storage == STORAGE_STRUCT || storage == STORAGE_UNION);
while (atype) {
size_t sub = *size;
switch (atype->member_type) {
@@ -171,30 +171,30 @@ struct_init_from_atype(struct type_store *store, enum type_storage storage,
size, &usize, align, atype, ccompat);
break;
case MEMBER_TYPE_EMBEDDED:
- if (atype->embedded->storage == TYPE_STORAGE_UNION) {
+ if (atype->embedded->storage == STORAGE_UNION) {
*ccompat = false;
// We need to set the offset of all union
// members to the maximum alignment of the union
// members, so first we do a dry run to compute
// it:
size_t offs = 0, align_1 = 0;
- struct_init_from_atype(store, TYPE_STORAGE_UNION,
+ struct_init_from_atype(store, STORAGE_UNION,
&offs, &align_1, NULL,
&atype->embedded->struct_union, ccompat);
// Insert padding per the results:
*size += *size % align_1;
// Then insert the fields for real:
sub = *size;
- struct_init_from_atype(store, TYPE_STORAGE_UNION,
+ struct_init_from_atype(store, STORAGE_UNION,
&sub, align, fields,
&atype->embedded->struct_union, ccompat);
} else {
- struct_init_from_atype(store, TYPE_STORAGE_STRUCT,
+ struct_init_from_atype(store, STORAGE_STRUCT,
&sub, align, fields,
&atype->embedded->struct_union, ccompat);
}
- if (storage == TYPE_STORAGE_UNION) {
+ if (storage == STORAGE_UNION) {
usize = sub > usize ? sub : usize;
} else {
*size += sub;
@@ -206,7 +206,7 @@ struct_init_from_atype(struct type_store *store, enum type_storage storage,
atype = atype->next;
}
- if (storage == TYPE_STORAGE_UNION) {
+ if (storage == STORAGE_UNION) {
*size = usize;
}
}
@@ -218,7 +218,7 @@ sum_tagged_memb(struct type_store *store,
size_t nmemb = 0;
for (; u; u = u->next) {
const struct type *type = u->type;
- if (type->storage == TYPE_STORAGE_TAGGED) {
+ if (type->storage == STORAGE_TAGGED) {
nmemb += sum_tagged_memb(store, &type->tagged);
} else {
++nmemb;
@@ -235,7 +235,7 @@ sum_atagged_memb(struct type_store *store,
for (; u; u = u->next) {
const struct type *type =
type_store_lookup_atype(store, u->type);
- if (type->storage == TYPE_STORAGE_TAGGED) {
+ if (type->storage == STORAGE_TAGGED) {
nmemb += sum_tagged_memb(store, &type->tagged);
} else {
++nmemb;
@@ -252,7 +252,7 @@ collect_tagged_memb(struct type_store *store,
{
for (; src; src = src->next) {
const struct type *type = src->type;
- if (type->storage == TYPE_STORAGE_TAGGED) {
+ if (type->storage == STORAGE_TAGGED) {
collect_tagged_memb(store, ta, &type->tagged, i);
continue;
}
@@ -272,7 +272,7 @@ collect_atagged_memb(struct type_store *store,
for (; atu; atu = atu->next) {
const struct type *type =
type_store_lookup_atype(store, atu->type);
- if (type->storage == TYPE_STORAGE_TAGGED) {
+ if (type->storage == STORAGE_TAGGED) {
collect_tagged_memb(store, ta, &type->tagged, i);
continue;
}
@@ -391,30 +391,30 @@ type_init_from_atype(struct type_store *store,
const struct identifier *ident;
struct identifier temp;
switch (type->storage) {
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_STRING:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
assert(0); // Invariant
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
ident = &atype->alias;
if (ident->ns == NULL) {
temp = *ident;
@@ -443,7 +443,7 @@ type_init_from_atype(struct type_store *store,
type->size = type->alias.type->size;
type->align = type->alias.type->align;
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
type->array.length = ast_array_len(store, atype);
type->array.members = type_store_lookup_atype(
store, atype->array.members);
@@ -457,7 +457,7 @@ type_init_from_atype(struct type_store *store,
type->size = type->array.members->size * type->array.length;
}
break;
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
type->_enum.storage = atype->_enum.storage;
const struct type *storage =
builtin_type_for_storage(type->_enum.storage, true);
@@ -515,7 +515,7 @@ type_init_from_atype(struct type_store *store,
scope_pop(&store->check_context->scope, TR_CHECK);
scope_free(scope);
break;
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
type->size = SIZE_UNDEFINED;
type->align = SIZE_UNDEFINED;
type->func.result =
@@ -535,22 +535,22 @@ type_init_from_atype(struct type_store *store,
next = ¶m->next;
}
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
type->size = 8; // XXX: ARCH
type->align = 8;
type->pointer.flags = atype->pointer.flags;
type->pointer.referent = type_store_lookup_atype(
store, atype->pointer.referent);
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
type->size = 24; // XXX: ARCH
type->align = 8;
type->array.members = type_store_lookup_atype(
store, atype->array.members);
type->array.length = SIZE_UNDEFINED;
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
type->struct_union.c_compat = true;
struct_init_from_atype(store, type->storage, &type->size,
&type->align, &type->struct_union.fields,
@@ -566,10 +566,10 @@ type_init_from_atype(struct type_store *store,
}
}
break;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
tagged_init_from_atype(store, type, atype);
break;
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
tuple_init_from_atype(store, type, atype);
break;
}
@@ -630,7 +630,7 @@ type_store_lookup_pointer(struct type_store *store,
const struct type *referent, unsigned int ptrflags)
{
struct type ptr = {
- .storage = TYPE_STORAGE_POINTER,
+ .storage = STORAGE_POINTER,
.pointer = {
.referent = referent,
.flags = ptrflags,
@@ -646,7 +646,7 @@ type_store_lookup_array(struct type_store *store,
const struct type *members, size_t len)
{
struct type array = {
- .storage = TYPE_STORAGE_ARRAY,
+ .storage = STORAGE_ARRAY,
.array = {
.members = members,
.length = len,
@@ -662,7 +662,7 @@ const struct type *
type_store_lookup_slice(struct type_store *store, const struct type *members)
{
struct type slice = {
- .storage = TYPE_STORAGE_SLICE,
+ .storage = STORAGE_SLICE,
.array = {
.members = members,
.length = SIZE_UNDEFINED,
@@ -678,7 +678,7 @@ type_store_lookup_alias(struct type_store *store,
const struct identifier *ident, const struct type *secondary)
{
struct type alias = {
- .storage = TYPE_STORAGE_ALIAS,
+ .storage = STORAGE_ALIAS,
.alias = {
.ident = *ident,
.type = secondary,
@@ -701,7 +701,7 @@ type_store_lookup_tagged(struct type_store *store,
struct type_tagged_union *tags)
{
struct type type = {
- .storage = TYPE_STORAGE_TAGGED,
+ .storage = STORAGE_TAGGED,
};
size_t nmemb = sum_tagged_memb(store, tags);
struct type_tagged_union **tu =
@@ -716,7 +716,7 @@ const struct type *
type_store_lookup_tuple(struct type_store *store, struct type_tuple *values)
{
struct type type = {
- .storage = TYPE_STORAGE_TUPLE,
+ .storage = STORAGE_TUPLE,
.tuple = *values,
};
for (struct type_tuple *t = values; t; t = t->next) {
diff --git a/src/typedef.c b/src/typedef.c
@@ -13,37 +13,37 @@ static const char *
storage_to_suffix(enum type_storage storage)
{
switch (storage) {
- case TYPE_STORAGE_F32:
+ case STORAGE_F32:
return "f32";
- case TYPE_STORAGE_F64:
+ case STORAGE_F64:
return "f64";
- case TYPE_STORAGE_FCONST:
+ case STORAGE_FCONST:
return "";
- case TYPE_STORAGE_I16:
+ case STORAGE_I16:
return "i16";
- case TYPE_STORAGE_I32:
+ case STORAGE_I32:
return "i32";
- case TYPE_STORAGE_I64:
+ case STORAGE_I64:
return "i64";
- case TYPE_STORAGE_I8:
+ case STORAGE_I8:
return "i8";
- case TYPE_STORAGE_ICONST:
+ case STORAGE_ICONST:
return "";
- case TYPE_STORAGE_INT:
+ case STORAGE_INT:
return "i";
- case TYPE_STORAGE_SIZE:
+ case STORAGE_SIZE:
return "z";
- case TYPE_STORAGE_U16:
+ case STORAGE_U16:
return "u16";
- case TYPE_STORAGE_U32:
+ case STORAGE_U32:
return "u32";
- case TYPE_STORAGE_U64:
+ case STORAGE_U64:
return "u64";
- case TYPE_STORAGE_U8:
+ case STORAGE_U8:
return "u8";
- case TYPE_STORAGE_UINT:
+ case STORAGE_UINT:
return "u";
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
return "u64: uintptr";
default:
assert(0);
@@ -56,44 +56,44 @@ emit_const(const struct expression *expr, FILE *out)
assert(expr->type == EXPR_CONSTANT);
const union expression_constant *val = &expr->constant;
switch (expr->result->storage) {
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
fprintf(out, "%s", val->bval ? "false" : "true");
break;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
fprintf(out, "%lf%s", val->fval,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
fprintf(out, "%ld%s", val->ival,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
fprintf(out, "null");
break;
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
fprintf(out, "%lu%s", val->uval,
storage_to_suffix(expr->result->storage));
break;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
fprintf(out, "void");
break;
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
fprintf(out, "\'\\U%08" PRIx32 "\'", (uint32_t)val->uval);
break;
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
fprintf(out, "\"");
for (size_t i = 0; i < val->string.len; i += 1) {
char c = val->string.value[i];
@@ -105,18 +105,18 @@ emit_const(const struct expression *expr, FILE *out)
};
fprintf(out, "\"");
break;
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_ENUM:
+ case STORAGE_SLICE:
+ case STORAGE_STRUCT:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
assert(0); // TODO
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_CHAR:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_TAGGED:
assert(0); // Invariant
}
}
@@ -147,7 +147,7 @@ emit_struct(const struct type *type, FILE *out)
qsort(fields, n, sizeof(fields[0]), field_compar);
- fprintf(out, "%s { ", type->storage == TYPE_STORAGE_STRUCT
+ fprintf(out, "%s { ", type->storage == STORAGE_STRUCT
? "struct" : "union");
for (size_t i = 0; i < n; ++i) {
const struct struct_field *f = fields[i];
@@ -171,34 +171,34 @@ emit_type(const struct type *type, FILE *out)
char *ident;
switch (type->storage) {
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_STRING:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
+ case STORAGE_STRING:
fprintf(out, "%s", type_storage_unparse(type->storage));
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
fprintf(out, "%s*", type->pointer.flags & PTR_NULLABLE
? "nullable " : "");
emit_type(type->pointer.referent, out);
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
if (type->array.length == SIZE_UNDEFINED) {
fprintf(out, "[*]");
} else {
@@ -206,16 +206,16 @@ emit_type(const struct type *type, FILE *out)
}
emit_type(type->array.members, out);
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
fprintf(out, "[]");
emit_type(type->array.members, out);
break;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
ident = identifier_unparse(&type->alias.ident);
fprintf(out, "%s", ident);
free(ident);
break;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
fprintf(out, "(");
for (const struct type_tagged_union *tu = &type->tagged;
tu; tu = tu->next) {
@@ -226,11 +226,11 @@ emit_type(const struct type *type, FILE *out)
}
fprintf(out, ")");
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
emit_struct(type, out);
break;
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
if (type->func.flags & FN_NORETURN) {
fprintf(out, "@noreturn ");
}
@@ -253,7 +253,7 @@ emit_type(const struct type *type, FILE *out)
fprintf(out, ") ");
emit_type(type->func.result, out);
break;
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
fprintf(out, "enum %s { ", type_storage_unparse(type->_enum.storage));
for (const struct type_enum_value *ev = type->_enum.values;
ev; ev = ev->next) {
@@ -271,7 +271,7 @@ emit_type(const struct type *type, FILE *out)
}
fprintf(out, "}");
break;
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
fprintf(out, "(");
for (const struct type_tuple *tuple = &type->tuple;
tuple; tuple = tuple->next) {
@@ -282,8 +282,8 @@ emit_type(const struct type *type, FILE *out)
}
fprintf(out, ")");
break;
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0); // Invariant
}
}
diff --git a/src/types.c b/src/types.c
@@ -8,9 +8,9 @@ const struct type *
type_dereference(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return type_dereference(type_dealias(type));
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
if (type->pointer.flags & PTR_NULLABLE) {
return NULL;
}
@@ -23,7 +23,7 @@ type_dereference(const struct type *type)
const struct type *
type_dealias(const struct type *type)
{
- while (type->storage == TYPE_STORAGE_ALIAS) {
+ while (type->storage == STORAGE_ALIAS) {
assert(type->alias.type != NULL);
type = type->alias.type;
}
@@ -35,8 +35,8 @@ type_get_field(const struct type *type, const char *name)
{
// TODO: We should consider lowering unions into structs with explicit
// offsets
- assert(type->storage == TYPE_STORAGE_STRUCT
- || type->storage == TYPE_STORAGE_UNION);
+ assert(type->storage == STORAGE_STRUCT
+ || type->storage == STORAGE_UNION);
struct struct_field *field = type->struct_union.fields;
while (field) {
if (strcmp(field->name, name) == 0) {
@@ -50,7 +50,7 @@ type_get_field(const struct type *type, const char *name)
const struct type_tuple *
type_get_value(const struct type *type, uintmax_t index)
{
- assert(type->storage == TYPE_STORAGE_TUPLE);
+ assert(type->storage == STORAGE_TUPLE);
const struct type_tuple *tuple = &type->tuple;
while (tuple) {
if (index == 0) {
@@ -66,69 +66,69 @@ const char *
type_storage_unparse(enum type_storage storage)
{
switch (storage) {
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return "alias";
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
return "array";
- case TYPE_STORAGE_BOOL:
+ case STORAGE_BOOL:
return "bool";
- case TYPE_STORAGE_CHAR:
+ case STORAGE_CHAR:
return "char";
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
return "enum";
- case TYPE_STORAGE_F32:
+ case STORAGE_F32:
return "f32";
- case TYPE_STORAGE_F64:
+ case STORAGE_F64:
return "f64";
- case TYPE_STORAGE_FCONST:
+ case STORAGE_FCONST:
return "fconst";
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
return "function";
- case TYPE_STORAGE_I16:
+ case STORAGE_I16:
return "i16";
- case TYPE_STORAGE_I32:
+ case STORAGE_I32:
return "i32";
- case TYPE_STORAGE_I64:
+ case STORAGE_I64:
return "i64";
- case TYPE_STORAGE_I8:
+ case STORAGE_I8:
return "i8";
- case TYPE_STORAGE_ICONST:
+ case STORAGE_ICONST:
return "iconst";
- case TYPE_STORAGE_INT:
+ case STORAGE_INT:
return "int";
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
return "pointer";
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
return "rune";
- case TYPE_STORAGE_RUNE:
+ case STORAGE_RUNE:
return "rune";
- case TYPE_STORAGE_SIZE:
+ case STORAGE_SIZE:
return "size";
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
return "slice";
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
return "str";
- case TYPE_STORAGE_STRUCT:
+ case STORAGE_STRUCT:
return "struct";
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
return "tagged union";
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
return "tuple";
- case TYPE_STORAGE_U16:
+ case STORAGE_U16:
return "u16";
- case TYPE_STORAGE_U32:
+ case STORAGE_U32:
return "u32";
- case TYPE_STORAGE_U64:
+ case STORAGE_U64:
return "u64";
- case TYPE_STORAGE_U8:
+ case STORAGE_U8:
return "u8";
- case TYPE_STORAGE_UINT:
+ case STORAGE_UINT:
return "uint";
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
return "uintptr";
- case TYPE_STORAGE_UNION:
+ case STORAGE_UNION:
return "union";
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return "void";
}
assert(0);
@@ -138,40 +138,40 @@ bool
type_is_integer(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_VOID:
+ case STORAGE_ARRAY:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_BOOL:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
return false;
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
return true;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return type_is_integer(type_dealias(type));
}
assert(0); // Unreachable
@@ -181,40 +181,40 @@ bool
type_is_numeric(const struct type *type)
{
switch (type->storage) {
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_ENUM:
+ case STORAGE_VOID:
+ case STORAGE_ARRAY:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_RUNE:
+ case STORAGE_NULL:
+ case STORAGE_ENUM:
return false;
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
return true;
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return type_is_numeric(type_dealias(type));
}
assert(0); // Unreachable
@@ -223,47 +223,47 @@ type_is_numeric(const struct type *type)
bool
type_is_float(const struct type *type)
{
- return type->storage == TYPE_STORAGE_F32 || type->storage == TYPE_STORAGE_F64;
+ return type->storage == STORAGE_F32 || type->storage == STORAGE_F64;
}
bool
type_storage_is_signed(enum type_storage storage)
{
switch (storage) {
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_VOID:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_ENUM:
+ case STORAGE_FUNCTION:
+ case STORAGE_POINTER:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_RUNE:
+ case STORAGE_NULL:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
return false;
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_INT:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
return true;
- case TYPE_STORAGE_ICONST:
+ case STORAGE_ICONST:
assert(0); // XXX
}
assert(0); // Unreachable
@@ -272,7 +272,7 @@ type_storage_is_signed(enum type_storage storage)
bool
type_is_signed(const struct type *type)
{
- if (type->storage == TYPE_STORAGE_ENUM) {
+ if (type->storage == STORAGE_ENUM) {
return type_storage_is_signed(type->_enum.storage);
}
return type_storage_is_signed(type_dealias(type)->storage);
@@ -281,39 +281,39 @@ type_is_signed(const struct type *type)
bool storage_is_flexible(enum type_storage storage)
{
switch (storage) {
- case TYPE_STORAGE_ALIAS:
- case TYPE_STORAGE_ARRAY:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_POINTER:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_VOID:
+ case STORAGE_ALIAS:
+ case STORAGE_ARRAY:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FUNCTION:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_I8:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_POINTER:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_SLICE:
+ case STORAGE_STRING:
+ case STORAGE_STRUCT:
+ case STORAGE_TAGGED:
+ case STORAGE_TUPLE:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_U8:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_UNION:
+ case STORAGE_VOID:
return false;
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
return true;
}
assert(0); // Unreachable
@@ -327,41 +327,41 @@ type_hash(const struct type *type)
hash = fnv1a(hash, type->storage);
hash = fnv1a(hash, type->flags);
switch (type->storage) {
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- case TYPE_STORAGE_UINTPTR:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_STRING:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_F32:
+ case STORAGE_F64:
+ case STORAGE_FCONST:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_ICONST:
+ case STORAGE_INT:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ case STORAGE_UINTPTR:
+ case STORAGE_VOID:
+ case STORAGE_STRING:
break; // built-ins
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
for (const struct identifier *ident = &type->alias.ident; ident;
ident = ident->ns) {
hash = fnv1a_s(hash, ident->name);
hash = fnv1a(hash, 0);
}
break;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
hash = fnv1a_u32(hash, type_hash(type->array.members));
hash = fnv1a_u32(hash, type->array.length);
break;
- case TYPE_STORAGE_FUNCTION:
+ case STORAGE_FUNCTION:
hash = fnv1a_u32(hash, type_hash(type->func.result));
hash = fnv1a(hash, type->func.variadism);
hash = fnv1a(hash, type->func.flags);
@@ -370,7 +370,7 @@ type_hash(const struct type *type)
hash = fnv1a_u32(hash, type_hash(param->type));
}
break;
- case TYPE_STORAGE_ENUM:
+ case STORAGE_ENUM:
hash = fnv1a(hash, type->_enum.storage);
for (struct type_enum_value *value = type->_enum.values; value;
value = value->next) {
@@ -378,15 +378,15 @@ type_hash(const struct type *type)
hash = fnv1a(hash, value->uval);
}
break;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
hash = fnv1a(hash, type->pointer.flags);
hash = fnv1a_u32(hash, type_hash(type->pointer.referent));
break;
- case TYPE_STORAGE_SLICE:
+ case STORAGE_SLICE:
hash = fnv1a_u32(hash, type_hash(type->array.members));
break;
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
for (const struct struct_field *field = type->struct_union.fields;
field; field = field->next) {
hash = fnv1a_s(hash, field->name);
@@ -394,7 +394,7 @@ type_hash(const struct type *type)
hash = fnv1a_u32(hash, field->offset);
}
break;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
// Invariant: subtypes must be sorted by ID and must not include
// any other tagged union types, nor any duplicates.
for (const struct type_tagged_union *tu = &type->tagged;
@@ -402,7 +402,7 @@ type_hash(const struct type *type)
hash = fnv1a_u32(hash, type_hash(tu->type));
}
break;
- case TYPE_STORAGE_TUPLE:
+ case STORAGE_TUPLE:
for (const struct type_tuple *tuple = &type->tuple;
tuple; tuple = tuple->next) {
hash = fnv1a_u32(hash, type_hash(tuple->type));
@@ -430,7 +430,7 @@ const struct type *
tagged_select_subtype(const struct type *tagged, const struct type *subtype)
{
tagged = type_dealias(tagged);
- assert(tagged->storage == TYPE_STORAGE_TAGGED);
+ assert(tagged->storage == STORAGE_TAGGED);
size_t nassign = 0;
const struct type *selected = NULL;
@@ -439,7 +439,7 @@ tagged_select_subtype(const struct type *tagged, const struct type *subtype)
if (tu->type->id == subtype->id) {
return tu->type;
}
- if (type_dealias(tu->type)->storage == TYPE_STORAGE_VOID) {
+ if (type_dealias(tu->type)->storage == STORAGE_VOID) {
continue;
}
if (type_is_assignable(tu->type, subtype)) {
@@ -461,7 +461,7 @@ tagged_subset_compat(const struct type *to, const struct type *from)
// Note: this implementation depends on the invariant that tagged union
// member types are sorted by their type ID.
to = type_dealias(to), from = type_dealias(from);
- if (to->storage != TYPE_STORAGE_TAGGED || from->storage != TYPE_STORAGE_TAGGED) {
+ if (to->storage != STORAGE_TAGGED || from->storage != STORAGE_TAGGED) {
return false;
}
const struct type_tagged_union *to_tu = &to->tagged,
@@ -493,44 +493,44 @@ type_is_assignable(const struct type *to, const struct type *from)
struct type _to_secondary, _from_secondary;
const struct type *to_secondary, *from_secondary;
switch (to->storage) {
- case TYPE_STORAGE_ICONST:
- case TYPE_STORAGE_FCONST:
+ case STORAGE_ICONST:
+ case STORAGE_FCONST:
assert(0); // Invariant
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_INT:
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_INT:
return type_is_integer(from)
&& type_is_signed(from)
&& to->size >= from->size;
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U8:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U32:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
+ case STORAGE_SIZE:
+ case STORAGE_U8:
+ case STORAGE_U16:
+ case STORAGE_U32:
+ case STORAGE_U64:
+ case STORAGE_UINT:
return type_is_integer(from)
&& !type_is_signed(from)
&& to->size >= from->size;
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
+ case STORAGE_F32:
+ case STORAGE_F64:
return type_is_float(from);
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
to_secondary = type_dealias(to->pointer.referent);
to_secondary = strip_flags(to_secondary, &_to_secondary);
switch (from->storage) {
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_UINTPTR:
return true;
- case TYPE_STORAGE_NULL:
+ case STORAGE_NULL:
return to->pointer.flags & PTR_NULLABLE;
- case TYPE_STORAGE_POINTER:
+ case STORAGE_POINTER:
from_secondary = type_dealias(from->pointer.referent);
from_secondary = strip_flags(from_secondary, &_from_secondary);
switch (to_secondary->storage) {
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return true;
- case TYPE_STORAGE_ARRAY:
+ case STORAGE_ARRAY:
if (type_is_assignable(to_secondary, from_secondary)) {
return true;
}
@@ -545,50 +545,50 @@ type_is_assignable(const struct type *to, const struct type *from)
return to->pointer.flags & PTR_NULLABLE;
}
return true;
- case TYPE_STORAGE_STRING:
- return to->pointer.referent->storage == TYPE_STORAGE_CHAR
+ case STORAGE_STRING:
+ return to->pointer.referent->storage == STORAGE_CHAR
&& to->pointer.referent->flags & TYPE_CONST;
default:
return false;
}
assert(0); // Unreachable
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_ALIAS:
return type_is_assignable(to->alias.type, from);
- case TYPE_STORAGE_STRING:
+ case STORAGE_STRING:
return to->id == builtin_type_ptr_const_char.id;
- case TYPE_STORAGE_VOID:
+ case STORAGE_VOID:
return true;
- case TYPE_STORAGE_SLICE:
- if (from->storage != TYPE_STORAGE_ARRAY
- && from->storage != TYPE_STORAGE_SLICE) {
+ case STORAGE_SLICE:
+ if (from->storage != STORAGE_ARRAY
+ && from->storage != STORAGE_SLICE) {
return false;
}
to_secondary = strip_flags(to->array.members, &_to_secondary);
from_secondary = strip_flags(from->array.members, &_from_secondary);
- if (to->storage == TYPE_STORAGE_SLICE
- && to_secondary->storage == TYPE_STORAGE_VOID) {
+ if (to->storage == STORAGE_SLICE
+ && to_secondary->storage == STORAGE_VOID) {
return true;
}
return to_secondary->id == from_secondary->id;
- case TYPE_STORAGE_ARRAY:
- return from->storage == TYPE_STORAGE_ARRAY
+ case STORAGE_ARRAY:
+ return from->storage == STORAGE_ARRAY
&& to->array.length == SIZE_UNDEFINED
&& from->array.length != SIZE_UNDEFINED;
- case TYPE_STORAGE_TAGGED:
+ case STORAGE_TAGGED:
return tagged_select_subtype(to, from) != NULL
|| tagged_subset_compat(to, from);
// The following types are only assignable from themselves, and are
// handled above:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_CHAR:
- case TYPE_STORAGE_ENUM:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_NULL:
- case TYPE_STORAGE_RUNE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_UINTPTR:
+ case STORAGE_BOOL:
+ case STORAGE_CHAR:
+ case STORAGE_ENUM:
+ case STORAGE_FUNCTION:
+ case STORAGE_NULL:
+ case STORAGE_RUNE:
+ case STORAGE_STRUCT:
+ case STORAGE_TUPLE:
+ case STORAGE_UNION:
+ case STORAGE_UINTPTR:
return false;
}
@@ -612,12 +612,12 @@ castable_from_tagged(const struct type *to, const struct type *from)
bool
type_is_castable(const struct type *to, const struct type *from)
{
- if (type_dealias(to)->storage == TYPE_STORAGE_TAGGED) {
+ if (type_dealias(to)->storage == STORAGE_TAGGED) {
return tagged_select_subtype(to, from) != NULL
|| tagged_subset_compat(to, from);
}
- if (type_dealias(from)->storage == TYPE_STORAGE_TAGGED) {
+ if (type_dealias(from)->storage == STORAGE_TAGGED) {
return castable_from_tagged(to, from);
}
@@ -627,67 +627,67 @@ type_is_castable(const struct type *to, const struct type *from)
}
switch (to->storage) {
- case TYPE_STORAGE_FCONST:
- case TYPE_STORAGE_ICONST:
+ case STORAGE_FCONST:
+ case STORAGE_ICONST:
assert(0); // TODO
- case TYPE_STORAGE_I8:
- case TYPE_STORAGE_I16:
- case TYPE_STORAGE_I32:
- case TYPE_STORAGE_I64:
- case TYPE_STORAGE_INT:
- case TYPE_STORAGE_SIZE:
- case TYPE_STORAGE_U16:
- case TYPE_STORAGE_U64:
- case TYPE_STORAGE_UINT:
- return from->storage == TYPE_STORAGE_ENUM || type_is_numeric(from);
- case TYPE_STORAGE_U8:
- return from->storage == TYPE_STORAGE_ENUM
+ case STORAGE_I8:
+ case STORAGE_I16:
+ case STORAGE_I32:
+ case STORAGE_I64:
+ case STORAGE_INT:
+ case STORAGE_SIZE:
+ case STORAGE_U16:
+ case STORAGE_U64:
+ case STORAGE_UINT:
+ return from->storage == STORAGE_ENUM || type_is_numeric(from);
+ case STORAGE_U8:
+ return from->storage == STORAGE_ENUM
|| type_is_numeric(from)
- || from->storage == TYPE_STORAGE_CHAR;
- case TYPE_STORAGE_U32:
- return from->storage == TYPE_STORAGE_ENUM
+ || from->storage == STORAGE_CHAR;
+ case STORAGE_U32:
+ return from->storage == STORAGE_ENUM
|| type_is_numeric(from)
- || from->storage == TYPE_STORAGE_RUNE;
- case TYPE_STORAGE_CHAR:
- return from->storage == TYPE_STORAGE_U8;
- case TYPE_STORAGE_RUNE:
- return from->storage == TYPE_STORAGE_U32;
- case TYPE_STORAGE_ENUM:
- return from->storage == TYPE_STORAGE_ENUM || type_is_integer(from);
- case TYPE_STORAGE_F32:
- case TYPE_STORAGE_F64:
+ || from->storage == STORAGE_RUNE;
+ case STORAGE_CHAR:
+ return from->storage == STORAGE_U8;
+ case STORAGE_RUNE:
+ return from->storage == STORAGE_U32;
+ case STORAGE_ENUM:
+ return from->storage == STORAGE_ENUM || type_is_integer(from);
+ case STORAGE_F32:
+ case STORAGE_F64:
return type_is_numeric(from);
- case TYPE_STORAGE_UINTPTR:
- return from->storage == TYPE_STORAGE_POINTER
- || from->storage == TYPE_STORAGE_NULL
+ case STORAGE_UINTPTR:
+ return from->storage == STORAGE_POINTER
+ || from->storage == STORAGE_NULL
|| type_is_numeric(from);
- case TYPE_STORAGE_POINTER:
- if (from->storage == TYPE_STORAGE_STRING
- && to->pointer.referent->storage == TYPE_STORAGE_CHAR
+ case STORAGE_POINTER:
+ if (from->storage == STORAGE_STRING
+ && to->pointer.referent->storage == STORAGE_CHAR
&& to->pointer.referent->flags & TYPE_CONST) {
return true;
}
- return from->storage == TYPE_STORAGE_POINTER
- || from->storage == TYPE_STORAGE_NULL
- || from->storage == TYPE_STORAGE_UINTPTR
- || (to->pointer.referent->storage == TYPE_STORAGE_ARRAY
- && from->storage == TYPE_STORAGE_SLICE);
- case TYPE_STORAGE_SLICE:
- case TYPE_STORAGE_ARRAY:
- return from->storage == TYPE_STORAGE_SLICE
- || from->storage == TYPE_STORAGE_ARRAY;
+ return from->storage == STORAGE_POINTER
+ || from->storage == STORAGE_NULL
+ || from->storage == STORAGE_UINTPTR
+ || (to->pointer.referent->storage == STORAGE_ARRAY
+ && from->storage == STORAGE_SLICE);
+ case STORAGE_SLICE:
+ case STORAGE_ARRAY:
+ return from->storage == STORAGE_SLICE
+ || from->storage == STORAGE_ARRAY;
// Cannot be cast:
- case TYPE_STORAGE_BOOL:
- case TYPE_STORAGE_VOID:
- case TYPE_STORAGE_FUNCTION:
- case TYPE_STORAGE_TUPLE:
- case TYPE_STORAGE_STRUCT:
- case TYPE_STORAGE_UNION:
- case TYPE_STORAGE_STRING:
- case TYPE_STORAGE_NULL:
+ case STORAGE_BOOL:
+ case STORAGE_VOID:
+ case STORAGE_FUNCTION:
+ case STORAGE_TUPLE:
+ case STORAGE_STRUCT:
+ case STORAGE_UNION:
+ case STORAGE_STRING:
+ case STORAGE_NULL:
return false;
- case TYPE_STORAGE_TAGGED:
- case TYPE_STORAGE_ALIAS:
+ case STORAGE_TAGGED:
+ case STORAGE_ALIAS:
assert(0); // Handled above
}
@@ -725,226 +725,226 @@ builtin_types_init()
// Built-in type singletons
struct type builtin_type_bool = {
- .storage = TYPE_STORAGE_BOOL,
+ .storage = STORAGE_BOOL,
.size = 4, // XXX: ARCH
.align = 4,
},
builtin_type_char = {
- .storage = TYPE_STORAGE_CHAR,
+ .storage = STORAGE_CHAR,
.size = 1,
.align = 1,
},
builtin_type_f32 = {
- .storage = TYPE_STORAGE_F32,
+ .storage = STORAGE_F32,
.size = 4,
.align = 4,
},
builtin_type_f64 = {
- .storage = TYPE_STORAGE_F64,
+ .storage = STORAGE_F64,
.size = 8,
.align = 8,
},
builtin_type_fconst = {
- .storage = TYPE_STORAGE_FCONST,
+ .storage = STORAGE_FCONST,
.size = SIZE_UNDEFINED,
.align = ALIGN_UNDEFINED,
},
builtin_type_i8 = {
- .storage = TYPE_STORAGE_I8,
+ .storage = STORAGE_I8,
.size = 1,
.align = 1,
},
builtin_type_i16 = {
- .storage = TYPE_STORAGE_I16,
+ .storage = STORAGE_I16,
.size = 2,
.align = 2,
},
builtin_type_i32 = {
- .storage = TYPE_STORAGE_I32,
+ .storage = STORAGE_I32,
.size = 4,
.align = 4,
},
builtin_type_i64 = {
- .storage = TYPE_STORAGE_I64,
+ .storage = STORAGE_I64,
.size = 8,
.align = 8,
},
builtin_type_iconst = {
- .storage = TYPE_STORAGE_ICONST,
+ .storage = STORAGE_ICONST,
.size = SIZE_UNDEFINED,
.align = ALIGN_UNDEFINED,
},
builtin_type_int = {
- .storage = TYPE_STORAGE_INT,
+ .storage = STORAGE_INT,
.size = 4, // XXX: ARCH
.align = 4,
},
builtin_type_u8 = {
- .storage = TYPE_STORAGE_U8,
+ .storage = STORAGE_U8,
.size = 1,
.align = 1,
},
builtin_type_u16 = {
- .storage = TYPE_STORAGE_U16,
+ .storage = STORAGE_U16,
.size = 2,
.align = 2,
},
builtin_type_u32 = {
- .storage = TYPE_STORAGE_U32,
+ .storage = STORAGE_U32,
.size = 4,
.align = 4,
},
builtin_type_u64 = {
- .storage = TYPE_STORAGE_U64,
+ .storage = STORAGE_U64,
.size = 8,
.align = 8,
},
builtin_type_uint = {
- .storage = TYPE_STORAGE_UINT,
+ .storage = STORAGE_UINT,
.size = 4,
.align = 4,
},
builtin_type_uintptr = {
- .storage = TYPE_STORAGE_UINTPTR,
+ .storage = STORAGE_UINTPTR,
.size = 8, // XXX: ARCH
.align = 8,
},
builtin_type_null = {
- .storage = TYPE_STORAGE_NULL,
+ .storage = STORAGE_NULL,
.size = 8, // XXX: ARCH
.align = 8,
},
builtin_type_rune = {
- .storage = TYPE_STORAGE_RUNE,
+ .storage = STORAGE_RUNE,
.size = 4,
.align = 4,
},
builtin_type_size = {
- .storage = TYPE_STORAGE_SIZE,
+ .storage = STORAGE_SIZE,
.size = 8, // XXX: ARCH
.align = 8,
},
builtin_type_void = {
- .storage = TYPE_STORAGE_VOID,
+ .storage = STORAGE_VOID,
.size = 0,
.align = 0,
},
builtin_type_const_bool = {
- .storage = TYPE_STORAGE_BOOL,
+ .storage = STORAGE_BOOL,
.flags = TYPE_CONST,
.size = 4, // XXX: ARCH
.align = 4,
},
builtin_type_const_char = {
- .storage = TYPE_STORAGE_CHAR,
+ .storage = STORAGE_CHAR,
.flags = TYPE_CONST,
.size = 1,
.align = 1,
},
builtin_type_const_f32 = {
- .storage = TYPE_STORAGE_F32,
+ .storage = STORAGE_F32,
.flags = TYPE_CONST,
.size = 4,
.align = 4,
},
builtin_type_const_f64 = {
- .storage = TYPE_STORAGE_F64,
+ .storage = STORAGE_F64,
.flags = TYPE_CONST,
.size = 8,
.align = 8,
},
builtin_type_const_fconst = {
- .storage = TYPE_STORAGE_FCONST,
+ .storage = STORAGE_FCONST,
.flags = TYPE_CONST,
.size = SIZE_UNDEFINED,
.align = ALIGN_UNDEFINED,
},
builtin_type_const_i8 = {
- .storage = TYPE_STORAGE_I8,
+ .storage = STORAGE_I8,
.flags = TYPE_CONST,
.size = 1,
.align = 1,
},
builtin_type_const_i16 = {
- .storage = TYPE_STORAGE_I16,
+ .storage = STORAGE_I16,
.flags = TYPE_CONST,
.size = 2,
.align = 2,
},
builtin_type_const_i32 = {
- .storage = TYPE_STORAGE_I32,
+ .storage = STORAGE_I32,
.flags = TYPE_CONST,
.size = 4,
.align = 4,
},
builtin_type_const_i64 = {
- .storage = TYPE_STORAGE_I64,
+ .storage = STORAGE_I64,
.flags = TYPE_CONST,
.size = 8,
.align = 8,
},
builtin_type_const_iconst = {
- .storage = TYPE_STORAGE_ICONST,
+ .storage = STORAGE_ICONST,
.flags = TYPE_CONST,
.size = SIZE_UNDEFINED,
.align = ALIGN_UNDEFINED,
},
builtin_type_const_int = {
- .storage = TYPE_STORAGE_INT,
+ .storage = STORAGE_INT,
.flags = TYPE_CONST,
.size = 4, // XXX: ARCH
.align = 4,
},
builtin_type_const_u8 = {
- .storage = TYPE_STORAGE_U8,
+ .storage = STORAGE_U8,
.flags = TYPE_CONST,
.size = 1,
.align = 1,
},
builtin_type_const_u16 = {
- .storage = TYPE_STORAGE_U16,
+ .storage = STORAGE_U16,
.flags = TYPE_CONST,
.size = 2,
.align = 2,
},
builtin_type_const_u32 = {
- .storage = TYPE_STORAGE_U32,
+ .storage = STORAGE_U32,
.flags = TYPE_CONST,
.size = 4,
.align = 4,
},
builtin_type_const_u64 = {
- .storage = TYPE_STORAGE_U64,
+ .storage = STORAGE_U64,
.flags = TYPE_CONST,
.size = 8,
.align = 8,
},
builtin_type_const_uint = {
- .storage = TYPE_STORAGE_UINT,
+ .storage = STORAGE_UINT,
.flags = TYPE_CONST,
.size = 4,
.align = 4,
},
builtin_type_const_uintptr = {
- .storage = TYPE_STORAGE_UINTPTR,
+ .storage = STORAGE_UINTPTR,
.flags = TYPE_CONST,
.size = 8, // XXX: ARCH
.align = 8,
},
builtin_type_const_rune = {
- .storage = TYPE_STORAGE_RUNE,
+ .storage = STORAGE_RUNE,
.flags = TYPE_CONST,
.size = 4,
.align = 4,
},
builtin_type_const_size = {
- .storage = TYPE_STORAGE_SIZE,
+ .storage = STORAGE_SIZE,
.flags = TYPE_CONST,
.size = 8, // XXX: ARCH
.align = 8,
},
builtin_type_const_void = {
- .storage = TYPE_STORAGE_VOID,
+ .storage = STORAGE_VOID,
.flags = TYPE_CONST,
.size = 0,
.align = 0,
@@ -952,7 +952,7 @@ builtin_type_const_void = {
// Others
struct type builtin_type_ptr_const_char = {
- .storage = TYPE_STORAGE_POINTER,
+ .storage = STORAGE_POINTER,
.size = 8, // XXX: ARCH
.align = 8,
.pointer = {
@@ -960,12 +960,12 @@ struct type builtin_type_ptr_const_char = {
},
},
builtin_type_str = {
- .storage = TYPE_STORAGE_STRING,
+ .storage = STORAGE_STRING,
.size = 24, // XXX: ARCH
.align = 8,
},
builtin_type_const_str = {
- .storage = TYPE_STORAGE_STRING,
+ .storage = STORAGE_STRING,
.flags = TYPE_CONST,
.size = 24, // XXX: ARCH
.align = 8,