gobject-introspection r1057 - in trunk: . giscanner tests/scanner



Author: johan
Date: Thu Jan 22 00:02:49 2009
New Revision: 1057
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=1057&view=rev

Log:
2009-01-21  Johan Dahlin  <jdahlin async com br>

        Bug 562622 â Errordomains missing

        * giscanner/girwriter.py:
        * giscanner/glibast.py:
        * giscanner/glibtransformer.py:
        * tests/scanner/Makefile.am:
        * tests/scanner/foo-1.0-expected.gir:
        * tests/scanner/foo-1.0-expected.tgir:
        * tests/scanner/foo.c (foo_error_get_type), (foo_error_quark):
        * tests/scanner/foo.h:



Modified:
   trunk/ChangeLog
   trunk/giscanner/girwriter.py
   trunk/giscanner/glibast.py
   trunk/giscanner/glibtransformer.py
   trunk/tests/scanner/Makefile.am
   trunk/tests/scanner/foo-1.0-expected.gir
   trunk/tests/scanner/foo-1.0-expected.tgir
   trunk/tests/scanner/foo.c
   trunk/tests/scanner/foo.h

Modified: trunk/giscanner/girwriter.py
==============================================================================
--- trunk/giscanner/girwriter.py	(original)
+++ trunk/giscanner/girwriter.py	Thu Jan 22 00:02:49 2009
@@ -240,8 +240,11 @@
             attrs.extend([('glib:type-name', enum.type_name),
                           ('glib:get-type', enum.get_type),
                           ('c:type', enum.ctype)])
+            if enum.error_quark:
+                attrs.append(('glib:error-quark', enum.error_quark))
         else:
             attrs.append(('c:type', enum.symbol))
+
         with self.tagcontext('enumeration', attrs):
             for member in enum.members:
                 self._write_member(member)

Modified: trunk/giscanner/glibast.py
==============================================================================
--- trunk/giscanner/glibast.py	(original)
+++ trunk/giscanner/glibast.py	Thu Jan 22 00:02:49 2009
@@ -70,6 +70,7 @@
         self.ctype = type_name
         self.type_name = type_name
         self.get_type = get_type
