diff options
author | Colin Walters <walters@verbum.org> | 2009-02-25 15:25:36 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-02-25 15:34:21 -0500 |
commit | 0b9dda0e725446882dca84b6a64688c8f0e5a4e3 (patch) | |
tree | fd7b7e5d75dc86ea18c1168310d80402fddf5c45 /giscanner | |
parent | c58582c7a88a95616fa87b81517ab8a2a76af92f (diff) | |
download | gobject-introspection-0b9dda0e725446882dca84b6a64688c8f0e5a4e3.tar.gz |
Bug 555964 - Parse floating-point #defines
Previously we just supported int and string, add double to this.
Technically we should probably differentiate between float and
double, but it's not likely to be very useful in practice to do so.
Diffstat (limited to 'giscanner')
-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 |
5 files changed, 42 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 |