aboutsummaryrefslogtreecommitdiff
path: root/src/checker.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-09-20 22:59:46 +0100
committerGinger Bill <bill@gingerbill.org>2017-09-20 22:59:46 +0100
commit3bfaac08446e36caaf83fb2121abdbfeb04e261e (patch)
treefbeabc6f08192caafc5b679ebbf651409bb3f7d0 /src/checker.cpp
parent14d0cbf6d77e180fb752b468ad78aa3a689726fb (diff)
Fix decimal.odin assignment bug
Diffstat (limited to 'src/checker.cpp')
-rw-r--r--src/checker.cpp194
1 files changed, 97 insertions, 97 deletions
diff --git a/src/checker.cpp b/src/checker.cpp
index 8665529e5..7758d7803 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -327,6 +327,90 @@ void entity_graph_node_swap(EntityGraphNode **data, isize i, isize j) {
+struct ImportGraphNode;
+typedef PtrSet<ImportGraphNode *> ImportGraphNodeSet;
+
+void import_graph_node_set_destroy(ImportGraphNodeSet *s) {
+ if (s->hashes.data != nullptr) {
+ ptr_set_destroy(s);
+ }
+}
+
+void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) {
+ if (s->hashes.data == nullptr) {
+ ptr_set_init(s, heap_allocator());
+ }
+ ptr_set_add(s, n);
+}
+
+bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) {
+ return ptr_set_exists(s, n);
+}
+
+void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) {
+ ptr_set_remove(s, n);
+}
+
+struct ImportGraphNode {
+ Scope * scope;
+ String path;
+ isize file_id;
+ ImportGraphNodeSet pred;
+ ImportGraphNodeSet succ;
+ isize index; // Index in array/queue
+ isize dep_count;
+};
+
+ImportGraphNode *import_graph_node_create(gbAllocator a, Scope *scope) {
+ ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode);
+ n->scope = scope;
+ n->path = scope->file->tokenizer.fullpath;
+ n->file_id = scope->file->id;
+ return n;
+}
+
+
+void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) {
+ import_graph_node_set_destroy(&n->pred);
+ import_graph_node_set_destroy(&n->succ);
+ gb_free(a, n);
+}
+
+
+int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) {
+ ImportGraphNode *x = data[i];
+ ImportGraphNode *y = data[j];
+ GB_ASSERT(x != y);
+
+ GB_ASSERT(x->scope != y->scope);
+
+ bool xg = x->scope->is_global;
+ bool yg = y->scope->is_global;
+ if (xg != yg) return xg ? -1 : +1;
+ if (x->dep_count < y->dep_count) return -1;
+ if (x->dep_count > y->dep_count) return +1;
+ return 0;
+}
+
+void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) {
+ ImportGraphNode *x = data[i];
+ ImportGraphNode *y = data[j];
+ data[i] = y;
+ data[j] = x;
+ x->index = j;
+ y->index = i;
+}
+
+GB_COMPARE_PROC(ast_node_cmp) {
+ AstNode *x = *cast(AstNode **)a;
+ AstNode *y = *cast(AstNode **)b;
+ Token i = ast_node_token(x);
+ Token j = ast_node_token(y);
+ return token_pos_cmp(i.pos, j.pos);
+}
+
+
+
struct CheckerContext {
Scope * file_scope;
Scope * scope;
@@ -378,6 +462,7 @@ struct Checker {
// NOTE(bill): Procedures to check
Map<ProcedureInfo> procs; // Key: DeclInfo *
Map<Scope *> file_scopes; // Key: String (fullpath)
+ Array<ImportGraphNode *> file_order;
Pool pool;
gbAllocator allocator;
@@ -899,6 +984,8 @@ void init_checker(Checker *c, Parser *parser) {
map_init(&c->file_scopes, heap_allocator());
ptr_set_init(&c->checked_files, heap_allocator());
+
+ array_init(&c->file_order, heap_allocator(), c->parser->files.count);
}
void destroy_checker(Checker *c) {
@@ -912,6 +999,7 @@ void destroy_checker(Checker *c) {
map_destroy(&c->file_scopes);
ptr_set_destroy(&c->checked_files);
+ array_free(&c->file_order);
}
@@ -2185,88 +2273,6 @@ String path_to_entity_name(String name, String fullpath) {
-struct ImportGraphNode;
-typedef PtrSet<ImportGraphNode *> ImportGraphNodeSet;
-
-void import_graph_node_set_destroy(ImportGraphNodeSet *s) {
- if (s->hashes.data != nullptr) {
- ptr_set_destroy(s);
- }
-}
-
-void import_graph_node_set_add(ImportGraphNodeSet *s, ImportGraphNode *n) {
- if (s->hashes.data == nullptr) {
- ptr_set_init(s, heap_allocator());
- }
- ptr_set_add(s, n);
-}
-
-bool import_graph_node_set_exists(ImportGraphNodeSet *s, ImportGraphNode *n) {
- return ptr_set_exists(s, n);
-}
-
-void import_graph_node_set_remove(ImportGraphNodeSet *s, ImportGraphNode *n) {
- ptr_set_remove(s, n);
-}
-
-struct ImportGraphNode {
- Scope * scope;
- String path;
- isize file_id;
- ImportGraphNodeSet pred;
- ImportGraphNodeSet succ;
- isize index; // Index in array/queue
- isize dep_count;
-};
-
-ImportGraphNode *import_graph_node_create(gbAllocator a, Scope *scope) {
- ImportGraphNode *n = gb_alloc_item(a, ImportGraphNode);
- n->scope = scope;
- n->path = scope->file->tokenizer.fullpath;
- n->file_id = scope->file->id;
- return n;
-}
-
-
-void import_graph_node_destroy(ImportGraphNode *n, gbAllocator a) {
- import_graph_node_set_destroy(&n->pred);
- import_graph_node_set_destroy(&n->succ);
- gb_free(a, n);
-}
-
-
-int import_graph_node_cmp(ImportGraphNode **data, isize i, isize j) {
- ImportGraphNode *x = data[i];
- ImportGraphNode *y = data[j];
- GB_ASSERT(x != y);
-
- GB_ASSERT(x->scope != y->scope);
-
- bool xg = x->scope->is_global;
- bool yg = y->scope->is_global;
- if (xg != yg) return xg ? -1 : +1;
- if (x->dep_count < y->dep_count) return -1;
- if (x->dep_count > y->dep_count) return +1;
- return 0;
-}
-
-void import_graph_node_swap(ImportGraphNode **data, isize i, isize j) {
- ImportGraphNode *x = data[i];
- ImportGraphNode *y = data[j];
- data[i] = y;
- data[j] = x;
- x->index = j;
- y->index = i;
-}
-
-GB_COMPARE_PROC(ast_node_cmp) {
- AstNode *x = *cast(AstNode **)a;
- AstNode *y = *cast(AstNode **)b;
- Token i = ast_node_token(x);
- Token j = ast_node_token(y);
- return token_pos_cmp(i.pos, j.pos);
-}
-
void add_import_dependency_node(Checker *c, AstNode *decl, Map<ImportGraphNode *> *M) {
Scope *parent_file_scope = decl->file->scope;
@@ -2818,10 +2824,6 @@ void check_import_entities(Checker *c) {
ptr_set_init(&emitted, heap_allocator());
defer (ptr_set_destroy(&emitted));
- Array<ImportGraphNode *> file_order = {};
- array_init(&file_order, heap_allocator());
- defer (array_free(&file_order));
-
while (pq.queue.count > 0) {
ImportGraphNode *n = priority_queue_pop(&pq);
@@ -2844,12 +2846,10 @@ void check_import_entities(Checker *c) {
Token token = mt(s);
error(token, "Cyclic importation of `%.*s`", LIT(token.string));
for (isize i = path.count-1; i >= 0; i--) {
- token = mt(s);
- error(token, "\t`%.*s` refers to", LIT(token.string));
+ gb_printf_err("\t`%.*s` refers to", LIT(token.string));
s = path[i];
}
- token = mt(s);
- error(token, "\t`%.*s`", LIT(token.string));
+ gb_printf_err("\t`%.*s`", LIT(token.string));
}
}
@@ -2869,7 +2869,7 @@ void check_import_entities(Checker *c) {
}
ptr_set_add(&emitted, s);
- array_add(&file_order, n);
+ array_add(&c->file_order, n);
}
for_array(file_index, c->parser->files) {
@@ -2880,16 +2880,16 @@ void check_import_entities(Checker *c) {
}
}
- // for_array(file_index, file_order) {
- // ImportGraphNode *node = file_order[file_index];
+ // for_array(file_index, c->file_order) {
+ // ImportGraphNode *node = c->file_order[file_index];
// AstFile *f = node->scope->file;
// gb_printf_err("--- %.*s\n", LIT(f->fullpath));
// }
for (;;) {
bool new_files = false;
- for_array(file_index, file_order) {
- ImportGraphNode *node = file_order[file_index];
+ for_array(file_index, c->file_order) {
+ ImportGraphNode *node = c->file_order[file_index];
AstFile *f = node->scope->file;
if (!ptr_set_exists(&c->checked_files, f)) {
@@ -2905,8 +2905,8 @@ void check_import_entities(Checker *c) {
if (new_files) break;
}
- for (isize file_index = 0; file_index < file_order.count; file_index += 1) {
- ImportGraphNode *node = file_order[file_index];
+ for (isize file_index = 0; file_index < c->file_order.count; file_index += 1) {
+ ImportGraphNode *node = c->file_order[file_index];
AstFile *f = node->scope->file;
if (!ptr_set_exists(&c->checked_files, f)) {