Remove struct #ordered

This commit is contained in:
gingerBill
2017-12-17 14:53:40 +00:00
parent 436928d06a
commit 30530d058c
15 changed files with 83 additions and 396 deletions
-1
View File
@@ -6380,7 +6380,6 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
case_ast_node(st, StructType, node);
str = gb_string_appendc(str, "struct ");
if (st->is_packed) str = gb_string_appendc(str, "#packed ");
if (st->is_ordered) str = gb_string_appendc(str, "#ordered ");
if (st->is_raw_union) str = gb_string_appendc(str, "#raw_union ");
str = gb_string_append_rune(str, '{');
str = write_struct_fields_to_string(str, st->fields);
+4 -10
View File
@@ -216,8 +216,6 @@ Array<Entity *> check_struct_fields(Checker *c, AstNode *node, Array<AstNode *>
// TODO(bill): Cleanup struct field reordering
// TODO(bill): Inline sorting procedure?
gb_global gbAllocator __checker_allocator = {};
GB_COMPARE_PROC(cmp_reorder_struct_fields) {
// Rule:
// 'using' over non-'using'
@@ -232,10 +230,10 @@ GB_COMPARE_PROC(cmp_reorder_struct_fields) {
GB_ASSERT(y->kind == Entity_Variable);
bool xu = (x->flags & EntityFlag_Using) != 0;
bool yu = (y->flags & EntityFlag_Using) != 0;
i64 xa = type_align_of(__checker_allocator, x->type);
i64 ya = type_align_of(__checker_allocator, y->type);
i64 xs = type_size_of(__checker_allocator, x->type);
i64 ys = type_size_of(__checker_allocator, y->type);
i64 xa = type_align_of(heap_allocator(), x->type);
i64 ya = type_align_of(heap_allocator(), y->type);
i64 xs = type_size_of(heap_allocator(), x->type);
i64 ys = type_size_of(heap_allocator(), y->type);
if (xu != yu) {
return xu ? -1 : +1;
@@ -545,7 +543,6 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
struct_type->Struct.scope = c->context.scope;
struct_type->Struct.is_packed = st->is_packed;
struct_type->Struct.is_ordered = st->is_ordered;
struct_type->Struct.polymorphic_params = polymorphic_params;
struct_type->Struct.is_polymorphic = is_polymorphic;
struct_type->Struct.is_poly_specialized = is_poly_specialized;
@@ -590,7 +587,6 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
// NOTE(bill): Hacky thing
// TODO(bill): Probably make an inline sorting procedure rather than use global variables
__checker_allocator = c->allocator;
// NOTE(bill): compound literal order must match source not layout
gb_sort_array(reordered_fields.data, fields.count, cmp_reorder_struct_fields);
@@ -1806,7 +1802,6 @@ void generate_map_entry_type(gbAllocator a, Type *type) {
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("value")), type->Map.value, false, 2));
entry_type->Struct.is_ordered = true;
entry_type->Struct.fields = fields;
entry_type->Struct.fields_in_src_order = fields;
@@ -1844,7 +1839,6 @@ void generate_map_internal_types(gbAllocator a, Type *type) {
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("hashes")), hashes_type, false, 0));
array_add(&fields, make_entity_field(a, s, make_token_ident(str_lit("entries")), entries_type, false, 1));
generated_struct_type->Struct.is_ordered = true;
generated_struct_type->Struct.fields = fields;
generated_struct_type->Struct.fields_in_src_order = fields;
+4 -1
View File
@@ -1389,7 +1389,7 @@ void add_type_info_type(Checker *c, Type *t) {
}
}
void check_procedure_later(Checker *c, ProcedureInfo const &info) {
void check_procedure_later(Checker *c, ProcedureInfo info) {
GB_ASSERT(info.decl != nullptr);
array_add(&c->procs, info);
}
@@ -3064,9 +3064,12 @@ void check_import_entities(Checker *c) {
};
if (path.count == 1) {
// TODO(bill): Should this be allowed or disabled?
#if 0
ImportPathItem item = path[0];
String filename = fn(item);
error(item.decl, "Self importation of '%.*s'", LIT(filename));
#endif
} else if (path.count > 0) {
ImportPathItem item = path[path.count-1];
String filename = fn(item);
+7 -4
View File
@@ -7245,6 +7245,11 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
irValue *next = ir_add_local_generated(proc, t_context);
ir_emit_store(proc, next, new_context);
Selection sel = lookup_field(proc->module->allocator, t_context, str_lit("parent"), false);
GB_ASSERT(sel.entity != nullptr);
irValue *parent_ptr = ir_emit_deep_field_gep(proc, next, sel);
ir_emit_store(proc, parent_ptr, prev);
array_add(&proc->context_stack, next);
defer (array_pop(&proc->context_stack));
@@ -8030,13 +8035,11 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
{
irValue *is_packed = ir_const_bool(a, t->Struct.is_packed);
irValue *is_ordered = ir_const_bool(a, t->Struct.is_ordered);
irValue *is_raw_union = ir_const_bool(a, t->Struct.is_raw_union);
irValue *is_custom_align = ir_const_bool(a, t->Struct.custom_align != 0);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 4), is_packed);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 5), is_ordered);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 6), is_raw_union);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 7), is_custom_align);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 5), is_raw_union);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 6), is_custom_align);
}
isize count = t->Struct.fields.count;
+3 -308
View File
@@ -185,10 +185,6 @@ Array<AstNode *> make_ast_node_array(AstFile *f, isize init_capacity = 8) {
Array<AstNode *> elems; \
Token open, close; \
}) \
AST_NODE_KIND(Alias, "alias", struct { \
Token token; \
AstNode *expr; \
}) \
AST_NODE_KIND(_ExprBegin, "", i32) \
AST_NODE_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \
AST_NODE_KIND(TagExpr, "tag expression", struct { Token token, name; AstNode *expr; }) \
@@ -461,7 +457,6 @@ AST_NODE_KIND(_TypeBegin, "", i32) \
isize field_count; \
AstNode * polymorphic_params; \
bool is_packed; \
bool is_ordered; \
bool is_raw_union; \
AstNode * align; \
}) \
@@ -562,7 +557,6 @@ Token ast_node_token(AstNode *node) {
return ast_node_token(node->CompoundLit.type);
}
return node->CompoundLit.open;
case AstNode_Alias: return node->Alias.token;
case AstNode_TagExpr: return node->TagExpr.token;
case AstNode_RunExpr: return node->RunExpr.token;
@@ -698,9 +692,6 @@ AstNode *clone_ast_node(gbAllocator a, AstNode *node) {
n->CompoundLit.type = clone_ast_node(a, n->CompoundLit.type);
n->CompoundLit.elems = clone_ast_node_array(a, n->CompoundLit.elems);
break;
case AstNode_Alias:
n->Alias.expr = clone_ast_node(a, n->Alias.expr);
break;
case AstNode_BadExpr: break;
case AstNode_TagExpr:
@@ -1177,12 +1168,6 @@ AstNode *ast_compound_lit(AstFile *f, AstNode *type, Array<AstNode *> elems, Tok
result->CompoundLit.close = close;
return result;
}
AstNode *ast_alias(AstFile *f, Token token, AstNode *expr) {
AstNode *result = make_ast_node(f, AstNode_Alias);
result->Alias.token = token;
result->Alias.expr = expr;
return result;
}
AstNode *ast_ternary_expr(AstFile *f, AstNode *cond, AstNode *x, AstNode *y) {
@@ -1499,7 +1484,7 @@ AstNode *ast_dynamic_array_type(AstFile *f, Token token, AstNode *elem) {
}
AstNode *ast_struct_type(AstFile *f, Token token, Array<AstNode *> fields, isize field_count,
AstNode *polymorphic_params, bool is_packed, bool is_ordered, bool is_raw_union,
AstNode *polymorphic_params, bool is_packed, bool is_raw_union,
AstNode *align) {
AstNode *result = make_ast_node(f, AstNode_StructType);
result->StructType.token = token;
@@ -1507,7 +1492,6 @@ AstNode *ast_struct_type(AstFile *f, Token token, Array<AstNode *> fields, isize
result->StructType.field_count = field_count;
result->StructType.polymorphic_params = polymorphic_params;
result->StructType.is_packed = is_packed;
result->StructType.is_ordered = is_ordered;
result->StructType.is_raw_union = is_raw_union;
result->StructType.align = align;
return result;
@@ -2226,7 +2210,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
return ast_helper_type(f, token, parse_type(f));
}
Token name = expect_token(f, Token_Ident);
if (name.string == "alias") {
if (name.string == "type_alias") {
return ast_alias_type(f, token, parse_type(f));
} else if (name.string == "run") {
AstNode *expr = parse_expr(f, false);
@@ -2405,7 +2389,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
Token token = expect_token(f, Token_struct);
AstNode *polymorphic_params = nullptr;
bool is_packed = false;
bool is_ordered = false;
bool is_raw_union = false;
AstNode *align = nullptr;
@@ -2429,11 +2412,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_packed = true;
} else if (tag.string == "ordered") {
if (is_ordered) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_ordered = true;
} else if (tag.string == "align") {
if (align) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
@@ -2451,17 +2429,10 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
f->expr_level = prev_level;
if (is_packed && is_ordered) {
syntax_error(token, "'#ordered' is not needed with '#packed' which implies ordering");
}
if (is_raw_union && is_packed) {
is_packed = false;
syntax_error(token, "'#raw_union' cannot also be '#packed'");
}
if (is_raw_union && is_ordered) {
is_ordered = false;
syntax_error(token, "'#raw_union' cannot also be '#ordered'");
}
Token open = expect_token_after(f, Token_OpenBrace, "struct");
@@ -2475,7 +2446,7 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
decls = fields->FieldList.list;
}
return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_ordered, is_raw_union, align);
return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, align);
} break;
case Token_union: {
@@ -3659,7 +3630,6 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok
}
AstNode *parse_type_or_ident(AstFile *f) {
#if 1
bool prev_allow_type = f->allow_type;
isize prev_expr_level = f->expr_level;
defer (f->allow_type = prev_allow_type);
@@ -3669,281 +3639,6 @@ AstNode *parse_type_or_ident(AstFile *f) {
AstNode *operand = parse_operand(f, true);
AstNode *type = parse_atom_expr(f, operand, true);
return type;
#else
switch (f->curr_token.kind) {
case Token_Dollar: {
Token token = expect_token(f, Token_Dollar);
AstNode *type = parse_ident(f);
return ast_poly_type(f, token, type);
} break;
case Token_type_of: {
AstNode *i = ast_implicit(f, expect_token(f, Token_type_of));
AstNode *type = parse_call_expr(f, i);
while (f->curr_token.kind == Token_Period) {
Token token = advance_token(f);
AstNode *sel = parse_ident(f);
type = ast_selector_expr(f, token, type, sel);
}
return type;
} break;
case Token_Ident: {
AstNode *e = parse_ident(f);
while (f->curr_token.kind == Token_Period) {
Token token = advance_token(f);
AstNode *sel = parse_ident(f);
e = ast_selector_expr(f, token, e, sel);
}
// TODO(bill): Merge type_or_ident into the general parsing for expressions
// if (f->curr_token.kind == Token_OpenParen) {
// HACK NOTE(bill): For type_of_val(expr) et al.
// e = parse_call_expr(f, e);
// }
return e;
} break;
case Token_Pointer: {
Token token = expect_token(f, Token_Pointer);
AstNode *elem = parse_type(f);
return ast_pointer_type(f, token, elem);
} break;
case Token_atomic: {
Token token = expect_token(f, Token_atomic);
AstNode *elem = parse_type(f);
return ast_atomic_type(f, token, elem);
} break;
case Token_Hash: {
Token hash_token = expect_token(f, Token_Hash);
Token type_token = expect_token(f, Token_type);
AstNode *type = parse_type(f);
return ast_helper_type(f, hash_token, type);
}
case Token_OpenBracket: {
Token token = expect_token(f, Token_OpenBracket);
AstNode *count_expr = nullptr;
bool is_vector = false;
if (f->curr_token.kind == Token_Ellipsis) {
count_expr = ast_unary_expr(f, expect_token(f, Token_Ellipsis), nullptr);
} else if (allow_token(f, Token_vector)) {
if (f->curr_token.kind != Token_CloseBracket) {
f->expr_level++;
count_expr = parse_expr(f, false);
f->expr_level--;
} else {
syntax_error(f->curr_token, "Vector type missing count");
}
is_vector = true;
} else if (allow_token(f, Token_dynamic)) {
expect_token(f, Token_CloseBracket);
return ast_dynamic_array_type(f, token, parse_type(f));
} else if (f->curr_token.kind != Token_CloseBracket) {
f->expr_level++;
count_expr = parse_expr(f, false);
f->expr_level--;
}
expect_token(f, Token_CloseBracket);
if (is_vector) {
return ast_vector_type(f, token, count_expr, parse_type(f));
}
return ast_array_type(f, token, count_expr, parse_type(f));
} break;
case Token_map: {
Token token = expect_token(f, Token_map);
AstNode *count = nullptr;
AstNode *key = nullptr;
AstNode *value = nullptr;
Token open = expect_token_after(f, Token_OpenBracket, "map");
key = parse_expr(f, true);
if (allow_token(f, Token_Comma)) {
count = key;
key = parse_type(f);
}
Token close = expect_token(f, Token_CloseBracket);
value = parse_type(f);
return ast_map_type(f, token, count, key, value);
} break;
case Token_struct: {
Token token = expect_token(f, Token_struct);
bool is_packed = false;
bool is_ordered = false;
AstNode *align = nullptr;
isize prev_level = f->expr_level;
f->expr_level = -1;
while (allow_token(f, Token_Hash)) {
Token tag = expect_token_after(f, Token_Ident, "#");
if (tag.string == "packed") {
if (is_packed) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_packed = true;
} else if (tag.string == "ordered") {
if (is_ordered) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_ordered = true;
} else if (tag.string == "align") {
if (align) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
align = parse_expr(f, true);
} else {
syntax_error(tag, "Invalid struct tag '#%.*s'", LIT(tag.string));
}
}
f->expr_level = prev_level;
if (is_packed && is_ordered) {
syntax_error(token, "'#ordered' is not needed with '#packed' which implies ordering");
}
Token open = expect_token_after(f, Token_OpenBrace, "struct");
isize name_count = 0;
AstNode *fields = parse_struct_field_list(f, &name_count);
Token close = expect_token(f, Token_CloseBrace);
Array<AstNode *> decls = {};
if (fields != nullptr) {
GB_ASSERT(fields->kind == AstNode_FieldList);
decls = fields->FieldList.list;
}
return ast_struct_type(f, token, decls, name_count, is_packed, is_ordered, align);
} break;
case Token_union: {
Token token = expect_token(f, Token_union);
Token open = expect_token_after(f, Token_OpenBrace, "union");
Array<AstNode *> variants = make_ast_node_array(f);
isize total_decl_name_count = 0;
CommentGroup docs = f->lead_comment;
Token start_token = f->curr_token;
while (f->curr_token.kind != Token_CloseBrace &&
f->curr_token.kind != Token_EOF) {
AstNode *type = parse_type(f);
if (type->kind != AstNode_BadExpr) {
array_add(&variants, type);
}
if (!allow_token(f, Token_Comma)) {
break;
}
}
Token close = expect_token(f, Token_CloseBrace);
return ast_union_type(f, token, variants);
} break;
case Token_raw_union: {
Token token = expect_token(f, Token_raw_union);
Token open = expect_token_after(f, Token_OpenBrace, "raw_union");
isize decl_count = 0;
AstNode *fields = parse_struct_field_list(f, &decl_count);
Token close = expect_token(f, Token_CloseBrace);
Array<AstNode *> decls = {};
if (fields != nullptr) {
GB_ASSERT(fields->kind == AstNode_FieldList);
decls = fields->FieldList.list;
}
return ast_raw_union_type(f, token, decls, decl_count);
} break;
case Token_enum: {
Token token = expect_token(f, Token_enum);
AstNode *base_type = nullptr;
if (f->curr_token.kind != Token_OpenBrace) {
base_type = parse_type(f);
}
Token open = expect_token(f, Token_OpenBrace);
Array<AstNode *> values = parse_element_list(f);
Token close = expect_token(f, Token_CloseBrace);
return ast_enum_type(f, token, base_type, values);
} break;
case Token_bit_field: {
Token token = expect_token(f, Token_bit_field);
Array<AstNode *> fields = make_ast_node_array(f);
AstNode *align = nullptr;
Token open, close;
isize prev_level = f->expr_level;
f->expr_level = -1;
while (allow_token(f, Token_Hash)) {
Token tag = expect_token_after(f, Token_Ident, "#");
if (tag.string == "align") {
if (align) {
syntax_error(tag, "Duplicate bit_field tag '#%.*s'", LIT(tag.string));
}
align = parse_expr(f, true);
} else {
syntax_error(tag, "Invalid bit_field tag '#%.*s'", LIT(tag.string));
}
}
f->expr_level = prev_level;
open = expect_token_after(f, Token_OpenBrace, "bit_field");
while (f->curr_token.kind != Token_EOF &&
f->curr_token.kind != Token_CloseBrace) {
AstNode *name = parse_ident(f);
Token colon = expect_token(f, Token_Colon);
AstNode *value = parse_expr(f, true);
AstNode *field = ast_field_value(f, name, value, colon);
array_add(&fields, field);
if (f->curr_token.kind != Token_Comma) {
break;
}
advance_token(f);
}
close = expect_token(f, Token_CloseBrace);
return ast_bit_field_type(f, token, fields, align);
} break;
case Token_proc: {
Token token = advance_token(f);
AstNode *pt = parse_proc_type(f, token, nullptr);
if (pt->ProcType.tags != 0) {
syntax_error(token, "A procedure type cannot have tags");
}
return pt;
} break;
case Token_OpenParen: {
Token open = expect_token(f, Token_OpenParen);
AstNode *type = parse_type(f);
Token close = expect_token(f, Token_CloseParen);
return ast_paren_expr(f, type, open, close);
} break;
}
return nullptr;
#endif
}
-3
View File
@@ -80,7 +80,6 @@ struct TypeStruct {
bool are_offsets_set;
bool are_offsets_being_processed;
bool is_packed;
bool is_ordered;
bool is_raw_union;
bool is_polymorphic;
bool is_poly_specialized;
@@ -1177,7 +1176,6 @@ bool are_types_identical(Type *x, Type *y) {
if (x->Struct.is_raw_union == y->Struct.is_raw_union &&
x->Struct.fields.count == y->Struct.fields.count &&
x->Struct.is_packed == y->Struct.is_packed &&
x->Struct.is_ordered == y->Struct.is_ordered &&
x->Struct.custom_align == y->Struct.custom_align) {
// TODO(bill); Fix the custom alignment rule
for_array(i, x->Struct.fields) {
@@ -2338,7 +2336,6 @@ gbString write_type_to_string(gbString str, Type *type) {
case Type_Struct: {
str = gb_string_appendc(str, "struct");
if (type->Struct.is_packed) str = gb_string_appendc(str, " #packed");
if (type->Struct.is_ordered) str = gb_string_appendc(str, " #ordered");
if (type->Struct.is_raw_union) str = gb_string_appendc(str, " #raw_union");
str = gb_string_appendc(str, " {");
for_array(i, type->Struct.fields) {