[glibmm/gmmproc-refactor] Support {OUT} or {RET} and default values.



commit d0d8cf1858731b999f7962c6c8b2fe8fad6f70e0
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Wed Jun 13 03:58:25 2012 +0200

    Support {OUT} or {RET} and default values.

 tools/pm/Common/CxxFunctionInfo.pm |   17 +++++++---
 tools/pm/Common/Output/Method.pm   |   61 +++++++++++++++++++++++++++++-------
 tools/pm/Common/Output/Shared.pm   |   12 +++++--
 tools/pm/Common/Shared.pm          |    9 +++++
 tools/pm/Common/WrapParser.pm      |    4 +-
 5 files changed, 81 insertions(+), 22 deletions(-)
---
diff --git a/tools/pm/Common/CxxFunctionInfo.pm b/tools/pm/Common/CxxFunctionInfo.pm
index ea47a2f..801c462 100644
--- a/tools/pm/Common/CxxFunctionInfo.pm
+++ b/tools/pm/Common/CxxFunctionInfo.pm
@@ -38,8 +38,9 @@ sub new_from_string ($$)
   my $param_names = [];
   my $param_values = [];
   my $param_nullables = [];
-  my $param_outs = [];
+  my $param_out_index = -1;
   my $const = ($cxx_parts->[4] =~ /\bconst\b/);
+  my $index = 0;
 
   foreach my $desc (@{$params})
   {
@@ -47,7 +48,13 @@ sub new_from_string ($$)
     push @{$param_names}, $desc->{'name'};
     push @{$param_values}, $desc->{'value'};
     push (@{$param_nullables}, $desc->{'nullable'});
-    push (@{$param_outs}, $desc->{'out'});
+
+    if ($desc->{'out'})
+    {
+      die if ($param_out_index > -1);
+      $param_out_index = $index;
+    }
+    ++$index;
   }
 
   $params = undef;
@@ -61,7 +68,7 @@ sub new_from_string ($$)
     'param_names' => $param_names,
     'param_values' => $param_values,
     'param_nullables' => $param_nullables,
-    'param_outs' => $param_outs,
+    'param_out_index' => $param_out_index,
     'const' => $const
   };
 
@@ -117,11 +124,11 @@ sub get_param_nullables ($)
   return $self->{'param_nullables'};
 }
 
-sub get_param_outs ($)
+sub get_param_out_index ($)
 {
   my ($self) = @_;
 
-  return $self->{'param_outs'};
+  return $self->{'param_out_index'};
 }
 
 sub get_const ($)
diff --git a/tools/pm/Common/Output/Method.pm b/tools/pm/Common/Output/Method.pm
index 725ba80..3eb8188 100644
--- a/tools/pm/Common/Output/Method.pm
+++ b/tools/pm/Common/Output/Method.pm
@@ -28,9 +28,9 @@ sub nl
   return Common::Output::Shared::nl @_;
 }
 
-sub _output_h ($$$$$$$)
+sub _output_h ($$$$$$$$)
 {
-  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $const) = @_;
+  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $cxx_param_values, $const) = @_;
   my $section_manager = $wrap_parser->get_section_manager;
   my $main_section = $wrap_parser->get_main_section;
   my $code_string = '';
@@ -44,7 +44,7 @@ sub _output_h ($$$$$$$)
   }
   $code_string .= $cpp_ret_type . ' ' . $cpp_func_name;
 
-  my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names;
+  my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names, $cxx_param_values;
 
   $code_string .= '(' . $cpp_params_str . ')';
   if ($const)
@@ -55,9 +55,9 @@ sub _output_h ($$$$$$$)
   $section_manager->append_string_to_section (nl ($code_string), $main_section);
 }
 
-sub _output_cc ($$$$$$$$$$$$$$$$)
+sub _output_cc ($$$$$$$$$$$$$$$$$)
 {
-  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow) = @_;
+  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $cxx_param_out_index, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow) = @_;
   my $section_manager = $wrap_parser->get_section_manager;
   my $code_string = '';
   my $ret_void = ($cpp_ret_type eq 'void');
@@ -66,7 +66,13 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
   # if dies then it is internal error. should not happen here.
   die if ($static and ($const or $constversion));
   die if (scalar (@{$cpp_param_types}) != scalar(@{$cpp_param_names}));
