diff options
-rw-r--r-- | giscanner/giscannermodule.c | 21 | ||||
-rw-r--r-- | giscanner/scannerparser.y | 7 | ||||
-rw-r--r-- | giscanner/sourcescanner.h | 2 | ||||
-rw-r--r-- | giscanner/sourcescanner.py | 7 | ||||
-rw-r--r-- | giscanner/transformer.py | 12 | ||||
-rw-r--r-- | tests/scanner/foo-1.0-expected.gir | 3 | ||||
-rw-r--r-- | tests/scanner/foo-1.0-expected.tgir | 3 | ||||
-rw-r--r-- | tests/scanner/foo.h | 2 |
8 files changed, 50 insertions, 7 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 7d637845..80d7f6b9 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -135,10 +135,27 @@ static PyObject * symbol_get_const_int (PyGISourceSymbol *self, void *context) { + if (!self->symbol->const_int_set) + { + Py_INCREF(Py_None); + return Py_None; + } return PyInt_FromLong (self->symbol->const_int); } static PyObject * +symbol_get_const_double (PyGISourceSymbol *self, + void *context) +{ + if (!self->symbol->const_double_set) + { + Py_INCREF(Py_None); + return Py_None; + } + return PyFloat_FromDouble (self->symbol->const_double); +} + +static PyObject * symbol_get_const_string (PyGISourceSymbol *self, void *context) { @@ -171,7 +188,9 @@ static const PyGetSetDef _PyGISourceSymbol_getsets[] = { { "ident", (getter)symbol_get_ident, NULL, NULL}, { "base_type", (getter)symbol_get_base_type, NULL, NULL}, /* gboolean const_int_set; */ - { "const_int", (getter)symbol_get_const_int, NULL, NULL}, + { "const_int", (getter)symbol_get_const_int, NULL, NULL}, + /* gboolean const_double_set; */ + { "const_double", (getter)symbol_get_const_double, NULL, NULL}, { "const_string", (getter)symbol_get_const_string, NULL, NULL}, { "source_filename", (getter)symbol_get_source_filename, NULL, NULL}, { 0 } diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index 85640fec..c92a5381 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -167,7 +167,10 @@ primary_expression } | FLOATING { - $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID); + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST); + $$->const_double_set = TRUE; + $$->const_double = 0.0; + sscanf (yytext, "%lf", &($$->const_double)); } | strings | '(' expression ')' @@ -1256,7 +1259,7 @@ function_macro_define object_macro_define : object_macro constant_expression { - if ($2->const_int_set || $2->const_string != NULL) { + if ($2->const_int_set || $2->const_double_set || $2->const_string != NULL) { $2->ident = $1; gi_source_scanner_add_symbol (scanner, $2); gi_source_symbol_unref ($2); diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h index bbc49770..a49de5c7 100644 --- a/giscanner/sourcescanner.h +++ b/giscanner/sourcescanner.h @@ -116,6 +116,8 @@ struct _GISourceSymbol gboolean const_int_set; int const_int; char *const_string; + gboolean const_double_set; + double const_double; char *source_filename; }; diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index 30e624bb..1a8194d5 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -146,7 +146,8 @@ class SourceType(object): class SourceSymbol(object): - __members__ = ['const_int', 'const_string', 'ident', 'type', 'base_type'] + __members__ = ['const_int', 'const_double', 'const_string', 'ident', + 'type', 'base_type'] def __init__(self, scanner, symbol): self._scanner = scanner @@ -163,6 +164,10 @@ class SourceSymbol(object): return self._symbol.const_int @property + def const_double(self): + return self._symbol.const_double + + @property def const_string(self): return self._symbol.const_string diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 58c2fbc9..eb76f830 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -465,12 +465,18 @@ class Transformer(object): if not symbol.source_filename.endswith('.h'): return None name = self.remove_prefix(symbol.ident) - if symbol.const_string is None: + if symbol.const_string is not None: + type_name = 'utf8' + value = symbol.const_string + elif symbol.const_int is not None: type_name = 'int' value = symbol.const_int + elif symbol.const_double is not None: + type_name = 'double' + value = symbol.const_double else: - type_name = 'utf8' - value = symbol.const_string + raise AssertionError() + const = Constant(name, type_name, value) return const diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir index 2f821754..4bd77452 100644 --- a/tests/scanner/foo-1.0-expected.gir +++ b/tests/scanner/foo-1.0-expected.gir @@ -399,6 +399,9 @@ and/or use gtk-doc annotations. --> </parameters> </callback> </record> + <constant name="PIE_IS_TASTY" value="3.14159"> + <type name="double"/> + </constant> <record name="Rectangle" c:type="FooRectangle"> <field name="x" writable="1"> <type name="int" c:type="gint"/> diff --git a/tests/scanner/foo-1.0-expected.tgir b/tests/scanner/foo-1.0-expected.tgir index edf58eff..dcd97891 100644 --- a/tests/scanner/foo-1.0-expected.tgir +++ b/tests/scanner/foo-1.0-expected.tgir @@ -277,6 +277,9 @@ <type name="GObject.ObjectClass"/> </field> </record> + <constant name="PIE_IS_TASTY" value="3.141590"> + <type name="double"/> + </constant> <record name="Rectangle"> <field name="x" writable="1"> <type name="int"/> diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h index d3dd29f9..da30df38 100644 --- a/tests/scanner/foo.h +++ b/tests/scanner/foo.h @@ -8,6 +8,8 @@ #define FOO_DEFINE_SHOULD_BE_EXPOSED "should be exposed" +#define FOO_PIE_IS_TASTY 3.14159 + #define FOO_TYPE_INTERFACE (foo_interface_get_type ()) #define FOO_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), FOO_TYPE_INTERFACE, FooInterface)) #define FOO_IS_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), FOO_TYPE_INTERFACE)) |