Commit 8075c331 authored by Emmanuele Bassi's avatar Emmanuele Bassi 👣
Browse files

gir: Parse Interface nodes

They are just like classes, only with fewer sections.
parent 7701bab9
......@@ -336,11 +336,12 @@ def run(options):
namespace = repository.get_namespace()
shlibs = ', '.join(namespace.get_shared_libraries())
classes = sorted(namespace.get_classes(), key=lambda cls: cls.name.lower())
aliases = sorted(namespace.get_aliases(), key=lambda alias: alias.name.lower())
classes = sorted(namespace.get_classes(), key=lambda cls: cls.name.lower())
constants = sorted(namespace.get_constants(), key=lambda const: const.name.lower())
enums = sorted(namespace.get_enumerations(), key=lambda enum: enum.name.lower())
domains = sorted(namespace.get_error_domains(), key=lambda domain: domain.name.lower())
enums = sorted(namespace.get_enumerations(), key=lambda enum: enum.name.lower())
interfaces = sorted(namespace.get_interfaces(), key=lambda interface: interface.name.lower())
title = str(log.color('Namespace', 36))
log.log(f'└── {title}: {namespace.name}, version: {namespace.version}')
......@@ -387,6 +388,42 @@ def run(options):
sections.remove('functions')
_print_class_functions(cls, sections, is_last_class)
title = str(log.color('Interfaces', 36))
log.log(f' ├── {title}')
if len(interfaces) == 0:
log.log( ' │ └── None')
else:
for i, iface in enumerate(interfaces):
is_last_iface = i == len(interfaces) - 1
if is_last_iface:
log.log(f' │ └── {iface.name}')
else:
log.log(f' │ ├── {iface.name}')
sections = []
if iface.properties:
sections += ['properties']
if iface.signals:
sections += ['signals']
if iface.methods:
sections += ['methods']
if iface.functions:
sections += ['functions']
if 'properties' in sections:
sections.remove('properties')
_print_class_properties(iface, sections, is_last_iface)
if 'signals' in sections:
sections.remove('signals')
_print_class_signals(iface, sections, is_last_iface)
if 'methods' in sections:
sections.remove('methods')
_print_class_methods(iface, sections, is_last_iface)
if 'functions' in sections:
sections.remove('functions')
_print_class_functions(cls, sections, is_last_iface)
title = str(log.color('Aliases', 36))
log.log(f' ├── {title}')
......
......@@ -178,6 +178,29 @@ class Class(Type):
self.functions.extend(functions)
class Interface(Type):
def __init__(self, name: str, ctype: str, symbol_prefix: str, gtype: GType):
super().__init__(name, ctype)
self.symbol_prefix = symbol_prefix
self.gtype = gtype
self.methods = []
self.properties = []
self.signals = []
self.functions = []
def set_methods(self, methods: T.List[Method]) -> None:
self.methods.extend(methods)
def set_properties(self, properties: T.List[Property]) -> None:
self.properties.extend(properties)
def set_signals(self, signals: T.List[Signal]) -> None:
self.signals.extend(signals)
def set_functions(self, functions: T.List[Function]) -> None:
self.functions.extend(functions)
class EnumerationMember(GIRElement):
def __init__(self, name: str, value: str, identifier: str, nick: str):
super().__init__()
......@@ -222,12 +245,14 @@ class Namespace:
self._shared_libraries = []
self._aliases = []
self._boxed = []
self._classes = []
self._constants = []
self._enumerations = []
self._error_domains = []
self._classes = []
self._records = []
self._functions = []
self._interfaces = []
self._records = []
def __str__(self):
return f"{self.name}-{self.version}"
......@@ -253,6 +278,9 @@ class Namespace:
def add_constant(self, constant: Constant) -> None:
self._constants.append(constant)
def add_interface(self, interface: Interface) -> None:
self._interfaces.append(interface)
def get_classes(self) -> T.List[Class]:
return self._classes
......@@ -268,6 +296,9 @@ class Namespace:
def get_aliases(self) -> T.List[Alias]:
return self._aliases
def get_interfaces(self) -> T.List[Interface]:
return self._interfaces
class Include:
def __init__(self, name: str, version: str):
......
......@@ -82,10 +82,11 @@ class GirParser:
repository.add_namespace(namespace)
parse_methods = {
_corens('class'): self._parse_class,
_corens('alias'): self._parse_alias,
_corens('class'): self._parse_class,
_corens('constant'): self._parse_constant,
_corens('enumeration'): self._parse_enumeration,
_corens('interface'): self._parse_interface,
}
for node in ns:
......@@ -390,3 +391,52 @@ class GirParser:
res.set_signals(signals)
ns.add_class(res)
def _parse_interface(self, node: ET.Element, ns: ast.Namespace) -> None:
name = node.attrib.get('name')
symbol_prefix = node.attrib.get(_cns('symbol-prefix'))
ctype = node.attrib.get(_cns('type'))
type_name = node.attrib.get(_glibns('type-name'))
get_type = node.attrib.get(_glibns('get-type'))
type_struct = node.attrib.get(_glibns('type-struct'))
gtype = None
if type_name is not None:
gtype = ast.GType(type_name=type_name, get_type=get_type, type_struct=type_struct)
doc = self._maybe_parse_doc(node)
source_pos = self._maybe_parse_source_position(node)
res = ast.Interface(name=name, symbol_prefix=symbol_prefix, ctype=ctype, gtype=gtype)
res.set_doc(doc)
res.set_source_position(source_pos)
methods = []
children = node.findall('core:method', GI_NAMESPACES)
for child in children:
methods.append(self._parse_method(child))
res.set_methods(methods)
functions = []
children = node.findall('core:function', GI_NAMESPACES)
for child in children:
functions.append(self._parse_function(child))
res.set_functions(functions)
properties = []
children = node.findall('core:property', GI_NAMESPACES)
for child in children:
properties.append(self._parse_property(child))
res.set_properties(properties)
signals = []
children = node.findall('glib:signal', GI_NAMESPACES)
for child in children:
signals.append(self._parse_signal(child))
res.set_signals(signals)
ns.add_interface(res)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment