From 8b4d1acc40c03ddb0255b6a9f10ee5d731b39016 Mon Sep 17 00:00:00 2001 From: Alban Browaeys Date: Fri, 29 Jun 2012 04:38:04 +0200 Subject: [PATCH] scanner: handle unsigned properly for type of defined size --- giscanner/transformer.py | 18 +++++++++++++++++- tests/scanner/Regress-1.0-expected.gir | 5 +++++ tests/scanner/regress.h | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 26c7793b..6afad889 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -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, ) diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 43258f2a..9b773fb5 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -44,6 +44,11 @@ and/or use gtk-doc annotations. --> c:type="REGRESS_DOUBLE_CONSTANT"> + + + diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index 0c071f51..ce5d1dc2 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -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; -- 2.34.1