mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-19 01:01:31 -07:00
Remove dead code; fix referencing of a type assertion in a selector expression
This commit is contained in:
@@ -1354,6 +1354,9 @@ void check_is_expressible(Checker *c, Operand *o, Type *type) {
|
||||
bool check_is_not_addressable(Checker *c, Operand *o) {
|
||||
if (o->mode == Addressing_OptionalOk) {
|
||||
AstNode *expr = unparen_expr(o->expr);
|
||||
while (expr->kind == AstNode_SelectorExpr) {
|
||||
expr = expr->SelectorExpr.selector;
|
||||
}
|
||||
if (expr->kind != AstNode_TypeAssertion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+13
-48
@@ -210,41 +210,6 @@ void check_struct_fields(Checker *c, AstNode *node, Array<Entity *> *fields, Arr
|
||||
}
|
||||
|
||||
|
||||
// TODO(bill): Cleanup struct field reordering
|
||||
// TODO(bill): Inline sorting procedure?
|
||||
GB_COMPARE_PROC(cmp_reorder_struct_fields) {
|
||||
// Rule:
|
||||
// 'using' over non-'using'
|
||||
// Biggest to smallest alignment
|
||||
// if same alignment: biggest to smallest size
|
||||
// if same size: order by source order
|
||||
Entity *x = *(Entity **)a;
|
||||
Entity *y = *(Entity **)b;
|
||||
GB_ASSERT(x != nullptr);
|
||||
GB_ASSERT(y != nullptr);
|
||||
GB_ASSERT(x->kind == Entity_Variable);
|
||||
GB_ASSERT(y->kind == Entity_Variable);
|
||||
bool xu = (x->flags & EntityFlag_Using) != 0;
|
||||
bool yu = (y->flags & EntityFlag_Using) != 0;
|
||||
i64 xa = type_align_of(heap_allocator(), x->type);
|
||||
i64 ya = type_align_of(heap_allocator(), y->type);
|
||||
i64 xs = type_size_of(heap_allocator(), x->type);
|
||||
i64 ys = type_size_of(heap_allocator(), y->type);
|
||||
|
||||
if (xu != yu) {
|
||||
return xu ? -1 : +1;
|
||||
}
|
||||
|
||||
if (xa != ya) {
|
||||
return xa > ya ? -1 : xa < ya;
|
||||
}
|
||||
if (xs != ys) {
|
||||
return xs > ys ? -1 : xs < ys;
|
||||
}
|
||||
i32 diff = x->Variable.field_index - y->Variable.field_index;
|
||||
return diff < 0 ? -1 : diff > 0;
|
||||
}
|
||||
|
||||
Entity *make_names_field_for_struct(Checker *c, Scope *scope) {
|
||||
Entity *e = make_entity_field(c->allocator, scope,
|
||||
make_token_ident(str_lit("names")), t_string_slice, false, 0);
|
||||
@@ -428,12 +393,12 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, Array<Opera
|
||||
if (type_expr->TypeType.specialization != nullptr) {
|
||||
AstNode *s = type_expr->TypeType.specialization;
|
||||
specialization = check_type(c, s);
|
||||
if (false && !is_type_polymorphic_struct(specialization)) {
|
||||
gbString str = type_to_string(specialization);
|
||||
defer (gb_string_free(str));
|
||||
error(s, "Expected a polymorphic struct, got %s", str);
|
||||
specialization = nullptr;
|
||||
}
|
||||
// if (!is_type_polymorphic_struct(specialization)) {
|
||||
// gbString str = type_to_string(specialization);
|
||||
// defer (gb_string_free(str));
|
||||
// error(s, "Expected a polymorphic struct, got %s", str);
|
||||
// specialization = nullptr;
|
||||
// }
|
||||
}
|
||||
type = make_type_generic(c->allocator, c->context.scope, 0, str_lit(""), specialization);
|
||||
} else {
|
||||
@@ -1667,7 +1632,7 @@ bool check_procedure_type(Checker *c, Type *type, AstNode *proc_type_node, Array
|
||||
type->Proc.results = results;
|
||||
type->Proc.result_count = cast(i32)result_count;
|
||||
type->Proc.variadic = variadic;
|
||||
type->Proc.variadic_index = variadic_index;
|
||||
type->Proc.variadic_index = cast(i32)variadic_index;
|
||||
type->Proc.calling_convention = cc;
|
||||
type->Proc.is_polymorphic = pt->generic;
|
||||
type->Proc.specialization_count = specialization_count;
|
||||
@@ -1936,12 +1901,12 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
||||
|
||||
AstNode *s = pt->specialization;
|
||||
specific = check_type(c, s);
|
||||
if (false && !is_type_polymorphic_struct(specific)) {
|
||||
gbString str = type_to_string(specific);
|
||||
error(s, "Expected a polymorphic struct, got %s", str);
|
||||
gb_string_free(str);
|
||||
specific = nullptr;
|
||||
}
|
||||
// if (!is_type_polymorphic_struct(specific)) {
|
||||
// gbString str = type_to_string(specific);
|
||||
// error(s, "Expected a polymorphic struct, got %s", str);
|
||||
// gb_string_free(str);
|
||||
// specific = nullptr;
|
||||
// }
|
||||
}
|
||||
Type *t = make_type_generic(c->allocator, c->context.scope, 0, token.string, specific);
|
||||
if (c->context.allow_polymorphic_types) {
|
||||
|
||||
+1
-3
@@ -39,7 +39,7 @@ void scope_reset(Scope *scope) {
|
||||
}
|
||||
|
||||
i32 is_scope_an_ancestor(Scope *parent, Scope *child) {
|
||||
isize i = 0;
|
||||
i32 i = 0;
|
||||
while (child != nullptr) {
|
||||
if (parent == child) {
|
||||
return i;
|
||||
@@ -612,8 +612,6 @@ void init_checker(Checker *c, Parser *parser) {
|
||||
if (global_error_collector.count > 0) {
|
||||
gb_exit(1);
|
||||
}
|
||||
BuildContext *bc = &build_context;
|
||||
|
||||
gbAllocator a = heap_allocator();
|
||||
|
||||
c->parser = parser;
|
||||
|
||||
@@ -1789,8 +1789,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
case Token_OpenBracket: {
|
||||
Token token = expect_token(f, Token_OpenBracket);
|
||||
AstNode *count_expr = nullptr;
|
||||
bool is_vector = false;
|
||||
|
||||
if (f->curr_token.kind == Token_Question) {
|
||||
count_expr = ast_unary_expr(f, expect_token(f, Token_Question), nullptr);
|
||||
} else if (allow_token(f, Token_dynamic)) {
|
||||
@@ -1887,7 +1885,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) {
|
||||
Token token = expect_token(f, Token_union);
|
||||
Token open = expect_token_after(f, Token_OpenBrace, "union");
|
||||
auto variants = array_make<AstNode *>(heap_allocator());
|
||||
isize total_decl_name_count = 0;
|
||||
AstNode *align = nullptr;
|
||||
|
||||
CommentGroup docs = f->lead_comment;
|
||||
@@ -2143,7 +2140,6 @@ AstNode *parse_atom_expr(AstFile *f, AstNode *operand, bool lhs) {
|
||||
f->curr_token.kind != Token_HalfClosed) {
|
||||
indices[0] = parse_expr(f, false);
|
||||
}
|
||||
bool is_index = true;
|
||||
|
||||
if ((f->curr_token.kind == Token_Ellipsis ||
|
||||
f->curr_token.kind == Token_HalfClosed)) {
|
||||
@@ -2889,7 +2885,6 @@ AstNode *parse_struct_field_list(AstFile *f, isize *name_count_) {
|
||||
}
|
||||
|
||||
AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, TokenKind follow, bool allow_default_parameters, bool allow_type_token) {
|
||||
TokenKind separator = Token_Comma;
|
||||
Token start_token = f->curr_token;
|
||||
|
||||
CommentGroup docs = f->lead_comment;
|
||||
|
||||
@@ -128,7 +128,6 @@ enum TimingUnit {
|
||||
char const *timing_unit_strings[TimingUnit_COUNT] = {"s", "ms", "us"};
|
||||
|
||||
f64 time_stamp(TimeStamp const &ts, u64 freq, TimingUnit unit) {
|
||||
f64 total_time = 0;
|
||||
switch (unit) {
|
||||
case TimingUnit_Millisecond: return time_stamp_as_ms(ts, freq);
|
||||
case TimingUnit_Microsecond: return time_stamp_as_us(ts, freq);
|
||||
|
||||
+1
-1
@@ -2245,7 +2245,7 @@ i64 type_offset_of(gbAllocator allocator, Type *t, i32 index) {
|
||||
case 3: return 3*build_context.word_size; // allocator
|
||||
}
|
||||
} else if (t->kind == Type_Union) {
|
||||
i64 s = type_size_of(allocator, t);
|
||||
/* i64 s = */ type_size_of(allocator, t);
|
||||
switch (index) {
|
||||
case -1: return align_formula(t->Union.variant_block_size, build_context.word_size); // __type_info
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user