Tagged unions memory layout change; begin demo 002

This commit is contained in:
Ginger Bill
2016-09-04 22:50:17 +01:00
parent c2e3c3801a
commit ae72b3c5bd
7 changed files with 142 additions and 83 deletions
+12 -17
View File
@@ -1238,22 +1238,10 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
switch (e->kind) {
case Entity_TypeName: {
Type *t = get_base_type(e->type);
if (is_type_enum(t)) {
if (is_type_struct(t) || is_type_enum(t)) {
for (isize i = 0; i < t->Record.other_field_count; i++) {
Entity *f = t->Record.other_fields[i];
Entity *found = scope_insert_entity(c->context.scope, f);
if (found != NULL) {
error(&c->error_collector, us->token, "Namespace collision while `using` `%s` of the constant: %.*s", expr_str, LIT(found->token.string));
return;
}
f->using_parent = e;
}
} else if (is_type_struct(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
GB_ASSERT(found != NULL);
gb_for_array(i, (*found)->elements.entries) {
Entity *f = (*found)->elements.entries[i].value;
Entity *found = scope_insert_entity(c->context.scope, f);
if (found != NULL) {
error(&c->error_collector, us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string));
return;
@@ -1261,10 +1249,17 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
f->using_parent = e;
}
} else if (is_type_union(t)) {
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
GB_ASSERT(found != NULL);
gb_for_array(i, (*found)->elements.entries) {
Entity *f = (*found)->elements.entries[i].value;
for (isize i = 0; i < t->Record.field_count; i++) {
Entity *f = t->Record.fields[i];
Entity *found = scope_insert_entity(c->context.scope, f);
if (found != NULL) {
error(&c->error_collector, us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string));
return;
}
f->using_parent = e;
}
for (isize i = 0; i < t->Record.other_field_count; i++) {
Entity *f = t->Record.other_fields[i];
Entity *found = scope_insert_entity(c->context.scope, f);
if (found != NULL) {
error(&c->error_collector, us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string));