mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-13 06:41:26 -07:00
Fix alignment and size bug of enums; Remove #ordered and make the default #ordered.
This commit is contained in:
+1
-1
@@ -534,7 +534,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
|
||||
|
||||
isize field_count = 0;
|
||||
for_array(field_index, st->fields) {
|
||||
AstNode *field = st->fields.e[field_index];
|
||||
AstNode *field = st->fields.e[field_index];
|
||||
switch (field->kind) {
|
||||
case_ast_node(f, Field, field);
|
||||
field_count += f->names.count;
|
||||
|
||||
+5
-5
@@ -2745,11 +2745,11 @@ AstNode *parse_type_or_ident(AstFile *f) {
|
||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||
}
|
||||
is_packed = true;
|
||||
} else if (str_eq(tag.string, str_lit("ordered"))) {
|
||||
if (is_ordered) {
|
||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||
}
|
||||
is_ordered = true;
|
||||
// } else if (str_eq(tag.string, str_lit("ordered"))) {
|
||||
// if (is_ordered) {
|
||||
// syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||
// }
|
||||
// is_ordered = true;
|
||||
} else if (str_eq(tag.string, str_lit("align"))) {
|
||||
if (align) {
|
||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||
|
||||
@@ -1595,6 +1595,8 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
|
||||
case Type_Record: {
|
||||
switch (t->Record.kind) {
|
||||
case TypeRecord_Enum:
|
||||
return type_align_of_internal(allocator, t->Record.enum_base_type, path);
|
||||
case TypeRecord_Struct:
|
||||
if (t->Record.custom_align > 0) {
|
||||
return gb_clamp(t->Record.custom_align, 1, build_context.max_align);
|
||||
@@ -1844,6 +1846,9 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
||||
|
||||
case Type_Record: {
|
||||
switch (t->Record.kind) {
|
||||
case TypeRecord_Enum:
|
||||
return type_size_of_internal(allocator, t->Record.enum_base_type, path);
|
||||
|
||||
case TypeRecord_Struct: {
|
||||
i64 count = t->Record.field_count;
|
||||
if (count == 0) {
|
||||
|
||||
Reference in New Issue
Block a user