commit e6e8f8824d2d9eb8388e5580ae630c1bcadac90e
parent 5e962deb4ad7827c31cfb9b297895677c8c6d9ae
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 12 Jan 2021 12:08:29 -0500
s/identifier_eq/identifier_cmp/g
Finishes up the work from the last commit
Diffstat:
4 files changed, 12 insertions(+), 16 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);
-bool identifier_eq(const struct identifier *a, const struct identifier *b);
+int identifier_cmp(const struct identifier *a, const struct identifier *b);
#endif
diff --git a/src/identifier.c b/src/identifier.c
@@ -71,16 +71,17 @@ identifier_dup(struct identifier *new, const struct identifier *ident)
}
}
-bool
-identifier_eq(const struct identifier *a, const struct identifier *b)
+int
+identifier_cmp(const struct identifier *a, const struct identifier *b)
{
if (!a && !b) {
- return true;
- } else if ((!a && b) || (a && !b)) {
- return false;
+ return 0;
+ } else if (!!a != !!b) {
+ return a ? 1 : b ? -1 : 0;
}
- if (strcmp(a->name, b->name) != 0) {
- return false;
+ int c;
+ if ((c = strcmp(a->name, b->name)) != 0) {
+ return c;
}
- return identifier_eq(a->ns, b->ns);
+ return identifier_cmp(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_eq(&o->name, ident)) {
+ if (identifier_cmp(&o->name, ident) == 0) {
return o;
}
o = o->next;
diff --git a/src/type_store.c b/src/type_store.c
@@ -401,12 +401,7 @@ type_cmp(const struct type *a, const struct type *b)
case TYPE_STORAGE_STRING:
return 0;
case TYPE_STORAGE_ALIAS:
- // TODO: Relative comparison
- if (!identifier_eq(&a->alias.ident, &b->alias.ident)) {
- return 1;
- }
- assert(type_cmp(a->alias.type, b->alias.type) == 0);
- return 0;
+ 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;