mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Add enum type info and fix enum casting
This commit is contained in:
@@ -1177,7 +1177,6 @@ void check_global_collect_entities_from_file(Checker *c, Scope *parent_scope, As
|
||||
case_end;
|
||||
case_ast_node(vs, ValueSpec, spec);
|
||||
switch (vs->keyword) {
|
||||
case Token_let:
|
||||
case Token_var: {
|
||||
// NOTE(bill): You need to store the entity information here unline a constant declaration
|
||||
isize entity_count = vs->names.count;
|
||||
@@ -1202,7 +1201,7 @@ void check_global_collect_entities_from_file(Checker *c, Scope *parent_scope, As
|
||||
error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind]));
|
||||
continue;
|
||||
}
|
||||
Entity *e = make_entity_variable(c->allocator, parent_scope, name->Ident, NULL, vs->keyword == Token_let);
|
||||
Entity *e = make_entity_variable(c->allocator, parent_scope, name->Ident, NULL);
|
||||
e->identifier = name;
|
||||
entities[entity_index++] = e;
|
||||
|
||||
|
||||
+4
-2
@@ -95,18 +95,20 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra
|
||||
error(lhs[0]->token, "Assignment count mismatch `%td` = `%td`", lhs_count, rhs_count);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (lhs[0]->kind == Entity_Variable &&
|
||||
lhs[0]->Variable.is_let) {
|
||||
if (lhs_count != rhs_count) {
|
||||
error(lhs[0]->token, "`let` variables must be initialized, `%td` = `%td`", lhs_count, rhs_count);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
gb_temp_arena_memory_end(tmp);
|
||||
}
|
||||
|
||||
void check_var_spec_node(Checker *c, AstNodeValueSpec *vs) {
|
||||
GB_ASSERT(vs->keyword == Token_var || vs->keyword == Token_let);
|
||||
GB_ASSERT(vs->keyword == Token_var);
|
||||
isize entity_count = vs->names.count;
|
||||
isize entity_index = 0;
|
||||
Entity **entities = gb_alloc_array(c->allocator, Entity *, entity_count);
|
||||
@@ -123,7 +125,7 @@ void check_var_spec_node(Checker *c, AstNodeValueSpec *vs) {
|
||||
found = current_scope_lookup_entity(c->context.scope, str);
|
||||
}
|
||||
if (found == NULL) {
|
||||
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, vs->keyword == Token_let);
|
||||
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL);
|
||||
add_entity_definition(&c->info, name, entity);
|
||||
} else {
|
||||
TokenPos pos = found->token.pos;
|
||||
|
||||
@@ -57,7 +57,6 @@ struct Entity {
|
||||
struct {
|
||||
i32 field_index;
|
||||
i32 field_src_index;
|
||||
bool is_let;
|
||||
} Variable;
|
||||
i32 TypeName;
|
||||
struct {
|
||||
@@ -97,9 +96,8 @@ Entity *alloc_entity(gbAllocator a, EntityKind kind, Scope *scope, Token token,
|
||||
return entity;
|
||||
}
|
||||
|
||||
Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *type, bool is_let) {
|
||||
Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *type) {
|
||||
Entity *entity = alloc_entity(a, Entity_Variable, scope, token, type);
|
||||
entity->Variable.is_let = is_let;
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -124,7 +122,7 @@ Entity *make_entity_type_name(gbAllocator a, Scope *scope, Token token, Type *ty
|
||||
}
|
||||
|
||||
Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous) {
|
||||
Entity *entity = make_entity_variable(a, scope, token, type, false);
|
||||
Entity *entity = make_entity_variable(a, scope, token, type);
|
||||
entity->flags |= EntityFlag_Used;
|
||||
entity->flags |= EntityFlag_Anonymous*(anonymous != 0);
|
||||
entity->flags |= EntityFlag_Param;
|
||||
@@ -132,7 +130,7 @@ Entity *make_entity_param(gbAllocator a, Scope *scope, Token token, Type *type,
|
||||
}
|
||||
|
||||
Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type, bool anonymous, i32 field_src_index) {
|
||||
Entity *entity = make_entity_variable(a, scope, token, type, false);
|
||||
Entity *entity = make_entity_variable(a, scope, token, type);
|
||||
entity->Variable.field_src_index = field_src_index;
|
||||
entity->Variable.field_index = field_src_index;
|
||||
entity->flags |= EntityFlag_Field;
|
||||
@@ -141,7 +139,7 @@ Entity *make_entity_field(gbAllocator a, Scope *scope, Token token, Type *type,
|
||||
}
|
||||
|
||||
Entity *make_entity_vector_elem(gbAllocator a, Scope *scope, Token token, Type *type, i32 field_src_index) {
|
||||
Entity *entity = make_entity_variable(a, scope, token, type, false);
|
||||
Entity *entity = make_entity_variable(a, scope, token, type);
|
||||
entity->Variable.field_src_index = field_src_index;
|
||||
entity->Variable.field_index = field_src_index;
|
||||
entity->flags |= EntityFlag_Field;
|
||||
@@ -186,6 +184,6 @@ Entity *make_entity_implicit_value(gbAllocator a, String name, Type *type, Impli
|
||||
|
||||
Entity *make_entity_dummy_variable(gbAllocator a, Scope *file_scope, Token token) {
|
||||
token.string = str_lit("_");
|
||||
return make_entity_variable(a, file_scope, token, NULL, false);
|
||||
return make_entity_variable(a, file_scope, token, NULL);
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -791,7 +791,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
|
||||
continue;
|
||||
}
|
||||
|
||||
GB_ASSERT(c->context.iota.kind == ExactValue_Invalid);
|
||||
ExactValue context_iota = c->context.iota;
|
||||
c->context.iota = e->Constant.value;
|
||||
e->Constant.value = (ExactValue){0};
|
||||
|
||||
@@ -799,7 +799,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
|
||||
check_expr(c, &operand, init);
|
||||
|
||||
check_init_constant(c, e, &operand);
|
||||
c->context.iota = (ExactValue){0};
|
||||
c->context.iota = context_iota;
|
||||
|
||||
if (operand.mode == Addressing_Constant) {
|
||||
HashKey key = hash_string(name);
|
||||
@@ -1001,9 +1001,9 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type) {
|
||||
}
|
||||
#else
|
||||
o->mode = Addressing_Variable;
|
||||
if (e->Variable.is_let) {
|
||||
o->mode = Addressing_Value;
|
||||
}
|
||||
// if (e->Variable.is_let) {
|
||||
// o->mode = Addressing_Value;
|
||||
// }
|
||||
#endif
|
||||
break;
|
||||
|
||||
@@ -1770,8 +1770,8 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) {
|
||||
}
|
||||
|
||||
Type *x = operand->type;
|
||||
Type *xb = base_type(x);
|
||||
Type *yb = base_type(y);
|
||||
Type *xb = base_type(base_enum_type(x));
|
||||
Type *yb = base_type(base_enum_type(y));
|
||||
if (are_types_identical(xb, yb)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-3
@@ -848,7 +848,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
tt = make_type_pointer(c->allocator, case_type);
|
||||
add_type_info_type(c, tt);
|
||||
}
|
||||
Entity *tag_var = make_entity_variable(c->allocator, c->context.scope, ms->var->Ident, tt, false);
|
||||
Entity *tag_var = make_entity_variable(c->allocator, c->context.scope, ms->var->Ident, tt);
|
||||
tag_var->flags |= EntityFlag_Used;
|
||||
add_entity(c, c->context.scope, ms->var, tag_var);
|
||||
add_entity_use(c, ms->var, tag_var);
|
||||
@@ -1106,7 +1106,6 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
case_end;
|
||||
case_ast_node(vs, ValueSpec, spec);
|
||||
switch (vs->keyword) {
|
||||
case Token_let:
|
||||
case Token_var: {
|
||||
isize entity_count = vs->names.count;
|
||||
isize entity_index = 0;
|
||||
@@ -1124,7 +1123,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
found = current_scope_lookup_entity(c->context.scope, str);
|
||||
}
|
||||
if (found == NULL) {
|
||||
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, vs->keyword == Token_let);
|
||||
entity = make_entity_variable(c->allocator, c->context.scope, token, NULL);
|
||||
add_entity_definition(&c->info, name, entity);
|
||||
} else {
|
||||
TokenPos pos = found->token.pos;
|
||||
|
||||
Reference in New Issue
Block a user