[glibmm/gmmproc-refactor] Fix code bugs in generated code.



commit 8ef85537e38d1d171dd214b33233c841161f7674
Author: Krzesimir Nowak <qdlacz gmail com>
Date:   Wed Apr 18 05:27:18 2012 +0200

    Fix code bugs in generated code.

 tools/pm/Common/Output/Ctor.pm     |    4 +-
 tools/pm/Common/Output/GObject.pm  |   37 ++++++++++++++++++++++++++++-------
 tools/pm/Common/Output/Method.pm   |   22 +++++++++++++++++---
 tools/pm/Common/Output/Property.pm |    4 +-
 tools/pm/Common/WrapParser.pm      |    4 +-
 5 files changed, 53 insertions(+), 18 deletions(-)
---
diff --git a/tools/pm/Common/Output/Ctor.pm b/tools/pm/Common/Output/Ctor.pm
index b5e1dc8..194f963 100644
--- a/tools/pm/Common/Output/Ctor.pm
+++ b/tools/pm/Common/Output/Ctor.pm
@@ -97,7 +97,7 @@ sub wrap_ctor ($$$$$$)
   my $base_member = (lc $cpp_class_type) . '_';
   my $conditional = initially_unowned_sink $wrap_parser;
   my $conversions_store = $wrap_parser->get_conversions_store;
-  my $ctor_params_str = join ', ', '', (map { join '', '"', $c_prop_names->[$_], '"', $conversions_store->get_conversion ($cpp_param_types->[$_], $c_param_types->[$_], $c_param_transfers->[$_], $cpp_param_names->[$_]) } 0 .. (@{$cpp_param_types} - 1)), 'static_cast<char*>(0)';
+  my $ctor_params_str = join ', ', '', (map { join '', '"', $c_prop_names->[$_], '", ', ($conversions_store->get_conversion ($cpp_param_types->[$_], $c_param_types->[$_], $c_param_transfers->[$_], $cpp_param_names->[$_])) } 0 .. (@{$cpp_param_types} - 1)), 'static_cast<char*>(0)';
 
   $section_manager->append_string_to_section ($code_string, $main_section);
   $code_string = (nl $full_cpp_type, '::', $cpp_type, '(', $cpp_params_str, ')') .
@@ -126,7 +126,7 @@ sub wrap_create ($$$)
   my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
   my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names;
   my $cpp_names_str = join ', ', @{$cpp_param_names};
-  my $code_string = (nl 'static Glib::RefPtr< ', $cpp_type, ' > create(', $cpp_params_str, ')');
+  my $code_string = (nl 'static Glib::RefPtr< ', $cpp_type, ' > create(', $cpp_params_str, ');');
 
   $section_manager->append_string_to_section ($code_string, $main_section);
   $code_string = (nl 'Glib::RefPtr< ', $full_cpp_type, ' > ', $full_cpp_type, '::create(', $cpp_params_str, ')') .
diff --git a/tools/pm/Common/Output/GObject.pm b/tools/pm/Common/Output/GObject.pm
index 6f4ad06..7409f66 100644
--- a/tools/pm/Common/Output/GObject.pm
+++ b/tools/pm/Common/Output/GObject.pm
@@ -84,7 +84,7 @@ sub _output_h_in_class ($$$$$$)
   my $base_member = lc ($cpp_class_type) . '_';
 
   $code_string = nl ('  friend class ' . $cpp_class_type . ';') .
-                 nl ('  static CppClassType ' . $base_member . '_;') .
+                 nl ('  static CppClassType ' . $base_member . ';') .
                  nl () .
                  nl ('private:') .
                  nl ('  // noncopyable') .
@@ -109,7 +109,7 @@ sub _output_h_in_class ($$$$$$)
   $section_manager->append_conditional ($conditional);
   $section_manager->set_variable_for_conditional ($variable, $conditional);
 
-  my $copy_proto = 'no';
+  my $copy_proto = 'yes';
   my $reinterpret = 1;
   my $definitions = 1;
 
