giscanner: special case G_GINT64_CONSTANT and G_GUINT64_CONSTANT + misc
authorAlban Browaeys <prahal@yahoo.com>
Thu, 28 Jun 2012 16:34:02 +0000 (18:34 +0200)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Fri, 3 Aug 2012 11:57:11 +0000 (13:57 +0200)
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

giscanner/scannerlexer.l
giscanner/scannerparser.y
giscanner/transformer.py
tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.h

index 8ff6b7be4e463db95ae469895d43a71d077c959b..a783ec069df8fd374bf07ef0273feb256b297e50 100644 (file)
@@ -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; }
index 48e3c132bf0599272bc716796a9f97950eeb459d..06a10efad969d23e3395bde99eead0b169c8c3e6 100644 (file)
@@ -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;
          }
index d6320d84a98b46189b5cfce160a35cb0e0eba569..26c7793bfd7287659f5aeace754cc57c80bacb5b 100644 (file)
@@ -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
index 37f222503bf596dd95f289d1e5f1263fccefad67..43258f2ab79c2131dddd058d36cf0965cde35e2e 100644 (file)
@@ -44,6 +44,11 @@ and/or use gtk-doc annotations.  -->
               c:type="REGRESS_DOUBLE_CONSTANT">
       <type name="gdouble" c:type="gdouble"/>
     </constant>
+    <constant name="G_GINT64_CONSTANT"
+              value="1000"
+              c:type="REGRESS_G_GINT64_CONSTANT">
+      <type name="gint64" c:type="gint64"/>
+    </constant>
     <constant name="INT_CONSTANT" value="4422" c:type="REGRESS_INT_CONSTANT">
       <type name="gint" c:type="gint"/>
     </constant>
index d8db7aa8d9c4a26d2545068c3e30c4002f2d6eca..0c071f512bcd86cef2d0a16dd506b313f1ddf933 100644 (file)
@@ -259,6 +259,7 @@ GQuark regress_atest_error_quark (void);
 #define REGRESS_DOUBLE_CONSTANT 44.22
 #define REGRESS_STRING_CONSTANT "Some String"
 #define REGRESS_Mixed_Case_Constant 4423
+#define REGRESS_G_GINT64_CONSTANT (G_GINT64_CONSTANT (1000))
 
 /* structures */
 typedef struct _RegressTestStructA RegressTestStructA;