Fix Scoping of proc type decls

This commit is contained in:
gingerBill
2016-08-17 12:04:17 +01:00
parent 511f3744f6
commit c4fe2ace05
9 changed files with 7342 additions and 361 deletions
-8
View File
@@ -101,7 +101,6 @@ struct Scope {
Scope *prev, *next;
Scope *first_child, *last_child;
Map<Entity *> elements; // Key: String
gbArray(AstNode *) deferred_stmts;
};
enum ExpressionKind {
@@ -196,7 +195,6 @@ Scope *make_scope(Scope *parent, gbAllocator allocator) {
Scope *s = gb_alloc_item(allocator, Scope);
s->parent = parent;
map_init(&s->elements, gb_heap_allocator());
gb_array_init(s->deferred_stmts, gb_heap_allocator());
if (parent != NULL && parent != universal_scope) {
DLIST_APPEND(parent->first_child, parent->last_child, s);
}
@@ -513,12 +511,6 @@ void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *dec
gb_array_append(c->procs, info);
}
void check_add_deferred_stmt(Checker *c, AstNode *stmt) {
GB_ASSERT(stmt != NULL);
GB_ASSERT(is_ast_node_stmt(stmt));
gb_array_append(c->context.scope->deferred_stmts, stmt);
}
void push_procedure(Checker *c, Type *type) {
gb_array_append(c->proc_stack, type);
}
+3
View File
@@ -409,7 +409,10 @@ Type *check_type(Checker *c, AstNode *e, Type *named_type) {
case_ast_node(pt, ProcType, e);
type = alloc_type(c->allocator, Type_Proc);
set_base_type(named_type, type);
CheckerContext context = c->context;
c->context.scope = make_scope(c->context.scope, c->allocator);
check_procedure_type(c, type, e);
c->context = context;
goto end;
case_end;
-1
View File
@@ -737,7 +737,6 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
c->in_defer = true;
check_stmt(c, ds->stmt, 0);
c->in_defer = out_in_defer;
check_add_deferred_stmt(c, ds->stmt);
}
case_end;
+6 -1
View File
@@ -144,7 +144,12 @@ void ssa_print_type(gbFile *f, BaseTypeSizes s, Type *t) {
if (i > 0) {
ssa_fprintf(f, ", ");
}
ssa_print_type(f, s, t->structure.fields[i]->type);
Type *ft = t->structure.fields[i]->type;
Type *bft = get_base_type(ft);
if (bft->kind != Type_Structure) {
ft = bft;
}
ssa_print_type(f, s, ft);
}
ssa_fprintf(f, "}");
if (t->structure.is_packed) {
+8 -5
View File
@@ -1824,7 +1824,8 @@ ssaValue *ssa_build_expr(ssaProcedure *proc, AstNode *expr) {
ssaValue *value = NULL;
if (tv->mode == Addressing_Variable) {
value = ssa_lvalue_load(proc, ssa_build_addr(proc, expr));
ssaLvalue addr = ssa_build_addr(proc, expr);
value = ssa_lvalue_load(proc, addr);
} else {
value = ssa_build_single_expr(proc, expr, tv);
}
@@ -1844,7 +1845,11 @@ ssaLvalue ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
Entity *e = entity_of_ident(proc->module->info, expr);
ssaValue *v = NULL;
ssaValue **found = map_get(&proc->module->values, hash_pointer(e));
if (found) v = *found;
if (found) {
v = *found;
} else {
GB_PANIC("Unknown value: %s, entity: %p\n", expr_to_string(expr), e);
}
return ssa_make_lvalue(v, expr);
case_end;
@@ -1860,17 +1865,15 @@ ssaLvalue ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
GB_ASSERT(entity != NULL);
ssaValue *e = ssa_build_addr(proc, se->expr).address;
Type *gep_type = entity->type;
if (is_type_pointer(type)) {
// NOTE(bill): Allow x^.y and x.y to be the same
gep_type = type_deref(gep_type);
e = ssa_emit_load(proc, e);
e = ssa_emit_ptr_offset(proc, e, v_zero);
ssa_value_set_type(e, type_deref(type));
}
ssaValue *v = ssa_emit_struct_gep(proc, e, field_index, gep_type);
ssaValue *v = ssa_emit_struct_gep(proc, e, field_index, entity->type);
return ssa_make_lvalue(v, expr);
case_end;