[gobject-introspection] Add glib:name to enum member



commit b8880276b257d584f2d7120a05daba19093de319
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Tue Mar 23 20:43:47 2021 +0400

    Add glib:name to enum member
    
    This member will contain the string from the GEnumValue/GFlagsValue
    'value_name' introspection dump.
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 docs/gir-1.2.rnc                       |  4 +-
 giscanner/ast.py                       |  3 +-
 giscanner/gdumpparser.py               |  3 +-
 giscanner/girparser.py                 |  3 +-
 giscanner/girwriter.py                 |  2 +
 giscanner/transformer.py               |  4 +-
 tests/scanner/Regress-1.0-expected.gir | 84 ++++++++++++++++++++++------------
 7 files changed, 68 insertions(+), 35 deletions(-)
---
diff --git a/docs/gir-1.2.rnc b/docs/gir-1.2.rnc
index a6478119..8f53c18e 100644
--- a/docs/gir-1.2.rnc
+++ b/docs/gir-1.2.rnc
@@ -679,8 +679,10 @@ grammar {
       attribute value { xsd:string },
       ## corresponding C type of the member
       attribute c:identifier { xsd:string },
-      ## short nickname of the member
+      ## short nickname of the member (from GEnumValue/GFlagsValue)
       attribute glib:nick { xsd:string }?,
+      ## name of the member (from GEnumValue/GFlagsValue)
+      attribute glib:name { xsd:string }?,
 
       Info.elements
     }
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 593969f2..9a0d95c7 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -972,12 +972,13 @@ class Bitfield(Node, Registered):
 
 class Member(Annotated):
 
-    def __init__(self, name, value, symbol, nick):
+    def __init__(self, name, value, symbol, nick=None, dump_name=None):
         Annotated.__init__(self)
         self.name = name
         self.value = value
         self.symbol = symbol
         self.nick = nick
+        self.dump_name = dump_name
         self.parent = None
 
     def _compare(self, other, op):
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index ada1503d..03a4ecc3 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -285,7 +285,8 @@ blob containing data gleaned from GObject's primitive introspection."""
             members.append(ast.Member(name,
                                       value,
                                       symbol,
-                                      member.attrib['nick']))
+                                      member.attrib['nick'],
+                                      member.attrib['name']))
 
         if xmlnode.tag == 'flags':
             klass = ast.Bitfield
diff --git a/giscanner/girparser.py b/giscanner/girparser.py
index d229b164..da200a65 100644
--- a/giscanner/girparser.py
+++ b/giscanner/girparser.py
@@ -609,7 +609,8 @@ class GIRParser(object):
         member = ast.Member(node.attrib['name'],
                             node.attrib['value'],
                             node.attrib.get(_cns('identifier')),
-                            node.attrib.get(_glibns('nick')))
+                            node.attrib.get(_glibns('nick')),
+                            node.attrib.get(_glibns('name')))
         self._parse_generic_attribs(node, member)
         return member
 
diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py
index 2b837362..54c957c0 100644
--- a/giscanner/girwriter.py
+++ b/giscanner/girwriter.py
@@ -442,6 +442,8 @@ class GIRWriter(XMLWriter):
         self._append_version(member, attrs)
         if member.nick is not None:
             attrs.append(('glib:nick', member.nick))
