mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Bug Fixes: some assertions; variable inits;
Remove some dead code
This commit is contained in:
+14
-7
@@ -624,9 +624,13 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
||||
|
||||
void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
|
||||
GB_ASSERT(identifier != NULL);
|
||||
GB_ASSERT(identifier->kind == AstNode_Ident);
|
||||
HashKey key = hash_pointer(identifier);
|
||||
map_set(&i->definitions, key, entity);
|
||||
if (identifier->kind == AstNode_Ident) {
|
||||
GB_ASSERT(identifier->kind == AstNode_Ident);
|
||||
HashKey key = hash_pointer(identifier);
|
||||
map_set(&i->definitions, key, entity);
|
||||
} else {
|
||||
// NOTE(bill): Error should handled elsewhere
|
||||
}
|
||||
}
|
||||
|
||||
b32 add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
|
||||
@@ -1139,10 +1143,11 @@ void check_parsed_files(Checker *c) {
|
||||
|
||||
add_curr_ast_file(c, d->scope->file);
|
||||
|
||||
Scope *prev_scope = c->context.scope;
|
||||
c->context.scope = d->scope;
|
||||
GB_ASSERT(d->scope == e->scope);
|
||||
check_entity_decl(c, e, d, NULL);
|
||||
if (d->scope == e->scope) {
|
||||
Scope *prev_scope = c->context.scope;
|
||||
c->context.scope = d->scope;
|
||||
check_entity_decl(c, e, d, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1178,6 +1183,7 @@ void check_parsed_files(Checker *c) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
gb_for_array(i, c->parser->files) {
|
||||
AstFile *f = &c->parser->files[i];
|
||||
Scope *scope = f->scope;
|
||||
@@ -1192,6 +1198,7 @@ void check_parsed_files(Checker *c) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ struct Entity {
|
||||
struct {
|
||||
} TypeName;
|
||||
struct {
|
||||
b32 used;
|
||||
} Procedure;
|
||||
struct {
|
||||
BuiltinProcId id;
|
||||
|
||||
@@ -806,22 +806,6 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
|
||||
error(n->Ident, "`_` cannot be used as a value type");
|
||||
} else {
|
||||
auto *entries = c->context.scope->elements.entries;
|
||||
// gb_for_array(i, entries) {
|
||||
// Entity *elem = entries[i].value;
|
||||
// if (i > 0) {
|
||||
// gb_printf(", ");
|
||||
// }
|
||||
// gb_printf("%.*s", LIT(elem->token.string));
|
||||
// }
|
||||
// for (Scope *s = c->context.scope; s != NULL; s = s->parent) {
|
||||
// Entity *elem = s->elements.entries[0].value;
|
||||
// if (elem == NULL) continue;
|
||||
// gb_printf("%.*s\n", LIT(elem->token.pos.file));
|
||||
// }
|
||||
// gb_printf("\n");
|
||||
|
||||
|
||||
// Entity *e = scope_lookup_entity(c->context.scope, n->Ident.string);
|
||||
error(n->Ident,
|
||||
"Undeclared name: %.*s", LIT(n->Ident.string));
|
||||
}
|
||||
|
||||
+6
-61
@@ -9,7 +9,6 @@ enum StmtFlag : u32 {
|
||||
|
||||
void check_stmt(Checker *c, AstNode *node, u32 flags);
|
||||
void check_proc_decl(Checker *c, Entity *e, DeclInfo *d);
|
||||
void check_const_decl_node(Checker *c, AstNode *node);
|
||||
|
||||
void check_stmt_list(Checker *c, AstNodeArray stmts, u32 flags) {
|
||||
// TODO(bill): Allow declaration (expect variable) in any order
|
||||
@@ -474,7 +473,7 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def, Cycle
|
||||
named->Named.base = base_type;
|
||||
named->Named.base = get_base_type(named->Named.base);
|
||||
if (named->Named.base == t_invalid) {
|
||||
// gb_printf("check_type_decl: %s\n", type_to_string(named));
|
||||
gb_printf("check_type_decl: %s\n", type_to_string(named));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,18 +718,11 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
|
||||
}
|
||||
}
|
||||
|
||||
// c->context.decl = d;
|
||||
// Scope *prev = c->context.scope;
|
||||
// c->context.scope = d->scope;
|
||||
// defer (c->context.scope = prev);
|
||||
|
||||
if (e->kind == Entity_Procedure) {
|
||||
check_proc_decl(c, e, d);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
switch (e->kind) {
|
||||
case Entity_Constant: {
|
||||
Scope *prev = c->context.scope;
|
||||
@@ -758,15 +750,7 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type, Cyc
|
||||
c->context.scope = d->scope;
|
||||
defer (c->context.scope = prev);
|
||||
|
||||
CycleChecker local_cycle_checker = {};
|
||||
if (cycle_checker == NULL) {
|
||||
cycle_checker = &local_cycle_checker;
|
||||
}
|
||||
check_type_decl(c, e, d->type_expr, named_type, cycle_checker);
|
||||
|
||||
if (local_cycle_checker.path != NULL) {
|
||||
gb_array_free(local_cycle_checker.path);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
@@ -782,8 +766,8 @@ void check_var_decl_node(Checker *c, AstNode *node) {
|
||||
gb_for_array(i, vd->names) {
|
||||
AstNode *name = vd->names[i];
|
||||
Entity *entity = NULL;
|
||||
Token token = name->Ident;
|
||||
if (name->kind == AstNode_Ident) {
|
||||
Token token = name->Ident;
|
||||
String str = token.string;
|
||||
Entity *found = NULL;
|
||||
// NOTE(bill): Ignore assignments to `_`
|
||||
@@ -803,10 +787,11 @@ void check_var_decl_node(Checker *c, AstNode *node) {
|
||||
entity = found;
|
||||
}
|
||||
} else {
|
||||
error(token, "A variable declaration must be an identifier");
|
||||
error(ast_node_token(name), "A variable declaration must be an identifier");
|
||||
}
|
||||
if (entity == NULL) {
|
||||
entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name));
|
||||
}
|
||||
if (entity == NULL)
|
||||
entity = make_entity_dummy_variable(c->allocator, c->global_scope, token);
|
||||
entities[entity_index++] = entity;
|
||||
}
|
||||
|
||||
@@ -841,46 +826,6 @@ void check_var_decl_node(Checker *c, AstNode *node) {
|
||||
}
|
||||
|
||||
|
||||
void check_const_decl_node(Checker *c, AstNode *node) {
|
||||
ast_node(vd, ConstDecl, node);
|
||||
isize entity_count = gb_array_count(vd->names);
|
||||
isize entity_index = 0;
|
||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
|
||||
|
||||
gb_for_array(i, vd->values) {
|
||||
AstNode *name = vd->names[i];
|
||||
AstNode *value = vd->values[i];
|
||||
|
||||
GB_ASSERT(name->kind == AstNode_Ident);
|
||||
ExactValue v = {ExactValue_Invalid};
|
||||
String str = name->Ident.string;
|
||||
Entity *found = current_scope_lookup_entity(c->context.scope, str);
|
||||
if (found == NULL) {
|
||||
Entity *e = make_entity_constant(c->allocator, c->context.scope, name->Ident, NULL, v);
|
||||
entities[entity_index++] = e;
|
||||
check_const_decl(c, e, vd->type, value);
|
||||
} else {
|
||||
entities[entity_index++] = found;
|
||||
}
|
||||
}
|
||||
|
||||
isize lhs_count = gb_array_count(vd->names);
|
||||
isize rhs_count = gb_array_count(vd->values);
|
||||
|
||||
// TODO(bill): Better error messages or is this good enough?
|
||||
if (rhs_count == 0 && vd->type == NULL) {
|
||||
error(ast_node_token(node), "Missing type or initial expression");
|
||||
} else if (lhs_count < rhs_count) {
|
||||
error(ast_node_token(node), "Extra initial expression");
|
||||
}
|
||||
|
||||
gb_for_array(i, vd->names) {
|
||||
add_entity(c, c->context.scope, vd->names[i], entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
u32 mod_flags = flags & (~Stmt_FallthroughAllowed);
|
||||
|
||||
Reference in New Issue
Block a user