[glibmm/glibmm-2-60] gmmproc: Update enum.pl and h2def.py for new glib deprecation macros



commit 17904b2a8555649315e7349e7809c37535eb92dd
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Jul 8 15:00:02 2019 +0200

    gmmproc: Update enum.pl and h2def.py for new glib deprecation macros
    
    * tools/enum.pl:  Don't replace MY_ENUMERATOR = '}' with MY_ENUMERATOR = ']'.
    Remove *_DEPRECATED_TYPE_IN_* and *_DEPRECATED_ENUMERATOR_IN_* when enum
    definitions are parsed.
    * tools/defs_gen/h2def.py: When parsing function declarations:
    Remove G_GNUC_BEGIN_IGNORE_DEPRECATIONS, G_GNUC_END_IGNORE_DEPRECATIONS
    and G_DECLARE_INTERFACE(*). Update the removals of *_DEPRECATED*
    and *_AVAILABLE_IN* so the new *_DEPRECATED_TYPE* and friends won't
    affect the result.

 tools/defs_gen/h2def.py | 31 +++++++++++++------------------
 tools/enum.pl           | 39 ++++++++++++++++++++++++++++-----------
 2 files changed, 41 insertions(+), 29 deletions(-)
---
diff --git a/tools/defs_gen/h2def.py b/tools/defs_gen/h2def.py
index 1c0a79b8..9ca95d27 100755
--- a/tools/defs_gen/h2def.py
+++ b/tools/defs_gen/h2def.py
@@ -12,17 +12,17 @@
 # GTK object conventions) and generates a set of scheme defs.
 #
 # h2def searches through a header file looking for function prototypes and
-# generates a scheme style defenition for each prototype.
+# generates a scheme style definition for each prototype.
 # Basically the operation of h2def is:
 #
 # - read each .h file into a buffer which is scrubbed of extraneous data
-# - find all object defenitions:
+# - find all object definitions:
 #   - find all structures that may represent a GtkObject
 #   - find all structures that might represent a class
 #   - find all structures that may represent a GtkObject subclass
 #   - find all structures that might represent a class/Iface inherited from
 #     GTypeInterface
-# - find all enum defenitions
+# - find all enum definitions
 # - write out the defs
 #
 # The command line options are:
@@ -294,8 +294,7 @@ def clean_func(buf):
     buf = pat.sub('', buf)
 
     #typedefs, structs, and enums
-    pat = re.compile(r"""^(typedef|struct|enum)(\s|.|\n)*?;\s*""",
-                     re.MULTILINE)
+    pat = re.compile(r"""^(typedef|struct|enum)(\s|.|\n)*?;\s*""", re.MULTILINE)
     buf = pat.sub('', buf)
 
     #strip DECLS macros
@@ -306,27 +305,23 @@ def clean_func(buf):
     pat = re.compile(r"""G_GNUC_WARN_UNUSED_RESULT|G_INLINE_FUNC""", re.MULTILINE)
     buf = pat.sub('', buf)
 
-    #strip *_DEPRECATED_IN_*_FOR (*)
-    #e.g. GDK_DEPRECATED_IN_*_FOR (*) and GDK_PIXBUF_DEPRECATED_IN_*_FOR (*)
-    pat = re.compile(r"""([A-Z]+_){1,2}?DEPRECATED_IN_[0-9]_([0-9]*)_FOR\s*\(.*\)\S*""", re.MULTILINE)
+    #strip G_GNUC_BEGIN_IGNORE_DEPRECATIONS and G_GNUC_END_IGNORE_DEPRECATIONS
+    pat = re.compile(r"""G_GNUC_(BEGIN|END)_IGNORE_DEPRECATIONS""", re.MULTILINE)
     buf = pat.sub('', buf)
 
-    #strip *_DEPRECATED*
-    pat = re.compile(r"""([A-Z]+_){1,2}?DEPRECATED\S*""", re.MULTILINE)
+    #strip *_DEPRECATED[_IN_n_m][_FOR (*)]
+    #e.g. GDK_DEPRECATED_IN_*_FOR (*) and GDK_PIXBUF_DEPRECATED_IN_*_FOR (*)
+    pat = re.compile(r"""([A-Z]+_){1,2}?DEPRECATED(_IN_[0-9]_[0-9]+)?(_FOR\s*\(.*?\))?""", re.MULTILINE)
     buf = pat.sub('', buf)
 
     #strip *_AVAILABLE_IN_*
-    pat = re.compile(r"""([A-Z]+_){1,2}?AVAILABLE_IN_[0-9]_[0-9]\S*""", re.MULTILINE)
+    pat = re.compile(r"""([A-Z]+_){1,2}?AVAILABLE_IN_[A-Z_0-9]+""", re.MULTILINE)
     buf = pat.sub('', buf)
 
