[gi-docgen/derived-implements: 1/5] gir: Resolve each interface implementation




commit a57bdb977b60584763b7167ed366ba49a54fda06
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Oct 18 00:13:53 2021 +0100

    gir: Resolve each interface implementation
    
    We want to know the classes that implement an interface within the
    current namespace.

 gidocgen/gir/ast.py    | 13 +++++++++++++
 gidocgen/gir/parser.py |  3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/gidocgen/gir/ast.py b/gidocgen/gir/ast.py
index 4382941..dda2d16 100644
--- a/gidocgen/gir/ast.py
+++ b/gidocgen/gir/ast.py
@@ -514,6 +514,7 @@ class Interface(Type):
         self.functions: T.List[Function] = []
         self.fields: T.List[Field] = []
         self.prerequisite: T.Optional[str] = None
+        self.implementations: T.List[Type] = []
 
     @property
     def type_struct(self) -> T.Optional[str]:
@@ -1139,6 +1140,18 @@ class Repository:
                 symbols[m.identifier] = union
         self.namespace._symbols = symbols
 
+    def resolve_interface_implementations(self) -> None:
+        seen_impls = {}
+        for iface in self.namespace.get_interfaces():
+            for cls in self.namespace.get_classes():
+                if cls.implements is None:
+                    continue
+                if iface in cls.implements:
+                    seen_impls.setdefault(iface.name, []).append(cls)
+        for iface, seen in seen_impls.items():
+            if iface in self.namespace._interfaces:
+                self.namespace._interfaces[iface].implementations = seen
+
     def get_class_hierarchy(self, root=None):
         flat_tree = []
         seen_types = {}
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index 0d4bd86..31be618 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -96,10 +96,11 @@ class GirParser:
                 repository.girfile = girfile.name
             self._repository = repository
             self._repository.resolve_empty_ctypes(self._seen_types)
-            self._repository.resolve_interface_requires()
             self._repository.resolve_class_type()
             self._repository.resolve_class_implements()
             self._repository.resolve_class_ancestors()
+            self._repository.resolve_interface_requires()
+            self._repository.resolve_interface_implementations()
             self._repository.resolve_moved_to()
             self._repository.resolve_symbols()
 


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