diff options
author | Florian Müllner <fmuellner@gnome.org> | 2013-11-29 01:12:40 +0100 |
---|---|---|
committer | Florian Müllner <fmuellner@gnome.org> | 2013-11-29 18:45:31 +0000 |
commit | e4efb97c8a20f5dcbf6cd2736bd5bcd92e1d814d (patch) | |
tree | baa632338c6712a1582fe0711d4c46e4f2a13637 /giscanner | |
parent | 9112ec1e845015a17bba49fb1dd385a2c6e9efd7 (diff) | |
download | gobject-introspection-e4efb97c8a20f5dcbf6cd2736bd5bcd92e1d814d.tar.gz |
scanner: Support boolean constants
Aliasing TRUE or FALSE is not very common, but done occasionally
for extra clarity. Namely G_SOURCE_REMOVE / G_SOURCE_CONTINUE are
self-explanatory, unlike the "raw" booleans.
https://bugzilla.gnome.org/show_bug.cgi?id=719566
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/giscannermodule.c | 15 | ||||
-rw-r--r-- | giscanner/scannerlexer.l | 6 | ||||
-rw-r--r-- | giscanner/scannerparser.y | 10 | ||||
-rw-r--r-- | giscanner/sourcescanner.c | 3 | ||||
-rw-r--r-- | giscanner/sourcescanner.h | 2 | ||||
-rw-r--r-- | giscanner/sourcescanner.py | 8 | ||||
-rw-r--r-- | giscanner/transformer.py | 3 |
7 files changed, 43 insertions, 4 deletions
diff --git a/giscanner/giscannermodule.c b/giscanner/giscannermodule.c index 2f413a02..925b3e0a 100644 --- a/giscanner/giscannermodule.c +++ b/giscanner/giscannermodule.c @@ -193,6 +193,19 @@ symbol_get_const_string (PyGISourceSymbol *self, } static PyObject * +symbol_get_const_boolean (PyGISourceSymbol *self, + void *context) +{ + if (!self->symbol->const_boolean_set) + { + Py_INCREF(Py_None); + return Py_None; + } + + return PyBool_FromLong (self->symbol->const_boolean); +} + +static PyObject * symbol_get_source_filename (PyGISourceSymbol *self, void *context) { @@ -216,6 +229,8 @@ static const PyGetSetDef _PyGISourceSymbol_getsets[] = { /* gboolean const_double_set; */ { "const_double", (getter)symbol_get_const_double, NULL, NULL}, { "const_string", (getter)symbol_get_const_string, NULL, NULL}, + /* gboolean const_boolean_set; */ + { "const_boolean", (getter)symbol_get_const_boolean, NULL, NULL}, { "source_filename", (getter)symbol_get_source_filename, NULL, NULL}, { "line", (getter)symbol_get_line, NULL, NULL}, { "private", (getter)symbol_get_private, NULL, NULL}, diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l index 89a34b88..413bd98a 100644 --- a/giscanner/scannerlexer.l +++ b/giscanner/scannerlexer.l @@ -169,6 +169,12 @@ stringtext ([^\\\"])|(\\.) "G_GINT64_CONSTANT" { return INTL_CONST; } "G_GUINT64_CONSTANT" { return INTUL_CONST; } + +"TRUE" { return BOOLEAN; } +"FALSE" { return BOOLEAN; } +"true" { return BOOLEAN; } +"false" { return BOOLEAN; } + [a-zA-Z_][a-zA-Z_0-9]* { if (scanner->macro_scan) return check_identifier(scanner, yytext); else REJECT; } "asm" { if (!parse_ignored_macro()) REJECT; } diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index faf73410..6cbf36ad 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -226,7 +226,7 @@ toggle_conditional (GISourceScanner *scanner) %token <str> IDENTIFIER "identifier" %token <str> TYPEDEF_NAME "typedef-name" -%token INTEGER FLOATING CHARACTER STRING +%token INTEGER FLOATING BOOLEAN CHARACTER STRING %token INTL_CONST INTUL_CONST %token ELLIPSIS ADDEQ SUBEQ MULEQ DIVEQ MODEQ XOREQ ANDEQ OREQ SL SR @@ -326,6 +326,12 @@ primary_expression $$->const_int = value; $$->const_int_is_unsigned = (rest && (rest[0] == 'U')); } + | BOOLEAN + { + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_boolean_set = TRUE; + $$->const_boolean = g_ascii_strcasecmp (yytext, "true") == 0 ? TRUE : FALSE; + } | CHARACTER { $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); @@ -1475,7 +1481,7 @@ function_macro_define object_macro_define : object_macro constant_expression { - if ($2->const_int_set || $2->const_double_set || $2->const_string != NULL) { + if ($2->const_int_set || $2->const_boolean_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.c b/giscanner/sourcescanner.c index 98dbebd2..070397b4 100644 --- a/giscanner/sourcescanner.c +++ b/giscanner/sourcescanner.c @@ -60,6 +60,9 @@ gi_source_symbol_copy (GISourceSymbol * symbol) new_symbol->const_int = symbol->const_int; new_symbol->const_int_is_unsigned = symbol->const_int_is_unsigned; new_symbol->const_int_set = TRUE; + } else if (symbol->const_boolean_set) { + new_symbol->const_boolean = symbol->const_boolean; + new_symbol->const_boolean_set = TRUE; } else if (symbol->const_double_set) { new_symbol->const_double = symbol->const_double; new_symbol->const_double_set = TRUE; diff --git a/giscanner/sourcescanner.h b/giscanner/sourcescanner.h index 39ae84d7..9e371312 100644 --- a/giscanner/sourcescanner.h +++ b/giscanner/sourcescanner.h @@ -131,6 +131,8 @@ struct _GISourceSymbol char *const_string; gboolean const_double_set; double const_double; + gboolean const_boolean_set; + int const_boolean; char *source_filename; int line; }; diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py index 42af96ff..a115158e 100644 --- a/giscanner/sourcescanner.py +++ b/giscanner/sourcescanner.py @@ -154,8 +154,8 @@ class SourceType(object): class SourceSymbol(object): - __members__ = ['const_int', 'const_double', 'const_string', 'ident', - 'type', 'base_type'] + __members__ = ['const_int', 'const_double', 'const_string', 'const_boolean', + 'ident', 'type', 'base_type'] def __init__(self, scanner, symbol): self._scanner = scanner @@ -186,6 +186,10 @@ class SourceSymbol(object): return self._symbol.const_string @property + def const_boolean(self): + return self._symbol.const_boolean + + @property def ident(self): return self._symbol.ident diff --git a/giscanner/transformer.py b/giscanner/transformer.py index bd476cc7..156148f4 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -728,6 +728,9 @@ raise ValueError.""" value = str(symbol.const_int % 2 ** 16) else: value = str(symbol.const_int) + elif symbol.const_boolean is not None: + typeval = ast.TYPE_BOOLEAN + value = "true" if symbol.const_boolean else "false" elif symbol.const_double is not None: typeval = ast.TYPE_DOUBLE value = '%f' % (symbol.const_double, ) |