[gobject-introspection] compiler: girparser: parse 'nullable' attribute



commit bb9b9bd77309134ad5d1b06a0af9755a3e93a5d8
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Apr 16 11:39:09 2014 -0400

    compiler: girparser: parse 'nullable' attribute
    
    Parse the 'nullable' attribute on parameters and function return types.
    
    Additionally, tweak the meaning of the 'allow-none' attribute.  We now
    only treat it as equivalent to 'nullable' for non-out parameters.  For
    out parameters, we treat it to mean the same as the already-recognised
    'optional' parameter (which we only recently started actually using).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=660879

 girepository/girparser.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/girepository/girparser.c b/girepository/girparser.c
index ac21f6a..6c76866 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -1065,6 +1065,7 @@ start_parameter (GMarkupParseContext *context,
   const gchar *closure;
   const gchar *destroy;
   const gchar *skip;
+  const gchar *nullable;
   GIrNodeParam *param;
 
   if (!(strcmp (element_name, "parameter") == 0 &&
@@ -1082,6 +1083,7 @@ start_parameter (GMarkupParseContext *context,
   closure = find_attribute ("closure", attribute_names, attribute_values);
   destroy = find_attribute ("destroy", attribute_names, attribute_values);
   skip = find_attribute ("skip", attribute_names, attribute_values);
+  nullable = find_attribute ("nullable", attribute_names, attribute_values);
 
   if (name == NULL)
     name = "unknown";
@@ -1126,11 +1128,19 @@ start_parameter (GMarkupParseContext *context,
   else
     param->optional = FALSE;
 
-  if (allow_none && strcmp (allow_none, "1") == 0)
+  if (nullable && strcmp (nullable, "1") == 0)
     param->nullable = TRUE;
   else
     param->nullable = FALSE;
 
+  if (allow_none && strcmp (allow_none, "1") == 0)
+    {
+      if (param->out)
+        param->optional = TRUE;
+      else
+        param->nullable = TRUE;
+    }
+
   if (skip && strcmp (skip, "1") == 0)
     param->skip = TRUE;
   else
@@ -2172,6 +2182,7 @@ start_return_value (GMarkupParseContext *context,
   GIrNodeParam *param;
   const gchar  *transfer;
   const gchar  *skip;
+  const gchar  *nullable;
 
   if (!(strcmp (element_name, "return-value") == 0 &&
        ctx->state == STATE_FUNCTION))
@@ -2197,6 +2208,10 @@ start_return_value (GMarkupParseContext *context,
   if (!parse_param_transfer (param, transfer, NULL, error))
     return FALSE;
 
+  nullable = find_attribute ("nullable", attribute_names, attribute_values);
+  if (nullable && g_str_equal (nullable, "1"))
+    param->nullable = TRUE;
+
   switch (CURRENT_NODE (ctx)->type)
     {
     case G_IR_NODE_FUNCTION:


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