[gobject-introspection/wip/transformer: 7/7] parser fixes



commit 36f87239e468038ebd6ca427998f0b0a4084db36
Author: Colin Walters <walters verbum org>
Date:   Tue Jul 27 09:40:57 2010 -0400

    parser fixes

 girepository/girparser.c |   50 ++++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 21 deletions(-)
---
diff --git a/girepository/girparser.c b/girepository/girparser.c
index 6fc8fbb..494b5c0 100644
--- a/girepository/girparser.c
+++ b/girepository/girparser.c
@@ -48,28 +48,28 @@ typedef enum
   STATE_REPOSITORY,
   STATE_INCLUDE,
   STATE_C_INCLUDE,
-  STATE_PACKAGE,
-  STATE_NAMESPACE, /* 5 */
+  STATE_PACKAGE,  /* 5 */
+  STATE_NAMESPACE,
   STATE_ENUM,
   STATE_BITFIELD,
   STATE_FUNCTION,
-  STATE_FUNCTION_RETURN,
-  STATE_FUNCTION_PARAMETERS, /* 10 */
+  STATE_FUNCTION_RETURN,  /* 10 */
+  STATE_FUNCTION_PARAMETERS,
   STATE_FUNCTION_PARAMETER,
   STATE_CLASS,
   STATE_CLASS_FIELD,
-  STATE_CLASS_PROPERTY,
-  STATE_INTERFACE, /* 15 */
+  STATE_CLASS_PROPERTY,  /* 15 */
+  STATE_INTERFACE,
   STATE_INTERFACE_PROPERTY,
   STATE_INTERFACE_FIELD,
   STATE_IMPLEMENTS,
-  STATE_PREREQUISITE,
-  STATE_BOXED,   /* 20 */
+  STATE_PREREQUISITE,    /* 20 */
+  STATE_BOXED,
   STATE_BOXED_FIELD,
   STATE_STRUCT,
   STATE_STRUCT_FIELD,
-  STATE_ERRORDOMAIN,
-  STATE_UNION, /* 25 */
+  STATE_ERRORDOMAIN, /* 25 */
+  STATE_UNION, 
   STATE_UNION_FIELD,
   STATE_NAMESPACE_CONSTANT,
   STATE_CLASS_CONSTANT,
@@ -964,15 +964,16 @@ parse_property_transfer (GIrNodeProperty *property,
     }
 }
 
-static void
-parse_param_transfer (GIrNodeParam *param, const gchar *transfer, const gchar *name)
+static gboolean
+parse_param_transfer (GIrNodeParam *param, const gchar *transfer, const gchar *name,
+		      GError **error)
 {
   if (transfer == NULL)
   {
-    if (!name)
-      g_warning ("required attribute 'transfer-ownership' missing");
-    else
-      g_warning ("required attribute 'transfer-ownership' for function '%s'", name);
+    g_set_error (error, G_MARKUP_ERROR,
+		 G_MARKUP_ERROR_INVALID_CONTENT,
+		 "required attribute 'transfer-ownership' missing");
+    return FALSE;
   }
   else if (strcmp (transfer, "none") == 0)
     {
@@ -991,8 +992,12 @@ parse_param_transfer (GIrNodeParam *param, const gchar *transfer, const gchar *n
     }
   else
     {
-      g_warning ("Unknown transfer-ownership value: %s", transfer);
+      g_set_error (error, G_MARKUP_ERROR,
+		   G_MARKUP_ERROR_INVALID_CONTENT,
+		   "invalid value for 'transfer-ownership': %s", transfer);
+      return FALSE;
     }
+  return TRUE;
 }
 
 static gboolean
@@ -1078,7 +1083,8 @@ start_parameter (GMarkupParseContext *context,
   else
     param->allow_none = FALSE;
 
-  parse_param_transfer (param, transfer, name);
+  if (!parse_param_transfer (param, transfer, name, error))
+    return FALSE;
 
   if (scope && strcmp (scope, "call") == 0)
     param->scope = GI_SCOPE_TYPE_CALL;
@@ -2166,7 +2172,8 @@ start_return_value (GMarkupParseContext *context,
   state_switch (ctx, STATE_FUNCTION_RETURN);
 
   transfer = find_attribute ("transfer-ownership", attribute_names, attribute_values);
-  parse_param_transfer (param, transfer, NULL);
+  if (!parse_param_transfer (param, transfer, NULL, error))
+    return FALSE;
 
   switch (CURRENT_NODE (ctx)->type)
     {
@@ -2976,8 +2983,9 @@ start_element_handler (GMarkupParseContext *context,
     {
       g_markup_parse_context_get_position (context, &line_number, &char_number);
       if (!g_str_has_prefix (element_name, "c:"))
-	g_printerr ("%s:%d:%d: warning: dropping to PASSTHROUGH\n",
-		    ctx->file_path, line_number, char_number);
+	g_printerr ("%s:%d:%d: warning: element %s from state %d is unknown, ignoring\n",
+		    ctx->file_path, line_number, char_number, element_name,
+		    ctx->state);
       state_switch (ctx, STATE_PASSTHROUGH);
       ctx->unknown_depth = 1;
     }



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