}
expect_token(parser, '{');
+
+ // HACK: There should be a better way to change which scope symbols will
+ // be placed in when converted to entities. Right now, you have to mess
+ // with parser->file_scope to change that. There is the block stack mechanism,
+ // but that feels very limited for this purpose.
+ Scope* parent_scope = parser->file_scope;
+
b32 member_is_used = 0;
while (parser->curr->type != '}') {
if (parser->hit_unexpected_token) return s_node;
if (!s_node->scope) {
// NOTE: The parent scope will be filled out during symbol resolution.
- s_node->scope = scope_create(context.ast_alloc, NULL, s_node->token->pos);
+ s_node->scope = scope_create(context.ast_alloc, parent_scope, s_node->token->pos);
+ parser->file_scope = s_node->scope;
}
AstBinding* binding = parse_top_level_binding(parser, member_name);
expect_token(parser, '}');
+ parser->file_scope = parent_scope;
+
if (poly_struct != NULL) {
// NOTE: Not a StructType
return (AstStructType *) poly_struct;
static void symres_use(AstUse* use) {
symres_expression(&use->expr);
- if (use->expr == NULL) return;
+ if (use->expr == NULL || use->expr->kind == Ast_Kind_Error) return;
if (use->expr->kind == Ast_Kind_Enum_Type) {
AstEnumType* et = (AstEnumType *) use->expr;
return;
}
+ if (use->expr->kind == Ast_Kind_Struct_Type) {
+ AstStructType* st = (AstStructType *) use->expr;
+
+ if (st->scope)
+ scope_include(curr_scope, st->scope, use->token->pos);
+
+ return;
+ }
+
if (use->expr->type_node == NULL && use->expr->type == NULL) goto cannot_use;
AstType* effective_type = use->expr->type_node;
s_type->Struct.memarr = NULL;
s_type->Struct.poly_sln = NULL;
- bh_table_init(global_heap_allocator, s_type->Struct.members, s_type->Struct.mem_count);
+ bh_table_init(global_heap_allocator, s_type->Struct.members, s_type->Struct.mem_count + 1);
bh_arr_new(global_heap_allocator, s_type->Struct.memarr, s_type->Struct.mem_count);
b32 is_union = (s_node->flags & Ast_Flag_Struct_Is_Union) != 0;