Better constant strings for SSA; Fix Type_Info

This commit is contained in:
Ginger Bill
2016-10-26 20:10:32 +01:00
parent aed7a83f5b
commit 09f39ae2cc
12 changed files with 420 additions and 294 deletions
+9 -5
View File
@@ -200,7 +200,7 @@ struct CheckerInfo {
Map<Entity *> foreign_procs; // Key: String
Map<AstFile *> files; // Key: String (full path)
Map<isize> type_info_map; // Key: Type *
isize type_info_index;
isize type_info_count;
Entity * implicit_values[ImplicitValue_Count];
};
@@ -536,7 +536,7 @@ void init_checker_info(CheckerInfo *i) {
map_init(&i->foreign_procs, a);
map_init(&i->type_info_map, a);
map_init(&i->files, a);
i->type_info_index = 0;
i->type_info_count = 0;
}
@@ -736,19 +736,21 @@ void add_type_info_type(Checker *c, Type *t) {
Type *prev_type = cast(Type *)e->key.ptr;
if (are_types_identical(t, prev_type)) {
// Duplicate entry
ti_index = i;
ti_index = e->value;
break;
}
}
if (ti_index < 0) {
// Unique entry
// NOTE(bill): map entries grow linearly and in order
ti_index = c->info.type_info_index;
c->info.type_info_index++;
ti_index = c->info.type_info_count;
c->info.type_info_count++;
}
map_set(&c->info.type_info_map, hash_pointer(t), ti_index);
// Add nested types
if (t->kind == Type_Named) {
@@ -758,6 +760,8 @@ void add_type_info_type(Checker *c, Type *t) {
}
Type *bt = base_type(t);
add_type_info_type(c, bt);
switch (bt->kind) {
case Type_Basic: {
switch (bt->Basic.kind) {
+11 -6
View File
@@ -248,16 +248,17 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
CycleChecker *cycle_checker, String context) {
PROF_PROC();
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
defer (gb_temp_arena_memory_end(tmp));
Map<Entity *> entity_map = {};
map_init(&entity_map, heap_allocator());
defer (map_destroy(&entity_map));
map_init_with_reserve(&entity_map, c->tmp_allocator, 2*(field_count+other_field_count));
// defer (map_destroy(&entity_map));
isize other_field_index = 0;
Entity *using_index_expr = NULL;
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
defer (gb_temp_arena_memory_end(tmp));
struct Delay {
Entity *e;
AstNode *t;
@@ -661,9 +662,13 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
GB_ASSERT(is_type_enum(enum_type));
ast_node(et, EnumType, node);
gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&c->tmp_arena);
defer (gb_temp_arena_memory_end(tmp));
Map<Entity *> entity_map = {};
map_init(&entity_map, heap_allocator());
defer (map_destroy(&entity_map));
map_init_with_reserve(&entity_map, c->tmp_allocator, 2*(et->fields.count));
// defer (map_destroy(&entity_map));
Type *base_type = t_int;
if (et->base_type != NULL) {
+1 -1
View File
@@ -633,7 +633,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
Token token;
};
Map<TypeAndToken> seen = {}; // Multimap
Map<TypeAndToken> seen = {}; // NOTE(bill): Multimap
map_init(&seen, heap_allocator());
defer (map_destroy(&seen));
for_array(i, bs->stmts) {
+3 -2
View File
@@ -1347,7 +1347,7 @@ gbString write_type_to_string(gbString str, Type *type) {
for (isize i = 1; i < type->Record.field_count; i++) {
Entity *f = type->Record.fields[i];
GB_ASSERT(f->kind == Entity_TypeName);
if (i > 0) {
if (i > 1) {
str = gb_string_appendc(str, "; ");
}
str = gb_string_append_length(str, f->token.string.text, f->token.string.len);
@@ -1362,8 +1362,9 @@ gbString write_type_to_string(gbString str, Type *type) {
for (isize i = 0; i < type->Record.field_count; i++) {
Entity *f = type->Record.fields[i];
GB_ASSERT(f->kind == Entity_Variable);
if (i > 0)
if (i > 0) {
str = gb_string_appendc(str, ", ");
}
str = gb_string_append_length(str, f->token.string.text, f->token.string.len);
str = gb_string_appendc(str, ": ");
str = write_type_to_string(str, f->type);