scanner: handle unsigned properly for type of defined size
authorAlban Browaeys <prahal@yahoo.com>
Fri, 29 Jun 2012 02:38:04 +0000 (04:38 +0200)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 3 Aug 2012 11:57:19 +0000 (13:57 +0200)
giscanner/transformer.py
tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.h

index 26c7793..6afad88 100644 (file)
@@ -723,7 +723,23 @@ raise ValueError."""
                 typeval = self._create_type_from_base(symbol.base_type)
             else:
                 typeval = ast.TYPE_INT
-            value = '%d' % (symbol.const_int, )
+            unaliased = typeval
+            self._resolve_type_from_ctype(unaliased)
+            if typeval.target_giname and typeval.ctype:
+                target = self.lookup_giname(typeval.target_giname)
+                target = self.resolve_aliases(target)
+                if isinstance(target, ast.Type):
+                    unaliased = target
+            if unaliased == ast.TYPE_UINT64:
+                value = str(symbol.const_int % 2**64)
+            elif unaliased == ast.TYPE_UINT32:
+                value = str(symbol.const_int % 2**32)
+            elif unaliased == ast.TYPE_UINT16:
+                value = str(symbol.const_int % 2**16)
+            elif unaliased == ast.TYPE_UINT8:
+                value = str(symbol.const_int % 2**16)
+            else:
+                value = str(symbol.const_int)
         elif symbol.const_double is not None:
             typeval = ast.TYPE_DOUBLE
             value = '%f' % (symbol.const_double, )
index 43258f2..9b773fb 100644 (file)
@@ -44,6 +44,11 @@ and/or use gtk-doc annotations.  -->
               c:type="REGRESS_DOUBLE_CONSTANT">
       <type name="gdouble" c:type="gdouble"/>
     </constant>
+    <constant name="GUINT64_CONSTANT"
+              value="18446744073709551615"
+              c:type="REGRESS_GUINT64_CONSTANT">
+      <type name="guint64" c:type="guint64"/>
+    </constant>
     <constant name="G_GINT64_CONSTANT"
               value="1000"
               c:type="REGRESS_G_GINT64_CONSTANT">
index 0c071f5..ce5d1dc 100644 (file)
@@ -260,6 +260,7 @@ GQuark regress_atest_error_quark (void);
 #define REGRESS_STRING_CONSTANT "Some String"
 #define REGRESS_Mixed_Case_Constant 4423
 #define REGRESS_G_GINT64_CONSTANT (G_GINT64_CONSTANT (1000))
+#define REGRESS_GUINT64_CONSTANT ((guint64) -1)
 
 /* structures */
 typedef struct _RegressTestStructA RegressTestStructA;