From a00bad39cb8288172c2b792d5f507e9fc7c2c5d1 Mon Sep 17 00:00:00 2001 From: Kjell Ahlstedt Date: Mon, 7 Jan 2019 15:19:44 +0100 Subject: 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 | 28 ++++++++++++++++++---------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tools/m4/enum.m4 b/tools/m4/enum.m4 index 9064e353..be07f5e0 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', `optional_refdoc_comment', 'deprecated') -dnl $1 $2 $3 $4 $5 $6 $7 +dnl _ENUM(cpp_type, c_type, value_suffix, `element_list', `gtype_func', `optional_refdoc_comment', 'deprecated') +dnl $1 $2 $3 $4 $5 $6 $7 dnl m4_define(`_ENUM',`dnl _PUSH() @@ -71,7 +71,7 @@ inline __ENUM_CPPNAME__& operator^=(__ENUM_CPPNAME__& lhs, __ENUM_CPPNAME__ rhs) ')dnl endif Flags ifelse(`$7',,,`_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 @@ -96,7 +96,11 @@ ifelse(`$7',,,`_DEPRECATE_IFDEF_START')`'dnl // static GType Glib::Value<__NAMESPACE__::__ENUM_CPPNAME__>::value_type() { +m4_ifelse(`$5',,`dnl return _GET_TYPE_FUNC(__ENUM_CNAME__); +',`dnl + return `$5()'; +')dnl } ifelse(`$7',,,`_DEPRECATE_IFDEF_END')`'dnl diff --git a/tools/m4/gerror.m4 b/tools/m4/gerror.m4 index f7515bb1..51b4985c 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 f0a011ae..ed630d2b 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, +# $comment, $ref_subst_in, $ref_subst_out, $gtype_func, # $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, + $comment, $ref_subst_in, $ref_subst_out, $gtype_func, $deprecated, $deprecation_docs, $newin) = @_; my $objEnum = GtkDefs::lookup_enum($c_type); @@ -725,7 +725,7 @@ sub output_wrap_enum($$$$$$$$$$$$) $c_type, $value_suffix, $elements, - $no_gtype, + $gtype_func, $comment, $deprecated ); @@ -758,12 +758,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}; @@ -822,12 +822,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 ac2ed979..bf2597f1 100644 --- a/tools/pm/WrapParser.pm +++ b/tools/pm/WrapParser.pm @@ -1440,11 +1440,20 @@ sub on_wrap_any_enum($$) my @subst_in = []; my @subst_out = []; - my $no_gtype = ""; + my $gtype_func = ""; 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) { @@ -1452,12 +1461,11 @@ sub on_wrap_any_enum($$) if ($arg eq "NO_GTYPE") { - $no_gtype = "NO_GTYPE"; + $gtype_func = "NO_GTYPE"; } - elsif ($arg =~ /^(get_type_func=)(\s*)$/) + elsif ($arg =~ /^gtype_func\s+(\w+)/) { - my $part1 = $1; - my $part2 = $2; + $gtype_func = $1; } elsif ($arg =~ /^s#([^#]+)#([^#]*)#$/) { @@ -1478,7 +1486,7 @@ 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, $argDeprecated, $deprecation_docs, $newin); } @@ -1491,12 +1499,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, + my ($cpp_type, $c_type, undef, $ref_subst_in, $ref_subst_out, $gtype_func, $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, + $comment, $ref_subst_in, $ref_subst_out, $gtype_func, $argDeprecated, $deprecation_docs, $newin); } @@ -1533,12 +1541,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, + my ($cpp_type, $c_type, $domain, $ref_subst_in, $ref_subst_out, $gtype_func, $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); } -- cgit v1.2.1