[glibmm/gmmproc-refactor] Print nice error message where conversion has failed.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/gmmproc-refactor] Print nice error message where conversion has failed.
- Date: Mon, 9 Jul 2012 20:36:51 +0000 (UTC)
commit 4e9008085f60b87e367ea2f18d7e40a84e65b788
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Mon Jul 9 22:14:04 2012 +0200
Print nice error message where conversion has failed.
tools/pm/Common/Output/Ctor.pm | 9 +++++++--
tools/pm/Common/Output/Member.pm | 24 +++++++++---------------
tools/pm/Common/Output/Method.pm | 5 ++---
tools/pm/Common/Output/Shared.pm | 27 ++++++++++++++++++++++-----
tools/pm/Common/Output/Signal.pm | 8 +++-----
tools/pm/Common/Output/VFunc.pm | 8 +++-----
tools/pm/Common/TypeInfo/Global.pm | 2 --
7 files changed, 46 insertions(+), 37 deletions(-)
---
diff --git a/tools/pm/Common/Output/Ctor.pm b/tools/pm/Common/Output/Ctor.pm
index 593136a..b09f5e0 100644
--- a/tools/pm/Common/Output/Ctor.pm
+++ b/tools/pm/Common/Output/Ctor.pm
@@ -93,8 +93,13 @@ sub wrap_ctor ($$$$$$$)
my $section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::CC_NAMESPACE;
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type $wrap_parser;
my $conditional = initially_unowned_sink $wrap_parser;
- my $type_info_local = $wrap_parser->get_type_info_local ();
- my $ctor_params_str = join ', ', '', (map { join '', '"', $c_prop_names->[$_], '", ', ($type_info_local->get_conversion ($cxx_param_types->[$_], $c_param_types->[$_], $c_param_transfers->[$_], $cxx_param_names->[$_])) } 0 .. (@{$cxx_param_types} - 1)), 'static_cast<char*>(0)';
+ my $ctor_params_str = '';
+
+ if (@{$c_prop_names} > 0)
+ {
+# TODO: consider using C++11 nullptr
+ $ctor_params_str = join (', ', '', (map { join ('', '"', $c_prop_names->[$_], '", ', Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_param_types->[$_], $c_param_types->[$_], $c_param_transfers->[$_], $cxx_param_names->[$_])); } 0 .. (@{$cxx_param_types} - 1)), 'static_cast<char*>(0)');
+ }
$section_manager->append_string_to_section ($code_string, $main_section);
$code_string = (nl $full_cxx_type, '::', $cxx_type, '(', $cxx_params_str_cc, ')') .
diff --git a/tools/pm/Common/Output/Member.pm b/tools/pm/Common/Output/Member.pm
index 857f382..5e1bc78 100644
--- a/tools/pm/Common/Output/Member.pm
+++ b/tools/pm/Common/Output/Member.pm
@@ -34,11 +34,10 @@ sub output_get
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
- my $conversion = $type_info_local->get_conversion ($c_type, $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
if ($deprecated)
{
@@ -69,12 +68,11 @@ sub output_get_ptr
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
- my $conversion = $type_info_local->get_conversion ($c_type, $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
- my $const_conversion = $type_info_local->get_conversion ($c_type, 'const ' . $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
+ my $const_conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, 'const ' . $cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
if ($deprecated)
{
@@ -111,14 +109,13 @@ sub output_get_ref_ptr
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
my $reffed_cxx_type = 'Glib::RefPtr< ' . $cxx_type . '>';
my $reffed_const_cxx_type = 'Glib::RefPtr< const ' . $cxx_type . '>';
- my $conversion = $type_info_local->get_conversion ($c_type, $reffed_cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
- my $const_conversion = $type_info_local->get_conversion ($c_type, $reffed_const_cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, $reffed_cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
+ my $const_conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, $reffed_const_cxx_type, Common::TypeInfo::Common::TRANSFER_NONE, 'gobj()->' . $c_name);
if ($deprecated)
{
@@ -155,11 +152,10 @@ sub output_set
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
- my $conversion = $type_info_local->get_conversion ($cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
if ($deprecated)
{
@@ -190,11 +186,10 @@ sub output_set_ptr
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
- my $conversion = $type_info_local->get_conversion ($cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
if ($deprecated)
{
@@ -225,13 +220,12 @@ sub output_set_ref_ptr
my $section_manager = $wrap_parser->get_section_manager ();
my $main_section = $wrap_parser->get_main_section ();
my $cc_section = Common::Output::Shared::get_section ($wrap_parser, Common::Sections::CC_NAMESPACE);
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $main_code_string = '';
my $cc_code_string = '';
my $full_cxx_type = Common::Output::Shared::get_full_cxx_type ($wrap_parser);
my $ref_cxx_type = join ('', 'Glib::RefPtr< ', $cxx_type, ' >');
- my $conversion = $type_info_local->get_conversion ($ref_cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
- my $old_conversion = $type_info_local->get_conversion ($c_type, $ref_cxx_type, Common::TypeInfo::TRANSFER_FULL, 'gobj->' . $c_name);
+ my $conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $ref_cxx_type, $c_type, Common::TypeInfo::Common::TRANSFER_NONE, 'value');
+ my $old_conversion = Common::Output::Shared::convert_or_die ($wrap_parser, $c_type, $ref_cxx_type, Common::TypeInfo::Common::TRANSFER_FULL, 'gobj->' . $c_name);
if ($deprecated)
{
diff --git a/tools/pm/Common/Output/Method.pm b/tools/pm/Common/Output/Method.pm
index bea505f..e8a1139 100644
--- a/tools/pm/Common/Output/Method.pm
+++ b/tools/pm/Common/Output/Method.pm
@@ -122,7 +122,6 @@ sub _output_cc ($$$$$$$$$$$$$$$$$)
push @params, $this_param;
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $prepped_cxx_param_types = [];
my $prepped_cxx_param_names = [];
@@ -159,11 +158,11 @@ sub _output_cc ($$$$$$$$$$$$$$$$$)
unless ($ret_void)
{
- $ret_convert = $type_info_local->get_conversion ($c_ret_type, $cxx_ret_type, $ret_transfer, $c_func_invocation);
+ $ret_convert = Common::Output::Shared::convert_or_die ($wrap_parser, $c_ret_type, $cxx_ret_type, $ret_transfer, $c_func_invocation);
}
elsif ($cxx_param_out_index > -1)
{
- $ret_convert = $type_info_local->get_conversion ($c_ret_type, $cxx_param_types->[$cxx_param_out_index], $ret_transfer, $c_func_invocation);
+ $ret_convert = Common::Output::Shared::convert_or_die ($wrap_parser, $c_ret_type, $cxx_param_types->[$cxx_param_out_index], $ret_transfer, $c_func_invocation);
}
if ($errthrow)
diff --git a/tools/pm/Common/Output/Shared.pm b/tools/pm/Common/Output/Shared.pm
index 94d583b..4384066 100644
--- a/tools/pm/Common/Output/Shared.pm
+++ b/tools/pm/Common/Output/Shared.pm
@@ -609,10 +609,26 @@ sub get_parent_from_object ($$)
return $code_string;
}
+sub convert_or_die
+{
+ my ($wrap_parser, $from, $to, $transfer, $subst) = @_;
+ my $type_info_local = $wrap_parser->get_type_info_local ();
+ my $conversion = $type_info_local->get_conversion ($from,
+ $to,
+ $transfer,
+ $subst);
+
+ unless (defined ($conversion))
+ {
+ my $message = join ('', 'Could not find conversion from `', $from, '\' to `', $to, '\' with transfer `', Common::TypeInfo::Common::transfer_to_string ($transfer), '\' for substitution `', $subst, '\'');
+
+ $wrap_parser->fixed_error ($message);
+ }
+}
+
sub convzipstr ($$$$$)
{
my ($wrap_parser, $from_types, $to_types, $transfers, $substs) = @_;
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $from_types_count = @{$from_types};
my $to_types_count = @{$to_types};
my $transfers_count = @{$transfers};
@@ -628,10 +644,11 @@ sub convzipstr ($$$$$)
if (defined ($from_types->[$index]))
{
push (@conversions,
- $type_info_local->get_conversion ($from_types->[$index],
- $to_types->[$index],
- $transfers->[$index],
- $substs->[$index]));
+ convert_or_die ($wrap_parser,
+ $from_types->[$index],
+ $to_types->[$index],
+ $transfers->[$index],
+ $substs->[$index]));
}
else
{
diff --git a/tools/pm/Common/Output/Signal.pm b/tools/pm/Common/Output/Signal.pm
index c481882..76c4d93 100644
--- a/tools/pm/Common/Output/Signal.pm
+++ b/tools/pm/Common/Output/Signal.pm
@@ -85,7 +85,6 @@ sub _output_cc ($$$$$$$$$$$$$$)
my $proxy_info = $signal_prefix . '_signal_' . $cxx_signal_name . '_info';
my $ret_void = ($c_return_type eq 'void');
my $cxx_param_types_str = join ', ', @cxx_param_types;
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $code_string = Common::Output::Shared::ifdef $ifdef;
if ($ret_void and not @{$c_param_types} and $cxx_return_type eq 'void' and not @{$cxx_param_types})
@@ -127,7 +126,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
# TODO: print a warning - pointers returned from signals ought to have ownership transferred fully.
# TODO continued: need warning or error with fixed line number for this.
}
- my $conv = $type_info_local->get_conversion ($cxx_return_type, $c_return_type, $c_return_transfer, $return_string);
+ my $conv = Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_return_type, $c_return_type, $c_return_transfer, $return_string);
$return_string = 'return ' . $conv;
$last_return = nl () .
@@ -237,7 +236,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
}
else
{
- my $conv = $type_info_local->get_conversion ($c_return_type, $cxx_return_type, $c_return_transfer, $c_func_invocation);
+ my $conv = Common::Output::Shared::convert_or_die ($wrap_parser, $c_return_type, $cxx_return_type, $c_return_transfer, $c_func_invocation);
$code_string .= nl (' return ' . $conv . ';');
$last_return = nl () .
@@ -273,7 +272,6 @@ sub _output_p_cc ($$$$$$$$$$$$$)
my $c_params_str = Common::Output::Shared::zupstr $c_param_types, $c_param_names, ' ', ', ';
my $ret_void = ($c_return_type eq 'void');
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $convs_str = Common::Output::Shared::convzipstr $c_param_types, $cxx_param_types, $c_param_transfers, $c_param_names;
my $vfunc_call = 'obj->on_' . $cxx_signal_name . '(' . $convs_str . ')';
my $c_callback_call = '(*base->' . $c_signal_name . '(self, ' . (join ', ', @{$c_param_names}) . ')';
@@ -281,7 +279,7 @@ sub _output_p_cc ($$$$$$$$$$$$$)
unless ($ret_void)
{
- $vfunc_call = 'return ' . $type_info_local->get_conversion ($cxx_return_type, $c_return_type, $c_return_transfer, $vfunc_call);
+ $vfunc_call = 'return ' . Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_return_type, $c_return_type, $c_return_transfer, $vfunc_call);
$c_callback_call = 'return ' . $c_callback_call;
$last_return = nl () .
nl (' typedef ' . $c_return_type . ' RType;') .
diff --git a/tools/pm/Common/Output/VFunc.pm b/tools/pm/Common/Output/VFunc.pm
index 964d477..6c5c620 100644
--- a/tools/pm/Common/Output/VFunc.pm
+++ b/tools/pm/Common/Output/VFunc.pm
@@ -76,7 +76,6 @@ sub _output_cc ($$$$$$$$$$$$$)
my $cxx_to_c_params_str = (Common::Output::Shared::convzipstr $wrap_parser, $cxx_param_types, $c_param_types, $c_param_transfers, $cxx_param_names) . ($errthrow ? ', &temp_error' : '');
my $c_func_invocation = join '', '(*base->', $c_vfunc_name, ')(', $gobj, ', ', $cxx_to_c_params_str . ')';
my $last_return = '';
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $error_init_string = (nl ' GError* temp_error(0);');
my $errthrow_string = (nl ' if (temp_error)') .
(nl ' {') .
@@ -112,11 +111,11 @@ sub _output_cc ($$$$$$$$$$$$$)
(nl) .
$errthrow_string .
(nl);
- $conv = $type_info_local->get_conversion ($c_return_type, $cxx_return_type, $c_return_transfer, 'temp_retval');
+ $conv = Common::Output::Shared::convert_or_die ($wrap_parser, $c_return_type, $cxx_return_type, $c_return_transfer, 'temp_retval');
}
else
{
- $conv = $type_info_local->get_conversion ($c_return_type, $cxx_return_type, $c_return_transfer, $c_func_invocation);
+ $conv = Common::Output::Shared::convert_or_die ($wrap_parser, $c_return_type, $cxx_return_type, $c_return_transfer, $c_func_invocation);
}
$code_string .= nl (' return ' . $conv . ';');
$last_return = (nl) .
@@ -147,7 +146,6 @@ sub _output_p_cc ($$$$$$$$$$$$)
my $c_params_str = (Common::Output::Shared::paramzipstr $c_param_types, $c_param_names) . ($errthrow ? ', GError** gerror' : '');
my $ret_void = ($c_return_type eq 'void');
- my $type_info_local = $wrap_parser->get_type_info_local ();
my $convs_str = Common::Output::Shared::convzipstr $wrap_parser, $c_param_types, $cxx_param_types, $c_param_transfers, $c_param_names;
my $vfunc_call = 'obj->' . $cxx_vfunc_name . '(' . $convs_str . ')';
my $c_callback_call = '(*base->' . $c_vfunc_name . '(self, ' . (join ', ', @{$c_param_names}) . ($errthrow ? ', gerror' : '') . ')';
@@ -156,7 +154,7 @@ sub _output_p_cc ($$$$$$$$$$$$)
unless ($ret_void)
{
- $vfunc_call = 'return ' . $type_info_local->get_conversion ($cxx_return_type, $c_return_type, $c_return_transfer, $vfunc_call);
+ $vfunc_call = 'return ' . Common::Output::Shared::convert_or_die ($wrap_parser, $cxx_return_type, $c_return_type, $c_return_transfer, $vfunc_call);
$c_callback_call = 'return ' . $c_callback_call;
$after_catch_return = (nl) .
(nl ' typedef ', $c_return_type, ' RType;') .
diff --git a/tools/pm/Common/TypeInfo/Global.pm b/tools/pm/Common/TypeInfo/Global.pm
index a656d0b..2eb0264 100644
--- a/tools/pm/Common/TypeInfo/Global.pm
+++ b/tools/pm/Common/TypeInfo/Global.pm
@@ -801,8 +801,6 @@ sub get_conversion ($$$$$)
}
}
-# TODO: throw proper exception
- die join '', 'Could not find any conversion from `', $from, '\' to `', $to, '\' with transfer `', (Common::TypeInfo::Common::transfer_to_string $transfer), '\'';
return undef;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]