harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fa2070af209e9ed255f2d321a6e2d46f47a25fad
parent baa263225dfba47e1fa987e3f9c2ba88fd79e2e3
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 14 Jan 2021 09:47:31 -0500

type store: revert type sort order support

We are going to change the specification to not require this.

This reverts commit e6e8f8824d2d9eb8388e5580ae630c1bcadac90e.
This reverts commit 5e962deb4ad7827c31cfb9b297895677c8c6d9ae.

Diffstat:
Minclude/identifier.h | 2+-
Msrc/identifier.c | 17++++++++---------
Msrc/scope.c | 2+-
Msrc/type_store.c | 72+++++++++++++++++++++++++++++++++---------------------------------------
4 files changed, 43 insertions(+), 50 deletions(-)

diff --git a/include/identifier.h b/include/identifier.h @@ -12,6 +12,6 @@ char *identifier_unparse(const struct identifier *ident); int identifier_unparse_static( const struct identifier *ident, char *buf, size_t len); void identifier_dup(struct identifier *new, const struct identifier *ident); -int identifier_cmp(const struct identifier *a, const struct identifier *b); +bool identifier_eq(const struct identifier *a, const struct identifier *b); #endif diff --git a/src/identifier.c b/src/identifier.c @@ -71,17 +71,16 @@ identifier_dup(struct identifier *new, const struct identifier *ident) } } -int -identifier_cmp(const struct identifier *a, const struct identifier *b) +bool +identifier_eq(const struct identifier *a, const struct identifier *b) { if (!a && !b) { - return 0; - } else if (!!a != !!b) { - return a ? 1 : b ? -1 : 0; + return true; + } else if ((!a && b) || (a && !b)) { + return false; } - int c; - if ((c = strcmp(a->name, b->name)) != 0) { - return c; + if (strcmp(a->name, b->name) != 0) { + return false; } - return identifier_cmp(a->ns, b->ns); + return identifier_eq(a->ns, b->ns); } diff --git a/src/scope.c b/src/scope.c @@ -86,7 +86,7 @@ scope_lookup(struct scope *scope, const struct identifier *ident) { struct scope_object *o = scope->objects; while (o) { - if (identifier_cmp(&o->name, ident) == 0) { + if (identifier_eq(&o->name, ident)) { return o; } o = o->next; diff --git a/src/type_store.c b/src/type_store.c @@ -374,17 +374,17 @@ builtin_for_type(const struct type *type) return builtin_type_for_storage(type->storage, is_const); } -static int -type_cmp(const struct type *a, const struct type *b) +static bool +type_eq_type(struct type_store *store, + const struct type *a, const struct type *b) { if (a == b) { - return 0; + return true; } - if (a->storage != b->storage) { - return a->storage - b->storage; + if (a->storage != b->storage || a->flags != b->flags) { + return false; } - int c; switch (a->storage) { case TYPE_STORAGE_BOOL: case TYPE_STORAGE_CHAR: @@ -406,47 +406,41 @@ type_cmp(const struct type *a, const struct type *b) case TYPE_STORAGE_UINTPTR: case TYPE_STORAGE_VOID: case TYPE_STORAGE_STRING: - return 0; + return true; case TYPE_STORAGE_ALIAS: - return identifier_cmp(&a->alias.ident, &b->alias.ident); - case TYPE_STORAGE_ARRAY: - if (a->array.length != b->array.length) { - return a->array.length - b->array.length; - } - if (a->array.expandable != b->array.expandable) { - return a->array.expandable - b->array.expandable; + if (!identifier_eq(&a->alias.ident, &b->alias.ident)) { + return false; } - return type_cmp(a->array.members, b->array.members); + assert(type_eq_type(store, a->alias.type, b->alias.type)); + return true; + case TYPE_STORAGE_ARRAY: + return a->array.length == b->array.length + && a->array.expandable == b->array.expandable + && type_eq_type(store, a->array.members, b->array.members); case TYPE_STORAGE_ENUM: assert(0); // TODO case TYPE_STORAGE_FUNCTION: - if (a->func.variadism != b->func.variadism) { - return a->func.variadism - b->func.variadism; - } - if (a->func.flags != b->func.flags) { - return a->func.flags - b->func.flags; - } - if ((c = type_cmp(a->func.result, b->func.result)) != 0) { - return c; + if (a->func.variadism != b->func.variadism + || a->func.flags != b->func.flags + || !type_eq_type(store, a->func.result, b->func.result)) { + return false; } struct type_func_param *aparam = a->func.params; struct type_func_param *bparam = b->func.params; while (aparam && bparam) { - if ((c = type_cmp(aparam->type, bparam->type)) != 0) { - return c; + if (!type_eq_type(store, aparam->type, bparam->type)) { + return false; } aparam = aparam->next; bparam = bparam->next; } - return aparam ? 1 : bparam ? -1 : 0; + return !aparam && !bparam; case TYPE_STORAGE_POINTER: - if (a->pointer.flags != b->pointer.flags) { - return a->pointer.flags - b->pointer.flags; - } - return type_cmp(a->pointer.referent, b->pointer.referent); + return a->pointer.flags == b->pointer.flags && + type_eq_type(store, a->pointer.referent, b->pointer.referent); case TYPE_STORAGE_SLICE: - return type_cmp(a->array.members, b->array.members); + return type_eq_type(store, a->array.members, b->array.members); case TYPE_STORAGE_STRUCT: case TYPE_STORAGE_UNION: for (const struct struct_field *afield = a->struct_union.fields, @@ -454,19 +448,19 @@ type_cmp(const struct type *a, const struct type *b) afield && bfield; afield = afield->next, bfield = bfield->next) { if (!!afield->next != !!bfield->next) { - return afield->next ? 1 : bfield->next ? -1 : 0; + return false; } - if ((c = strcmp(afield->name, bfield->name)) != 0) { - return c; + if (strcmp(afield->name, bfield->name) != 0) { + return false; } - if ((c = type_cmp(afield->type, bfield->type)) != 0) { - return c; + if (!type_eq_type(store, afield->type, bfield->type)) { + return false; } if (afield->offset != bfield->offset) { - return afield->offset - bfield->offset; + return false; } } - return 0; + return true; case TYPE_STORAGE_TAGGED_UNION: assert(0); // TODO } @@ -762,7 +756,7 @@ type_store_lookup_type(struct type_store *store, const struct type *type) while (*next) { bucket = *next; - if (type_cmp(&bucket->type, type) == 0) { + if (type_eq_type(store, &bucket->type, type)) { return &bucket->type; } next = &bucket->next;