mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 20:02:22 -07:00
#file #line directives
This commit is contained in:
+51
-30
@@ -402,6 +402,23 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void check_scope_usage(Checker *c, Scope *scope) {
|
||||
// TODO(bill): Use this?
|
||||
#if 0
|
||||
gb_for_array(i, scope->elements.entries) {
|
||||
auto *entry = scope->elements.entries + i;
|
||||
Entity *e = entry->value;
|
||||
if (e->kind == Entity_Variable && !e->Variable.used) {
|
||||
warning(e->token, "Unused variable: %.*s", LIT(e->token.string));
|
||||
}
|
||||
}
|
||||
|
||||
for (Scope *child = scope->first_child; child != NULL; child = child->next) {
|
||||
check_scope_usage(c, child);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void add_dependency(DeclInfo *d, Entity *e) {
|
||||
map_set(&d->deps, hash_pointer(e), cast(b32)true);
|
||||
@@ -807,6 +824,39 @@ void check_type_name_cycles(Checker *c, CycleCheck *cc, Entity *e) {
|
||||
// }
|
||||
}
|
||||
|
||||
void init_type_info_types(Checker *c) {
|
||||
if (t_type_info == NULL) {
|
||||
String type_info_str = make_string("Type_Info");
|
||||
Entity *e = current_scope_lookup_entity(c->global_scope, type_info_str);
|
||||
GB_ASSERT_MSG(e != NULL, "Internal Compiler Error: Could not find type declaration for `Type_Info`");
|
||||
t_type_info = e->type;
|
||||
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
|
||||
|
||||
auto *record = &get_base_type(e->type)->Record;
|
||||
|
||||
t_type_info_member = record->other_fields[0]->type;
|
||||
t_type_info_member_ptr = make_type_pointer(c->allocator, t_type_info_member);
|
||||
|
||||
GB_ASSERT_MSG(record->field_count == 16, "Internal Compiler Error: Invalid `Type_Info` layout");
|
||||
t_type_info_named = record->fields[ 1]->type;
|
||||
t_type_info_integer = record->fields[ 2]->type;
|
||||
t_type_info_float = record->fields[ 3]->type;
|
||||
t_type_info_string = record->fields[ 4]->type;
|
||||
t_type_info_boolean = record->fields[ 5]->type;
|
||||
t_type_info_pointer = record->fields[ 6]->type;
|
||||
t_type_info_procedure = record->fields[ 7]->type;
|
||||
t_type_info_array = record->fields[ 8]->type;
|
||||
t_type_info_slice = record->fields[ 9]->type;
|
||||
t_type_info_vector = record->fields[10]->type;
|
||||
t_type_info_tuple = record->fields[11]->type;
|
||||
t_type_info_struct = record->fields[12]->type;
|
||||
t_type_info_union = record->fields[13]->type;
|
||||
t_type_info_raw_union = record->fields[14]->type;
|
||||
t_type_info_enum = record->fields[15]->type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void check_parsed_files(Checker *c) {
|
||||
|
||||
@@ -1016,37 +1066,8 @@ void check_parsed_files(Checker *c) {
|
||||
|
||||
check_global_entity(c, Entity_TypeName);
|
||||
|
||||
init_type_info_types(c);
|
||||
#if 1
|
||||
if (t_type_info == NULL) {
|
||||
String type_info_str = make_string("Type_Info");
|
||||
Entity *e = current_scope_lookup_entity(c->global_scope, type_info_str);
|
||||
GB_ASSERT_MSG(e != NULL, "Internal Compiler Error: Could not find type declaration for `Type_Info`");
|
||||
t_type_info = e->type;
|
||||
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
|
||||
|
||||
auto *record = &get_base_type(e->type)->Record;
|
||||
|
||||
t_type_info_member = record->other_fields[0]->type;
|
||||
t_type_info_member_ptr = make_type_pointer(c->allocator, t_type_info_member);
|
||||
|
||||
GB_ASSERT_MSG(record->field_count == 16, "Internal Compiler Error: Invalid `Type_Info` layout");
|
||||
t_type_info_named = record->fields[ 1]->type;
|
||||
t_type_info_integer = record->fields[ 2]->type;
|
||||
t_type_info_float = record->fields[ 3]->type;
|
||||
t_type_info_string = record->fields[ 4]->type;
|
||||
t_type_info_boolean = record->fields[ 5]->type;
|
||||
t_type_info_pointer = record->fields[ 6]->type;
|
||||
t_type_info_procedure = record->fields[ 7]->type;
|
||||
t_type_info_array = record->fields[ 8]->type;
|
||||
t_type_info_slice = record->fields[ 9]->type;
|
||||
t_type_info_vector = record->fields[10]->type;
|
||||
t_type_info_tuple = record->fields[11]->type;
|
||||
t_type_info_struct = record->fields[12]->type;
|
||||
t_type_info_union = record->fields[13]->type;
|
||||
t_type_info_raw_union = record->fields[14]->type;
|
||||
t_type_info_enum = record->fields[15]->type;
|
||||
}
|
||||
|
||||
check_global_entity(c, Entity_Constant);
|
||||
check_global_entity(c, Entity_Procedure);
|
||||
check_global_entity(c, Entity_Variable);
|
||||
|
||||
@@ -388,6 +388,8 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
|
||||
CheckerContext old_context = c->context;
|
||||
c->context.scope = decl->scope;
|
||||
c->context.decl = decl;
|
||||
defer (c->context = old_context);
|
||||
|
||||
|
||||
GB_ASSERT(type->kind == Type_Proc);
|
||||
if (type->Proc.param_count > 0) {
|
||||
@@ -431,7 +433,8 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
|
||||
}
|
||||
pop_procedure(c);
|
||||
|
||||
c->context = old_context;
|
||||
|
||||
check_scope_usage(c, c->context.scope);
|
||||
}
|
||||
|
||||
void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
|
||||
@@ -1211,6 +1214,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
Type *tag_ptr_type = make_type_pointer(c->allocator, tag_type);
|
||||
Entity *tag_var = make_entity_variable(c->allocator, c->context.scope, ms->var->Ident, tag_ptr_type);
|
||||
add_entity(c, c->context.scope, ms->var, tag_var);
|
||||
add_entity_use(&c->info, ms->var, tag_var);
|
||||
}
|
||||
check_stmt_list(c, cc->stmts, mod_flags);
|
||||
check_close_scope(c);
|
||||
|
||||
@@ -759,7 +759,7 @@ Selection lookup_field(Type *type_, String field_name, b32 is_type, Selection se
|
||||
if (entity__string_data == NULL) {
|
||||
Token token = {Token_Identifier};
|
||||
token.string = data_str;
|
||||
entity__string_data = make_entity_field(a, NULL, token, make_type_pointer(a, t_byte), false, 0);
|
||||
entity__string_data = make_entity_field(a, NULL, token, make_type_pointer(a, t_u8), false, 0);
|
||||
}
|
||||
|
||||
if (entity__string_count == NULL) {
|
||||
|
||||
@@ -1258,6 +1258,18 @@ AstNode *parse_operand(AstFile *f, b32 lhs) {
|
||||
expect_token(f, Token_String);
|
||||
}
|
||||
operand = parse_operand(f, lhs);
|
||||
} else if (are_strings_equal(name, make_string("file"))) {
|
||||
Token token = operand->TagExpr.name;
|
||||
token.kind = Token_String;
|
||||
token.string = token.pos.file;
|
||||
return make_basic_lit(f, token);
|
||||
} else if (are_strings_equal(name, make_string("line"))) {
|
||||
Token token = operand->TagExpr.name;
|
||||
token.kind = Token_Integer;
|
||||
char *str = gb_alloc_array(gb_arena_allocator(&f->arena), char, 20);
|
||||
gb_i64_to_str(token.pos.line, str, 10);
|
||||
token.string = make_string(str);
|
||||
return make_basic_lit(f, token);
|
||||
} else {
|
||||
operand->TagExpr.expr = parse_expr(f, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user