GNOME Bugzilla – Bug 719566
scanner: Support boolean constants
Last modified: 2017-05-04 21:27:11 UTC
See patch. Basically I got fed up with consulting API docs every other time I set up an idle/timeout source ... :-)
Created attachment 263142 [details] [review] 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.
Review of attachment 263142 [details] [review]: ::: giscanner/scannerlexer.l @@ +172,3 @@ + +"TRUE" { return BOOLEAN; } +"FALSE" { return BOOLEAN; } It's worth noting C99 has "true" and "false" (lowercase). Up to you whether or not to support... ::: giscanner/scannerparser.y @@ +331,3 @@ + $$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, scanner->current_file, lineno); + $$->const_boolean_set = TRUE; + $$->const_boolean = strcmp (yytext, "TRUE") == 0 ? TRUE : FALSE; Might as well future proof with g_ascii_strcasecmp() ::: giscanner/transformer.py @@ +732,3 @@ + typeval = ast.TYPE_BOOLEAN + value = str(symbol.const_boolean) + print value Leftover debug print?
Created attachment 263148 [details] [review] scanner: Support boolean constants (In reply to comment #2) > It's worth noting C99 has "true" and "false" (lowercase). Up to you whether or > not to support... It's an easy addition, so sure. > Might as well future proof with g_ascii_strcasecmp() Done. > ::: giscanner/transformer.py > Leftover debug print? Whoops, indeed. Fixed.
Review of attachment 263148 [details] [review]: One other comment, feel free to commit after addressing. ::: giscanner/transformer.py @@ +731,3 @@ + elif symbol.const_boolean is not None: + typeval = ast.TYPE_BOOLEAN + value = str(symbol.const_boolean) So we're putting the Python stringifcation into the .gir, so it shows up as "True" or "False". But girnode.c:parse_boolean_value() only looks for TRUE/FALSE. I think we should: 1) Write either "TRUE" or "true" (I have no opinion on which), but not the Python "True" 2) Also change parse_boolean_value to use g_ascii_strcasecmp() to be defensive (remember .gir files can also be generated by vala)
Attachment 263148 [details] pushed as e4efb97 - scanner: Support boolean constants Adjusted as suggested and pushed, thanks!
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
*** Bug 680387 has been marked as a duplicate of this bug. ***