@@ -220,12 +220,34 @@ sub _output_cc ($$$$$$)
   my $section_manager = $wrap_parser->get_section_manager;
   my $complete_cpp_type = Common::Output::Shared::get_complete_cpp_type $wrap_parser;
   my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
+
+  {
+    my $mm_module = $wrap_parser->get_mm_module;
+    my $base = $wrap_parser->get_base;
+    my $header_include = join '', $mm_module, '/', $base. '.h';
+    my $private_include = join '', $mm_module, '/private/', $base, '_p.h';
+    my $generated_headers_section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::CC_GENERATED_INCLUDES;
+
+    unless (Common::Output::Shared::already_included $wrap_parser, $header_include)
+    {
+      my $code_string = nl '#include <', $header_include, '>';
+
+      $section_manager->append_string_to_section ($code_string, $generated_headers_section);
+    }
+    unless (Common::Output::Shared::already_included $wrap_parser, $private_include)
+    {
+      my $code_string = nl '#include <', $private_include, '>';
+
+      $section_manager->append_string_to_section ($code_string, $generated_headers_section);
+    }
+  }
+
   my $code_string = nl ('namespace Glib') .
                     nl ('{') .
                     nl () .
                     nl ('Glib::RefPtr< ' . $complete_cpp_type . ' > wrap(' . $c_type . '* object, bool take_copy)') .
                     nl ('{') .
-                    nl ('  return Glib::RefPtr< ' . $complete_cpp_type . ' >(dynamic_cast< ' . $complete_cpp_type . ' >(Glib::wrap_auto (static_cast< GObject* >(object), take_copy)));') .
+                    nl ('  return Glib::RefPtr< ' . $complete_cpp_type . ' >(dynamic_cast< ' . $complete_cpp_type . '* >(Glib::wrap_auto (reinterpret_cast< GObject* >(object), take_copy)));') .
                     nl ('  // We use dynamic_cast<> in case of multiple inheritance.') .
                     nl ('}') .
                     nl () .
@@ -264,7 +286,7 @@ sub _output_cc ($$$$$$)
                  nl () .
                  nl ($full_cpp_type . '::' . $cpp_type . '(' . $c_type . '* castitem)') .
                  nl (':') .
-                 nl ('  ' . $cpp_parent_type . '(static_cast< ' . $c_parent_type . '* >(castitem))') .
+                 nl ('  ' . $cpp_parent_type . '(reinterpret_cast< ' . $c_parent_type . '* >(castitem))') .
                  nl ('{}') .
                  nl ();
   $section_manager->append_string_to_conditional ($code_string, $conditional, 0);
@@ -289,14 +311,14 @@ sub _output_cc ($$$$$$)
                  nl () .
                  nl ('GType ' . $full_cpp_type . '::get_type()') .
                  nl ('{') .
-                 nl ('  return ' . $base_member . '_.init().get_type();') .
+                 nl ('  return ' . $base_member . '.init().get_type();') .
                  nl ('}') .
                  nl ();
   $section_manager->append_string ($code_string);
   $conditional = Common::Output::Shared::generate_conditional ($wrap_parser);
   $code_string = nl ('GType ' . $full_cpp_type . '::get_type(GTypeModule* module)') .
                  nl ('{') .
-                 nl ('  return ' . $base_member . '_.init(module).get_type();') .
+                 nl ('  return ' . $base_member . '.init(module).get_type();') .
                  nl ('}') .
                  nl ();
 
@@ -461,7 +483,7 @@ sub _output_p_cc ($$$$)
 
   $code_string = nl ('Glib::ObjectBase* ' . $cpp_class_type . '::wrap_new(GObject* object)') .
                  nl ('{') .
-                 nl ('  return new ' . $full_cpp_type . '(static_cast< ' . $c_type . '* >(object));') .
+                 nl ('  return new ' . $full_cpp_type . '(reinterpret_cast< ' . $c_type . '* >(object));') .
                  nl ('}') .
                  nl ();
   $conditional = Common::Output::Shared::generate_conditional ($wrap_parser);
@@ -471,7 +493,6 @@ sub _output_p_cc ($$$$)
   $section_manager->append_string_to_conditional ($code_string, $conditional, 0);
   $section_manager->append_conditional ($conditional);
   $section_manager->set_variable_for_conditional ($custom_wrap_new_var, $conditional);
