[gobject-introspection/wip/transformer] type fixes
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/transformer] type fixes
- Date: Tue, 20 Jul 2010 15:39:52 +0000 (UTC)
commit 2a6e5b70185099623254876c0f4922b14fc1caac
Author: Colin Walters <walters verbum org>
Date: Tue Jul 20 11:05:49 2010 -0400
type fixes
girepository/girparser.c | 2 +-
giscanner/ast.py | 3 ++-
giscanner/girparser.py | 4 ++--
giscanner/girwriter.py | 30 +++++++++++++++++++-----------
giscanner/glibtransformer.py | 14 +++++++++++---
5 files changed, 35 insertions(+), 18 deletions(-)
---
diff --git a/girepository/girparser.c b/girepository/girparser.c
index 8af0396..b408e75 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -1241,7 +1241,7 @@ start_alias (GMarkupParseContext *context,
}
target = find_attribute ("target", attribute_names, attribute_values);
- if (name == NULL)
+ if (target == NULL)
{
MISSING_ATTRIBUTE (context, error, element_name, "target");
return FALSE;
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 8af0198..92a047f 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -605,7 +605,7 @@ class Class(Node):
# When we're in the scanner, we keep around a list
# of parents so that we can transparently fall back
# if there are 'hidden' parents
- self.parent_chain = None
+ self.parent_chain = []
self.glib_type_struct = None
self.is_abstract = is_abstract
self.methods = []
@@ -629,6 +629,7 @@ class Interface(Node):
def __init__(self, name, parent):
Node.__init__(self, name)
self.parent = parent
+ self.parent_chain = []
self.methods = []
self.virtual_methods = []
self.glib_type_struct = None
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index 113ca49..0ae84f8 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -230,9 +230,9 @@ class GIRParser(object):
ctor_args.append(node.attrib.get(_cns('type')))
for iface in self._find_children(node, _corens('implements')):
- obj.interfaces.append(Type(target_giname=iface.attrib['name']))
+ obj.interfaces.append(Type(target_giname=iface.attrib[_corens('name')]))
for iface in self._find_children(node, _corens('prerequisite')):
- obj.prerequisites.append(Type(target_giname=iface.attrib['name']))
+ obj.prerequisites.append(Type(target_giname=iface.attrib[_corens('name')]))
for func_node in self._find_children(node, _corens('function')):
func = self._parse_function_common(func_node, Function)
obj.static_methods.append(func)
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index d3c95be..04c6f73 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -230,6 +230,15 @@ and/or use gtk-doc annotations. ''')
self._write_generic(parameter)
self._write_type(parameter.type)
+ def _type_to_name(self, typeval):
+ if not typeval.resolved:
+ raise AssertionError("Caught unresolved type %r (ctype=%r)" % (typeval, typeval.ctype))
+ assert typeval.target_giname is not None
+ prefix = self._namespace.name + '.'
+ if typeval.target_giname.startswith(prefix):
+ return typeval.target_giname[len(prefix):]
+ return typeval.target_giname
+
def _write_type(self, ntype, relation=None):
assert isinstance(ntype, Type)
attrs = []
@@ -264,12 +273,7 @@ and/or use gtk-doc annotations. ''')
else:
# REWRITEFIXME - enable this for 1.2
if ntype.target_giname:
- # attrs.insert(0, ('ref', ntype.target_giname))
- prefix = self._namespace.name + '.'
- if ntype.target_giname.startswith(prefix):
- attrs.insert(0, ('name', ntype.target_giname[len(prefix):]))
- else:
- attrs.insert(0, ('name', ntype.target_giname))
+ attrs.insert(0, ('name', self._type_to_name(ntype)))
elif ntype.target_fundamental:
# attrs = [('fundamental', ntype.target_fundamental)]
attrs.insert(0, ('name', ntype.target_fundamental))
@@ -334,7 +338,8 @@ and/or use gtk-doc annotations. ''')
if isinstance(node, Class):
tag_name = 'class'
if node.parent is not None:
- attrs.append(('parent', node.parent.target_giname))
+ attrs.append(('parent',
+ self._type_to_name(node.parent)))
if node.is_abstract:
attrs.append(('abstract', '1'))
else:
@@ -344,7 +349,8 @@ and/or use gtk-doc annotations. ''')
if node.get_type:
attrs.append(('glib:get-type', node.get_type))
if node.glib_type_struct:
- attrs.append(('glib:type-struct', node.glib_type_struct.target_giname))
+ attrs.append(('glib:type-struct',
+ self._type_to_name(node.glib_type_struct)))
if isinstance(node, GLibObject):
if node.fundamental:
attrs.append(('glib:fundamental', '1'))
@@ -360,10 +366,12 @@ and/or use gtk-doc annotations. ''')
self._write_generic(node)
if isinstance(node, GLibObject):
for iface in node.interfaces:
- self.write_tag('implements', [('name', iface.target_giname)])
+ self.write_tag('implements',
+ [('name', self._type_to_name(iface))])
if isinstance(node, Interface):
for iface in node.prerequisites:
- self.write_tag('prerequisite', [('name', iface.target_giname)])
+ self.write_tag('prerequisite',
+ [('name', self._type_to_name(iface))])
if isinstance(node, Class):
for method in node.constructors:
self._write_constructor(method)
@@ -438,7 +446,7 @@ and/or use gtk-doc annotations. ''')
if record.is_gtype_struct_for:
is_gtype_struct = True
attrs.append(('glib:is-gtype-struct-for',
- record.is_gtype_struct_for.target_giname))
+ self._type_to_name(record.is_gtype_struct_for)))
self._append_version(record, attrs)
self._append_node_generic(record, attrs)
if isinstance(record, GLibBoxed):
diff --git a/giscanner/glibtransformer.py b/giscanner/glibtransformer.py
index d3ed7d5..158d61a 100644
--- a/giscanner/glibtransformer.py
+++ b/giscanner/glibtransformer.py
@@ -173,11 +173,19 @@ class GLibTransformer(object):
for field in node.fields:
self._transformer.resolve_type(field.type)
if isinstance(node, (Class, Interface)):
+ resolved_parent = None
for parent in node.parent_chain:
try:
-
+ self._transformer.resolve_type(parent)
+ resolved_parent = parent
+ except ValueError, e:
+ continue
+ node.parent = resolved_parent
for prop in node.properties:
self._transformer.resolve_type(prop.type)
+ if isinstance(node, Class):
+ for iface in node.interfaces:
+ self._transformer.resolve_type(iface)
def _resolve_quarks(self):
# self._uscore_type_names is an authoritative mapping of types
@@ -539,7 +547,7 @@ blob containing data gleaned from GObject's primitive introspection."""
gclass_struct = GLibRecord.from_record(class_struct)
self._namespace.append(gclass_struct, replace=True)
- pair_class.glib_type_struct = gclass_struct
+ pair_class.glib_type_struct = gclass_struct.create_type()
pair_class.inherit_file_positions(class_struct)
gclass_struct.is_gtype_struct_for = pair_class.create_type()
@@ -689,7 +697,7 @@ blob containing data gleaned from GObject's primitive introspection."""
parent_type,
type_name,
xmlnode.attrib['get-type'], is_abstract)
- node.parent_types = parent_types
+ node.parent_chain = parent_types
node.fundamental = True
self._introspect_implemented_interfaces(node, xmlnode)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]