From f6d650d47351ba71d4df9049436c9e8a506578b7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 2 Mar 2020 21:15:21 +0900 Subject: [PATCH] [qfcc] Merge duplicate methods in interfaces Duplicate methods in an interface (especially across protocols and between protocols and the interface) are both harmless and even to be expected. They certainly should not cause the compiler to demand duplicate method implementations :) --- tools/qfcc/source/class.c | 9 +++------ tools/qfcc/source/method.c | 6 ++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/qfcc/source/class.c b/tools/qfcc/source/class.c index 381b37e1e..e4861b8d2 100644 --- a/tools/qfcc/source/class.c +++ b/tools/qfcc/source/class.c @@ -631,8 +631,7 @@ class_add_methods (class_t *class, methodlist_t *methods) if (!methods) return; - *class->methods->tail = methods->head; - class->methods->tail = methods->tail; + copy_methods (class->methods, methods); free (methods); methods_set_self_type (class, class->methods); @@ -1260,8 +1259,7 @@ category_add_methods (category_t *category, methodlist_t *methods) { if (!methods) return; - *category->methods->tail = methods->head; - category->methods->tail = methods->tail; + copy_methods (category->methods, methods); free (methods); methods_set_self_type (category->class, category->methods); @@ -1520,8 +1518,7 @@ protocol_add_methods (protocol_t *protocol, methodlist_t *methods) { if (!methods) return; - *protocol->methods->tail = methods->head; - protocol->methods->tail = methods->tail; + copy_methods (protocol->methods, methods); free (methods); } diff --git a/tools/qfcc/source/method.c b/tools/qfcc/source/method.c index 2ae50f39d..4bc819621 100644 --- a/tools/qfcc/source/method.c +++ b/tools/qfcc/source/method.c @@ -147,6 +147,12 @@ add_method (methodlist_t *methodlist, method_t *method) if (method->next) internal_error (0, "add_method: method loop detected"); + for (method_t *m = methodlist->head; m; m = m->next) { + if (method_compare (m, method)) { + debug (0, "dropping duplicate method: %s", method->name); + return; + } + } *methodlist->tail = method; methodlist->tail = &method->next; }