This commit is contained in:
Ginger Bill
2016-09-28 21:25:14 +01:00
parent 5f6b0942f4
commit 6e39a42c8a
8 changed files with 95 additions and 39 deletions
+3 -1
View File
@@ -256,7 +256,9 @@ struct CycleChecker {
};
CycleChecker *cycle_checker_add(CycleChecker *cc, Entity *e) {
GB_ASSERT(cc != NULL);
if (cc == NULL) {
return NULL;
}
if (cc->path == NULL) {
gb_array_init(cc->path, gb_heap_allocator());
}
+21 -19
View File
@@ -796,7 +796,7 @@ void check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node) {
}
void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, CycleChecker *cycle_checker = NULL) {
void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, CycleChecker *cycle_checker) {
GB_ASSERT(n->kind == AstNode_Ident);
o->mode = Addressing_Invalid;
o->expr = n;
@@ -816,13 +816,13 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
}
add_entity_use(c, n, e);
CycleChecker local_cycle_checker = {};
if (cycle_checker == NULL) {
cycle_checker = &local_cycle_checker;
}
defer (if (local_cycle_checker.path != NULL) {
gb_array_free(local_cycle_checker.path);
});
// CycleChecker local_cycle_checker = {};
// if (cycle_checker == NULL) {
// cycle_checker = &local_cycle_checker;
// }
// defer (if (local_cycle_checker.path != NULL) {
// gb_array_free(local_cycle_checker.path);
// });
check_entity_decl(c, e, NULL, named_type, cycle_checker);
@@ -857,17 +857,19 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
o->mode = Addressing_Type;
#if 0
// TODO(bill): Fix cyclical dependancy checker
gb_for_array(i, cycle_checker->path) {
Entity *prev = cycle_checker->path[i];
if (prev == e) {
error(e->token, "Illegal declaration cycle for %.*s", LIT(e->token.string));
for (isize j = i; j < gb_array_count(cycle_checker->path); j++) {
Entity *ref = cycle_checker->path[j];
error(ref->token, "\t%.*s refers to", LIT(ref->token.string));
if (cycle_checker != NULL) {
gb_for_array(i, cycle_checker->path) {
Entity *prev = cycle_checker->path[i];
if (prev == e) {
error(e->token, "Illegal declaration cycle for %.*s", LIT(e->token.string));
for (isize j = i; j < gb_array_count(cycle_checker->path); j++) {
Entity *ref = cycle_checker->path[j];
error(ref->token, "\t%.*s refers to", LIT(ref->token.string));
}
error(e->token, "\t%.*s", LIT(e->token.string));
type = t_invalid;
break;
}
error(e->token, "\t%.*s", LIT(e->token.string));
type = t_invalid;
break;
}
}
#endif
@@ -3170,7 +3172,7 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
case_end;
case_ast_node(i, Ident, node);
check_identifier(c, o, node, type_hint);
check_identifier(c, o, node, type_hint, NULL);
case_end;
case_ast_node(bl, BasicLit, node);
+6
View File
@@ -590,6 +590,11 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
"You cannot apply both `inline` and `no_inline` to a procedure");
}
if (is_foreign && is_link_name) {
error(ast_node_token(pd->type),
"You cannot apply both `foreign` and `link_name` to a procedure");
}
if (pd->body != NULL) {
if (is_foreign) {
error(ast_node_token(pd->body),
@@ -695,6 +700,7 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
d = *found;
} else {
e->type = t_invalid;
set_base_type(named_type, t_invalid);
return;
// GB_PANIC("`%.*s` should been declared!", LIT(e->token.string));
}
+3 -2
View File
@@ -180,8 +180,9 @@ int main(int argc, char **argv) {
"%.*sbin/opt %s -o %.*s.bc "
"-mem2reg "
"-memcpyopt "
"-die -dse "
"-dce "
"-die "
// "-dse "
// "-dce "
// "-S "
// "-debug-pass=Arguments "
"",