+        self.error_quark = None
 
     def __repr__(self):
         return 'GlibEnum(%r, %r, %r)' % (self.name, self.members,

Modified: trunk/giscanner/glibtransformer.py
==============================================================================
--- trunk/giscanner/glibtransformer.py	(original)
+++ trunk/giscanner/glibtransformer.py	Thu Jan 22 00:02:49 2009
@@ -90,6 +90,7 @@
         self._uscore_type_names = {}
         self._binary = None
         self._get_type_functions = []
+        self._error_quark_functions = []
         self._gtype_data = {}
         self._failed_types = {}
         self._boxed_types = {}
@@ -150,7 +151,7 @@
                 self._pair_class_record(node)
         for (ns, alias) in self._names.aliases.itervalues():
             self._resolve_alias(alias)
-
+        self._resolve_quarks()
         self._print_statistics()
         # Fourth pass: ensure all types are known
         if not self._noclosure:
@@ -202,6 +203,13 @@
         no_uscore_prefixed = (prefix + '_' + to_underscores(suffix)).lower()
         self._uscore_type_names[no_uscore_prefixed] = node
 
+    def _resolve_quarks(self):
+        for node in self._error_quark_functions:
+            short = node.symbol[:-len('_quark')]
+            enum = self._uscore_type_names.get(short)
+            if enum is not None:
+                enum.error_quark = node.symbol
+
     # Helper functions
 
     def _resolve_gtypename(self, gtype_name):
@@ -214,6 +222,7 @@
     def _execute_binary(self):
         in_path = os.path.join(self._binary.tmpdir, 'types.txt')
         f = open(in_path, 'w')
+        # TODO: Introspect GQuark functions
         for func in self._get_type_functions:
             f.write(func)
             f.write('\n')
@@ -304,6 +313,8 @@
                 return
         if self._parse_get_type_function(func):
             return
+        if self._parse_error_quark_function(func):
+            return
 
         self._add_attribute(func)
 
@@ -328,6 +339,18 @@
         self._get_type_functions.append(symbol)
         return True
 
+    def _parse_error_quark_function(self, func):
+        if not func.symbol.endswith('_error_quark'):
+            return False
+        if func.parameters:
+            return False
+        if func.retval.type.name not in ['GLib.Quark',
+                                         'GQuark']:
+            return False
+
+        self._error_quark_functions.append(func)
+        return True
+
     def _name_is_internal_gtype(self, giname):
         try:
             node = self._get_attribute(giname)

Modified: trunk/tests/scanner/Makefile.am
==============================================================================
--- trunk/tests/scanner/Makefile.am	(original)
+++ trunk/tests/scanner/Makefile.am	Thu Jan 22 00:02:49 2009
@@ -34,8 +34,8 @@
 TGIRS = $(GIRS:.gir=.tgir)
 CHECKTGIRS = $(GIRS:.gir=.tgir.check)
 EXPECTEDTGIRS = $(GIRS:.gir=-expected.tgir)
-CLEANFILES = $(TYPELIBS)  $(GIRS) $(TGIRS)
-BUILT_SOURCES = $(TYPELIBS) $(GIRS)
+CLEANFILES = $(TYPELIBS)  $(GIRS)
+BUILT_SOURCES = $(TYPELIBS) $(GIRS) $(TGIRS)
 EXTRA_DIST = $(EXPECTEDGIRS) $(EXPECTEDTGIRS)
 
 annotation-1.0.gir: libannotation.la annotation.c annotation.h utility-1.0.gir $(SCANNER_BIN) $(SCANNER_LIBS) Makefile
@@ -149,10 +149,13 @@
 	 $(DEBUG) $(top_builddir)/tools/g-ir-generate --includedir=. --includedir=$(top_builddir)/gir $< -o $@
 
 %.tgir.check: %.tgir
-	@diff -u -U 10 $(srcdir)/$*-expected.tgir $*.tgir && echo "* $*.tgir"
+	@diff -u -U 10 $(srcdir)/$*-expected.tgir $*.tgir; \
+	if test "$$?" = "0"; then \
+           echo "* $*.tgir"; \
+           rm -f $*.tgir; \
+        fi
 
 check-local: pre-check
 check-local: $(CHECKGIRS) $(CHECKTGIRS) $(TYPELIBS)
-CLEANFILES += $(TGIRS)
 
 check-local: post-check

Modified: trunk/tests/scanner/foo-1.0-expected.gir
==============================================================================
--- trunk/tests/scanner/foo-1.0-expected.gir	(original)
+++ trunk/tests/scanner/foo-1.0-expected.gir	Thu Jan 22 00:02:49 2009
@@ -617,6 +617,24 @@
         </parameter>
       </parameters>
     </function>
+    <enumeration name="Error"
+                 glib:type-name="FooError"
+                 glib:get-type="foo_error_get_type"
+                 c:type="FooError"
+                 glib:error-quark="foo_error_quark">
+      <member name="good"
+              value="0"
+              c:identifier="FOO_ERROR_GOOD"
+              glib:nick="good"/>
+      <member name="bad"
+              value="1"
+              c:identifier="FOO_ERROR_BAD"
+              glib:nick="bad"/>
+      <member name="ugly"
+              value="2"
+              c:identifier="FOO_ERROR_UGLY"
+              glib:nick="ugly"/>
+    </enumeration>
     <constant name="SUCCESS_INT" value="4408">
       <type name="int"/>
     </constant>

Modified: trunk/tests/scanner/foo-1.0-expected.tgir
==============================================================================
--- trunk/tests/scanner/foo-1.0-expected.tgir	(original)
+++ trunk/tests/scanner/foo-1.0-expected.tgir	Thu Jan 22 00:02:49 2009
@@ -485,6 +485,11 @@
         </parameter>
       </parameters>
     </function>
+    <enumeration name="Error" glib:type-name="FooError" glib:get-type="foo_error_get_type">
+      <member name="good" value="0"/>
+      <member name="bad" value="1"/>
+      <member name="ugly" value="2"/>
+    </enumeration>
     <constant name="SUCCESS_INT" value="4408">
       <type name="int"/>
     </constant>

Modified: trunk/tests/scanner/foo.c
==============================================================================
--- trunk/tests/scanner/foo.c	(original)
+++ trunk/tests/scanner/foo.c	Thu Jan 22 00:02:49 2009
@@ -433,3 +433,25 @@
   return our_type;
 }
 
+GType
+foo_error_get_type (void)
+{
+    static GType etype = 0;
+    if (G_UNLIKELY(etype == 0)) {
+        static const GEnumValue values[] = {
+            { FOO_ERROR_GOOD, "FOO_ERROR_GOOD", "good" },
+            { FOO_ERROR_BAD, "FOO_ERROR_BAD", "bad" },
+            { FOO_ERROR_UGLY, "FOO_ERROR_UGLY", "ugly" },
+            { 0, NULL, NULL }
+        };
+        etype = g_enum_register_static (g_intern_static_string ("FooError"), values);
+    }
+    return etype;
+}
+
+GQuark
+foo_error_quark (void)
+{
+  return g_quark_from_static_string ("foo-error-quark");
+}
+

Modified: trunk/tests/scanner/foo.h
==============================================================================
--- trunk/tests/scanner/foo.h	(original)
+++ trunk/tests/scanner/foo.h	Thu Jan 22 00:02:49 2009
@@ -293,4 +293,13 @@
 void foo_test_const_char_param (const char * param);
 void foo_test_const_struct_param (const FooStruct * param);
 
+typedef enum {
+  FOO_ERROR_GOOD,
+  FOO_ERROR_BAD,
+  FOO_ERROR_UGLY
+} FooError;
+GType foo_error_get_type (void);
+
+GQuark foo_error_quark (void);
+
 #endif /* __FOO_OBJECT_H__ */



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