Sort enum entities; Remove sprint* from fmt.odin

This commit is contained in:
Ginger Bill
2016-09-20 09:33:29 +01:00
parent 59b0cf61ef
commit 31c11a5037
4 changed files with 90 additions and 79 deletions
+21
View File
@@ -541,6 +541,25 @@ void check_raw_union_type(Checker *c, Type *union_type, AstNode *node, CycleChec
union_type->Record.other_field_count = other_field_count;
}
GB_COMPARE_PROC(cmp_enum_order) {
// Rule:
// 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 != NULL);
GB_ASSERT(y != NULL);
GB_ASSERT(x->kind == Entity_Constant);
GB_ASSERT(y->kind == Entity_Constant);
GB_ASSERT(x->Constant.value.kind == ExactValue_Integer);
GB_ASSERT(y->Constant.value.kind == ExactValue_Integer);
i64 i = x->Constant.value.value_integer;
i64 j = y->Constant.value.value_integer;
return i < j ? -1 : i > j;
}
void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *node) {
@@ -640,6 +659,8 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
add_entity_use(&c->info, f->field, e);
}
gb_sort_array(fields, gb_array_count(et->fields), cmp_enum_order);
enum_type->Record.other_fields = fields;
enum_type->Record.other_field_count = gb_array_count(et->fields);