[gi-docgen/derived-implements: 4/5] gir: Resolve class descendants




commit ce0cddd6ab59cfd277de7dd341e850c524d6937d
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Oct 18 13:16:07 2021 +0100

    gir: Resolve class descendants
    
    Store the direct descendants of each class when resolving the namespace,
    so we can display them later.

 gidocgen/gir/ast.py    | 10 ++++++++++
 gidocgen/gir/parser.py |  1 +
 2 files changed, 11 insertions(+)
---
diff --git a/gidocgen/gir/ast.py b/gidocgen/gir/ast.py
index dda2d16..650b4cc 100644
--- a/gidocgen/gir/ast.py
+++ b/gidocgen/gir/ast.py
@@ -573,6 +573,7 @@ class Class(Type):
         self.functions: T.List[Function] = []
         self.fields: T.List[Field] = []
         self.callbacks: T.List[Callback] = []
+        self.descendants: T.List[Type] = []
 
     @property
     def type_struct(self) -> T.Optional[str]:
@@ -1091,6 +1092,15 @@ class Repository:
             cls.parent = ancestors[0]
             log.debug(f"Ancestors for {cls}: parent: {cls.parent}, ancestors: {cls.ancestors}")
 
+    def resolve_class_descendants(self) -> None:
+        seen_parents = {}
+        for cls in self.namespace.get_classes():
+            if cls.parent is not None:
+                seen_parents.setdefault(cls.parent.name, []).append(cls)
+        for name, descendants in seen_parents.items():
+            if name in self.namespace._classes:
+                self.namespace._classes[name].descendants = descendants
+
     def resolve_moved_to(self) -> None:
         functions = list(self.namespace.get_functions())
         old_len = len(functions)
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index 31be618..cdab096 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -99,6 +99,7 @@ class GirParser:
             self._repository.resolve_class_type()
             self._repository.resolve_class_implements()
             self._repository.resolve_class_ancestors()
+            self._repository.resolve_class_descendants()
             self._repository.resolve_interface_requires()
             self._repository.resolve_interface_implementations()
             self._repository.resolve_moved_to()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]