gobject-introspection r363 - in trunk: . gir giscanner tests/scanner
- From: walters svn gnome org
- To: svn-commits-list gnome org
- Subject: gobject-introspection r363 - in trunk: . gir giscanner tests/scanner
- Date: Wed, 13 Aug 2008 22:06:59 +0000 (UTC)
Author: walters
Date: Wed Aug 13 22:06:59 2008
New Revision: 363
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=363&view=rev
Log:
2008-08-13 Colin Walters <walters verbum org>
* gir/gobject-2.0.gir: Use correct namespace, add GType.
* giscanner/girparser.py: Handle aliases.
* giscanner/transformer.py: Record aliases. Make resolver
functions public; we now call into these explicitly from
glibtransformer. Handle resolving aliases.
* giscanner/glibtransformer.py: Separate our internal namespace
from included ones. Call up into transformer's resolver functions.
Modified:
trunk/ChangeLog
trunk/gir/gobject-2.0.gir
trunk/giscanner/girparser.py
trunk/giscanner/glibtransformer.py
trunk/giscanner/transformer.py
trunk/tests/scanner/Foo-expected.gir
Modified: trunk/gir/gobject-2.0.gir
==============================================================================
--- trunk/gir/gobject-2.0.gir (original)
+++ trunk/gir/gobject-2.0.gir Wed Aug 13 22:06:59 2008
@@ -2,7 +2,8 @@
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">
- <namespace name="GLib">
+ <namespace name="GObject">
+ <alias name="GType" target="gsize"/>
<class name="Object"
glib:type-name="GObject"
glib:get-type="intern">
Modified: trunk/giscanner/girparser.py
==============================================================================
--- trunk/giscanner/girparser.py (original)
+++ trunk/giscanner/girparser.py Wed Aug 13 22:06:59 2008
@@ -64,6 +64,8 @@
assert ns is not None
self._namespace_name = ns.attrib['name']
for child in ns.getchildren():
+ if child.tag == _corens('alias'):
+ self._add_node(self._parse_alias(child))
if child.tag in (_corens('callback'), ):
self._add_node(self._parse_function(child, Callback))
if child.tag in (_corens('function'), ):
@@ -72,7 +74,7 @@
c = GLibObject(child.attrib['name'],
child.attrib.get('parent'),
child.attrib[_glibns('type-name')],
- child.attrib[_glibns('get-type')])
+ child.attrib.get(_glibns('get-type')))
self._parse_functions_props(child, c)
self._add_node(c)
if child.tag == _corens('interface'):
@@ -87,6 +89,10 @@
pass
+ def _parse_alias(self, child):
+ return Alias(child.attrib['name'], child.attrib['target'])
+
+
def _parse_functions_props(self, child, obj):
for meth in child.findall(_corens('method')):
obj.methods.append(self._parse_function(meth, Function))
Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py (original)
+++ trunk/giscanner/glibtransformer.py Wed Aug 13 22:06:59 2008
@@ -40,7 +40,7 @@
self._aliases = []
self._output_ns = odict()
self._libraries = []
- self._type_names = {}
+ self._internal_types = {}
# Public API
@@ -52,7 +52,6 @@
def parse(self):
namespace = self._transformer.parse()
self._namespace_name = namespace.name
- self._type_names = self._transformer.get_type_names()
for node in namespace.nodes:
self._parse_node(node)
@@ -83,21 +82,27 @@
return self._output_ns.get(name)
def _register_internal_type(self, type_name, node):
- self._type_names[type_name] = (None, node)
+ self._internal_types[type_name] = node
def _resolve_type_name(self, type_name):
- item = self._type_names.get(type_name)
- if item is not None:
- nsname, item = item
- if nsname is None:
- return item.name
- return '%s.%s' % (nsname, item.name)
+ type_name = type_name.replace('*', '')
+ possible_name = self._transformer.resolve_type_name(type_name)
+ if possible_name != type_name:
+ return possible_name
+ possible_node = self._internal_types.get(type_name)
+ if possible_node:
+ return possible_node.name
return type_name
def _resolve_param_type(self, ptype):
- type_name = ptype.name.replace('*', '')
+ ptype.name = ptype.name.replace('*', '')
+ type_name = ptype.name
type_name = self._transformer.resolve_possible_typedef(type_name)
- ptype.name = self._resolve_type_name(type_name)
+ possible_node = self._internal_types.get(type_name)
+ if possible_node:
+ ptype.name = possible_node.name
+ else:
+ ptype = self._transformer.resolve_param_type(ptype)
return ptype
def _parse_node(self, node):
@@ -182,7 +187,7 @@
symbol = func.symbol
if not symbol.endswith('_get_type'):
return False
- if func.retval.type.name != 'GType':
+ if func.retval.type.name != 'GObject.GType':
return False
if func.parameters:
return False
Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py (original)
+++ trunk/giscanner/transformer.py Wed Aug 13 22:06:59 2008
@@ -42,6 +42,7 @@
self.generator = generator
self._namespace = Namespace(namespace_name)
self._output_ns = {}
+ self._alias_names = {}
self._type_names = {}
self._ctype_names = {}
self._typedefs_ns = {}
@@ -51,6 +52,9 @@
def get_type_names(self):
return self._type_names
+ def get_alias_names(self):
+ return self._alias_names
+
def set_strip_prefix(self, strip_prefix):
self._strip_prefix = strip_prefix
@@ -85,6 +89,8 @@
if isinstance(node, GLibBoxed) or isinstance(node, GLibInterface) \
or isinstance(node, GLibObject):
self._type_names[node.type_name] = (nsname, node)
+ elif isinstance(node, Alias):
+ self._alias_names[node.name] = (nsname, node)
else:
self._type_names[node.name] = (nsname, node)
@@ -227,7 +233,7 @@
def _create_type(self, source_type):
ctype = self._create_source_type(source_type)
type_name = type_name_from_ctype(ctype)
- resolved_type_name = self._resolve_type_name(type_name)
+ resolved_type_name = self.resolve_type_name(type_name)
return Type(resolved_type_name, ctype)
def _create_parameter(self, symbol, options):
@@ -253,7 +259,7 @@
if not options:
options = []
rtype = self._create_type(source_type)
- rtype = self._resolve_param_type(rtype)
+ rtype = self.resolve_param_type(rtype)
return_ = Return(rtype)
for option in options:
if option == 'caller-owns':
@@ -281,7 +287,7 @@
struct = self._typedefs_ns.get(symbol.ident, None)
if struct is None:
name = self._remove_prefix(symbol.ident)
- name = self._resolve_type_name(name)
+ name = self.resolve_type_name(name)
struct = Struct(name, symbol.ident)
for child in symbol.base_type.child_list:
@@ -308,14 +314,17 @@
return item.name
return '%s.%s' % (nsname, item.name)
- def _resolve_type_name(self, type_name):
+ def resolve_type_name(self, type_name):
resolved = self._type_names.get(type_name)
if resolved:
return self._typepair_to_str(resolved)
+ resolved = self._alias_names.get(type_name)
+ if resolved:
+ return self._typepair_to_str(resolved)
return type_name
- def _resolve_param_type(self, ptype):
- type_name = ptype.name
+ def resolve_param_type(self, ptype):
+ type_name = ptype.name.replace('*', '')
resolved = self._type_names.get(type_name)
if resolved:
ptype.name = self._typepair_to_str(resolved)
@@ -325,4 +334,9 @@
resolved = self._ctype_names.get(ctype)
if resolved:
ptype.name = self._typepair_to_str(resolved)
+ return ptype
+ resolved = self._alias_names.get(type_name)
+ if resolved:
+ ptype.name = self._typepair_to_str(resolved)
+ return ptype
return ptype
Modified: trunk/tests/scanner/Foo-expected.gir
==============================================================================
--- trunk/tests/scanner/Foo-expected.gir (original)
+++ trunk/tests/scanner/Foo-expected.gir Wed Aug 13 22:06:59 2008
@@ -197,7 +197,7 @@
<type name="any" c:type="void*"/>
</parameter>
<parameter name="some_type">
- <type name="GType" c:type="GType"/>
+ <type name="GObject.GType" c:type="GType"/>
</parameter>
</parameters>
</method>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]