[gobject-introspection/wip/transformer: 15/16] [major] rename-to handling, annotaton fixes
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection/wip/transformer: 15/16] [major] rename-to handling, annotaton fixes
- Date: Fri, 13 Aug 2010 18:05:26 +0000 (UTC)
commit 0bbcbc7281327b61a5ca3621e9d384b280b19539
Author: Colin Walters <walters verbum org>
Date: Thu Aug 12 14:19:23 2010 -0400
[major] rename-to handling, annotaton fixes
giscanner/ast.py | 6 --
giscanner/girwriter.py | 4 ++
giscanner/primarytransformer.py | 26 +++++++--
giscanner/transformer.py | 49 +++++++++++-------
tests/scanner/Annotation-1.0-expected.gir | 78 ++++++++++++++++++----------
tests/scanner/annotation.c | 2 +-
6 files changed, 106 insertions(+), 59 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 67af8db..0006c12 100755
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -50,10 +50,6 @@ In this case, the ctype must be specified.
elif target_fundamental:
assert target_giname is None
assert target_foreign is None
- if block:
- rename_to = block.get(TAG_RENAME_TO)
- if rename_to:
- for
elif target_giname:
assert '.' in target_giname
assert target_fundamental is None
@@ -332,8 +328,6 @@ identifier string."""
node.namespace = None
if hasattr(node, 'ctype'):
del self._ctypes[node.ctype]
- if hasattr(node, 'symbol'):
- del self._ctypes[node.symbol]
if isinstance(node, Function):
del self._symbols[node.symbol]
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index eab3572..73cf985 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -176,6 +176,10 @@ and/or use gtk-doc annotations. ''')
attrs = []
if hasattr(func, 'symbol'):
attrs.append(('c:identifier', func.symbol))
+ if func.shadowed_by:
+ attrs.append(('shadowed_by', func.shadowed_by))
+ elif func.shadows:
+ attrs.append(('shadows', func.shadows))
self._write_callable(func, tag_name, attrs)
def _write_method(self, method):
diff --git a/giscanner/primarytransformer.py b/giscanner/primarytransformer.py
index d7fd346..e262a18 100644
--- a/giscanner/primarytransformer.py
+++ b/giscanner/primarytransformer.py
@@ -135,12 +135,24 @@ class PrimaryTransformer(object):
if block:
rename_to = block.get(TAG_RENAME_TO)
if rename_to:
- target = self._namespace.get_by_symbol(rename_to):
+ rename_to = rename_to.value
+ target = self._namespace.get_by_symbol(rename_to)
if not target:
self._transformer.log_node_warning(node,
- "Can't find symbol %r referenced by Rename annotation" % (target, ))
+ "Can't find symbol %r referenced by Rename annotation" % (rename_to, ))
+ elif target.shadowed_by:
+ self._transformer.log_node_warning(node,
+ "Function %r already shadowed by %r, can't overwrite with %r" % (target.symbol,
+ target.shadowed_by,
+ rename_to))
+ elif target.shadows:
+ self._transformer.log_node_warning(node,
+ "Function %r already shadows %r, can't multiply shadow with %r" % (target.symbol,
+ target.shadows,
+ rename_to))
else:
-
+ target.shadows = node.symbol
+ node.shadowed_by = target.symbol
def _pass_callable_defaults(self, node, chain):
if isinstance(node, (Callable, GLibSignal)):
@@ -356,6 +368,11 @@ class PrimaryTransformer(object):
def _apply_annotations_param_ret_common(self, parent, node, tag):
options = getattr(tag, 'options', {})
+
+ param_type = options.get(OPT_TYPE)
+ if param_type:
+ node.type = self._resolve(param_type.one(), node.type)
+
caller_allocates = False
annotated_direction = None
if (OPT_INOUT in options or
@@ -392,9 +409,6 @@ class PrimaryTransformer(object):
node.transfer = transfer_tag.one()
self._adjust_container_type(parent, node, options)
- param_type = options.get(OPT_TYPE)
- if param_type:
- node.type = self._resolve(param_type.one(), node.type)
if (OPT_ALLOW_NONE in options or
node.type.target_giname == 'Gio.Cancellable'):
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index 089b557..e03ede2 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -536,6 +536,27 @@ or raise ValueError."""
return self.create_type_from_ctype_string(ctype, is_const=const,
is_parameter=is_parameter, is_return=is_return)
+ def _create_bare_container_type(self, base, ctype=None,
+ is_const=False):
+ if base in ('GList', 'GSList', 'GLib.List', 'GLib.SList'):
+ if base in ('GList', 'GSList'):
+ name = 'GLib.' + base[1:]
+ else:
+ name = base
+ return List(name, TYPE_ANY, ctype=ctype,
+ is_const=is_const)
+ elif base in ('GArray', 'GPtrArray', 'GByteArray',
+ 'GLib.Array', 'GLib.PtrArray', 'GLib.ByteArray'):
+ if base in ('GArray', 'GPtrArray', 'GByteArray'):
+ name = 'GLib.' + base[1:]
+ else:
+ name = base
+ return Array(name, TYPE_ANY, ctype=ctype,
+ is_const=is_const)
+ elif base in ('GHashTable', 'GLib.HashTable'):
+ return Map(TYPE_ANY, TYPE_ANY, ctype=ctype, is_const=is_const)
+ return None
+
def create_type_from_ctype_string(self, ctype, is_const=False,
is_parameter=False, is_return=False):
canonical = self._canonicalize_ctype(ctype)
@@ -553,23 +574,9 @@ or raise ValueError."""
return Type(target_fundamental=fundamental.target_fundamental,
ctype=ctype,
is_const=is_const)
- elif base in ('GList', 'GSList', 'GLib.List', 'GLib.SList'):
- if base in ('GList', 'GSList'):
- name = 'GLib.' + base[1:]
- else:
- name = base
- return List(name, TYPE_ANY, ctype=ctype,
- is_const=is_const)
- elif base in ('GArray', 'GPtrArray', 'GByteArray',
- 'GLib.Array', 'GLib.PtrArray', 'GLib.ByteArray'):
- if base in ('GArray', 'GPtrArray', 'GByteArray'):
- name = 'GLib.' + base[1:]
- else:
- name = base
- return Array(name, TYPE_ANY, ctype=ctype,
- is_const=is_const)
- elif base in ('GHashTable', 'GLib.HashTable'):
- return Map(TYPE_ANY, TYPE_ANY, ctype=ctype, is_const=is_const)
+ container = self._create_bare_container_type(base, ctype=ctype, is_const=is_const)
+ if container:
+ return container
return Type(ctype=ctype, is_const=is_const)
def _create_parameter(self, symbol):
@@ -690,7 +697,13 @@ or raise ValueError."""
def create_type_from_user_string(self, typestr):
"""Parse a C type string (as might be given from an
- annotation) and resolve it."""
+ annotation) and resolve it. For compatibility, we can consume
+both GI type string (utf8, Foo.Bar) style, as well as C (char *, FooBar) style."""
+ if '.' in typestr:
+ container = self._create_bare_container_type(typestr)
+ if container:
+ return container
+ return self._namespace.type_from_name(typestr)
typeval = self.create_type_from_ctype_string(typestr)
self.resolve_type(typeval)
# Explicitly clear out the c_type; there isn't one in this case.
diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir
index b4501ce..23ae78f 100644
--- a/tests/scanner/Annotation-1.0-expected.gir
+++ b/tests/scanner/Annotation-1.0-expected.gir
@@ -453,7 +453,28 @@ type.</doc>
</parameter>
</parameters>
</method>
- <method name="watch" c:identifier="annotation_object_watch_full">
+ <method name="watch"
+ c:identifier="annotation_object_watch"
+ shadows="annotation_object_watch_full">
+ <doc xml:whitespace="preserve">This is here just for the sake of being overriden by its
+annotation_object_watch_full().</doc>
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="func" transfer-ownership="none" closure="1">
+ <doc xml:whitespace="preserve">The callback</doc>
+ <type name="ForeachFunc" c:type="AnnotationForeachFunc"/>
+ </parameter>
+ <parameter name="user_data" transfer-ownership="none">
+ <doc xml:whitespace="preserve">The callback data</doc>
+ <type name="gpointer" c:type="gpointer"/>
+ </parameter>
+ </parameters>
+ </method>
+ <method name="watch_full"
+ c:identifier="annotation_object_watch_full"
+ shadowed_by="annotation_object_watch">
<doc xml:whitespace="preserve">Test overriding via the "Rename To" annotation.</doc>
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
@@ -471,7 +492,7 @@ type.</doc>
<doc xml:whitespace="preserve">The callback data</doc>
<type name="gpointer" c:type="gpointer"/>
</parameter>
- <parameter name="destroy" transfer-ownership="none" scope="call">
+ <parameter name="destroy" transfer-ownership="none">
<doc xml:whitespace="preserve">Destroy notification</doc>
<type name="GLib.DestroyNotify" c:type="GDestroyNotify"/>
</parameter>
@@ -491,7 +512,7 @@ type.</doc>
writable="1"
construct="1"
transfer-ownership="none">
- <type name="Callback" c:type="gpointer"/>
+ <type name="Callback"/>
</property>
<property name="string-property"
version="1.0"
@@ -501,52 +522,52 @@ type.</doc>
construct="1"
transfer-ownership="none">
<doc xml:whitespace="preserve">This is a property which is a string</doc>
- <type name="utf8" c:type="gchararray"/>
+ <type name="utf8"/>
</property>
<field name="parent_instance">
<type name="GObject.Object" c:type="GObject"/>
</field>
<glib:signal name="attribute-signal">
<doc xml:whitespace="preserve">This signal tests a signal with attributes.</doc>
- <return-value transfer-ownership="full">
+ <return-value transfer-ownership="none">
<attribute name="some.annotation.foo3" value="val3"/>
<doc xml:whitespace="preserve">the return value</doc>
- <type name="utf8" c:type="gchararray"/>
+ <type name="utf8"/>
</return-value>
<parameters>
- <parameter name="arg1" transfer-ownership="none">
+ <parameter name="object" transfer-ownership="none">
<attribute name="some.annotation.foo1" value="val1"/>
<doc xml:whitespace="preserve">a value</doc>
- <type name="utf8" c:type="gchararray"/>
+ <type name="utf8"/>
</parameter>
- <parameter name="arg2" transfer-ownership="none">
+ <parameter name="p0" transfer-ownership="none">
<attribute name="some.annotation.foo2" value="val2"/>
<doc xml:whitespace="preserve">another value</doc>
- <type name="utf8" c:type="gchararray"/>
+ <type name="utf8"/>
</parameter>
</parameters>
</glib:signal>
<glib:signal name="doc-empty-arg-parsing">
<doc xml:whitespace="preserve">This signal tests an empty document argument (@arg1)</doc>
- <return-value transfer-ownership="full">
- <type name="none" c:type="void"/>
+ <return-value transfer-ownership="none">
+ <type name="none"/>
</return-value>
<parameters>
<parameter name="object" transfer-ownership="none">
- <type name="gpointer" c:type="gpointer"/>
+ <type name="gpointer"/>
</parameter>
</parameters>
</glib:signal>
<glib:signal name="list-signal">
<doc xml:whitespace="preserve">This is a signal which takes a list of strings, but it's not
known by GObject as it's only marked as G_TYPE_POINTER</doc>
- <return-value transfer-ownership="full">
- <type name="none" c:type="void"/>
+ <return-value transfer-ownership="none">
+ <type name="none"/>
</return-value>
<parameters>
- <parameter name="list" transfer-ownership="container">
+ <parameter name="object" transfer-ownership="container">
<doc xml:whitespace="preserve">a list of strings</doc>
- <type name="GLib.List" c:type="gpointer">
+ <type name="GLib.List">
<type name="utf8"/>
</type>
</parameter>
@@ -558,13 +579,13 @@ known by GObject as it's only marked as G_TYPE_POINTER</doc>
deprecated-version="1.2">
<doc xml:whitespace="preserve">This is a signal which has a broken signal handler,
it says it's pointer but it's actually a string.</doc>
- <return-value transfer-ownership="full">
- <type name="none" c:type="void"/>
+ <return-value transfer-ownership="none">
+ <type name="none"/>
</return-value>
<parameters>
- <parameter name="string" transfer-ownership="none">
+ <parameter name="object" transfer-ownership="none">
<doc xml:whitespace="preserve">a string</doc>
- <type name="utf8" c:type="gpointer"/>
+ <type name="utf8"/>
</parameter>
</parameters>
</glib:signal>
@@ -579,8 +600,8 @@ it says it's pointer but it's actually a string.</doc>
<record name="Struct" c:type="AnnotationStruct">
<doc xml:whitespace="preserve">This is a test of an array of object in an field of a struct.</doc>
<field name="objects" writable="1">
- <array zero-terminated="0" c:type="AnnotationObject*" fixed-size="10">
- <type name="Object"/>
+ <array zero-terminated="0" c:type="AnnotationObject" fixed-size="10">
+ <type name="Object" c:type="AnnotationObject*"/>
</array>
</field>
</record>
@@ -613,13 +634,12 @@ detection, and fixing it via annotations.</doc>
<parameters>
<parameter name="callback"
transfer-ownership="none"
- scope="call"
closure="2"
destroy="1">
<doc xml:whitespace="preserve">Destroy notification</doc>
<type name="Callback" c:type="AnnotationCallback"/>
</parameter>
- <parameter name="destroy" transfer-ownership="none" scope="call">
+ <parameter name="destroy" transfer-ownership="none" closure="2">
<type name="NotifyFunc" c:type="AnnotationNotifyFunc"/>
</parameter>
<parameter name="data" transfer-ownership="none">
@@ -630,7 +650,7 @@ detection, and fixing it via annotations.</doc>
<function name="get_source_file" c:identifier="annotation_get_source_file">
<return-value transfer-ownership="full">
<doc xml:whitespace="preserve">Source file</doc>
- <type name="filename" c:type="char*"/>
+ <type name="filename"/>
</return-value>
</function>
<function name="init" c:identifier="annotation_init">
@@ -668,7 +688,9 @@ detection, and fixing it via annotations.</doc>
</parameter>
</parameters>
</function>
- <function name="ptr_array" c:identifier="annotation_ptr_array">
+ <function name="ptr_array"
+ c:identifier="annotation_ptr_array"
+ introspectable="0">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
</return-value>
@@ -705,7 +727,7 @@ detection, and fixing it via annotations.</doc>
<parameters>
<parameter name="fname" transfer-ownership="none">
<doc xml:whitespace="preserve">Source file</doc>
- <type name="filename" c:type="char*"/>
+ <type name="filename"/>
</parameter>
</parameters>
</function>
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index 397a1c5..77f5a46 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -89,7 +89,7 @@ annotation_object_class_init (AnnotationObjectClass *klass)
/**
* AnnotationObject::list-signal:
* @annotation: the annotation object
- * @list: (type GLib.List): (element-type utf8): (transfer container): a list of strings
+ * @list: (type GLib.List) (element-type utf8): (transfer container): a list of strings
*
* This is a signal which takes a list of strings, but it's not
* known by GObject as it's only marked as G_TYPE_POINTER
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]