+        if member.dump_name is not None:
+            attrs.append(('glib:name', member.dump_name))
         with self.tagcontext('member', attrs):
             self._write_generic(member)
 
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index bcabdedc..ad2a87f4 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -432,9 +432,7 @@ raise ValueError."""
                 name = self._strip_symbol(child)
             members.append(ast.Member(name.lower(),
                                       child.const_int,
-                                      child.ident,
-                                      None))
-
+                                      child.ident))
         enum_name = self.strip_identifier(symbol.ident)
         if symbol.base_type.is_bitfield:
             klass = ast.Bitfield
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 302800cc..e0f02521 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -1623,17 +1623,20 @@ it says it's pointer but it's actually a string.</doc>
       <member name="alpha"
               value="0"
               c:identifier="REGRESS_FOO_ENUM_ALPHA"
-              glib:nick="alpha">
+              glib:nick="alpha"
+              glib:name="REGRESS_FOO_ENUM_ALPHA">
       </member>
       <member name="beta"
               value="1"
               c:identifier="REGRESS_FOO_ENUM_BETA"
-              glib:nick="beta">
+              glib:nick="beta"
+              glib:name="REGRESS_FOO_ENUM_BETA">
       </member>
       <member name="delta"
               value="2"
               c:identifier="REGRESS_FOO_ENUM_DELTA"
-              glib:nick="delta">
+              glib:nick="delta"
+              glib:name="REGRESS_FOO_ENUM_DELTA">
       </member>
       <function name="method" c:identifier="regress_foo_enum_type_method">
         <source-position filename="foo.h" line="236"/>
@@ -1666,17 +1669,20 @@ it says it's pointer but it's actually a string.</doc>
       <member name="good"
               value="0"
               c:identifier="REGRESS_FOO_ERROR_GOOD"
-              glib:nick="good">
+              glib:nick="good"
+              glib:name="REGRESS_FOO_ERROR_GOOD">
       </member>
       <member name="bad"
               value="1"
               c:identifier="REGRESS_FOO_ERROR_BAD"
-              glib:nick="bad">
+              glib:nick="bad"
+              glib:name="REGRESS_FOO_ERROR_BAD">
       </member>
       <member name="ugly"
               value="2"
               c:identifier="REGRESS_FOO_ERROR_UGLY"
-              glib:nick="ugly">
+              glib:nick="ugly"
+              glib:name="REGRESS_FOO_ERROR_UGLY">
       </member>
       <function name="quark" c:identifier="regress_foo_error_quark">
         <return-value transfer-ownership="none">
@@ -1727,17 +1733,20 @@ it says it's pointer but it's actually a string.</doc>
       <member name="first"
               value="1"
               c:identifier="REGRESS_FOO_FLAGS_FIRST"
-              glib:nick="first">
+              glib:nick="first"
+              glib:name="REGRESS_FOO_FLAGS_FIRST">
       </member>
       <member name="second"
               value="2"
               c:identifier="REGRESS_FOO_FLAGS_SECOND"
-              glib:nick="second">
+              glib:nick="second"
+              glib:name="REGRESS_FOO_FLAGS_SECOND">
       </member>
       <member name="third"
               value="4"
               c:identifier="REGRESS_FOO_FLAGS_THIRD"
-              glib:nick="third">
+              glib:nick="third"
+              glib:name="REGRESS_FOO_FLAGS_THIRD">
       </member>
     </bitfield>
     <record name="FooForeignStruct"
@@ -2934,17 +2943,20 @@ use it should be.</doc>
       <member name="code1"
               value="1"
               c:identifier="REGRESS_TEST_ABC_ERROR_CODE1"
-              glib:nick="code1">
+              glib:nick="code1"
+              glib:name="REGRESS_TEST_ABC_ERROR_CODE1">
       </member>
       <member name="code2"
               value="2"
               c:identifier="REGRESS_TEST_ABC_ERROR_CODE2"
-              glib:nick="code2">
+              glib:nick="code2"
+              glib:name="REGRESS_TEST_ABC_ERROR_CODE2">
       </member>
       <member name="code3"
               value="3"
               c:identifier="REGRESS_TEST_ABC_ERROR_CODE3"
-              glib:nick="code3">
+              glib:nick="code3"
+              glib:name="REGRESS_TEST_ABC_ERROR_CODE3">
       </member>
       <function name="quark" c:identifier="regress_test_abc_error_quark">
         <return-value transfer-ownership="none">
@@ -3339,29 +3351,34 @@ use it should be.</doc>
       <member name="value1"
               value="0"
               c:identifier="REGRESS_TEST_VALUE1"
-              glib:nick="value1">
+              glib:nick="value1"
+              glib:name="REGRESS_TEST_VALUE1">
         <doc xml:space="preserve" filename="regress.h" line="370">value 1</doc>
       </member>
       <member name="value2"
               value="1"
               c:identifier="REGRESS_TEST_VALUE2"
-              glib:nick="value2">
+              glib:nick="value2"
+              glib:name="REGRESS_TEST_VALUE2">
         <doc xml:space="preserve" filename="regress.h" line="371">value 2</doc>
       </member>
       <member name="value3"
               value="-1"
               c:identifier="REGRESS_TEST_VALUE3"
-              glib:nick="value3">
+              glib:nick="value3"
+              glib:name="REGRESS_TEST_VALUE3">
       </member>
       <member name="value4"
               value="48"
               c:identifier="REGRESS_TEST_VALUE4"
-              glib:nick="value4">
+              glib:nick="value4"
+              glib:name="REGRESS_TEST_VALUE4">
       </member>
       <member name="value5"
               value="49"
               c:identifier="REGRESS_TEST_VALUE5"
-              glib:nick="value5">
+              glib:nick="value5"
+              glib:name="REGRESS_TEST_VALUE5">
       </member>
       <function name="param" c:identifier="regress_test_enum_param">
         <source-position filename="regress.h" line="435"/>
@@ -3391,12 +3408,14 @@ use it should be.</doc>
       <member name="value1"
               value="1"
               c:identifier="REGRESS_TEST_UNSIGNED_VALUE1"
-              glib:nick="value1">
+              glib:nick="value1"
+              glib:name="REGRESS_TEST_UNSIGNED_VALUE1">
       </member>
       <member name="value2"
               value="2147483648"
               c:identifier="REGRESS_TEST_UNSIGNED_VALUE2"
-              glib:nick="value2">
+              glib:nick="value2"
+              glib:name="REGRESS_TEST_UNSIGNED_VALUE2">
       </member>
     </enumeration>
     <enumeration name="TestError"
@@ -3407,17 +3426,20 @@ use it should be.</doc>
       <member name="code1"
               value="1"
               c:identifier="REGRESS_TEST_ERROR_CODE1"
-              glib:nick="code1">
+              glib:nick="code1"
+              glib:name="REGRESS_TEST_ERROR_CODE1">
       </member>
       <member name="code2"
               value="2"
               c:identifier="REGRESS_TEST_ERROR_CODE2"
-              glib:nick="code2">
+              glib:nick="code2"
+              glib:name="REGRESS_TEST_ERROR_CODE2">
       </member>
       <member name="code3"
               value="3"
               c:identifier="REGRESS_TEST_ERROR_CODE3"
-              glib:nick="code3">
+              glib:nick="code3"
+              glib:name="REGRESS_TEST_ERROR_CODE3">
       </member>
       <function name="quark" c:identifier="regress_test_error_quark">
         <return-value transfer-ownership="none">
@@ -3447,17 +3469,20 @@ use it should be.</doc>
       <member name="flag1"
               value="1"
               c:identifier="REGRESS_TEST_FLAG1"
-              glib:nick="flag1">
+              glib:nick="flag1"
+              glib:name="TEST_FLAG1">
       </member>
       <member name="flag2"
               value="2"
               c:identifier="REGRESS_TEST_FLAG2"
-              glib:nick="flag2">
+              glib:nick="flag2"
+              glib:name="TEST_FLAG2">
       </member>
       <member name="flag3"
               value="4"
               c:identifier="REGRESS_TEST_FLAG3"
-              glib:nick="flag3">
+              glib:nick="flag3"
+              glib:name="TEST_FLAG3">
       </member>
     </bitfield>
     <class name="TestFloating"
@@ -5131,17 +5156,20 @@ the introspection client langage.</doc>
       <member name="code1"
               value="1"
               c:identifier="REGRESS_TEST_OTHER_ERROR_CODE1"
-              glib:nick="code1">
+              glib:nick="code1"
+              glib:name="REGRESS_TEST_OTHER_ERROR_CODE1">
       </member>
       <member name="code2"
               value="2"
               c:identifier="REGRESS_TEST_OTHER_ERROR_CODE2"
-              glib:nick="code2">
+              glib:nick="code2"
+              glib:name="REGRESS_TEST_OTHER_ERROR_CODE2">
       </member>
       <member name="code3"
               value="3"
               c:identifier="REGRESS_TEST_OTHER_ERROR_CODE3"
-              glib:nick="code3">
+              glib:nick="code3"
+              glib:name="REGRESS_TEST_OTHER_ERROR_CODE3">
       </member>
       <function name="quark"
                 c:identifier="regress_test_unconventional_error_quark">


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