-  die if (scalar (@{$c_param_types}) != scalar(@{$cpp_param_types}));
+  if ($cxx_param_out_index < 0) {
+    die if (scalar (@{$c_param_types}) != scalar(@{$cpp_param_types}));
+  }
+  else
+  {
+    die if (scalar (@{$c_param_types}) + 1 != scalar(@{$cpp_param_types}));
+  }
 
   if ($deprecated)
   {
@@ -117,9 +123,28 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
     push @params, $this_param;
 
     my $type_info_local = $wrap_parser->get_type_info_local ();
-    my $convs_str = Common::Output::Shared::convzipstr $wrap_parser, $cpp_param_types, $c_param_types, $c_param_transfers, $cpp_param_names;
+    my $prepped_cxx_param_types = [];
+    my $prepped_cxx_param_names = [];
+
+    if ($cxx_param_out_index < 0)
+    {
+      $prepped_cxx_param_types = $cpp_param_types;
+      $prepped_cxx_param_names = $cpp_param_names;
+    }
+    else
+    {
+      # copy arrays
+      $prepped_cxx_param_types = [ {$cpp_param_types}];
+      $prepped_cxx_param_names = [ {$cpp_param_names}];
+
+      splice (@{$prepped_cxx_param_types}, $cxx_param_out_index, 1);
+      splice (@{$prepped_cxx_param_names}, $cxx_param_out_index, 1);
+    }
+    my $convs_str = Common::Output::Shared::convzipstr $wrap_parser, $prepped_cxx_param_types, $c_param_types, $c_param_transfers, $prepped_cxx_param_names;
 
-    if ($convs_str)
+    $prepped_cxx_param_types = undef;
+    $prepped_cxx_param_names = undef;
+    if (defined ($convs_str) and $convs_str ne '')
     {
       push @params, $convs_str;
     }
@@ -136,6 +161,10 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
     {
       $ret_convert = $type_info_local->get_conversion ($c_ret_type, $cpp_ret_type, $ret_transfer, $c_func_invocation);
     }
+    elsif ($cxx_param_out_index > -1)
+    {
+      $ret_convert = $type_info_local->get_conversion ($c_ret_type, $cpp_param_types->[$cxx_param_out_index], $ret_transfer, $c_func_invocation);
+    }
 
     if ($errthrow)
     {
@@ -145,6 +174,10 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
       {
         $code_string .= nl ('  ' . $cpp_ret_type . ' retvalue(' . $ret_convert . ');');
       }
+      elsif ($cxx_param_out_index > -1)
+      {
+        $code_string .= nl ('  ' . $cpp_param_names->[$cxx_param_out_index] . ' = (' . $ret_convert . ');');
+      }
       else
       {
         $code_string .= nl () .
@@ -170,6 +203,10 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
       {
         $code_string .= nl ('  return ' . $ret_convert . ';');
       }
+      elsif ($cxx_param_out_index > -1)
+      {
+        $code_string .= nl ('  ' . $cpp_param_names->[$cxx_param_out_index] . ' = (' . $ret_convert . ');');
+      }
       else
       {
         $code_string .= nl ('  ' . $c_func_invocation . ';');
@@ -191,15 +228,15 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
   $section_manager->append_string_to_section ($code_string, $section);
 }
 
-sub output ($$$$$$$$$$$$$$$$$)
+sub output ($$$$$$$$$$$$$$$$$$$)
 {
-  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $cxx_param_nullables, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow) = @_;
+  my ($wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $cpp_param_types, $cpp_param_names, $cxx_param_values, $cxx_param_nullables, $cxx_param_out_index, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow) = @_;
   my $permutations = Common::Output::Shared::get_types_permutations ($cpp_param_types, $cxx_param_nullables);
 
   foreach my $permutation (@{$permutations})
   {
-    _output_h $wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $permutation, $cpp_param_names, $const;
-    _output_cc $wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $permutation, $cpp_param_names, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow;
+    _output_h $wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $permutation, $cpp_param_names, $cxx_param_values, $const;
+    _output_cc $wrap_parser, $static, $cpp_ret_type, $cpp_func_name, $permutation, $cpp_param_names, $cxx_param_out_index, $const, $constversion, $deprecated, $ifdef, $c_ret_type, $ret_transfer, $c_func_name, $c_param_types, $c_param_transfers, $errthrow;
   }
 }
 
diff --git a/tools/pm/Common/Output/Shared.pm b/tools/pm/Common/Output/Shared.pm
index 494dc25..37562c6 100644
--- a/tools/pm/Common/Output/Shared.pm
+++ b/tools/pm/Common/Output/Shared.pm
@@ -558,23 +558,29 @@ sub endif ($)
   return '';
 }
 
-sub paramzipstr ($$)
+sub paramzipstr
 {
-  my ($types, $names) = @_;
+  my ($types, $names, $values) = @_;
   my $count = @{$types};
 
 # TODO: throw runtime error or internal error or whatever.
   die if ($count != scalar (@{$names}));
+  unless (defined ($values))
+  {
+    $values = [];
+  }
 
   my @params = ();
 
   foreach my $index (0 .. $count - 1)
   {
     my $type = $types->[$index];
-    my $name = $names->[$index];
 
     if (defined ($type))
     {
+      my $value = $values->[$index];
+      my $name = $names->[$index] . (defined ($value) ? (' = ' . $value) : '');
+
       push (@params, join (' ', $type, $name));
     }
   }
diff --git a/tools/pm/Common/Shared.pm b/tools/pm/Common/Shared.pm
index 2aa22ca..993f807 100644
--- a/tools/pm/Common/Shared.pm
+++ b/tools/pm/Common/Shared.pm
@@ -67,6 +67,7 @@ sub extract_bracketed_text ($)
 
     $line_change += $add_to_line;
     last if ($token eq '(');
+    return undef if (not $line_change and $token != /^\s+$/);
   }
 
   my $escape = 0;
@@ -375,6 +376,14 @@ sub parse_params ($)
         {
           $out = 1;
         }
+        when (undef)
+        {
+          # That's fine - no {foo} was used at all.
+        }
+        default
+        {
+          die '|' . $param . '|';
+        }
       }
       $type = _type_fixup $type;
 
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 856a04d..250cfc3 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -802,9 +802,9 @@ sub _on_wrap_method ($)
                                   $cxx_function->get_name,
                                   $cxx_function->get_param_types,
                                   $cxx_function->get_param_names,
-                                  # $cxx_function->get_param_values,
+                                  $cxx_function->get_param_values,
                                   $cxx_function->get_param_nullables,
-                                  # $cxx_function->get_param_outs,
+                                  $cxx_function->get_param_out_index,
                                   $cxx_function->get_const,
                                   $constversion,
                                   $deprecated,



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