-    #strip *_AVAILABLE_IN_ALL
-    pat = re.compile(r"""([A-Z]+_){1,2}?AVAILABLE_IN_ALL\S*""", re.MULTILINE)
+    #strip G_DECLARE_FINAL_TYPE (*) and G_DECLARE_INTERFACE (*)
+    pat = re.compile(r"""G_DECLARE_(FINAL_TYPE|INTERFACE)\s*\(.*?\)""", re.MULTILINE)
     buf = pat.sub('', buf)
 
-    #strip G_DECLARE_FINAL_TYPE (*)
-    pat = re.compile(r"""G_DECLARE_FINAL_TYPE\s*\(.*?\)""", re.MULTILINE)
-    buf = pat.sub('', buf)
-    
     #we are not stripping G_GNUC_INTERNAL
 
     #extern "C"
@@ -375,7 +370,7 @@ def clean_func(buf):
                 start = match.start()
             bracket_cnt += 1
         else:
-            if (bracket_cnt == 0): 
+            if (bracket_cnt == 0):
                 continue
             if (bracket_cnt == 1):
                 buf = buf.replace(buf[start:match.start()+1], "\n")
diff --git a/tools/enum.pl b/tools/enum.pl
index 1b42a977..3091f113 100755
--- a/tools/enum.pl
+++ b/tools/enum.pl
@@ -68,6 +68,7 @@ sub parse($)
   my $from = 0;
   # 1, if only right bracket was found, not name.
   my $rbracket_only = 0;
+
   while(<$fd>)
   {
     my $tmp_rawline = $_;
@@ -116,7 +117,10 @@ sub parse($)
       }
       next;
     }
-    # XXX: what does it do?
+    # Replace the enumerator values ',' and '}' by strings that won't confuse
+    # process(). They are reset to the original strings when they are written
+    # to the output file.
+    # typedef enum { V1 = ',', V2 = '}' } E1; // is a legal definition.
     s/','/\%\%COMMA\%\%/;
     s/'}'/\%\%RBRACE\%\%/;
     # we have found an enum.
@@ -136,11 +140,14 @@ sub parse($)
        # between '}' and ';'.
        if (/;/)
        {
-         my $def = ($rbracket_only ? ("} " . $_) : ($_));
+         unless ($omit and /[A-Z]+_DEPRECATED_TYPE/)
+         {
+           my $def = ($rbracket_only ? ("} " . $_) : ($_));
+           print ";; Original typedef:\n";
+           print $raw_line . "\n";
+           process($line, $def);
+         }
          $enum = 0;
-         print ";; Original typedef:\n";
-         print $raw_line . "\n";
-         process($line, $def);
          $line = "";
          $raw_line = "";
          $rbracket_only = 0;
@@ -170,10 +177,11 @@ sub parse($)
 sub process($$)
 {
   my ($line,$def) = @_;
-  # strip whitespace and closing bracket before the name and whitespace and
-  # colon after the name.
-  $def =~ s/\s*\}\s*//g;
-  $def =~ s/\s*;\s*$//;
+  # The name is the first word after the closing bracket.
+  # The name can be followed by *_DEPRECATED_TYPE* or *_AVAILABLE_TYPE*
+  # before the semicolon.
+  $def =~ /^.*?(\w+)/;
+  $def = $1;
   my $c_name = $def;
   # replace all excessive whitespaces with one space.
   $line =~ s/\s+/ /g;
@@ -206,6 +214,12 @@ sub process($$)
 
   while ($iter < scalar @lines)
   {
+    # The enumerator name can be followed by *_DEPRECATED_ENUMERATOR*,
+    # *_DEPRECATED_ENUMERATOR*_FOR(*) or *_AVAILABLE_ENUMERATOR* before
+    # the equal sign or comma.
+    my $omit_enumerator = ($omit and $lines[$iter] =~ /[A-Z]+_DEPRECATED_ENUMERATOR/);
+    $lines[$iter] =~ s/^\s*(\w+)\s+\w+?_(:?DEPRECATED|AVAILABLE)_ENUMERATOR\w*(:?\s*\(.*?\))?/$1/;
+
     my $brackets_count = 0;
     my $begin = $iter;
 
@@ -225,6 +239,8 @@ sub process($$)
       } while ($iter < scalar @lines && $brackets_count != 0);
     }
 
+    next if ($omit_enumerator);
+
     my $i = join(',', @lines[$begin..$iter-1]);
 
     # remove leading and trailing spaces.
@@ -370,13 +386,14 @@ sub process($$)
       $unknown_flag = 0;
       $e_h{"enum"}++;
     }
-    # if... XXX: I do not know what is matched here.
+    # if it's one of the char values that were replaced by
+    # \%\%COMMA\%\% or \%\%RBRACE\%\%.
     elsif ($i =~ /^(\S+)\s*=\s*(\%\%[A-Z]+\%\%)$/)
     {
       my $tmp = $1;
       $_ = $2;
       s/\%\%COMMA\%\%/,/;
-      s/\%\%RBRACE\%\%/]/;
+      s/\%\%RBRACE\%\%/}/;
       push(@c_names, $tmp);
       push(@numbers, "\'$_\'");
       $val = ord($_);


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