[gobject-introspection] GScannerParser: recognize character constants



commit 89908f752a9467f0659c2d93aaf7ee1b99716119
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Apr 3 23:13:09 2011 +0200

    GScannerParser: recognize character constants
    
    Some enumerations (like GVariantClass) use characters instead of
    plain integers, so we need to recognize them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646635

 giscanner/scannerparser.y              |    4 +++-
 tests/scanner/Regress-1.0-expected.gir |    9 +++++++++
 tests/scanner/regress.c                |    1 +
 tests/scanner/regress.h                |   11 ++++++++++-
 4 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/giscanner/scannerparser.y b/giscanner/scannerparser.y
index fc4a285..6400f72 100644
--- a/giscanner/scannerparser.y
+++ b/giscanner/scannerparser.y
@@ -243,7 +243,9 @@ primary_expression
 	  }
 	| CHARACTER
 	  {
-		$$ = gi_source_symbol_new (CSYMBOL_TYPE_INVALID, lineno);
+		$$ = gi_source_symbol_new (CSYMBOL_TYPE_CONST, lineno);
+		$$->const_int_set = TRUE;
+		$$->const_int = g_utf8_get_char(yytext + 1);
 	  }
 	| FLOATING
 	  {
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 52c5f8d..90c9320 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -184,6 +184,15 @@ use it should be.</doc>
               value="-1"
               c:identifier="REGRESS_TEST_VALUE3"
               glib:nick="value3"/>
+      <member name="value4"
+              value="48"
+              c:identifier="REGRESS_TEST_VALUE4"
+              glib:nick="value4"/>
+    </enumeration>
+    <enumeration name="TestEnumNoGEnum" c:type="RegressTestEnumNoGEnum">
+      <member name="evalue1" value="0" c:identifier="REGRESS_TEST_EVALUE1"/>
+      <member name="evalue2" value="42" c:identifier="REGRESS_TEST_EVALUE2"/>
+      <member name="evalue3" value="48" c:identifier="REGRESS_TEST_EVALUE3"/>
     </enumeration>
     <enumeration name="TestEnumUnsigned"
                  glib:type-name="RegressTestEnumUnsigned"
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index a2fb90f..27031b1 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1234,6 +1234,7 @@ regress_test_enum_get_type (void)
             { REGRESS_TEST_VALUE1, "REGRESS_TEST_VALUE1", "value1" },
             { REGRESS_TEST_VALUE2, "REGRESS_TEST_VALUE2", "value2" },
             { REGRESS_TEST_VALUE3, "REGRESS_TEST_VALUE3", "value3" },
+            { REGRESS_TEST_VALUE4, "REGRESS_TEST_VALUE4", "value4" },
             { 0, NULL, NULL }
         };
         etype = g_enum_register_static (g_intern_static_string ("RegressTestEnum"), values);
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index fd41a29..aafc25c 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -137,7 +137,8 @@ typedef enum
 {
   REGRESS_TEST_VALUE1,
   REGRESS_TEST_VALUE2,
-  REGRESS_TEST_VALUE3 = -1
+  REGRESS_TEST_VALUE3 = -1,
+  REGRESS_TEST_VALUE4 = '0'
 } RegressTestEnum;
 
 typedef enum
@@ -160,6 +161,14 @@ GType regress_test_enum_unsigned_get_type (void) G_GNUC_CONST;
 GType regress_test_flags_get_type (void) G_GNUC_CONST;
 #define REGRESS_TEST_TYPE_FLAGS (regress_test_flags_get_type ())
 
+/* this is not registered with GType */
+typedef enum
+{
+  REGRESS_TEST_EVALUE1,
+  REGRESS_TEST_EVALUE2 = 42,
+  REGRESS_TEST_EVALUE3 = '0'
+} RegressTestEnumNoGEnum;
+
 const gchar * regress_test_enum_param(RegressTestEnum e);
 const gchar * regress_test_unsigned_enum_param(RegressTestEnumUnsigned e);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]