From 847912ca98c33c941517f3b8e864c87264628b7b Mon Sep 17 00:00:00 2001 From: Kwabena N Amponsah Date: Sat, 21 Sep 2024 19:57:00 +0000 Subject: [PATCH] #12 Document class sorting --- cppwg/input/module_info.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cppwg/input/module_info.py b/cppwg/input/module_info.py index f21831f..03bc3eb 100644 --- a/cppwg/input/module_info.py +++ b/cppwg/input/module_info.py @@ -80,7 +80,8 @@ def is_decl_in_source_path(self, decl: "declaration_t") -> bool: # noqa: F821 def sort_classes(self) -> None: """Sort the class info collection in inheritance order.""" - def compare(class_info_0, class_info_1): + def compare(class_info_0: "ClassInfo", class_info_1: "ClassInfo"): + # Sort classes with no declarations to the bottom if class_info_0.decls == class_info_1.decls: return 0 if class_info_0.decls is None: @@ -88,6 +89,7 @@ def compare(class_info_0, class_info_1): if class_info_1.decls is None: return -1 + # Get the base classes for each class bases_0 = [ base.related_class for decl in class_info_0.decls for base in decl.bases ] @@ -95,7 +97,10 @@ def compare(class_info_0, class_info_1): base.related_class for decl in class_info_1.decls for base in decl.bases ] + # 1 if class_0 is a child of class_1 child_0 = int(any(base in class_info_1.decls for base in bases_0)) + + # 1 if class_1 is a child of class 0 child_1 = int(any(base in class_info_0.decls for base in bases_1)) return child_0 - child_1