[gobject-introspection] giscanner: support nullable return types too



commit 17b19cfcad236fd2def64b9aac454ecb3cd42e8d
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Apr 16 18:05:07 2014 -0400

    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

 giscanner/ast.py       |   10 +++++-----
 giscanner/girparser.py |    3 ++-
 giscanner/girwriter.py |    2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 12304eb..a9537e8 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 b158399..40bc49e 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 49545e6..3bea2a1 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)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]