[glibmm/glibmm-2-36] gmmproc: Parse the argument list of methods correctly.



commit 139f479d672f2614c6860ca587ebb7a03b67f8eb
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Tue Apr 9 23:43:37 2013 -0400

    gmmproc: Parse the argument list of methods correctly.
    
        * tools/pm/Function.pm (parse_param): When splitting the argument
        list split the parameter '{...}' options out and separately and deal
        with them in their own 'elsif' which is more clear and avoids code
        duplication.  Also, don't split the '<...>' matches greedily because
        that causes problems when a Glib::RefPtr<> parameter has a default
        value.
    
        This problem was discovered while trying to not use the optional
        parameter syntax for the Gio::TlsCertificate::verify() method by using
        a default value for the 'trusted_ca' parameter although upon
        investigation it became clear that keeping the syntax (and the method
        overloads) would be useful because a verify() with no parameters can
        be used to verify things about a certificate unrelated to the identity
        and the trusted_ca (see the TlsCertificateFlags enum that the method
        returns).

 ChangeLog            | 20 ++++++++++++++
 tools/pm/Function.pm | 74 ++++++++++++++++------------------------------------
 2 files changed, 42 insertions(+), 52 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 71e02a7..48ff8a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-04-09  José Alburquerque  <jaalburquerque gmail com>
+
+       gmmproc: Parse the argument list of methods correctly.
+
+       * tools/pm/Function.pm (parse_param): When splitting the argument
+       list split the parameter '{...}' options out and separately and deal
+       with them in their own 'elsif' which is more clear and avoids code
+       duplication.  Also, don't split the '<...>' matches greedily because
+       that causes problems when a Glib::RefPtr<> parameter has a default
+       value.
+
+       This problem was discovered while trying to not use the optional
+       parameter syntax for the Gio::TlsCertificate::verify() method by using
+       a default value for the 'trusted_ca' parameter although upon
+       investigation it became clear that keeping the syntax (and the method
+       overloads) would be useful because a verify() with no parameters can
+       be used to verify things about a certificate unrelated to the identity
+       and the trusted_ca (see the TlsCertificateFlags enum that the method
+       returns).
+
 2013-04-06  Murray Cumming  <murrayc murrayc com>
 
        Add a test of implementing an interface.
diff --git a/tools/pm/Function.pm b/tools/pm/Function.pm
index 8934b2c..960208f 100644
--- a/tools/pm/Function.pm
+++ b/tools/pm/Function.pm
@@ -211,7 +211,7 @@ sub parse_param($$)
   # parse through argument list
   my @str = ();
   my $par = 0;
-  foreach (split(/(const )|([,=&*()])|(<[^,{}]*>)|(\s+)/, $line)) #special characters OR <something> OR 
whitespace.
+  foreach (split(/(const )|([,=&*()])|({.*?})|(<[^,]*?>)|(\s+)/, $line)) #special characters OR <something> 
OR whitespace.
   {
     next if ( !defined($_) or $_ eq "" );
 
@@ -227,7 +227,27 @@ sub parse_param($$)
        $par--; #Decrement the number of parameters.
        next;
     }
-    elsif ( $par || /^(const )|(<[^,{}]*>)|([*&])|(\s+)/ ) #TODO: What's happening here?
+    elsif( $_ =~ /{(.*)}/)
+    {
+      # gmmproc options have been specified for the current parameter so
+      # process them.
+
+      # Get the options.
+      my $options = $1;
+ 
+      # Check if param should be optional or an output param.
+      $flags = FLAG_PARAM_OPTIONAL if($options =~ /\?/);
+      $flags |= FLAG_PARAM_OUTPUT if($options =~ />>/);
+ 
+      # Check if it should be mapped to a C param.
+      if ($options =~ /(\w+|\.)/)
+      {
+        $mapping = $1;
+        $mapping = $name if($mapping eq ".");
+      }
+      next;
+    }
+    elsif ( $par || /^(const )|(<[^,]*>)|([*&>])|(\s+)/ ) #TODO: What's happening here?
     {
       push(@str, $_); #This looks like part of the type, so we store it.
       next;
@@ -257,31 +277,6 @@ sub parse_param($$)
 
       $type = string_trim($type);
 
-      # Determine if the param is optional, an output param or if a C param
-      # name should be mapped to the current C++ index (if name ends with
-      # {c_name>>?}). (A '.' for the name means use the C++ as the C name).
-      # '>>' - Means that it is an output parameter.
-      # '?' - Means that it is an optional parameter.
-      if ($name =~ /\{(.*)\}$/)
-      {
-        # Get the options.
-        my $options = $1;
- 
-        # Remove the options from the name.
-        $name =~ s/\{.*\}$//;
- 
-        # Check if param should be optional or an output param.
-        $flags = FLAG_PARAM_OPTIONAL if($options =~ /\?/);
-        $flags |= FLAG_PARAM_OUTPUT if($options =~ />>/);
- 
-        # Check if it should be mapped to a C param.
-        if ($options =~ /(\w+|\.)/)
-        {
-          $mapping = $1;
-          $mapping = $name if($mapping eq ".");
-        }
-      }
-
       push(@$param_types, $type);
       push(@$param_names, $name);
       push(@$param_default_values, $value);
@@ -343,31 +338,6 @@ sub parse_param($$)
 
   $type = string_trim($type);
 
-  # Determine if the param is optional, an output param or if a C param
-  # name should be mapped to the current C++ index (if name ends with
-  # {c_name>>?}). (A '.' for the name means use the C++ as the C name).
-  # '>>' - Means that it is an output parameter.
-  # '?' - Means that it is an optional parameter.
-  if ($name =~ /\{(.*)\}$/)
-  {
-    # Get the options.
-    my $options = $1;
- 
-    # Remove the options from the name.
-    $name =~ s/\{.*\}$//;
-        
-    # Check if param should be optional or an output param.
-    $flags = FLAG_PARAM_OPTIONAL if($options =~ /\?/);
-    $flags |= FLAG_PARAM_OUTPUT if($options =~ />>/);
-      
-    # Check if it should be mapped to a C param.
-    if ($options =~ /(\w+|\.)/)
-    {
-      $mapping = $1;
-      $mapping = $name if($mapping eq ".");
-    }
-  }
-
   push(@$param_types, $type);
   push(@$param_names, $name);
   push(@$param_default_values, $value);


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