[glib/wip/mak/mkenums-priv-trigraph] mkenums: Support public/private trigraphs again




commit 1261461840c4577cb2a269d0d671219ae86a7aa9
Author: Matthias Klumpp <matthias tenstral net>
Date:   Sun Jan 10 19:41:07 2021 +0100

    mkenums: Support public/private trigraphs again
    
    This change was previously implemented in
    9ba17d511e325eec1e0c1c27cb4d37de4f12ac1e but got dropped during the
    Python conversion of the Perl script.
    
    See the commit message of this commit as well as
    https://bugzilla.gnome.org/show_bug.cgi?id=782162
    for more information.
    This patch also adds a new test so we don't loose this feature again.

 gobject/glib-mkenums.in  | 29 ++++++++++++++++++++-----
 gobject/tests/mkenums.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 5 deletions(-)
---
diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in
index c4242ad13..199868039 100755
--- a/gobject/glib-mkenums.in
+++ b/gobject/glib-mkenums.in
@@ -132,6 +132,7 @@ option_lowercase_name = ''  # DEPRECATED.  A lower case name to use as part
                             # guess where to put the underscores.
 option_since = ''           # User provided version info for the enum.
 seenbitshift = 0            # Have we seen bitshift operators?
+seenprivate = False         # Have we seen a private option?
 enum_prefix = None          # Prefix for this enumeration
 enumname = ''               # Name for this enumeration
 enumshort = ''              # $enumname without prefix
@@ -161,7 +162,7 @@ def parse_trigraph(opts):
     return result
 
 def parse_entries(file, file_name):
-    global entries, enumindex, enumname, seenbitshift, flags
+    global entries, enumindex, enumname, seenbitshift, seenprivate, flags
     looking_for_name = False
 
     while True:
@@ -239,16 +240,33 @@ def parse_entries(file, file_name):
             if flags is None and value is not None and '<<' in value:
                 seenbitshift = 1
 
+            if seenprivate:
+                continue
+
             if options is not None:
                 options = parse_trigraph(options)
                 if 'skip' not in options:
                     entries.append((name, value, options.get('nick')))
             else:
                 entries.append((name, value))
-        elif re.match(r's*\#', line):
-            pass
         else:
-            print_warning('Failed to parse "{}" in {}'.format(line, file_name))
+            m = re.match(r'''\s*
+                         /\*< (([^*]|\*(?!/))*) >\s*\*/
+                         \s*$''', line, flags=re.X)
+            if m:
+                options = m.groups()[0]
+                if options is not None:
+                    options = parse_trigraph(options)
+                    if 'private' in options:
+                        seenprivate = True
+                        continue
+                    if 'public' in options:
+                        seenprivate = False
+                        continue
+            if re.match(r's*\#', line):
+                pass
+            else:
+                print_warning('Failed to parse "{}" in {}'.format(line, file_name))
     return False
 
 help_epilog = '''Production text substitutions:
@@ -464,7 +482,7 @@ if len(fhead) > 0:
     write_output(prod)
 
 def process_file(curfilename):
-    global entries, flags, seenbitshift, enum_prefix
+    global entries, flags, seenbitshift, seenprivate, enum_prefix
     firstenum = True
 
     try:
@@ -542,6 +560,7 @@ def process_file(curfilename):
                         break
 
             seenbitshift = 0
+            seenprivate = False
             entries = []
 
             # Now parse the entries
diff --git a/gobject/tests/mkenums.py b/gobject/tests/mkenums.py
index abde43deb..876089d4f 100644
--- a/gobject/tests/mkenums.py
+++ b/gobject/tests/mkenums.py
@@ -595,6 +595,61 @@ comment: {standard_bottom_comment}
             "0",
         )
 
+    def test_enum_private_public(self):
+        """Test private/public enums. Bug #782162."""
+        h_contents1 = """
+        typedef enum {
+          ENUM_VALUE_PUBLIC1,
+          /*< private >*/
+          ENUM_VALUE_PRIVATE,
+        } SomeEnumA
+        """
+
+        h_contents2 = """
+        typedef enum {
+          /*< private >*/
+          ENUM_VALUE_PRIVATE,
+          /*< public >*/
+          ENUM_VALUE_PUBLIC2,
+        } SomeEnumB;
+        """
+
+        result = self.runMkenumsWithHeader(h_contents1)
+        self.maxDiff = None
+        self.assertEqual("", result.err)
+        self.assertSingleEnum(
+            result,
+            "SomeEnumA",
+            "some_enum_a",
+            "SOME_ENUM_A",
+            "ENUM_A",
+            "SOME",
+            "",
+            "enum",
+            "Enum",
+            "ENUM",
+            "ENUM_VALUE_PUBLIC1",
+            "public1",
+            "0",
+        )
+        result = self.runMkenumsWithHeader(h_contents2)
+        self.assertEqual("", result.err)
+        self.assertSingleEnum(
+            result,
+            "SomeEnumB",
+            "some_enum_b",
+            "SOME_ENUM_B",
+            "ENUM_B",
+            "SOME",
+            "",
+            "enum",
+            "Enum",
+            "ENUM",
+            "ENUM_VALUE_PUBLIC2",
+            "public2",
+            "0",
+        )
+
 
 class TestRspMkenums(TestMkenums):
     """Run all tests again in @rspfile mode"""


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