[glibmm] gmmproc: _WRAP_ENUM and _WRAP_GERROR: Add gtype_func parameter



commit 6e166f0865f4af3abcc32ddaf03966b83fa9e27c
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Mon Jan 7 15:24:49 2019 +0100

    gmmproc: _WRAP_ENUM and _WRAP_GERROR: Add gtype_func parameter
    
    The M4 macro _GET_TYPE_FUNC() does not generate correct function names for
    GDBus* enums. This fix makes it possible to specify the function name in
    the call to _WRAP_ENUM or _WRAP_GERROR. See issue #37

 tools/m4/enum.m4       | 10 +++++++---
 tools/m4/gerror.m4     | 12 ++++++++----
 tools/pm/Output.pm     | 14 +++++++-------
 tools/pm/WrapParser.pm | 32 ++++++++++++++++++++++++--------
 4 files changed, 46 insertions(+), 22 deletions(-)
---
diff --git a/tools/m4/enum.m4 b/tools/m4/enum.m4
index ab7e8163..09f3111b 100644
--- a/tools/m4/enum.m4
+++ b/tools/m4/enum.m4
@@ -1,6 +1,6 @@
 dnl
-dnl _ENUM(cpp_type, c_type, value_suffix, `element_list', `no_gtype', `conv_to_int',
-dnl          $1       $2         $3             $4           $5            $6
+dnl _ENUM(cpp_type, c_type, value_suffix, `element_list', `gtype_func', `conv_to_int',
+dnl          $1       $2         $3             $4             $5            $6
 dnl in_class, `optional_refdoc_comment', 'deprecated')
 dnl   $7                $8                    $9
 dnl
@@ -108,7 +108,7 @@ _POP()
 
 ifelse(`$9',,,`_DEPRECATE_IFDEF_END')`'dnl The expansion of _DEPRECATE_IFDEF_END ends with a newline
 
-m4_ifelse($5,`NO_GTYPE',,`dnl else
+m4_ifelse(`$5',`NO_GTYPE',,`dnl else
 m4_ifelse($7,0,`dnl  not in_class
 __NAMESPACE_END__
 ',`dnl else
@@ -141,7 +141,11 @@ ifelse(`$9',,,`_DEPRECATE_IFDEF_START')`'dnl
 // static
 GType Glib::Value<__NAMESPACE__::__ENUM_CLASS_CPPNAME__>::value_type()
 {
+m4_ifelse(`$5',,`dnl
   return _GET_TYPE_FUNC(__ENUM_CNAME__);
+',`dnl
+  return `$5()';
+')dnl
 }
 ifelse(`$9',,,`_DEPRECATE_IFDEF_END')`'dnl
 
diff --git a/tools/m4/gerror.m4 b/tools/m4/gerror.m4
index f7515bb1..2f35e7e6 100644
--- a/tools/m4/gerror.m4
+++ b/tools/m4/gerror.m4
@@ -1,6 +1,6 @@
 dnl
-dnl _GERROR(cpp_type, c_type, domain, `element_list', `no_gtype', `class_docs', `enum_docs', 'deprecated')
-dnl            $1       $2      $3         $4             $5           $6           $7            $8
+dnl _GERROR(cpp_type, c_type, domain, `element_list', `gtype_func', `class_docs', `enum_docs', 'deprecated')
+dnl            $1       $2      $3         $4              $5           $6           $7            $8
 dnl
 
 m4_define(`_GERROR',`dnl
@@ -43,7 +43,7 @@ private:
 };
 ifelse(`$8',,,`_DEPRECATE_IFDEF_END')`'dnl The expansion of _DEPRECATE_IFDEF_END ends with a newline
 
-m4_ifelse($5,`NO_GTYPE',,`dnl else
+m4_ifelse(`$5',`NO_GTYPE',,`dnl else
 __NAMESPACE_END__
 
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -87,11 +87,15 @@ void __NAMESPACE__::__CPPNAME__::throw_func(GError* gobject)
   throw __NAMESPACE__::__CPPNAME__`'(gobject);
 }
 
-m4_ifelse($5,`NO_GTYPE',,`dnl else
+m4_ifelse(`$5',`NO_GTYPE',,`dnl else
 // static
 GType Glib::Value<__NAMESPACE__::__CPPNAME__::Code>::value_type()
 {
+m4_ifelse(`$5',,`dnl
   return _GET_TYPE_FUNC(__CNAME__);
+',`dnl
+  return `$5()';
+')dnl
 }
 
 ')dnl endif !NO_GTYPE
diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm
index c35cadf7..5fcfc9d6 100644
--- a/tools/pm/Output.pm
+++ b/tools/pm/Output.pm
@@ -684,12 +684,12 @@ sub output_wrap_sig_decl($$$$$$$$$$$$$$)
 }
 
 # void output_wrap_enum($filename, $line_num, $cpp_type, $c_type,
-#   $comment, $ref_subst_in, $ref_subst_out, $no_gtype, $conv_to_int,
+#   $comment, $ref_subst_in, $ref_subst_out, $gtype_func, $conv_to_int,
 #   $in_class, $deprecated, $deprecation_docs, $newin)
 sub output_wrap_enum($$$$$$$$$$$$$$)
 {
   my ($self, $filename, $line_num, $cpp_type, $c_type,
-    $comment, $ref_subst_in, $ref_subst_out, $no_gtype, $conv_to_int,
+    $comment, $ref_subst_in, $ref_subst_out, $gtype_func, $conv_to_int,
     $in_class, $deprecated, $deprecation_docs, $newin) = @_;
 
   my $objEnum = GtkDefs::lookup_enum($c_type);
@@ -734,7 +734,7 @@ sub output_wrap_enum($$$$$$$$$$$$$$)
     $c_type,
     $value_suffix,
     $elements,
-    $no_gtype,
+    $gtype_func,
     $conv_to_int,
     $in_class,
     $comment,
@@ -781,12 +781,12 @@ sub output_wrap_enum_docs_only($$$$$$$$$$$$)
 }
 
 # void output_wrap_gerror($filename, $line_num, $cpp_type, $c_type, $domain,
-#  $class_docs, $ref_subst_in, $ref_subst_out, $no_gtype,
+#  $class_docs, $ref_subst_in, $ref_subst_out, $gtype_func,
 #  $deprecated, $deprecation_docs, $newin)
 sub output_wrap_gerror($$$$$$$$$$$$$)
 {
   my ($self, $filename, $line_num, $cpp_type, $c_type, $domain,
-    $class_docs, $ref_subst_in, $ref_subst_out, $no_gtype,
+    $class_docs, $ref_subst_in, $ref_subst_out, $gtype_func,
     $deprecated, $deprecation_docs, $newin) = @_;
 
   my $objDefsParser = $$self{objDefsParser};
@@ -845,12 +845,12 @@ sub output_wrap_gerror($$$$$$$$$$$$$)
   # Prevent Doxygen from auto-linking to a class called Exception.
   $class_docs =~ s/([^%])(Exception class)/$1%$2/g;
 
-  my $str = sprintf("_GERROR(%s,%s,%s,\`%s\',%s,\`%s\',\`%s\',\`%s\')dnl\n",
+  my $str = sprintf("_GERROR(%s,%s,%s,\`%s\',\`%s\',\`%s\',\`%s\',\`%s\')dnl\n",
     $cpp_type,
     $c_type,
     $domain,
     $elements,
-    $no_gtype,
+    $gtype_func,
     $class_docs,
     $enum_docs,
     $deprecated
diff --git a/tools/pm/WrapParser.pm b/tools/pm/WrapParser.pm
index 7be5fd8a..36adfc4f 100644
--- a/tools/pm/WrapParser.pm
+++ b/tools/pm/WrapParser.pm
@@ -1435,12 +1435,21 @@ sub on_wrap_any_enum($$)
 
   my @subst_in  = [];
   my @subst_out = [];
-  my $no_gtype = "";
+  my $gtype_func = "";
   my $conv_to_int = "";
   my $argDeprecated = "";
   my $deprecation_docs = "";
   my $newin = "";
 
+  # $gtype_func:
+  # 1. If an empty string, the M4 macro _ENUM or _GERROR calls _GET_TYPE_FUNC()
+  #    that generates the function name from the name of the C type, e.g.
+  #    GFileAttributeType -> g_file_attribute_type_get_type
+  # 2. If NO_GTYPE, no call to a *_get_type() function and no Glib::Value
+  #    specialization is generated for the enum type.
+  # 3. If anything else, it's assumed to be the name of the *_get_type() function
+  #    to generate a call to.
+
   # Build a list of custom substitutions, and recognize some flags too.
   foreach (@args)
   {
@@ -1448,7 +1457,11 @@ sub on_wrap_any_enum($$)
 
     if ($arg eq "NO_GTYPE")
     {
-      $no_gtype = $arg;
+      $gtype_func = $arg;
+    }
+    elsif ($arg =~ /^gtype_func\s+(\w+)/)
+    {
+      $gtype_func = $1;
     }
     elsif (!$is_gerror and $arg eq "CONV_TO_INT")
     {
@@ -1473,16 +1486,19 @@ sub on_wrap_any_enum($$)
       $newin = string_unquote(string_trim($1));
     }
   }
-  return ($cpp_type, $c_type, $domain, \@subst_in, \@subst_out, $no_gtype,
+  return ($cpp_type, $c_type, $domain, \@subst_in, \@subst_out, $gtype_func,
     $conv_to_int, $argDeprecated, $deprecation_docs, $newin);
 }
 
 # void on_wrap_enum()
-# _WRAP_ENUM(cpp_type, c_type [,NO_GTYPE] [,CONV_TO_INT] [,s#regexpr#subst#]*)
+# _WRAP_ENUM(cpp_type, c_type [,NO_GTYPE] [,gtype_func funcname] [,CONV_TO_INT] [,s#regexpr#subst#]*)
 # Optional arguments:
 # NO_GTYPE Don't generate code for a specialization of the template
 #          Glib::Value_Enum or Glib::Value_Flags.
 #          Necessary, if the C type enum is not registered as a GType.
+# gtype_func funcname Call funcname() in the generated Glib::Value<>::value_type().
+#                     Necessary, if the M4 macro _GET_TYPE_FUNC() can't generate
+#                     the correct function name from the C type name of the enum.
 # CONV_TO_INT "Convertible to int" Generate a plain enum (not an enum class)
 #             within a class. Such an enum is scoped like an enum class,
 #             and it can be implicitly converted to int like a plain enum.
@@ -1505,12 +1521,12 @@ sub on_wrap_enum($)
   my $comment = $self->extract_preceding_documentation();
 
   # get the arguments
-  my ($cpp_type, $c_type, undef, $ref_subst_in, $ref_subst_out, $no_gtype, $conv_to_int,
+  my ($cpp_type, $c_type, undef, $ref_subst_in, $ref_subst_out, $gtype_func, $conv_to_int,
     $argDeprecated, $deprecation_docs, $newin) = $self->on_wrap_any_enum(0);
 
   $$self{objOutputter}->output_wrap_enum(
     $$self{filename}, $$self{line_num}, $cpp_type, $c_type,
-    $comment, $ref_subst_in, $ref_subst_out, $no_gtype, $conv_to_int,
+    $comment, $ref_subst_in, $ref_subst_out, $gtype_func, $conv_to_int,
     $$self{in_class}, $argDeprecated, $deprecation_docs, $newin);
 }
 
@@ -1547,12 +1563,12 @@ sub on_wrap_gerror($)
   my $class_docs = $self->extract_preceding_documentation();
 
   # get the arguments
-  my ($cpp_type, $c_type, $domain, $ref_subst_in, $ref_subst_out, $no_gtype, undef,
+  my ($cpp_type, $c_type, $domain, $ref_subst_in, $ref_subst_out, $gtype_func, undef,
     $argDeprecated, $deprecation_docs, $newin) = $self->on_wrap_any_enum(1);
 
   $$self{objOutputter}->output_wrap_gerror(
     $$self{filename}, $$self{line_num}, $cpp_type, $c_type, $domain,
-    $class_docs, $ref_subst_in, $ref_subst_out, $no_gtype,
+    $class_docs, $ref_subst_in, $ref_subst_out, $gtype_func,
     $argDeprecated, $deprecation_docs, $newin);
 }
 


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