summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2014-04-16 18:05:07 -0400
committerRyan Lortie <desrt@desrt.ca>2014-05-06 08:18:41 -0400
commit17b19cfcad236fd2def64b9aac454ecb3cd42e8d (patch)
tree3538405d943fbb4dc81191a61fcc497f20c2ed39 /giscanner
parent1459ff3eb242327fca8a2b5a696b14b7e46afdee (diff)
downloadgobject-introspection-17b19cfcad236fd2def64b9aac454ecb3cd42e8d.tar.gz
giscanner: support nullable return types too
Promote the 'nullable' field to the TypeContainer base class (which is shared by Return and Parameter types). Add .gir support for nullability on return values, both in the writer and in the (scanner's) parser. https://bugzilla.gnome.org/show_bug.cgi?id=660879
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/ast.py10
-rw-r--r--giscanner/girparser.py3
-rw-r--r--giscanner/girwriter.py2
3 files changed, 9 insertions, 6 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 12304eb7..a9537e8d 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -760,9 +760,10 @@ class Alias(Node):
class TypeContainer(Annotated):
"""A fundamental base class for Return and Parameter."""
- def __init__(self, typenode, transfer):
+ def __init__(self, typenode, nullable, transfer):
Annotated.__init__(self)
self.type = typenode
+ self.nullable = nullable
if transfer is not None:
self.transfer = transfer
elif typenode.is_const:
@@ -778,10 +779,9 @@ class Parameter(TypeContainer):
transfer=None, nullable=False, optional=False,
allow_none=False, scope=None,
caller_allocates=False):
- TypeContainer.__init__(self, typenode, transfer)
+ TypeContainer.__init__(self, typenode, nullable, transfer)
self.argname = argname
self.direction = direction
- self.nullable = nullable
self.optional = optional
if allow_none:
@@ -799,8 +799,8 @@ class Parameter(TypeContainer):
class Return(TypeContainer):
"""A return value from a function."""
- def __init__(self, rtype, transfer=None):
- TypeContainer.__init__(self, rtype, transfer)
+ def __init__(self, rtype, nullable=False, transfer=None):
+ TypeContainer.__init__(self, rtype, nullable, transfer)
self.direction = PARAM_DIRECTION_OUT
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index b1583998..40bc49e0 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -294,7 +294,8 @@ class GIRParser(object):
if not returnnode:
raise ValueError('node %r has no return-value' % (name, ))
transfer = returnnode.attrib.get('transfer-ownership')
- retval = ast.Return(self._parse_type(returnnode), transfer)
+ nullable = returnnode.attrib.get('nullable') == '1'
+ retval = ast.Return(self._parse_type(returnnode), nullable, transfer)
self._parse_generic_attribs(returnnode, retval)
parameters = []
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 49545e62..3bea2a1c 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -215,6 +215,8 @@ class GIRWriter(XMLWriter):
attrs.append(('transfer-ownership', return_.transfer))
if return_.skip:
attrs.append(('skip', '1'))
+ if return_.nullable:
+ attrs.append(('nullable', '1'))
with self.tagcontext('return-value', attrs):
self._write_generic(return_)
self._write_type(return_.type, parent=parent)