diff options
author | Alban Browaeys <prahal@yahoo.com> | 2012-06-28 18:34:02 +0200 |
---|---|---|
committer | Tomeu Vizoso <tomeu.vizoso@collabora.com> | 2012-08-03 13:57:11 +0200 |
commit | beb5c820139693c85f4e5277a7c430dd6042fbcb (patch) | |
tree | dec4ff90163f46aa8afaa22d0356609cde3f8dfa /giscanner | |
parent | d0ffee9bffacbeb45cc4e03079fe143d5f73288d (diff) | |
download | gobject-introspection-beb5c820139693c85f4e5277a7c430dd6042fbcb.tar.gz |
giscanner: special case G_GINT64_CONSTANT and G_GUINT64_CONSTANT + misc
This let the macro expands to its value as gint64/guint64.
Also
- fix lexer identifier/typdef detection for macro and misc
- do not discard cast
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/scannerlexer.l | 4 | ||||
-rw-r--r-- | giscanner/scannerparser.y | 23 | ||||
-rw-r--r-- | giscanner/transformer.py | 5 |
3 files changed, 28 insertions, 4 deletions
diff --git a/giscanner/scannerlexer.l b/giscanner/scannerlexer.l index 8ff6b7be..a783ec06 100644 --- a/giscanner/scannerlexer.l +++ b/giscanner/scannerlexer.l @@ -147,7 +147,9 @@ stringtext ([^\\\"])|(\\.) "__typeof" { if (!parse_ignored_macro()) REJECT; } "_Bool" { return BOOL; } -[a-zA-Z_][a-zA-Z_0-9]* { if (scanner->macro_scan) return IDENTIFIER; else REJECT; } +"G_GINT64_CONSTANT" { return INTL_CONST; } +"G_GUINT64_CONSTANT" { return INTUL_CONST; } +[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; } "auto" { return AUTO; } diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y index 48e3c132..06a10efa 100644 --- a/giscanner/scannerparser.y +++ b/giscanner/scannerparser.y @@ -150,6 +150,7 @@ out: %token INTEGER FLOATING CHARACTER STRING +%token INTL_CONST INTUL_CONST %token ELLIPSIS ADDEQ SUBEQ MULEQ DIVEQ MODEQ XOREQ ANDEQ OREQ SL SR %token SLEQ SREQ EQ NOTEQ LTEQ GTEQ ANDAND OROR PLUSPLUS MINUSMINUS ARROW @@ -377,6 +378,20 @@ unary_expression break; } } + | INTL_CONST '(' unary_expression ')' + { + $$ = $3; + if ($$->const_int_set) { + $$->base_type = gi_source_basic_type_new ("gint64"); + } + } + | INTUL_CONST '(' unary_expression ')' + { + $$ = $3; + if ($$->const_int_set) { + $$->base_type = gi_source_basic_type_new ("guint64"); + } + } | SIZEOF unary_expression { $$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, scanner->current_filename, lineno); @@ -419,8 +434,12 @@ cast_expression : unary_expression | '(' type_name ')' cast_expression { - ctype_free ($2); $$ = $4; + if ($$->const_int_set || $$->const_double_set || $$->const_string != NULL) { + $$->base_type = $2; + } else { + ctype_free ($2); + } } ; @@ -588,7 +607,7 @@ logical_or_expression conditional_expression : logical_or_expression - | logical_or_expression '?' expression ':' conditional_expression + | logical_or_expression '?' expression ':' expression { $$ = gi_source_symbol_get_const_boolean ($1) ? $3 : $5; } diff --git a/giscanner/transformer.py b/giscanner/transformer.py index d6320d84..26c7793b 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -719,7 +719,10 @@ raise ValueError.""" typeval = ast.TYPE_STRING value = unicode(symbol.const_string, 'utf-8') elif symbol.const_int is not None: - typeval = ast.TYPE_INT + if symbol.base_type is not None: + typeval = self._create_type_from_base(symbol.base_type) + else: + typeval = ast.TYPE_INT value = '%d' % (symbol.const_int, ) elif symbol.const_double is not None: typeval = ast.TYPE_DOUBLE |