From bcea756362e203628f6f4eb9d46c0e955410a0e3 Mon Sep 17 00:00:00 2001 From: Kjell Ahlstedt Date: Tue, 18 Sep 2012 18:26:08 +0200 Subject: gmmproc: Improve the search for unwrapped methods. * tools/pm/GtkDefs.pm: lookup_method_set_weak_mark(): New function. get_unwrapped(): Correct the search when methods from more than one class have been wrapped. GtkDefs::Function::new(): Take into account that a method (g_iconv) may be nameless. After this change the patch of g_iconv in glib_functions.defs.patch is probably unnecessary but harmless. * tools/pm/WrapParser.pm: on_wrap_method_docs_only(), on_wrap_ctor(): Call GtkDefs::lookup_method_set_weak_mark(). on_wrap_method(): Call GtkDefs::lookup_method_set_weak_mark() if the method is static. --- ChangeLog | 15 +++++++++++++++ tools/pm/GtkDefs.pm | 49 +++++++++++++++++++++++++++++++++++++------------ tools/pm/WrapParser.pm | 13 +++++++++---- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index fda7e2b6..531370c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2012-09-18 Kjell Ahlstedt + + gmmproc: Improve the search for unwrapped methods. + + * tools/pm/GtkDefs.pm: lookup_method_set_weak_mark(): New function. + get_unwrapped(): Correct the search when methods from more than one class + have been wrapped. + GtkDefs::Function::new(): Take into account that a method (g_iconv) may be + nameless. After this change the patch of g_iconv in glib_functions.defs.patch + is probably unnecessary but harmless. + * tools/pm/WrapParser.pm: on_wrap_method_docs_only(), on_wrap_ctor(): + Call GtkDefs::lookup_method_set_weak_mark(). + on_wrap_method(): Call GtkDefs::lookup_method_set_weak_mark() if the method + is static. + 2012-09-14 José Alburquerque _CLASS_GOBJECT: Allow classes to have custom wrap() functions. diff --git a/tools/pm/GtkDefs.pm b/tools/pm/GtkDefs.pm index 2111d501..d9e4532b 100644 --- a/tools/pm/GtkDefs.pm +++ b/tools/pm/GtkDefs.pm @@ -34,9 +34,12 @@ use FunctionBase; # @ get_methods() # @ get_signals() # @ get_properties() +# @ get_unwrapped() # # $ lookup_enum(c_type) # $ lookup_object(c_name) +# $ lookup_method_dont_mark(c_name) +# $ lookup_method_set_weak_mark(c_name) # $ lookup_method(c_name) # $ lookup_function(c_name) # $ lookup_property(object, c_name) @@ -369,19 +372,19 @@ sub get_marked } # This searches for items wrapped by this file and then tries to locate -# other functions/signal/properties which may have been left unmarked. +# other methods/signals/properties which may have been left unmarked. sub get_unwrapped { - # find methods which were used in for a _WRAP + # find methods which were used in a _WRAP or _IGNORE. my @targets; push @targets,grep {$$_{entity_type} eq "method" && $$_{mark}==1} values %GtkDefs::methods; push @targets,grep {$$_{mark}==1} values %GtkDefs::signals; push @targets,grep {$$_{mark}==1} values %GtkDefs::properties; # find the classes which used them. - my @classes = join(" ", unique(map { $$_{class} } @targets)); + my @classes = unique(map { $$_{class} } @targets); - # find methods which are in those classes which didn't get marked. + # find methods/signals/properties which are in those classes which didn't get marked. my @unwrapped; my $class; foreach $class (@classes) @@ -485,7 +488,7 @@ sub lookup_method_dont_mark($) sub lookup_method($) { - my $obj = lookup_method_dont_mark($_); + my $obj = lookup_method_dont_mark($_[0]); $$obj{mark} = 1 if($obj); return $obj; @@ -496,6 +499,26 @@ sub lookup_function($) return lookup_method($_[0]); } +sub lookup_method_set_weak_mark($) +{ + my $obj = lookup_method_dont_mark($_[0]); + + # A constructor or a static method may be listed in the .defs file as a method + # of another class, if its first parameter is a pointer to a class instance. + # Examples: + # GVariantIter* g_variant_iter_new(GVariant* value) + # GtkWidget* gtk_application_window_new(GtkApplication* application) + # GSocketConnection* g_socket_connection_factory_create_connection(GSocket* socket) + # + # The use of gtk_application_window_new() in Gtk::ApplicationWindow shall + # not cause get_unwrapped() to list all methods, signals and properties of + # GtkApplication as unwrapped in applicationwindow.hg. + # Therefore mark=2 instead of mark=1. + + $$obj{mark} = 2 if ($obj && $$obj{mark} == 0); + return $obj; +} + sub lookup_signal($$) { no warnings; @@ -520,21 +543,19 @@ package GtkDefs::Function; BEGIN { @GtkDefs::Function::ISA=qw(FunctionBase); } # class Function : FunctionBase -# # { -# string name; e.g. gtk_accelerator_valid -# string c_name; -# string class e.g. GtkButton +# string name; e.g. function: gtk_accelerator_valid, method: clicked +# string c_name; e.g. gtk_accelerator_valid, gtk_button_clicked +# string class; e.g. GtkButton # # string rettype; # string array param_types; # string array param_names; # -# string entity_type. e.g. method or signal +# string entity_type; e.g. method or function # # bool varargs; # bool mark; -# # } # "new" can't have prototype @@ -545,9 +566,13 @@ sub new my $self = {}; bless $self; + #Remove first and last braces: $def =~ s/^\(//; $def =~ s/\)$//; - $def =~ s/^\s*define-(\S+)\s+(\S+)\s*//; + + #In rare cases a method can be nameless (g_iconv). + #Don't interpret the following "(of-object" as the method's name. + $def =~ s/^\s*define-([^\s\(]+)\s*([^\s\(]*)\s*//; $$self{entity_type} = $1; $$self{name} = $2; $$self{name} =~ s/-/_/g; # change - to _ diff --git a/tools/pm/WrapParser.pm b/tools/pm/WrapParser.pm index 374a5758..3841fee4 100644 --- a/tools/pm/WrapParser.pm +++ b/tools/pm/WrapParser.pm @@ -870,7 +870,7 @@ sub on_wrap_method($) return; } - #Parse the method decaration and build an object that holds the details: + #Parse the method declaration and build an object that holds the details: $objCppfunc = &Function::new($argCppMethodDecl, $self); # handle second argument: @@ -884,7 +884,11 @@ sub on_wrap_method($) if ($argCFunctionName =~ m/^\S+$/s) { #c-name. e.g. gtk_clist_set_column_title - $objCfunc = GtkDefs::lookup_function($argCFunctionName); + if ($$objCppfunc{static}) { + $objCfunc = GtkDefs::lookup_method_set_weak_mark($argCFunctionName); + } else { + $objCfunc = GtkDefs::lookup_method($argCFunctionName); + } if(!$objCfunc) #If the lookup failed: { @@ -977,7 +981,7 @@ sub on_wrap_method_docs_only($) if ($argCFunctionName =~ m/^\S+$/s) { #c-name. e.g. gtk_clist_set_column_title - $objCfunc = GtkDefs::lookup_function($argCFunctionName); + $objCfunc = GtkDefs::lookup_method_set_weak_mark($argCFunctionName); if(!$objCfunc) #If the lookup failed: { @@ -1049,7 +1053,8 @@ sub on_wrap_ctor($) #Get the C function's details: if ($argCFunctionName =~ m/^\S+$/s) { - $objCfunc = GtkDefs::lookup_function($argCFunctionName); #c-name. e.g. gtk_clist_set_column_title + #c-name. e.g. gtk_button_new + $objCfunc = GtkDefs::lookup_method_set_weak_mark($argCFunctionName); if(!$objCfunc) #If the lookup failed: { $objOutputter->output_wrap_failed($argCFunctionName, "ctor defs lookup failed (2)"); -- cgit v1.2.1