diff options
Diffstat (limited to 'giscanner/girwriter.py')
-rw-r--r-- | giscanner/girwriter.py | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index 97f81616..e7af2533 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -28,40 +28,32 @@ from .xmlwriter import XMLWriter # Compatible changes we just make inline COMPATIBLE_GIR_VERSION = '1.2' + class GIRWriter(XMLWriter): - def __init__(self, namespace, shlibs, includes, pkgs, c_includes): + def __init__(self, namespace): super(GIRWriter, self).__init__() self.write_comment( -'''This file was automatically generated from C sources - DO NOT EDIT! -To affect the contents of this file, edit the original C definitions, -and/or use gtk-doc annotations. ''') - self._write_repository(namespace, shlibs, includes, pkgs, - c_includes) - - def _write_repository(self, namespace, shlibs, includes=None, - packages=None, c_includes=None): - if includes is None: - includes = frozenset() - if packages is None: - packages = frozenset() - if c_includes is None: - c_includes = frozenset() + 'This file was automatically generated from C sources - DO NOT EDIT!\n' + 'To affect the contents of this file, edit the original C definitions,\n' + 'and/or use gtk-doc annotations. ') + self._write_repository(namespace) + + def _write_repository(self, namespace): attrs = [ ('version', COMPATIBLE_GIR_VERSION), ('xmlns', 'http://www.gtk.org/introspection/core/1.0'), ('xmlns:c', 'http://www.gtk.org/introspection/c/1.0'), - ('xmlns:glib', 'http://www.gtk.org/introspection/glib/1.0'), - ] + ('xmlns:glib', 'http://www.gtk.org/introspection/glib/1.0')] with self.tagcontext('repository', attrs): - for include in sorted(includes): + for include in sorted(namespace.includes): self._write_include(include) - for pkg in sorted(set(packages)): + for pkg in sorted(set(namespace.exported_packages)): self._write_pkgconfig_pkg(pkg) - for c_include in sorted(set(c_includes)): + for c_include in sorted(set(namespace.c_includes)): self._write_c_include(c_include) self._namespace = namespace - self._write_namespace(namespace, shlibs) + self._write_namespace(namespace) self._namespace = None def _write_include(self, include): @@ -76,10 +68,10 @@ and/or use gtk-doc annotations. ''') attrs = [('name', c_include)] self.write_tag('c:include', attrs) - def _write_namespace(self, namespace, shlibs): + def _write_namespace(self, namespace): attrs = [('name', namespace.name), ('version', namespace.version), - ('shared-library', ','.join(shlibs)), + ('shared-library', ','.join(namespace.shared_libraries)), ('c:identifier-prefixes', ','.join(namespace.identifier_prefixes)), ('c:symbol-prefixes', ','.join(namespace.symbol_prefixes))] with self.tagcontext('namespace', attrs): @@ -134,7 +126,7 @@ and/or use gtk-doc annotations. ''') for key, value in node.attributes: self.write_tag('attribute', [('name', key), ('value', value)]) if hasattr(node, 'doc') and node.doc: - self.write_tag('doc', [('xml:whitespace', 'preserve')], + self.write_tag('doc', [('xml:space', 'preserve')], node.doc) def _append_node_generic(self, node, attrs): @@ -170,9 +162,11 @@ and/or use gtk-doc annotations. ''') with self.tagcontext(tag_name, attrs): self._write_generic(callable) self._write_return_type(callable.retval, parent=callable) - self._write_parameters(callable, callable.parameters) + self._write_parameters(callable) def _write_function(self, func, tag_name='function'): + if func.internal_skipped: + return attrs = [] if hasattr(func, 'symbol'): attrs.append(('c:identifier', func.symbol)) @@ -206,14 +200,16 @@ and/or use gtk-doc annotations. ''') self._write_generic(return_) self._write_type(return_.type, function=parent) - def _write_parameters(self, parent, parameters): - if not parameters: + def _write_parameters(self, callable): + if not callable.parameters and callable.instance_parameter is None: return with self.tagcontext('parameters'): - for parameter in parameters: - self._write_parameter(parent, parameter) + if callable.instance_parameter: + self._write_parameter(callable, callable.instance_parameter, 'instance-parameter') + for parameter in callable.parameters: + self._write_parameter(callable, parameter) - def _write_parameter(self, parent, parameter): + def _write_parameter(self, parent, parameter, nodename='parameter'): attrs = [] if parameter.argname is not None: attrs.append(('name', parameter.argname)) @@ -236,7 +232,7 @@ and/or use gtk-doc annotations. ''') attrs.append(('destroy', '%d' % (idx, ))) if parameter.skip: attrs.append(('skip', '1')) - with self.tagcontext('parameter', attrs): + with self.tagcontext(nodename, attrs): self._write_generic(parameter) self._write_type(parameter.type, function=parent) @@ -296,8 +292,8 @@ and/or use gtk-doc annotations. ''') attrs.append(('fixed-size', '%d' % (ntype.size, ))) if ntype.length_param_name is not None: assert function - attrs.insert(0, ('length', '%d' - % (function.get_parameter_index(ntype.length_param_name, )))) + length = function.get_parameter_index(ntype.length_param_name) + attrs.insert(0, ('length', '%d' % (length, ))) with self.tagcontext('array', attrs): self._write_type(ntype.element_type) @@ -363,13 +359,17 @@ and/or use gtk-doc annotations. ''') ('c:identifier', member.symbol)] if member.nick is not None: attrs.append(('glib:nick', member.nick)) - self.write_tag('member', attrs) + with self.tagcontext('member', attrs): + self._write_generic(member) def _write_constant(self, constant): attrs = [('name', constant.name), ('value', constant.value), ('c:type', constant.ctype)] + self._append_version(constant, attrs) + self._append_node_generic(constant, attrs) with self.tagcontext('constant', attrs): + self._write_generic(constant) self._write_type(constant.value_type) def _write_class(self, node): @@ -380,9 +380,9 @@ and/or use gtk-doc annotations. ''') self._append_node_generic(node, attrs) if isinstance(node, ast.Class): tag_name = 'class' - if node.parent is not None: + if node.parent_type is not None: attrs.append(('parent', - self._type_to_name(node.parent))) + self._type_to_name(node.parent_type))) if node.is_abstract: attrs.append(('abstract', '1')) else: @@ -482,7 +482,7 @@ and/or use gtk-doc annotations. ''') attrs = list(extra_attrs) if record.name is not None: attrs.append(('name', record.name)) - if record.ctype is not None: # the record might be anonymous + if record.ctype is not None: # the record might be anonymous attrs.append(('c:type', record.ctype)) if record.disguised: attrs.append(('disguised', '1')) @@ -513,7 +513,7 @@ and/or use gtk-doc annotations. ''') attrs = [] if union.name is not None: attrs.append(('name', union.name)) - if union.ctype is not None: # the union might be anonymous + if union.ctype is not None: # the union might be anonymous attrs.append(('c:type', union.ctype)) self._append_version(union, attrs) self._append_node_generic(union, attrs) @@ -544,8 +544,7 @@ and/or use gtk-doc annotations. ''') elif isinstance(field.anonymous_node, ast.Union): self._write_union(field.anonymous_node) else: - raise AssertionError("Unknown field anonymous: %r" \ - % (field.anonymous_node, )) + raise AssertionError("Unknown field anonymous: %r" % (field.anonymous_node, )) else: attrs = [('name', field.name)] self._append_node_generic(field, attrs) @@ -581,4 +580,4 @@ and/or use gtk-doc annotations. ''') with self.tagcontext('glib:signal', attrs): self._write_generic(signal) self._write_return_type(signal.retval) - self._write_parameters(signal, signal.parameters) + self._write_parameters(signal) |