mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Remove auto
This commit is contained in:
+1
-17
@@ -473,22 +473,6 @@ Entity *scope_insert_entity(Scope *s, Entity *entity) {
|
||||
|
||||
void check_scope_usage(Checker *c, Scope *scope) {
|
||||
// TODO(bill): Use this?
|
||||
#if 0
|
||||
for_array(i, scope->elements.entries) {
|
||||
auto *entry = scope->elements.entries + i;
|
||||
Entity *e = entry->value;
|
||||
if (e->kind == Entity_Variable) {
|
||||
auto *v = &e->Variable;
|
||||
if (!v->is_field && !v->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
|
||||
}
|
||||
|
||||
|
||||
@@ -961,7 +945,7 @@ void init_preload_types(Checker *c) {
|
||||
t_type_info = e->type;
|
||||
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
|
||||
GB_ASSERT(is_type_union(e->type));
|
||||
auto *record = &base_type(e->type)->Record;
|
||||
TypeRecord *record = &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);
|
||||
|
||||
@@ -74,7 +74,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra
|
||||
if (o.type->kind != Type_Tuple) {
|
||||
array_add(&operands, o);
|
||||
} else {
|
||||
auto *tuple = &o.type->Tuple;
|
||||
TypeTuple *tuple = &o.type->Tuple;
|
||||
for (isize j = 0; j < tuple->variable_count; j++) {
|
||||
o.type = tuple->variables[j]->type;
|
||||
array_add(&operands, o);
|
||||
@@ -315,8 +315,8 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def, Cycle
|
||||
bool are_signatures_similar_enough(Type *a_, Type *b_) {
|
||||
GB_ASSERT(a_->kind == Type_Proc);
|
||||
GB_ASSERT(b_->kind == Type_Proc);
|
||||
auto *a = &a_->Proc;
|
||||
auto *b = &b_->Proc;
|
||||
TypeProc *a = &a_->Proc;
|
||||
TypeProc *b = &b_->Proc;
|
||||
|
||||
if (a->param_count != b->param_count) {
|
||||
return false;
|
||||
@@ -368,7 +368,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
||||
if ((d->scope->is_file || d->scope->is_global) &&
|
||||
str_eq(e->token.string, str_lit("main"))) {
|
||||
if (proc_type != NULL) {
|
||||
auto *pt = &proc_type->Proc;
|
||||
TypeProc *pt = &proc_type->Proc;
|
||||
if (pt->param_count != 0 ||
|
||||
pt->result_count) {
|
||||
gbString str = type_to_string(proc_type);
|
||||
@@ -402,8 +402,8 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
||||
}
|
||||
|
||||
if (is_foreign) {
|
||||
auto *fp = &c->info.foreign_procs;
|
||||
auto *proc_decl = &d->proc_decl->ProcDecl;
|
||||
MapEntity *fp = &c->info.foreign_procs;
|
||||
AstNodeProcDecl *proc_decl = &d->proc_decl->ProcDecl;
|
||||
String name = proc_decl->name->Ident.string;
|
||||
if (proc_decl->foreign_name.len > 0) {
|
||||
name = proc_decl->foreign_name;
|
||||
@@ -425,8 +425,8 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
|
||||
map_entity_set(fp, key, e);
|
||||
}
|
||||
} else if (is_link_name) {
|
||||
auto *fp = &c->info.foreign_procs;
|
||||
auto *proc_decl = &d->proc_decl->ProcDecl;
|
||||
MapEntity *fp = &c->info.foreign_procs;
|
||||
AstNodeProcDecl *proc_decl = &d->proc_decl->ProcDecl;
|
||||
String name = proc_decl->link_name;
|
||||
|
||||
HashKey key = hash_string(name);
|
||||
@@ -492,7 +492,7 @@ void check_proc_body(Checker *c, Token token, DeclInfo *decl, Type *type, AstNod
|
||||
|
||||
GB_ASSERT(type->kind == Type_Proc);
|
||||
if (type->Proc.param_count > 0) {
|
||||
auto *params = &type->Proc.params->Tuple;
|
||||
TypeTuple *params = &type->Proc.params->Tuple;
|
||||
for (isize i = 0; i < params->variable_count; i++) {
|
||||
Entity *e = params->variables[i];
|
||||
GB_ASSERT(e->kind == Entity_Variable);
|
||||
|
||||
@@ -3401,7 +3401,7 @@ void check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNode
|
||||
if (o.type->kind != Type_Tuple) {
|
||||
array_add(&operands, o);
|
||||
} else {
|
||||
auto *tuple = &o.type->Tuple;
|
||||
TypeTuple *tuple = &o.type->Tuple;
|
||||
if (variadic && i >= param_count) {
|
||||
error(ast_node_token(ce->args.e[i]),
|
||||
"`..` in a variadic procedure cannot be applied to a %td-valued expression", tuple->variable_count);
|
||||
|
||||
@@ -441,7 +441,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
if (o.type->kind != Type_Tuple) {
|
||||
array_add(&operands, o);
|
||||
} else {
|
||||
auto *tuple = &o.type->Tuple;
|
||||
TypeTuple *tuple = &o.type->Tuple;
|
||||
for (isize j = 0; j < tuple->variable_count; j++) {
|
||||
o.type = tuple->variables[j]->type;
|
||||
array_add(&operands, o);
|
||||
@@ -553,7 +553,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
||||
if (result_count > 0) {
|
||||
Entity **variables = NULL;
|
||||
if (proc_type->Proc.results != NULL) {
|
||||
auto *tuple = &proc_type->Proc.results->Tuple;
|
||||
TypeTuple *tuple = &proc_type->Proc.results->Tuple;
|
||||
variables = tuple->variables;
|
||||
}
|
||||
if (rs->results.count == 0) {
|
||||
|
||||
+82
-96
@@ -58,34 +58,6 @@ typedef struct BasicType {
|
||||
String name;
|
||||
} BasicType;
|
||||
|
||||
|
||||
|
||||
#define TYPE_KINDS \
|
||||
TYPE_KIND(Invalid), \
|
||||
TYPE_KIND(Basic), \
|
||||
TYPE_KIND(Pointer), \
|
||||
TYPE_KIND(Array), \
|
||||
TYPE_KIND(Vector), \
|
||||
TYPE_KIND(Slice), \
|
||||
TYPE_KIND(Maybe), \
|
||||
TYPE_KIND(Record), \
|
||||
TYPE_KIND(Named), \
|
||||
TYPE_KIND(Tuple), \
|
||||
TYPE_KIND(Proc), \
|
||||
TYPE_KIND(Count),
|
||||
|
||||
typedef enum TypeKind {
|
||||
#define TYPE_KIND(k, ...) GB_JOIN2(Type_, k)
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
} TypeKind;
|
||||
|
||||
String const type_strings[] = {
|
||||
#define TYPE_KIND(k, ...) {cast(u8 *)#k, gb_size_of(#k)-1}
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
};
|
||||
|
||||
typedef enum TypeRecordKind {
|
||||
TypeRecord_Invalid,
|
||||
|
||||
@@ -97,75 +69,89 @@ typedef enum TypeRecordKind {
|
||||
TypeRecord_Count,
|
||||
} TypeRecordKind;
|
||||
|
||||
typedef struct TypeRecord {
|
||||
TypeRecordKind kind;
|
||||
|
||||
// All record types
|
||||
// Theses are arrays
|
||||
Entity **fields; // Entity_Variable (otherwise Entity_TypeName if union)
|
||||
i32 field_count; // == offset_count is struct
|
||||
AstNode *node;
|
||||
|
||||
union { // NOTE(bill): Reduce size_of Type
|
||||
struct { // enum only
|
||||
Type * enum_base; // Default is `int`
|
||||
Entity * enum_count;
|
||||
Entity * min_value;
|
||||
Entity * max_value;
|
||||
};
|
||||
struct { // struct only
|
||||
i64 * struct_offsets;
|
||||
bool struct_are_offsets_set;
|
||||
bool struct_is_packed;
|
||||
bool struct_is_ordered;
|
||||
Entity **fields_in_src_order; // Entity_Variable
|
||||
};
|
||||
};
|
||||
|
||||
// Entity_Constant or Entity_TypeName
|
||||
Entity **other_fields;
|
||||
i32 other_field_count;
|
||||
} TypeRecord;
|
||||
|
||||
#define TYPE_KINDS \
|
||||
TYPE_KIND(Basic, BasicType) \
|
||||
TYPE_KIND(Pointer, struct { Type *elem; }) \
|
||||
TYPE_KIND(Array, struct { Type *elem; i64 count; }) \
|
||||
TYPE_KIND(Vector, struct { Type *elem; i64 count; }) \
|
||||
TYPE_KIND(Slice, struct { Type *elem; }) \
|
||||
TYPE_KIND(Maybe, struct { Type *elem; }) \
|
||||
TYPE_KIND(Record, TypeRecord) \
|
||||
TYPE_KIND(Named, struct { \
|
||||
String name; \
|
||||
Type * base; \
|
||||
Entity *type_name; /* Entity_TypeName */ \
|
||||
}) \
|
||||
TYPE_KIND(Tuple, struct { \
|
||||
Entity **variables; /* Entity_Variable */ \
|
||||
i32 variable_count; \
|
||||
bool are_offsets_set; \
|
||||
i64 * offsets; \
|
||||
}) \
|
||||
TYPE_KIND(Proc, struct { \
|
||||
Scope *scope; \
|
||||
Type * params; /* Type_Tuple */ \
|
||||
Type * results; /* Type_Tuple */ \
|
||||
i32 param_count; \
|
||||
i32 result_count; \
|
||||
bool variadic; \
|
||||
})
|
||||
|
||||
typedef enum TypeKind {
|
||||
Type_Invalid,
|
||||
#define TYPE_KIND(k, ...) GB_JOIN2(Type_, k),
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
Type_Count,
|
||||
} TypeKind;
|
||||
|
||||
String const type_strings[] = {
|
||||
{cast(u8 *)"Invalid", gb_size_of("Invalid")},
|
||||
#define TYPE_KIND(k, ...) {cast(u8 *)#k, gb_size_of(#k)-1},
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
};
|
||||
|
||||
#define TYPE_KIND(k, ...) typedef __VA_ARGS__ GB_JOIN2(Type, k);
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
|
||||
typedef struct Type {
|
||||
TypeKind kind;
|
||||
union {
|
||||
BasicType Basic;
|
||||
struct {
|
||||
Type *elem;
|
||||
} Pointer;
|
||||
struct {
|
||||
Type *elem;
|
||||
i64 count;
|
||||
} Array;
|
||||
struct {
|
||||
Type *elem;
|
||||
i64 count;
|
||||
} Vector;
|
||||
struct {
|
||||
Type *elem;
|
||||
} Slice;
|
||||
struct {
|
||||
Type *elem;
|
||||
} Maybe;
|
||||
struct {
|
||||
TypeRecordKind kind;
|
||||
|
||||
// All record types
|
||||
// Theses are arrays
|
||||
Entity **fields; // Entity_Variable (otherwise Entity_TypeName if union)
|
||||
i32 field_count; // == offset_count is struct
|
||||
AstNode *node;
|
||||
|
||||
union { // NOTE(bill): Reduce size_of Type
|
||||
struct { // enum only
|
||||
Type * enum_base; // Default is `int`
|
||||
Entity * enum_count;
|
||||
Entity * min_value;
|
||||
Entity * max_value;
|
||||
};
|
||||
struct { // struct only
|
||||
i64 * struct_offsets;
|
||||
bool struct_are_offsets_set;
|
||||
bool struct_is_packed;
|
||||
bool struct_is_ordered;
|
||||
Entity **fields_in_src_order; // Entity_Variable
|
||||
};
|
||||
};
|
||||
|
||||
// Entity_Constant or Entity_TypeName
|
||||
Entity **other_fields;
|
||||
i32 other_field_count;
|
||||
} Record;
|
||||
struct {
|
||||
String name;
|
||||
Type * base;
|
||||
Entity *type_name; // Entity_TypeName
|
||||
} Named;
|
||||
struct {
|
||||
Entity **variables; // Entity_Variable
|
||||
i32 variable_count;
|
||||
bool are_offsets_set;
|
||||
i64 * offsets;
|
||||
} Tuple;
|
||||
struct {
|
||||
Scope *scope;
|
||||
Type * params; // Type_Tuple
|
||||
Type * results; // Type_Tuple
|
||||
i32 param_count;
|
||||
i32 result_count;
|
||||
bool variadic;
|
||||
} Proc;
|
||||
#define TYPE_KIND(k, ...) GB_JOIN2(Type, k) k;
|
||||
TYPE_KINDS
|
||||
#undef TYPE_KIND
|
||||
};
|
||||
} Type;
|
||||
|
||||
@@ -186,9 +172,9 @@ typedef Array(isize) Array_isize;
|
||||
typedef struct Selection {
|
||||
Entity * entity;
|
||||
Array_isize index;
|
||||
bool indirect; // Set if there was a pointer deref anywhere down the line
|
||||
bool indirect; // Set if there was a pointer deref anywhere down the line
|
||||
} Selection;
|
||||
Selection empty_selection = {};
|
||||
Selection empty_selection = {0};
|
||||
|
||||
Selection make_selection(Entity *entity, Array_isize index, bool indirect) {
|
||||
Selection s = {entity, index, indirect};
|
||||
|
||||
Reference in New Issue
Block a user