summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Alburquerque <jaalburqu@svn.gnome.org>2011-06-01 18:15:52 -0400
committerJosé Alburquerque <jaalburqu@svn.gnome.org>2011-06-01 18:25:59 -0400
commit3fd8f99ba9a6e437e57485fb6909111a7a8686f2 (patch)
tree42ef0814abb087486a44904698b954d199d834f0
parent1802c2814461aed5878005ce99640340f1d9d69d (diff)
downloadglibmm-3fd8f99ba9a6e437e57485fb6909111a7a8686f2.tar.gz
gmmproc: _WRAP_[CREATE|CTOR]: Add optional parameter functionality.
* tools/pm/Function.pm (new_ctor): Modified to initialize the new param_optional and possible_args_list members. * tools/pm/FunctionBase.pm (args_names_only): Typo. (get_declaration): Make sure that spacing is correct if the declaration is a constructor's declaration. * tools/pm/Output.pm (output_wrap_meth): Store the number of possible declarations instead of computing it each time in the for loop. (output_wrap_ctor): (output_wrap_create): Modified as output_wrap_meth() to loop through the list of the possible combination of arguments to output convenience overloads for the constructors and create() methods. (get_ctor_properties): Modified as convert_args_cpp_to_c() to accept an optional index specifying which argument list out of the possible ones to use and to insert a static_cast<char*>(0) for optional parameters not in the specified argument list. * tools/m4/class_gobject.m4: Added a blank line after the create() methods definitions.
-rw-r--r--ChangeLog22
-rw-r--r--tools/m4/class_gobject.m41
-rw-r--r--tools/pm/Function.pm7
-rw-r--r--tools/pm/FunctionBase.pm5
-rw-r--r--tools/pm/Output.pm103
5 files changed, 113 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index c3b50d76..4025785e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2011-06-01 José Alburquerque <jaalburqu@svn.gnome.org>
+
+ gmmproc: _WRAP_[CREATE|CTOR]: Add optional parameter functionality.
+
+ * tools/pm/Function.pm (new_ctor): Modified to initialize the new
+ param_optional and possible_args_list members.
+ * tools/pm/FunctionBase.pm (args_names_only): Typo.
+ (get_declaration): Make sure that spacing is correct if the
+ declaration is a constructor's declaration.
+ * tools/pm/Output.pm (output_wrap_meth): Store the number of possible
+ declarations instead of computing it each time in the for loop.
+ (output_wrap_ctor):
+ (output_wrap_create): Modified as output_wrap_meth() to loop through
+ the list of the possible combination of arguments to output
+ convenience overloads for the constructors and create() methods.
+ (get_ctor_properties): Modified as convert_args_cpp_to_c() to accept
+ an optional index specifying which argument list out of the possible
+ ones to use and to insert a static_cast<char*>(0) for optional
+ parameters not in the specified argument list.
+ * tools/m4/class_gobject.m4: Added a blank line after the create()
+ methods definitions.
+
2011-05-31 José Alburquerque <jaalburqu@svn.gnome.org>
gmmproc: _WRAP_METHOD: Add optional parameter functionality.
diff --git a/tools/m4/class_gobject.m4 b/tools/m4/class_gobject.m4
index 12cbec6c..9462de46 100644
--- a/tools/m4/class_gobject.m4
+++ b/tools/m4/class_gobject.m4
@@ -89,6 +89,7 @@ Glib::RefPtr<`'__CPPNAME__`'> __CPPNAME__`'::create(`'$2`')
{
return Glib::RefPtr<`'__CPPNAME__`'>( new __CPPNAME__`'(`'$3`') );
}
+
_POP()
')
diff --git a/tools/pm/Function.pm b/tools/pm/Function.pm
index 04348522..841afa30 100644
--- a/tools/pm/Function.pm
+++ b/tools/pm/Function.pm
@@ -134,6 +134,8 @@ sub new_ctor($$)
$$self{param_types} = [];
$$self{param_names} = [];
$$self{param_default_values} = [];
+ $$self{param_optional} = [];
+ $$self{possible_args_list} = [];
$$self{in_module} = "";
$$self{class} = "";
$$self{entity_type} = "method";
@@ -151,6 +153,11 @@ sub new_ctor($$)
{
$objWrapParser->error("fail to parse $line\n");
}
+
+ # Store the list of possible argument combinations based on if arguments
+ # are optional.
+ my $possible_args_list = $$self{possible_args_list};
+ push(@$possible_args_list, $self->possible_args_list());
return $self;
}
diff --git a/tools/pm/FunctionBase.pm b/tools/pm/FunctionBase.pm
index 83fc58f3..f363f76f 100644
--- a/tools/pm/FunctionBase.pm
+++ b/tools/pm/FunctionBase.pm
@@ -72,7 +72,7 @@ sub args_names_only($)
{
push(@out, $$param_names[$arg_indices[$i]]);
}
- return join(", ", @$param_names);
+ return join(", ", @out);
}
# $string args_types_and_names(int index = 0)
@@ -290,7 +290,8 @@ sub get_declaration($)
my $out = "";
$out = "static " if($$self{static});
- $out = $out . $$self{rettype} . " " . $$self{name} . "(" .
+ $out = $out . "$$self{rettype} " if($$self{rettype});
+ $out = $out . $$self{name} . "(" .
$self->args_types_and_names_with_default_values($index) . ")";
$out = $out . " const" if $$self{const};
$out = $out . ";";
diff --git a/tools/pm/Output.pm b/tools/pm/Output.pm
index 9d17ac40..f03c1d3c 100644
--- a/tools/pm/Output.pm
+++ b/tools/pm/Output.pm
@@ -282,8 +282,9 @@ sub output_wrap_meth($$$$$$$)
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $cppMethodDecl, $documentation, $ifdef) = @_;
my $objDefsParser = $$self{objDefsParser};
- for(my $arg_list = 0; $arg_list < $objCppfunc->get_num_possible_args_list();
- $arg_list++)
+ my $num_args_list = $objCppfunc->get_num_possible_args_list();
+
+ for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
{
# Allow the generated .h/.cc code to have an #ifndef around it, and add
@@ -307,7 +308,7 @@ sub output_wrap_meth($$$$$$$)
}
else
{
- $self->append("\n\n /// A $$objCppfunc{name}() convinience overload.\n");
+ $self->append("\n\n /// A $$objCppfunc{name}() convenience overload.\n");
}
$self->ifdef($ifdef);
@@ -397,19 +398,29 @@ sub output_wrap_ctor($$$$$)
my ($self, $filename, $line_num, $objCppfunc, $objCDefsFunc, $cppMethodDecl) = @_;
my $objDefsParser = $$self{objDefsParser};
- #Ctor Declaration:
- #TODO: Add explicit.
- $self->append("explicit " . $cppMethodDecl . ";");
+ my $num_args_list = $objCppfunc->get_num_possible_args_list();
- #Implementation:
- my $str = sprintf("_CTOR_IMPL(%s,%s,\`%s\',\`%s\')dnl\n",
- $$objCppfunc{name},
- $$objCDefsFunc{c_name},
- $objCppfunc->args_types_and_names(),
- get_ctor_properties($objCppfunc, $objCDefsFunc, $line_num)
- );
+ for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
+ {
+ if ($arg_list > 0)
+ {
+ $self->append("\n\n /// A $$objCppfunc{name}() convenience overload.\n");
+ }
+
+ #Ctor Declaration:
+ #TODO: Add explicit.
+ $self->append(" explicit " . $objCppfunc->get_declaration($arg_list) . "\n");
- $self->append($str);
+ #Implementation:
+ my $str = sprintf("_CTOR_IMPL(%s,%s,\`%s\',\`%s\')dnl\n",
+ $$objCppfunc{name},
+ $$objCDefsFunc{c_name},
+ $objCppfunc->args_types_and_names($arg_list),
+ get_ctor_properties($objCppfunc, $objCDefsFunc, $line_num, $arg_list)
+ );
+
+ $self->append($str);
+ }
}
sub output_wrap_create($$$)
@@ -420,14 +431,25 @@ sub output_wrap_create($$$)
my $fake_decl = "void fake_func(" . $args_type_and_name_with_default_values . ")";
my $objFunction = &Function::new($fake_decl, $objWrapParser);
- my $args_names_only = $objFunction->args_names_only();
- my $args_type_and_name_hpp = $objFunction->args_types_and_names_with_default_values();
- my $args_type_and_name_cpp = $objFunction->args_types_and_names();
- my $str = sprintf("_CREATE_METHOD(\`%s\',\`%s\',\`%s\')dnl\n",
- $args_type_and_name_hpp, , $args_type_and_name_cpp, $args_names_only);
+ my $num_args_list = $objFunction->get_num_possible_args_list();
- $self->append($str)
+ for(my $arg_list = 0; $arg_list < $num_args_list; $arg_list++)
+ {
+ my $args_names_only = $objFunction->args_names_only($arg_list);
+ my $args_type_and_name_hpp =
+ $objFunction->args_types_and_names_with_default_values($arg_list);
+ my $args_type_and_name_cpp = $objFunction->args_types_and_names($arg_list);
+
+ if ($arg_list > 0) {
+ $self->append("\n /// A create() convenience overload.");
+ }
+
+ my $str = sprintf("_CREATE_METHOD(\`%s\',\`%s\',\`%s\')dnl\n",
+ $args_type_and_name_hpp, , $args_type_and_name_cpp, $args_names_only);
+
+ $self->append($str)
+ }
}
# void output_wrap_sig_decl($filename, $line_num, $objCSignal, $objCppfunc, $signal_name, $bCustomCCallback)
@@ -915,13 +937,19 @@ sub convert_args_c_to_cpp($$$)
# generates the XXX in g_object_new(get_type(), XXX): A list of property names and values.
# Uses the cpp arg name as the property name.
-# $string get_ctor_properties($objCppfunc, $objCDefsFunc, $wrap_line_number)
-sub get_ctor_properties($$$$)
+# The optional index specifies which arg list out of the possible combination
+# of arguments based on whether any arguments are optional. index = 0 ==> all
+# the arguments.
+# $string get_ctor_properties($objCppfunc, $objCDefsFunc, $wrap_line_number, $index = 0)
+sub get_ctor_properties($$$$$)
{
- my ($objCppfunc, $objCDefsFunc, $wrap_line_number) = @_;
+ my ($objCppfunc, $objCDefsFunc, $wrap_line_number, $index) = @_;
+
+ $index = 0 unless defined $index;
my $cpp_param_names = $$objCppfunc{param_names};
my $cpp_param_types = $$objCppfunc{param_types};
+ my $cpp_param_optional = $$objCppfunc{param_optional};
my $c_param_types = $$objCDefsFunc{param_types};
my @result;
@@ -938,6 +966,10 @@ sub get_ctor_properties($$$$)
}
+ # Get the desired argument list combination.
+ my $possible_args_list = $$objCppfunc{possible_args_list};
+ my @arg_indices = split(" ", @$possible_args_list[$index]);
+
# Loop through the cpp parameters:
my $i = 0;
@@ -953,6 +985,31 @@ sub get_ctor_properties($$$$)
# Property name:
push(@result, "\"" . $cppParamName . "\"");
+ if(!@arg_indices)
+ {
+ # If there are no more arg indices that should be included, pass
+ # NULL to the C func unless the param is not optional (applies to a
+ # possibly added GError parameter).
+ if ($$cpp_param_optional[$i])
+ {
+ push(@result, "static_cast<char*>(0)");
+ next;
+ }
+ }
+ elsif($arg_indices[0] > $i)
+ {
+ # If this argument is not in the desired argument list (The argument
+ # indices are stored in ascending order) then pass NULL to C func.
+ push(@result, "static_cast<char*>(0)");
+ next;
+ }
+ else
+ {
+ # The current argument index from the desired list is <= the current
+ # index so go to the next index.
+ shift(@arg_indices);
+ }
+
# C property value:
if ($cppParamType ne $cParamType) #If a type conversion is needed.
{