Bug 562622 – Errordomains missing
authorJohan Dahlin <jdahlin@async.com.br>
Thu, 22 Jan 2009 00:02:49 +0000 (00:02 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Thu, 22 Jan 2009 00:02:49 +0000 (00:02 +0000)
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:

svn path=/trunk/; revision=1057

ChangeLog
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
tests/scanner/foo.h

index 46d9a2b06bab3f4af9d8b63d52e2be08c2f1cdec..487d1433a30f2efacedcb8259d60b99e9cee68fd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+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:
+
 2009-01-20  Johan Dahlin  <jdahlin@async.com.br>
 
        * giscanner/scannerlexer.l:
index 89af8fb977d02d5ec75fc4332a2616fb92c690e4..51a208d78fe50d3f2a2d9aba3d8ac6ee63a2c7fd 100644 (file)
@@ -240,8 +240,11 @@ and/or use gtk-doc annotations. ''')
             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)
index 11a5ed0b985ef6204332a7ccf4d42eecbfde70fa..f61cd5f30e7e4e627aeadf879cb3332d45397e96 100644 (file)
@@ -70,6 +70,7 @@ class GLibEnum(Enum):
         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,
index f4f5382aeaf0aba4069ed0fb2fb7f28ea56d19be..02b2767eda42f9c6c8b649ee09659088d2e29a38 100644 (file)
@@ -90,6 +90,7 @@ class GLibTransformer(object):
         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 @@ class GLibTransformer(object):
                 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 @@ class GLibTransformer(object):
         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 @@ class GLibTransformer(object):
     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 @@ class GLibTransformer(object):
                 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 @@ class GLibTransformer(object):
         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)
index 36fb772b80a73d241c4955211215f44b3c442d85..bc291b819b86caa9b98d2de390ab60b200d125d2 100644 (file)
@@ -34,8 +34,8 @@ EXPECTEDGIRS = $(GIRS:.gir=-expected.gir)
 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 @@ post-check:
         $(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
index 11a3b4e096acd5b860ddc64e5cbc22a79b48af86..d826a5d45680a55d6c84f8f204f1016469bc858d 100644 (file)
@@ -617,6 +617,24 @@ and/or use gtk-doc annotations.  -->
         </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>
index 59549192520befe8adda01889965fcea95ec550a..614f6f843b28faeb583ddb3e8f48adce2a59a5ba 100644 (file)
         </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>
index 50b78c20ad321ebede290f012f2462c315879896..ea55e9d8d184b659d46983ae9bbb0cb5f72c5cb0 100644 (file)
@@ -433,3 +433,25 @@ foo_hidden_get_type (void)
   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");
+}
+
index f08fc3c7f9c0dfe77921e3af4b122aeb81e81849..b3614f35e39ae5de81af2d37efd4e7415b362d8f 100644 (file)
@@ -293,4 +293,13 @@ const FooStruct * foo_test_const_struct_retval (void);
 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__ */