-  $section_manager->append_string (Common::Output::Shared::close_namespaces $wrap_parser);
   $section_manager->pop_entry;
 }
 
diff --git a/tools/pm/Common/Output/Method.pm b/tools/pm/Common/Output/Method.pm
index b5c6dc1..95317e4 100644
--- a/tools/pm/Common/Output/Method.pm
+++ b/tools/pm/Common/Output/Method.pm
@@ -103,18 +103,32 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
   else
   {
     my $this_param = '';
+    my @params = ();
 
     if ($const)
     {
-      $this_param = 'const_cast< ' . $c_type . '* >(gobj()), ';
+      $this_param = 'const_cast< ' . $c_type . '* >(gobj())';
     }
     elsif (not $static)
     {
-      $this_param = 'gobj(), ';
+      $this_param = 'gobj()';
     }
 
+    push @params, $this_param;
+
     my $conversions_store = $wrap_parser->get_conversions_store;
-    my $c_param_list_str = $this_param . (Common::Output::Shared::convzipstr $wrap_parser, $cpp_param_types, $c_param_types, $c_param_transfers, $cpp_param_names) . ($errthrow ? ', &gerror' : '');
+    my $convs_str = Common::Output::Shared::convzipstr $wrap_parser, $cpp_param_types, $c_param_types, $c_param_transfers, $cpp_param_names;
+
+    if ($convs_str)
+    {
+      push @params, $convs_str;
+    }
+    if ($errthrow)
+    {
+      push @params, '&gerror';
+    }
+
+    my $c_param_list_str = join ', ', @params;
     my $c_func_invocation = $c_func_name . '(' . $c_param_list_str . ')';
     my $ret_convert = '';
 
@@ -152,7 +166,7 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
     }
     else
     {
-      if ($ret_void)
+      unless ($ret_void)
       {
         $code_string .= nl ('  return ' . $ret_convert . ';');
       }
diff --git a/tools/pm/Common/Output/Property.pm b/tools/pm/Common/Output/Property.pm
index 79a87fe..095b66e 100644
--- a/tools/pm/Common/Output/Property.pm
+++ b/tools/pm/Common/Output/Property.pm
@@ -39,7 +39,7 @@ sub _output_h ($$$$)
                     (nl '   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when') .
                     (nl '   * the value of the property changes.') .
                     (nl '   */') .
-                    (nl '  ' . $proxy_type . ' property_' . $prop_cpp_name . '()' . $method_suffix);
+                    (nl '  ' . $proxy_type . ' property_' . $prop_cpp_name . '()' . $method_suffix . ';');
 
   $section_manager->append_string_to_section ($code_string, $main_section);
 }
@@ -54,7 +54,7 @@ sub _output_cc ($$$$$)
   my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
   my $code_string = (nl $proxy_type . ' ' . $full_cpp_type . '::property_' . $prop_cpp_name . '()' . $method_suffix) .
                     (nl '{') .
-                    (nl '  ' . $proxy_type . '(this, "' . $prop_c_name . '");') .
+                    (nl '  return ' . $proxy_type . '(this, "' . $prop_c_name . '");') .
                     (nl '}') .
                     (nl);
 
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 91e3297..2c9691b 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -2595,8 +2595,8 @@ sub new ($$$$$$$)
     'section_manager' => Common::SectionManager->new ($base, $mm_module),
     'stage_section_tuples' =>
     {
-      STAGE_HG() => [Common::Sections::H, 'tokens_hg', 'hg'],
-      STAGE_CCG() => [Common::Sections::CC, 'tokens_ccg', 'ccg'],
+      STAGE_HG() => [Common::Sections::H_CONTENTS, 'tokens_hg', 'hg'],
+      STAGE_CCG() => [Common::Sections::CC_CONTENTS, 'tokens_ccg', 'ccg'],
       STAGE_INVALID() => [Common::Sections::DEV_NULL, 'tokens_null', 'BAD']
     },
     'type_info_store' => $type_info_store,



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