[gobject-introspection] giscanner: change some internal field logic



commit 754f1965c08bb01b2e6440d2a6f1ab9edd6e1970
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Apr 16 17:16:17 2014 -0400

    giscanner: change some internal field logic
    
    Replace the 'allow_none' field on parameters with two separate fields:
    'nullable' and 'optional'.
    
    Currently, we use 'nullable' to mean the same thing as 'allow-none' for
    normal (non-out) parameters.  For out parameters, we use the 'optional'
    field instead.
    
    Note that the special case for GCancellable and GAsyncReadyCallback is
    already guarded by a check for being an in parameter, so we always use
    'nullable' here.
    
    On the .gir writer side, we decide which variable to consult when
    writing the allow-none attribute depending on the parameter direction.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660879

 giscanner/ast.py             |   10 +++++++++-
 giscanner/girwriter.py       |    8 ++++++--
 giscanner/maintransformer.py |    7 +++++--
 3 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 130f50c..35a764a 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -780,7 +780,15 @@ class Parameter(TypeContainer):
         TypeContainer.__init__(self, typenode, transfer)
         self.argname = argname
         self.direction = direction
-        self.allow_none = allow_none
+        self.nullable = False
+        self.optional = False
+
+        if allow_none:
+            if self.direction == PARAM_DIRECTION_OUT:
+                self.optional = True
+            else:
+                self.nullable = True
+
         self.scope = scope
         self.caller_allocates = caller_allocates
         self.closure_name = None
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 304cf32..49d24bc 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -239,8 +239,12 @@ class GIRWriter(XMLWriter):
         if parameter.transfer:
             attrs.append(('transfer-ownership',
                           parameter.transfer))
-        if parameter.allow_none:
-            attrs.append(('allow-none', '1'))
+        if parameter.nullable:
+            if parameter.direction != ast.PARAM_DIRECTION_OUT:
+                attrs.append(('allow-none', '1'))
+        if parameter.optional:
+            if parameter.direction == ast.PARAM_DIRECTION_OUT:
+                attrs.append(('allow-none', '1'))
         if parameter.scope:
             attrs.append(('scope', parameter.scope))
         if parameter.closure_name is not None:
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 8fad0d7..5f4788a 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -580,12 +580,15 @@ class MainTransformer(object):
         self._adjust_container_type(parent, node, annotations)
 
         if ANN_ALLOW_NONE in annotations:
-            node.allow_none = True
+            if node.direction == ast.PARAM_DIRECTION_OUT:
+                node.optional = True
+            else:
+                node.nullable = True
 
         if (node.direction == ast.PARAM_DIRECTION_IN and
                 (node.type.target_giname == 'Gio.AsyncReadyCallback' or
                  node.type.target_giname == 'Gio.Cancellable')):
-            node.allow_none = True
+            node.nullable = True
 
         if tag and tag.description:
             node.doc = tag.description


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