[gi-docgen/link-fixes: 2/3] gir: Mark fundamental C types
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gi-docgen/link-fixes: 2/3] gir: Mark fundamental C types
- Date: Sat, 25 Sep 2021 15:41:39 +0000 (UTC)
commit 5322689c4f55cfc4cf5a4ac01ec751a987c8f13c
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sat Sep 25 16:27:31 2021 +0100
gir: Mark fundamental C types
Types like "gint", "gboolean", or "gdouble" should be marked as such, so
we can detect them when traversing the AST.
gidocgen/gir/ast.py | 11 +++++++++--
gidocgen/gir/parser.py | 7 +++++--
2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/gidocgen/gir/ast.py b/gidocgen/gir/ast.py
index ef5133c..53a93ed 100644
--- a/gidocgen/gir/ast.py
+++ b/gidocgen/gir/ast.py
@@ -162,9 +162,10 @@ class GIRElement:
class Type(GIRElement):
"""Base class for all Type nodes"""
- def __init__(self, name: str, ctype: T.Optional[str] = None, namespace: T.Optional[str] = None):
+ def __init__(self, name: str, ctype: T.Optional[str] = None, namespace: T.Optional[str] = None,
is_fundamental: bool = False):
super().__init__(name=name, namespace=namespace)
self.ctype = ctype
+ self.is_fundamental = is_fundamental
def __eq__(self, other):
if isinstance(other, Type):
@@ -199,7 +200,9 @@ class Type(GIRElement):
@property
def fqtn(self):
- if '.' in self.name:
+ if self.is_fundamental:
+ return self.name
+ elif '.' in self.name:
return self.name
elif self.namespace is not None:
return f"{self.namespace}.{self.name}"
@@ -217,6 +220,7 @@ class ArrayType(GIRElement):
self.fixed_size = fixed_size
self.length = length
self.value_type = value_type
+ self.is_fundamental = False
class ListType(GIRElement):
@@ -225,6 +229,7 @@ class ListType(GIRElement):
super().__init__(name)
self.ctype = ctype
self.value_type = value_type
+ self.is_fundamental = False
class MapType(GIRElement):
@@ -234,6 +239,7 @@ class MapType(GIRElement):
self.ctype = ctype
self.key_type = key_type
self.value_type = value_type
+ self.is_fundamental = False
class GType:
@@ -389,6 +395,7 @@ class Callback(Callable):
def __init__(self, name: str, namespace: str, ctype: T.Optional[str], throws: bool = False):
super().__init__(name=name, namespace=namespace, identifier=None, throws=throws)
self.ctype = ctype
+ self.is_fundamental = False
@property
def base_ctype(self):
diff --git a/gidocgen/gir/parser.py b/gidocgen/gir/parser.py
index bf303be..076995d 100644
--- a/gidocgen/gir/parser.py
+++ b/gidocgen/gir/parser.py
@@ -119,15 +119,18 @@ class GirParser:
def _lookup_type(self, name: str, ctype: T.Optional[str] = None) -> ast.Type:
"""Look up a type, and if not found, register it"""
+ is_fundamental = False
if name in FUNDAMENTAL_TYPES:
if name in GLIB_ALIASES:
fqtn = GLIB_ALIASES[name]
else:
fqtn = name
+ is_fundamental = True
elif name == 'GType':
# This is messy, because GType is part of GObject, but GLib ends up
# registering it first
fqtn = 'GObject.Type'
+ is_fundamental = True
elif '.' in name:
fqtn = name
else:
@@ -151,14 +154,14 @@ class GirParser:
if t.resolved and t.ctype == ctype:
log.debug(f"Found seen type: {t} (with ctype)")
return t
- t = ast.Type(name=fqtn, ctype=ctype)
+ t = ast.Type(name=fqtn, ctype=ctype, is_fundamental=is_fundamental)
found_types.append(t)
log.debug(f"Seen new type: {t} (with ctype)")
return t
log.debug(f"Found seen type: {found_types[0]}")
return found_types[0]
# First time we saw this type
- res = ast.Type(name=fqtn, ctype=ctype)
+ res = ast.Type(name=fqtn, ctype=ctype, is_fundamental=is_fundamental)
self._seen_types[fqtn] = [res]
log.debug(f"Seen new type: {res}")
return res
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]