[glibmm/gmmproc-refactor] Fix a slew of compilation and runtime errors.
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/gmmproc-refactor] Fix a slew of compilation and runtime errors.
- Date: Wed, 6 Jun 2012 07:11:21 +0000 (UTC)
commit b9754a392e0e1a7b3fd0f98aaaeb03e269937c39
Author: Krzesimir Nowak <qdlacz gmail com>
Date: Sun Apr 15 17:02:47 2012 +0200
Fix a slew of compilation and runtime errors.
The code is still not working in some places I guess.
tools/gmmproc.in | 12 +-
tools/pm/Common/CFunctionInfo.pm | 2 +-
tools/pm/Common/CallableInfo.pm | 40 ++++---
tools/pm/Common/ConversionsStore.pm | 37 ++++++-
tools/pm/Common/CxxFunctionInfo.pm | 12 ++-
tools/pm/Common/Gmmproc.pm | 7 +-
tools/pm/Common/Output.pm | 3 +
tools/pm/Common/Output/BoxedType.pm | 6 +-
tools/pm/Common/Output/Ctor.pm | 11 +--
tools/pm/Common/Output/GObject.pm | 14 +-
tools/pm/Common/Output/Method.pm | 55 +++++----
tools/pm/Common/Output/OpaqueCopyable.pm | 10 +-
tools/pm/Common/Output/OpaqueRefcounted.pm | 8 +-
tools/pm/Common/Output/Property.pm | 4 +-
tools/pm/Common/Output/Shared.pm | 58 +++++++---
tools/pm/Common/Output/Signal.pm | 18 ++--
tools/pm/Common/Output/VFunc.pm | 14 +-
tools/pm/Common/Scanner.pm | 4 +-
tools/pm/Common/SectionManager.pm | 37 ++++---
tools/pm/Common/Sections/Section.pm | 20 +++-
tools/pm/Common/Shared.pm | 42 +++++--
tools/pm/Common/TypeInfoStore.pm | 4 +-
tools/pm/Common/WrapParser.pm | 178 ++++++++++++++++++----------
tools/pm/Gir/Parser.pm | 5 +-
24 files changed, 385 insertions(+), 216 deletions(-)
---
diff --git a/tools/gmmproc.in b/tools/gmmproc.in
index 28f6e1b..6f6e5ae 100644
--- a/tools/gmmproc.in
+++ b/tools/gmmproc.in
@@ -39,6 +39,7 @@ use warnings;
use IO::File;
use Getopt::Long qw(:config permute);
+require Gir::Parser;
require Gir::Repositories;
require Common::Gmmproc;
@@ -81,7 +82,7 @@ Options:
-u
--unwrapped Warn about possible unwrapped functions.
- -d basename
+ -r basename
--gir basename Specify the gir file base name. Examples: Gio-2.0.gir,
Gtk-3.0.gir.
@@ -120,13 +121,14 @@ sub main ()
'destination|d=s' => \$destination_dir,
'list|l=s' => sub { process_list_file ($templates, shift, shift) },
'unwrapped|u' => \$unwrapped,
- 'gir|d=s' => \$gir_basename,
- 'include|i= s' => \$include_paths,
+ 'gir|r=s' => \$gir_basename,
+ 'include|i=s@' => \$include_paths,
'debug|g' => \$debug,
'mm-module|m=s' => \$mm_module
'<>' => sub { add_file_to_list ($templates, shift); }
);
+# TODO: print what is wrong.
if (not $opt_parse_result or not $source_dir or not $destination_dir or
not $mm_module or @{$templates} < 1 or not $gir_basename or
@{$include_paths} < 1)
@@ -159,8 +161,8 @@ sub main ()
{
# TODO: warn about unwrapped stuff.
}
-
- }
+ };
+ die $@ if $@;
# TODO: catch the exception.
exit 0;
diff --git a/tools/pm/Common/CFunctionInfo.pm b/tools/pm/Common/CFunctionInfo.pm
index 7781966..4d27479 100644
--- a/tools/pm/Common/CFunctionInfo.pm
+++ b/tools/pm/Common/CFunctionInfo.pm
@@ -36,7 +36,7 @@ sub new_from_gir ($$)
{
my ($type, $gir_function) = @_;
my $class = (ref $type or $type or 'Common::CFunctionInfo');
- my $self = $class->SUPER::new ($gir_function);
+ my $self = $class->SUPER::new_from_gir ($gir_function);
my $throws = $gir_function->get_a_throws;
$self->{'throws'} = $throws;
diff --git a/tools/pm/Common/CallableInfo.pm b/tools/pm/Common/CallableInfo.pm
index 373bc11..1d5ae63 100644
--- a/tools/pm/Common/CallableInfo.pm
+++ b/tools/pm/Common/CallableInfo.pm
@@ -23,9 +23,9 @@ package Common::CallableInfo;
use strict;
use warnings;
-sub _parse_typed ($)
+sub _parse_typed ($$)
{
- my ($gir_typed) = @_;
+ my ($self, $gir_typed) = @_;
if ($gir_typed->get_g_type_count > 0)
{
@@ -43,12 +43,15 @@ sub _parse_typed ($)
{
return '...';
}
- else die;
+ else
+ {
+ die;
+ }
}
-sub _parse_parameters ($)
+sub _parse_parameters ($$)
{
- my ($gir_function) = @_;
+ my ($self, $gir_function) = @_;
my $param_types = [];
my $param_names = [];
my $param_transfers = [];
@@ -62,8 +65,9 @@ sub _parse_parameters ($)
{
my $gir_parameter = $gir_parameters->get_g_parameter_by_index ($iter);
my $name = $gir_parameter->get_a_name;
- my $transfer = Common::ConversionsStore::transfer_from_string $gir_parameter->get_a_transfer_ownership;
- my $type = _parse_parameter $gir_parameter;
+ my $gir_transfer = $gir_parameter->get_a_transfer_ownership;
+ my $transfer = Common::ConversionsStore::transfer_from_string $gir_transfer;
+ my $type = $self->_parse_parameter ($gir_parameter);
# TODO: error.
die unless ($type);
@@ -94,22 +98,20 @@ sub new_from_gir ($$)
my ($type, $gir_callable) = @_;
my $class = (ref $type or $type or 'Common::CallableInfo');
# Bless now, so we can use virtual methods.
- my $self = bless $class, $type;
+ my $self = bless {}, $class;
my $gir_return = $gir_callable->get_g_return_value_by_index (0);
my $ret = $self->_parse_return_value ($gir_return);
- my $ret_transfer = Common::ConversionsStore::transfer_from_string $gir_return->get_a_transfer_ownership;
- my $name = $self->_get_name_from_gir ($gir_callable)
+ my $gir_ret_transfer = $gir_return->get_a_transfer_ownership;
+ my $ret_transfer = Common::ConversionsStore::transfer_from_string $gir_ret_transfer;
+ my $name = $self->_get_name_from_gir ($gir_callable);
my ($param_types, $param_names, $param_transfers) = $self->_parse_parameters ($gir_callable);
- my $self =
- {
- 'ret' => $ret,
- 'ret_transfer' => $ret_transfer,
- 'name' => $name,
- 'param_types' => $param_types,
- 'param_names' => $param_names,
- 'param_transfers' => $param_transfers,
- };
+ $self->{'ret'} = $ret;
+ $self->{'ret_transfer'} = $ret_transfer;
+ $self->{'name'} = $name;
+ $self->{'param_types'} = $param_types;
+ $self->{'param_names'} = $param_names;
+ $self->{'param_transfers'} = $param_transfers;
return $self;
}
diff --git a/tools/pm/Common/ConversionsStore.pm b/tools/pm/Common/ConversionsStore.pm
index 94a13e1..4ee5788 100644
--- a/tools/pm/Common/ConversionsStore.pm
+++ b/tools/pm/Common/ConversionsStore.pm
@@ -128,6 +128,27 @@ sub _add_generic ($$$$$$$)
# TODO: what should be done with duplicates?
}
+sub _get_mm_module ($)
+{
+ my ($self) = @_;
+
+ return $self->{'mm_module'};
+}
+
+sub _get_include_paths ($)
+{
+ my ($self) = @_;
+
+ return $self->{'include_paths'};
+}
+
+sub _get_read_files ($)
+{
+ my ($self) = @_;
+
+ return $self->{'read_files'};
+}
+
sub new_local ($$)
{
my ($type, $global_store) = @_;
@@ -142,6 +163,7 @@ sub new_global ($$$)
$self->{'mm_module'} = $mm_module;
$self->{'include_paths'} = $include_paths;
+ $self->{'read_files'} = {};
return $self;
}
@@ -212,6 +234,13 @@ sub get_conversion ($$$$$)
$conversion = $other->get_conversion ($from, $to, $transfer, $name);
}
}
+ unless (defined $conversion)
+ {
+# TODO: Throw an error or something? Or should the lack of
+# TODO continued: conversion handled by caller? Rather the
+# TODO continued: former.
+ die 'Could not find conversion from `' . $from . '\' to `' . $to . '\' with transfer `' . (transfer_to_string $transfer) . '\'.' . "\n";
+ }
return $conversion;
}
@@ -247,8 +276,6 @@ sub add_from_file ($$)
}
my @lines = $fd->getlines;
- my $c_to_cpp = $self->_get_c_to_cpp (1);
- my $cpp_to_c = $self->_get_cpp_to_c (1);
my $line_num = 0;
my $from = undef;
my $to = undef;
@@ -273,7 +300,7 @@ sub add_from_file ($$)
}
elsif (defined $from and defined $to)
{
- if ($line =~ /\s*(\w)+\s*:\s*(.*)$/)
+ if ($line =~ /\s*(\w+)\s*:\s*(.*)$/)
{
my $transfer_str = $1;
my $transfer = $2;
@@ -306,6 +333,10 @@ sub add_from_file ($$)
}
# TODO: parsing error - no transfer specified.
die unless $added;
+
+ $from = undef;
+ $to = undef;
+ $transfers = [undef, undef, undef];
}
}
elsif ($line =~ /^(.+?)\s*=>\s*(.+):$/)
diff --git a/tools/pm/Common/CxxFunctionInfo.pm b/tools/pm/Common/CxxFunctionInfo.pm
index 8c34c44..3c72406 100644
--- a/tools/pm/Common/CxxFunctionInfo.pm
+++ b/tools/pm/Common/CxxFunctionInfo.pm
@@ -30,9 +30,13 @@ sub new_from_string ($$)
my ($type, $string) = @_;
my $class = (ref $type or $type or 'Common::CxxFunctionInfo');
my $cxx_parts = Common::Shared::parse_function_declaration $string;
+ my $static = ($cxx_parts->[0] =~ /\bstatic\b/);
+ my $ret = $cxx_parts->[1];
+ my $name = $cxx_parts->[2];
my $params = Common::Shared::parse_params $cxx_parts->[3];
my $param_types = [];
my $param_names = [];
+ my $const = ($cxx_parts->[4] =~ /\bconst\b/);
foreach my $desc (@{$params})
{
@@ -44,12 +48,12 @@ sub new_from_string ($$)
my $self =
{
- 'static' => ($cxx_parts->[0] =~ /\bstatic\b/),
- 'ret' => $cxx_parts->[1],
- 'name' => $cxx_parts->[2],
+ 'static' => $static,
+ 'ret' => $ret,
+ 'name' => $name,
'param_types' => $param_types,
'param_names' => $param_names,
- 'const' => ($cxx_parts->[4] =~ /\bconst\b/)
+ 'const' => $const
};
return bless $self, $class;
diff --git a/tools/pm/Common/Gmmproc.pm b/tools/pm/Common/Gmmproc.pm
index 88991e0..19d5bf4 100644
--- a/tools/pm/Common/Gmmproc.pm
+++ b/tools/pm/Common/Gmmproc.pm
@@ -25,6 +25,7 @@ use warnings;
use IO::File;
+use Common::Scanner;
use Common::Sections;
use Common::SectionManager;
use Common::TokensStore;
@@ -157,13 +158,12 @@ sub _parse_all_bases ($)
my ($self) = @_;
my $bases = $self->get_bases;
my $type_info_store = $self->get_type_info_store;
- my $section_managers = $self->get_section_managers;
my $repositories = $self->get_repositories;
my $conversions_store = $self->get_conversions_store;
my $mm_module = $self->get_mm_module;
# parallelize
- foreach my $base (@{$bases})
+ foreach my $base (sort keys %{$bases})
{
my $tokens_store = $bases->{$base};
my $tokens_hg = $tokens_store->get_hg_tokens;
@@ -173,7 +173,8 @@ sub _parse_all_bases ($)
$type_info_store,
$repositories,
$conversions_store,
- $mm_module);
+ $mm_module,
+ $base);
$wrap_parser->parse;
$tokens_store->set_section_manager ($wrap_parser->get_section_manager);
diff --git a/tools/pm/Common/Output.pm b/tools/pm/Common/Output.pm
index 200061d..cef7526 100644
--- a/tools/pm/Common/Output.pm
+++ b/tools/pm/Common/Output.pm
@@ -25,14 +25,17 @@ use warnings;
use Common::Output::BoxedTypeStatic;
use Common::Output::BoxedType;
+use Common::Output::Ctor;
use Common::Output::Enum;
use Common::Output::Generic;
use Common::Output::GError;
use Common::Output::GObject;
use Common::Output::GtkObject;
use Common::Output::Interface;
+use Common::Output::Method;
use Common::Output::OpaqueCopyable;
use Common::Output::OpaqueRefcounted;
+use Common::Output::Property;
use Common::Output::VFunc;
1; # indicate proper module load.
diff --git a/tools/pm/Common/Output/BoxedType.pm b/tools/pm/Common/Output/BoxedType.pm
index cefa3ee..d15d242 100644
--- a/tools/pm/Common/Output/BoxedType.pm
+++ b/tools/pm/Common/Output/BoxedType.pm
@@ -168,13 +168,13 @@ sub _output_cc ($$$$$$$)
nl(':');
if (defined $new_func and $new_func != '' and $new_func != 'NONE')
{
- $code_string += nl ('gobject_ (' . $new_func . '())');
+ $code_string .= nl ('gobject_ (' . $new_func . '())');
}
else
{
- $code_string += nl ('gobject_ (0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.');
+ $code_string .= nl ('gobject_ (0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.');
}
- $code_string += nl ('{}');
+ $code_string .= nl ('{}');
$section_manager->append_string_to_conditional ($code_string, $conditional, 0);
$section_manager->append_conditional ($conditional);
$section_manager->set_variable_for_conditional ($variable, $conditional);
diff --git a/tools/pm/Common/Output/Ctor.pm b/tools/pm/Common/Output/Ctor.pm
index 86e3fb6..b5e1dc8 100644
--- a/tools/pm/Common/Output/Ctor.pm
+++ b/tools/pm/Common/Output/Ctor.pm
@@ -82,14 +82,14 @@ sub ctor_default ($)
$section_manager->pop_entry;
}
-sub wrap_ctor ($$$$)
+sub wrap_ctor ($$$$$$)
{
my ($wrap_parser, $c_param_types, $c_param_transfers, $c_prop_names, $cpp_param_types, $cpp_param_names) = @_;
my $section_manager = $wrap_parser->get_section_manager;
my $main_section = $wrap_parser->get_main_section;
my $cpp_type = Common::Output::Shared::get_cpp_type $wrap_parser;
my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names;
- my $code_string = (nl 'explicit ', $cpp_type, '(', $cpp_param_str, ');') .
+ my $code_string = (nl 'explicit ', $cpp_type, '(', $cpp_params_str, ');') .
(nl);
my $section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::CC_NAMESPACE;
my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
@@ -97,12 +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 = '';
-
- if (@{$cpp_param_types} > 0)
- {
- $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}), '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, ')') .
diff --git a/tools/pm/Common/Output/GObject.pm b/tools/pm/Common/Output/GObject.pm
index c76f5b8..21f701a 100644
--- a/tools/pm/Common/Output/GObject.pm
+++ b/tools/pm/Common/Output/GObject.pm
@@ -337,8 +337,8 @@ sub _output_p_cc ($$$$)
my ($wrap_parser, $c_type, $c_type_class, $get_type_func) = @_;
my $section_manager = $wrap_parser->get_section_manager;
my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
- my $full_cpp_class_type = Common::Output::Shared::get_full_cpp_class_type $wrap_parser;
- my $code_string = nl ('const Glib::Class& ' . $full_cpp_class_type . '::init()') .
+ my $cpp_class_type = Common::Output::Shared::get_cpp_class_type $wrap_parser;
+ my $code_string = nl ('const Glib::Class& ' . $cpp_class_type . '::init()') .
nl ('{') .
nl (' if (!gtype_) // create the GType if necessary') .
nl (' {');
@@ -353,7 +353,7 @@ sub _output_p_cc ($$$$)
$code_string = nl (' gtype_ = CppClassParent::CppObjectType::get_type();');
$section_manager->append_string_to_conditional ($code_string, $conditional, 1);
$code_string = nl (' // Glib::Class has to know the class init function to clone custom types.') .
- nl (' class_init_func_ = &' . $full_cpp_class_type . '::class_init_function;') .
+ nl (' class_init_func_ = &' . $cpp_class_type . '::class_init_function;') .
nl () .
nl (' // This is actually just optimized away, apparently with no harm.') .
nl (' // Make sure that the parent type has been created.') .
@@ -381,7 +381,7 @@ sub _output_p_cc ($$$$)
my $dynamic_gtype_registration_var = Common::Output::Shared::get_variable $wrap_parser, Common::Variables::DYNAMIC_GTYPE_REGISTRATION;
- $code_string = nl ('const Glib::Class& ' . $full_cpp_class_type . '::init(GTypeModule* module)') .
+ $code_string = nl ('const Glib::Class& ' . $cpp_class_type . '::init(GTypeModule* module)') .
nl ('{') .
nl (' if (!gtype_) // create the GType if necessary') .
nl (' {');
@@ -394,7 +394,7 @@ sub _output_p_cc ($$$$)
nl (' gtype_ = CppClassParent::CppObjectType::get_type();');
$section_manager->append_string_to_conditional ($code_string, $subconditional, 1);
$code_string = nl (' // Glib::Class has to know the class init function to clone custom types.') .
- nl (' class_init_func_ = &' . $full_cpp_class_type . '::class_init_function;') .
+ nl (' class_init_func_ = &' . $cpp_class_type . '::class_init_function;') .
nl () .
nl (' // This is actually just optimized away, apparently with no harm.') .
nl (' // Make sure that the parent type has been created.') .
@@ -421,7 +421,7 @@ sub _output_p_cc ($$$$)
$section_manager->append_conditional ($conditional);
$section_manager->set_variable_for_conditional ($dynamic_gtype_registration_var, $conditional);
$conditional = Common::Output::Shared::generate_conditional ($wrap_parser);
- $code_string = nl ('void ' . $full_cpp_class_type . '::class_init_function(void* g_class, void* class_data)') .
+ $code_string = nl ('void ' . $cpp_class_type . '::class_init_function(void* g_class, void* class_data)') .
nl ('{') .
nl (' BaseClassType* const klass = static_cast< BaseClassType* >(g_class);') .
nl (' CppClassParent::class_init_function(klass, class_data);') .
@@ -459,7 +459,7 @@ sub _output_p_cc ($$$$)
$section_manager->append_string (nl);
}
- $code_string = nl ('Glib::ObjectBase* ' . $full_cpp_class_type . '::wrap_new(GObject* object)') .
+ $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 ('}') .
diff --git a/tools/pm/Common/Output/Method.pm b/tools/pm/Common/Output/Method.pm
index fc71542..b5c6dc1 100644
--- a/tools/pm/Common/Output/Method.pm
+++ b/tools/pm/Common/Output/Method.pm
@@ -40,18 +40,18 @@ sub _output_h ($$$$$$$)
if ($static)
{
- $code_string += 'static ';
+ $code_string .= 'static ';
}
- $code_string += $cpp_ret_type . ' ' . $cpp_func_name;
+ $code_string .= $cpp_ret_type . ' ' . $cpp_func_name;
my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names;
- $code_string += '(' . $cpp_params_str . ')';
+ $code_string .= '(' . $cpp_params_str . ')';
if ($const)
{
- $code_string += ' const';
+ $code_string .= ' const';
}
- $code_string += ';';
+ $code_string .= ';';
$section_manager->append_string_to_section (nl ($code_string), $main_section);
}
@@ -65,27 +65,27 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
# TODO: replace with exception throwing
# if dies then it is internal error. should not happen here.
die if ($static and ($const or $constversion));
- die if (scalar (@{$types_list}) != scalar(@{$names_list}));
- die if (scalar (@{$c_param_types}) != scalar(@{$types_list}));
+ die if (scalar (@{$cpp_param_types}) != scalar(@{$cpp_param_names}));
+ die if (scalar (@{$c_param_types}) != scalar(@{$cpp_param_types}));
if ($deprecated)
{
- $code_string += Common::Output::Shared::deprecate_start $wrap_parser;
+ $code_string .= Common::Output::Shared::deprecate_start $wrap_parser;
}
if ($ifdef)
{
- $code_string += nl ('#ifdef ' . $ifdef);
+ $code_string .= nl ('#ifdef ' . $ifdef);
}
if ($static)
{
- $code_string += nl ('// static');
+ $code_string .= nl ('// static');
}
my $cpp_params_str = Common::Output::Shared::paramzipstr $cpp_param_types, $cpp_param_names;
my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
- my $c_type = Common::Output::Shared::get_c_type;
+ my $c_type = Common::Output::Shared::get_c_type $wrap_parser;
- $code_string += nl ($cpp_ret_type . ' ' . $full_cpp_type . '::' . $cpp_func_name . '(' . $cpp_param_list_str . ')' . ($const ? ' const' : '')) .
+ $code_string .= nl ($cpp_ret_type . ' ' . $full_cpp_type . '::' . $cpp_func_name . '(' . $cpp_params_str . ')' . ($const ? ' const' : '')) .
nl ('{');
my $names_only = join ', ', @{$cpp_param_names};
@@ -98,7 +98,7 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
{
$ret = 'return ';
}
- $code_string += nl (' ' . $ret . 'const_cast< ' . $full_cpp_type . '* >(this)->' . $cpp_func_name . '(' . $names_only . ');');
+ $code_string .= nl (' ' . $ret . 'const_cast< ' . $full_cpp_type . '* >(this)->' . $cpp_func_name . '(' . $names_only . ');');
}
else
{
@@ -114,26 +114,31 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
}
my $conversions_store = $wrap_parser->get_conversions_store;
- my $c_param_list_str = $this_param . (Common::Output::Shared::convzipstr $cpp_param_types, $c_param_types, $c_param_transfers, $cpp_param_names) . ($errthrow ? ', &gerror' . '');
+ 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 $c_func_invocation = $c_func_name . '(' . $c_param_list_str . ')';
- my $ret_convert = $conversions_store->get_conversion ($c_ret_type, $cpp_ret_type, $ret_transfer, $c_func_invocation);
+ my $ret_convert = '';
+
+ unless ($ret_void)
+ {
+ $ret_convert = $conversions_store->get_conversion ($c_ret_type, $cpp_ret_type, $ret_transfer, $c_func_invocation);
+ }
if ($errthrow)
{
- $code_string += nl (' GError* gerror(0);');
+ $code_string .= nl (' GError* gerror(0);');
unless ($ret_void)
{
- $code_string += nl (' ' . $cpp_ret_type . ' retvalue(' . $ret_convert . ');');
+ $code_string .= nl (' ' . $cpp_ret_type . ' retvalue(' . $ret_convert . ');');
}
else
{
- $code_string += nl () .
+ $code_string .= nl () .
nl (' ' . $c_func_invocation . ';');
}
if ($errthrow)
{
- $code_string += nl () .
+ $code_string .= nl () .
nl (' if (gerror)') .
nl (' {') .
nl (' ::Glib::Error::throw_exception(gerror);') .
@@ -141,7 +146,7 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
}
unless ($ret_void)
{
- $code_string += nl () .
+ $code_string .= nl () .
nl ('return retvalue;');
}
}
@@ -149,22 +154,22 @@ sub _output_cc ($$$$$$$$$$$$$$$$)
{
if ($ret_void)
{
- $code_string += nl (' return ' . $ret_convert . ';');
+ $code_string .= nl (' return ' . $ret_convert . ';');
}
else
{
- $code_string += nl (' ' . $c_func_invocation . ';');
+ $code_string .= nl (' ' . $c_func_invocation . ';');
}
}
}
- $code_string += nl ('}');
+ $code_string .= nl ('}');
if ($ifdef)
{
- $code_string += nl ('#endif // ' . $ifdef);
+ $code_string .= nl ('#endif // ' . $ifdef);
}
if ($deprecated)
{
- $code_string += Common::Output::Shared::deprecate_end $wrap_parser;
+ $code_string .= Common::Output::Shared::deprecate_end $wrap_parser;
}
my $section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::CC_NAMESPACE;
diff --git a/tools/pm/Common/Output/OpaqueCopyable.pm b/tools/pm/Common/Output/OpaqueCopyable.pm
index 0912b1c..2a0884f 100644
--- a/tools/pm/Common/Output/OpaqueCopyable.pm
+++ b/tools/pm/Common/Output/OpaqueCopyable.pm
@@ -96,13 +96,13 @@ sub _output_cc ($$$$$$)
if (defined $new_func and $new_func ne '' and $new_func ne 'NONE')
{
- $code_string += nl (' gobject_(' . $new_func . '())');
+ $code_string .= nl (' gobject_(' . $new_func . '())');
}
else
{
- $code_string += nl (' gobject_(0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.');
+ $code_string .= nl (' gobject_(0) // Allows creation of invalid wrapper, e.g. for output arguments to methods.');
}
- $code_string += nl ();
+ $code_string .= nl ();
$section_manager->append_string_to_conditional ($code_string, $conditional, 0);
$section_manager->push_section ($section);
$section_manager->append_conditional ($conditional);
@@ -137,7 +137,7 @@ sub _output_cc ($$$$$$)
nl ();
if (defined $copy_func and $copy_func ne '' and $copy_func ne 'NONE')
{
- $code_string += nl ($full_cpp_type . '& ' . $full_cpp_type . '::operator=(const ' . $full_cpp_type . '& src)') .
+ $code_string .= nl ($full_cpp_type . '& ' . $full_cpp_type . '::operator=(const ' . $full_cpp_type . '& src)') .
nl ('{') .
nl (' ' . $c_type . '* const new_gobject = (src.gobject_) ? ' . $copy_func . '(src.gobject_) : 0;') .
nl () .
@@ -152,7 +152,7 @@ sub _output_cc ($$$$$$)
nl ('}') .
nl ();
}
- $code_string += nl ($full_cpp_type . '::~' . $cpp_type . '()') .
+ $code_string .= nl ($full_cpp_type . '::~' . $cpp_type . '()') .
nl ('{') .
nl (' if (gobject_)') .
nl (' {') .
diff --git a/tools/pm/Common/Output/OpaqueRefcounted.pm b/tools/pm/Common/Output/OpaqueRefcounted.pm
index 1fbb278..36889fb 100644
--- a/tools/pm/Common/Output/OpaqueRefcounted.pm
+++ b/tools/pm/Common/Output/OpaqueRefcounted.pm
@@ -41,7 +41,7 @@ sub _output_h_in_class ($$$$)
if (defined $new_func and $new_func ne '' and $new_func ne 'NONE')
{
- $code_string += nl (' static Glib::RefPtr< ' . $cpp_type . ' > create();') .
+ $code_string .= nl (' static Glib::RefPtr< ' . $cpp_type . ' > create();') .
nl ();
}
@@ -51,7 +51,7 @@ sub _output_h_in_class ($$$$)
my $full_cpp_type = Common::Output::Shared::get_full_cpp_type $wrap_parser;
my $main_section = $wrap_parser->get_main_section;
- $code_string += nl (' /** Increment the reference count for this object.') .
+ $code_string .= nl (' /** Increment the reference count for this object.') .
nl (' * You should never need to do this manually - use the object via a RefPtr instead.') .
nl (' */') .
nl (' void reference() const;') .
@@ -132,7 +132,7 @@ sub _output_cc ($$$$$)
nl ();
if (defined $new_func and $new_func ne '' and $new_func ne 'NONE')
{
- $code_string += nl ('// static') .
+ $code_string .= nl ('// static') .
nl ('Glib::RefPtr< ' . $full_cpp_type . ' > ' . $full_cpp_type . '::create()') .
nl ('{') .
nl (' // See the comment at the top of this file, if you want to know why the cast works.') .
@@ -141,7 +141,7 @@ sub _output_cc ($$$$$)
nl ();
}
- $code_string += nl ('void ' . $full_cpp_type . '::reference() const') .
+ $code_string .= nl ('void ' . $full_cpp_type . '::reference() const') .
nl ('{') .
nl (' // See the comment at the top of this file, if you want to know why the cast works.') .
nl (' ' . $ref_func . '(reinterpret_cast< ' . $c_type . '* >(const_cast< ' . $full_cpp_type . '* >(this)));') .
diff --git a/tools/pm/Common/Output/Property.pm b/tools/pm/Common/Output/Property.pm
index 4fb5bda..79a87fe 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_suffixP);
+ (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 ' ' . $proxy_type . '(this, "' . $prop_c_name . '");') .
(nl '}') .
(nl);
diff --git a/tools/pm/Common/Output/Shared.pm b/tools/pm/Common/Output/Shared.pm
index 7b47dd9..276fc8e 100644
--- a/tools/pm/Common/Output/Shared.pm
+++ b/tools/pm/Common/Output/Shared.pm
@@ -77,6 +77,30 @@ sub close_namespaces ($)
return $code_string;
}
+sub get_first_class ($)
+{
+ my ($wrap_parser) = @_;
+ my $classes = $wrap_parser->get_classes;
+
+ if (@{$classes})
+ {
+ return $classes->[0];
+ }
+ die;
+}
+
+sub get_first_namespace ($)
+{
+ my ($wrap_parser) = @_;
+ my $namespaces = $wrap_parser->get_namespaces;
+
+ if (@{$namespaces})
+ {
+ return $namespaces->[0];
+ }
+ die;
+}
+
# returns VteTerminal
sub get_c_type ($)
{
@@ -124,7 +148,7 @@ sub get_complete_cpp_type ($)
{
my ($wrap_parser) = @_;
my $namespaces = get_full_namespace $wrap_parser;
- my $classes = get_full_cpp_class $wrap_parser;
+ my $classes = get_full_cpp_type $wrap_parser;
return join '::', $namespaces, $classes;
}
@@ -294,24 +318,24 @@ sub wrap_proto ($$$$$$)
my ($wrap_parser, $c_name, $result_type, $take_copy, $open, $const) = @_;
my $section_manager = $wrap_parser->get_section_manager;
my $result = undef;
- my $full_cpp_name = get_full_cpp_name $wrap_parser;
+ my $complete_cpp_type = get_complete_cpp_type $wrap_parser;
# TODO: make result type constant
if ($result_type eq 'refptr')
{
- $result = 'Glib::RefPtr< ' . $full_cpp_name . ' >';
+ $result = 'Glib::RefPtr< ' . $complete_cpp_type . ' >';
}
elsif ($result_type eq 'ref')
{
- $result = $full_cpp_name . '&';
+ $result = $complete_cpp_type . '&';
}
elsif ($result_type eq 'ptr')
{
- $result = $full_cpp_name . '*';
+ $result = $complete_cpp_type . '*';
}
elsif ($result_type eq 'plain')
{
- $result = $full_cpp_name;
+ $result = $complete_cpp_type;
}
else
{
@@ -331,14 +355,14 @@ sub wrap_proto ($$$$$$)
$params_doc = nl ($params_doc) .
nl (' * @param take_copy @c false if the result should take ownership') .
' * of the C instance. @c true if it should take a new copy or reference.';
- $params += ', bool take_copy = ';
+ $params .= ', bool take_copy = ';
if ($take_copy eq 'yes')
{
- $params += 'true';
+ $params .= 'true';
}
elsif ($take_copy eq 'no')
{
- $params += 'false';
+ $params .= 'false';
}
else
{
@@ -352,23 +376,23 @@ sub wrap_proto ($$$$$$)
if ($open)
{
- $code_string += nl ('namespace Glib') .
+ $code_string .= nl ('namespace Glib') .
nl ('{') .
nl ();
}
- $code_string += nl ('/** A Glib::wrap() method for this object.') .
+ $code_string .= nl ('/** A Glib::wrap() method for this object.') .
nl (' *') .
nl ($params_doc) .
nl (' * @result A C++ instance that wraps this C instance') .
nl (' *') .
- nl (' * @relates ' . $full_cpp_name) .
+ nl (' * @relates ' . $complete_cpp_type) .
nl (' */') .
nl ($result . ' wrap(' . $params . ');') .
nl ();
if ($open)
{
- $code_string += nl ('} //namespace Glib') .
+ $code_string .= nl ('} //namespace Glib') .
nl ();
}
@@ -428,13 +452,13 @@ sub gobj_protos_str ($$$$)
' ' . $c_name . '* gobj_copy()';
if ($copy_proto eq 'const')
{
- $code_string += ' const';
+ $code_string .= ' const';
}
elsif ($copy_proto ne 'yes')
{
die;
}
- $code_string += ';';
+ $code_string .= ';';
}
return $code_string;
}
@@ -541,7 +565,7 @@ sub paramzipstr ($$)
# TODO: throw runtime error or internal error or whatever.
die if $count != scalar(@{$array2});
- return join ', ', map { join ' ', $array1->[$_], $array2->[$_] } 0 .. $count;
+ return join ', ', map { join ' ', $array1->[$_], $array2->[$_] } 0 .. $count - 1;
}
sub get_parent_from_object ($$)
@@ -576,7 +600,7 @@ sub convzipstr ($$$$$)
# TODO: throw runtime error or internal error or whatever.
die if $from_types_count != $to_types_count or $to_types_count != $transfers_count or $transfers_count != $from_names_count;
- return join ', ', map { $conversions_store->get_conversion ($from_types->[$_], $to_types->[$_], $transfers->[$_], $from_names->[$_]) } 0 .. $from_types_count;
+ return join ', ', map { $conversions_store->get_conversion ($from_types->[$_], $to_types->[$_], $transfers->[$_], $from_names->[$_]) } 0 .. $from_types_count - 1;
}
sub deprecate_start ($)
diff --git a/tools/pm/Common/Output/Signal.pm b/tools/pm/Common/Output/Signal.pm
index f1ffd92..b53f742 100644
--- a/tools/pm/Common/Output/Signal.pm
+++ b/tools/pm/Common/Output/Signal.pm
@@ -90,7 +90,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
if ($ret_void and not @{$c_param_types} and $cpp_return_type eq 'void' and not @{$cpp_param_types})
{
- $code_string += nl ('// Use predefined callback for SignalProxy0<void> to reduce code size.') .
+ $code_string .= nl ('// Use predefined callback for SignalProxy0<void> to reduce code size.') .
nl ('const Glib::SignalProxyInfo ' . $proxy_info . ' =') .
nl ('{') .
nl (' ' . $c_signal_string . ',') .
@@ -134,7 +134,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
nl (' typedef ' . $c_return_type . ' RType;') .
nl (' return RType();');
}
- $code_string += nl ($c_return_type . ' ' . $signal_callback . '(' . $c_type . '* self, ' . $c_params_str . ', gpointer data)') .
+ $code_string .= nl ($c_return_type . ' ' . $signal_callback . '(' . $c_type . '* self, ' . $c_params_str . ', gpointer data)') .
nl ('{') .
nl (' using namespace ' . (Common::Output::Shared::get_full_namespace $wrap_parser) . ';') .
nl (' typedef sigc::slot< ' . $cpp_return_type . ', ' . $cpp_param_types_str . ' > SlotType;') .
@@ -160,7 +160,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
nl ();
unless ($ret_void)
{
- $code_string += nl ($c_return_type . ' ' . $signal_notify . '(' . $c_type . '* self, ' . $c_params_str . ', gpointer data)') .
+ $code_string .= nl ($c_return_type . ' ' . $signal_notify . '(' . $c_type . '* self, ' . $c_params_str . ', gpointer data)') .
nl ('{') .
nl (' using namespace ' . (Common::Output::Shared::get_full_namespace $wrap_parser) . ';') .
nl (' typedef sigc::slot< void, ' . $cpp_param_types_str . ' > SlotType;') .
@@ -187,7 +187,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
nl ();
}
}
- $code_string += nl ('const Glib::SignalProxyInfo ' . $proxy_info . ' =') .
+ $code_string .= nl ('const Glib::SignalProxyInfo ' . $proxy_info . ' =') .
nl ('{') .
nl (' ' . $c_signal_string . ',') .
nl (' G_CALLBACK(&' . $signal_callback . '),') .
@@ -196,7 +196,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
nl ();
}
- $code_string += Common::Output::Shared::endif $ifdef;
+ $code_string .= Common::Output::Shared::endif $ifdef;
my $section = Common::Output::Shared::get_section $wrap_parser, Common::Sections::CC_UNNAMED_NAMESPACE;
@@ -224,7 +224,7 @@ sub _output_cc ($$$$$$$$$$$$$$)
my $c_func_invocation = '(*base->' . $c_signal_name . ')(gobj(), ' . $cpp_to_c_params_str . ')';
my $last_return = '';
- $code_string += nl ($cpp_return_type . ' ' . $full_cpp_type . '::on_' . $cpp_signal_name . '(' . $cpp_params_str . ')') .
+ $code_string .= nl ($cpp_return_type . ' ' . $full_cpp_type . '::on_' . $cpp_signal_name . '(' . $cpp_params_str . ')') .
nl ('{') .
nl (' BaseClassType* const base(static_cast<BaseClassType*>(' . $parent_from_object . '));') .
nl () .
@@ -233,20 +233,20 @@ sub _output_cc ($$$$$$$$$$$$$$)
if ($ret_void)
{
- $code_string += nl (' ' . $c_func_invocation . ';') .
+ $code_string .= nl (' ' . $c_func_invocation . ';') .
}
else
{
my $conv = $conversions_store->get_conversion ($c_return_type, $cpp_return_type, $c_return_transfer, $c_func_invocation);
- $code_string += nl (' return ' . $conv . ';');
+ $code_string .= nl (' return ' . $conv . ';');
$last_return = nl () .
nl (' typedef ' . $cpp_return_type . ' RType;') .
nl (' return RType();');
}
- $code_string += nl (' }') .
+ $code_string .= nl (' }') .
nl($last_return . '}') .
Common::Output::Shared::endif $ifdef;
diff --git a/tools/pm/Common/Output/VFunc.pm b/tools/pm/Common/Output/VFunc.pm
index f24978a..8b79c4b 100644
--- a/tools/pm/Common/Output/VFunc.pm
+++ b/tools/pm/Common/Output/VFunc.pm
@@ -87,7 +87,7 @@ sub _output_cc ($$$$$$$$$$$$$)
{
if ($errthrow)
{
- $code_string += $error_init_string .
+ $code_string .= $error_init_string .
(nl) .
(nl ' ', $c_func_invocation, ';') .
(nl) .
@@ -97,7 +97,7 @@ sub _output_cc ($$$$$$$$$$$$$)
}
else
{
- $code_string += (nl ' ', $c_func_invocation, ';') .
+ $code_string .= (nl ' ', $c_func_invocation, ';') .
(nl ' return;');
}
}
@@ -107,7 +107,7 @@ sub _output_cc ($$$$$$$$$$$$$)
if ($errthrow)
{
- $code_string += $error_init_string .
+ $code_string .= $error_init_string .
(nl ' ', $c_return_type, ' temp_retval(', $c_func_invocation, ');') .
(nl) .
$errthrow_string .
@@ -118,12 +118,12 @@ sub _output_cc ($$$$$$$$$$$$$)
{
$conv = $conversions_store->get_conversion ($c_return_type, $cpp_return_type, $c_return_transfer, $c_func_invocation);
}
- $code_string += nl (' return ' . $conv . ';');
+ $code_string .= nl (' return ' . $conv . ';');
$last_return = (nl) .
(nl ' typedef ' . $cpp_return_type . ' RType;') .
(nl ' return RType();');
}
- $code_string += (nl ' }') .
+ $code_string .= (nl ' }') .
(nl $last_return . '}') .
Common::Output::Shared::endif $ifdef;
@@ -205,13 +205,13 @@ sub _output_p_cc ($$$$$$$$$$$$)
if ($errthrow)
{
- $code_string += (nl ' catch (const Glib::Error& error)') .
+ $code_string .= (nl ' catch (const Glib::Error& error)') .
(nl ' {') .
(nl ' error.propagate(gerror);') .
(nl ' }');
}
- $code_string += (nl ' catch (...)') .
+ $code_string .= (nl ' catch (...)') .
(nl ' {') .
(nl ' Glib::exception_handlers_invoke();') .
(nl ' }') .
diff --git a/tools/pm/Common/Scanner.pm b/tools/pm/Common/Scanner.pm
index aa14cd8..eee7a37 100644
--- a/tools/pm/Common/Scanner.pm
+++ b/tools/pm/Common/Scanner.pm
@@ -141,7 +141,7 @@ sub _on_string_with_end ($$)
while (@{$tokens})
{
- my $token = $self->extract_token;
+ my $token = $self->_extract_token;
if ($token eq $end)
{
@@ -192,7 +192,7 @@ sub _append ($$$)
sub _get_params ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
diff --git a/tools/pm/Common/SectionManager.pm b/tools/pm/Common/SectionManager.pm
index 940ec8d..78d1f35 100644
--- a/tools/pm/Common/SectionManager.pm
+++ b/tools/pm/Common/SectionManager.pm
@@ -154,11 +154,13 @@ sub _push_entry ($$$)
sub _append_generic ($$$)
{
- my ($self, $stuff, $stuff_type) = @_;
+ my ($self, $type, $stuff) = @_;
my $entries_stack = $self->_get_entries_stack;
my $entry = $entries_stack->[-1];
+ my $entries = $entry->[0];
+ my $is_linked = $entry->[1];
- $self->_append_stuff_to_entries ($stuff_type, $stuff, $entry->[0], $entry->[1]);
+ $self->_append_stuff_to_entries ($type, $stuff, $entries, $is_linked);
}
sub _get_variables ($)
@@ -168,19 +170,21 @@ sub _get_variables ($)
return $self->{'variables'};
}
+sub _get_main_sections ($)
+{
+ my ($self) = @_;
+
+ return $self->{'main_sections'};
+}
+
sub new ($)
{
my ($type) = @_;
my $class = (ref $type or $type or 'Common::SectionManager');
- my $main_h_section = Common::Sections::Section->new (Common::Sections::H);
- my $main_cc_section = Common::Sections::Section->new (Common::Sections::CC);
- my $main_p_h_section = Common::Sections::Section->new (Common::Sections::P_H);
- my $main_dev_null_section = Common::Sections::Section->new (Common::Sections::DEV_NULL);
-
- $main_h_section->set_linked (Common::Sections::H);
- $main_cc_section->set_linked (Common::Sections::CC);
- $main_p_h_section->set_linked (Common::Sections::P_H);
- $main_dev_null_section->set_linked (Common::Sections::DEV_NULL);
+ my $main_h_section = Common::Sections::Section->new_main (Common::Sections::H->[0]);
+ my $main_cc_section = Common::Sections::Section->new_main (Common::Sections::CC->[0]);
+ my $main_p_h_section = Common::Sections::Section->new_main (Common::Sections::P_H->[0]);
+ my $main_dev_null_section = Common::Sections::Section->new_main (Common::Sections::DEV_NULL->[0]);
my $self =
{
@@ -290,12 +294,13 @@ sub set_variable_for_conditional ($$$)
sub write_main_section_to_file ($$$)
{
- my ($self, $section_name, $file_name) = @_;
- my $toplevel_sections = $self->{'toplevel_sections'};
+ my ($self, $section_constant, $file_name) = @_;
+ my $section_name = $section_constant->[0];
+ my $main_sections = $self->_get_main_sections;
- unless (exists $toplevel_sections->{$section_name})
+ unless (exists $main_sections->{$section_name})
{
- print STDERR 'No such toplevel section: `' . $section_name . '\'.';
+ print STDERR 'No such main section: `' . $section_name . '\'.' . "\n";
exit 1;
}
@@ -307,7 +312,7 @@ sub write_main_section_to_file ($$$)
exit 1;
}
- my $section = $toplevel_sections->{$section_name};
+ my $section = $main_sections->{$section_name};
my $entries = $section->get_entries;
for (my $iter = 0; $iter < @{$entries}; ++$iter)
diff --git a/tools/pm/Common/Sections/Section.pm b/tools/pm/Common/Sections/Section.pm
index 0bf36ce..4d6ea43 100644
--- a/tools/pm/Common/Sections/Section.pm
+++ b/tools/pm/Common/Sections/Section.pm
@@ -25,20 +25,34 @@ use warnings;
use Common::Sections::Entries;
-sub new ($$)
+sub _generic_new ($$$)
{
- my ($type, $name) = @_;
+ my ($type, $name, $linked) = @_;
my $class = (ref $type or $type or 'Common::Sections::Section');
my $self =
{
'name' => $name,
'entries' => Common::Sections::Entries->new,
- 'linked' => undef
+ 'linked' => $linked
};
return bless $self, $class;
}
+sub new ($$)
+{
+ my ($type, $name) = @_;
+
+ return _generic_new $type, $name, undef;
+}
+
+sub new_main ($$)
+{
+ my ($type, $name) = @_;
+
+ return _generic_new $type, $name, $name;
+}
+
sub get_name ($)
{
my ($self) = @_;
diff --git a/tools/pm/Common/Shared.pm b/tools/pm/Common/Shared.pm
index 0048dae..4d46caa 100644
--- a/tools/pm/Common/Shared.pm
+++ b/tools/pm/Common/Shared.pm
@@ -151,7 +151,7 @@ sub string_split_commas ($)
}
elsif ($token eq ',' and not $level)
{
- push @out, $str;
+ push @out, Common::Util::string_trim $str;
$str = '';
next;
}
@@ -159,7 +159,7 @@ sub string_split_commas ($)
$str .= $token;
}
- push @out, $str;
+ push @out, Common::Util::string_trim $str;
return @out;
}
@@ -252,6 +252,25 @@ sub string_split_func_params ($)
return \ out;
}
+sub _type_fixup ($)
+{
+ my ($type) = @_;
+
+ while ($type =~ /\s+[&*]+/)
+ {
+ $type =~ s/\s+([*&]+)/$1 /g;
+ }
+ while ($type =~ /<\S/)
+ {
+ $type =~ s/<(\S)/< $1/g;
+ }
+ while ($type =~ /\S>/)
+ {
+ $type =~ s/(\S)>/$1 >/g;
+ }
+ $type = Common::Util::string_simplify $type;
+}
+
# - split params with something similar to string_split_commas
# - split every part with `='
# - second part, if defined, is default value
@@ -264,6 +283,8 @@ sub parse_params ($)
$line =~ s/^\s*\(\s*//;
$line =~ s/\s*\)\s*$//;
+ return [] unless $line;
+
my $parts = string_split_func_params ($line);
my @params = ();
@@ -284,21 +305,23 @@ sub parse_params ($)
$type = $1;
$name = $2;
- while ($type =~ /\s+[&*]+/)
- {
- $type =~ s/\s+([*&]+)/$1 /g;
- }
- $type = Common::Util::string_simplify $type;
+ $type = _type_fixup $type;
}
else
{
return [];
}
+
push @params, {'type' => $type, 'name' => $name, 'value' => $value};
}
return \ params;
}
+# TODO: Do some basic checks after parsing. For example check
+# TODO continued: if there are any parens (to catch a case
+# TODO continued: when we want to wrap a method with no
+# TODO continued: parameters, but we actually forgot to append
+# TODO continued: `()' to method name.
# - start scanning string from its end.
# - string from end of string to last closing paren should be saved as $after
# - string from last closing paren to its opening counterpart should be stored as $params
@@ -488,6 +511,7 @@ sub parse_function_declaration ($)
my $name = Common::Util::string_simplify (join '', reverse @name_parts);
my $ret_type = Common::Util::string_simplify (join '', reverse @tokens);
+ $ret_type = _type_fixup $ret_type;
@name_parts = undef;
return [$before, $ret_type, $name, $params, $after];
}
@@ -569,9 +593,9 @@ sub get_args ($$)
{
my $ref_type = undef;
- if ($desc =~ /^(o?)([abs])\([\w-]+\)$/)
+ if ($desc =~ /^(o?)([abs])\(([\w-]+)\)$/)
{
- my $obsolete = (defined $1);
+ my $obsolete = ($1 eq 'o');
my $type = $2;
my $param = $3;
diff --git a/tools/pm/Common/TypeInfoStore.pm b/tools/pm/Common/TypeInfoStore.pm
index f18edb1..fdbbc52 100644
--- a/tools/pm/Common/TypeInfoStore.pm
+++ b/tools/pm/Common/TypeInfoStore.pm
@@ -72,7 +72,7 @@ sub _add_new_to ($$$$$)
$c_to_cpp->{$c_stuff} = $cpp_stuff;
}
- my $cpp_sub_types = Common::Shared::split_cpp_types_to_sub_types $cpp_stuff;
+ my $cpp_sub_types = Common::Shared::split_cpp_type_to_sub_types $cpp_stuff;
foreach my $cpp_sub_stuff (@{$cpp_sub_types})
{
@@ -180,7 +180,7 @@ sub _get_read_files ($)
{
my ($self) = @_;
- return $self->get_read_files;
+ return $self->{'read_files'};
}
sub _get_c_to_cpp ($$)
diff --git a/tools/pm/Common/WrapParser.pm b/tools/pm/Common/WrapParser.pm
index 0aca2a7..632e47a 100644
--- a/tools/pm/Common/WrapParser.pm
+++ b/tools/pm/Common/WrapParser.pm
@@ -25,6 +25,9 @@ use warnings;
use IO::File;
+use Common::CxxFunctionInfo;
+use Common::CFunctionInfo;
+use Common::SignalInfo;
use Common::Util;
use Common::SectionManager;
use Common::Shared;
@@ -86,7 +89,7 @@ sub _on_wrap_corba_method ($)
{
my ($self) = @_;
- $self->extract_bracketed_text;
+ $self->_extract_bracketed_text;
# my $objOutputter = $$self{objOutputter};
# return unless ($self->check_for_eof());
@@ -94,7 +97,7 @@ sub _on_wrap_corba_method ($)
# my $filename = $$self{filename};
# my $line_num = $$self{line_num};
- # my $str = $self->extract_bracketed_text();
+ # my $str = $self->_extract_bracketed_text();
# my @args = string_split_commas($str);
# my $entity_type = "method";
@@ -485,31 +488,31 @@ sub _on_close_brace ($)
# check if we are closing the class brace
if (@{$class_levels} and $class_levels->[-1] == $level)
{
- pop @{$class_levels};
- pop @{$classes};
-
- unless (@{$classes})
+ if (@{$classes} == 1)
{
my $section = Common::Output::Shared::get_section $self, Common::Sections::H_AFTER_FIRST_CLASS;
$self->_on_ending_brace;
$section_manager->append_section_to_section ($section, $main_section);
}
+
+ pop @{$class_levels};
+ pop @{$classes};
$self->_pop_gir_entity;
}
# check if we are closing the namespace brace
elsif (@{$namespace_levels} and $namespace_levels->[-1] == $level)
{
- pop @{$namespaces};
- pop @{$namespace_levels};
-
- unless (@{$namespaces})
+ if (@{$namespaces} == 1)
{
my $section = Common::Output::Shared::get_section $self, Common::Sections::H_AFTER_FIRST_NAMESPACE;
$self->_on_ending_brace;
$section_manager->append_section_to_section ($section, $main_section);
}
+
+ pop @{$namespaces};
+ pop @{$namespace_levels};
}
$self->dec_level;
@@ -638,7 +641,7 @@ sub _on_defs ($)
my ($self) = @_;
$self->fixed_warning ('Deprecated.');
- $self->extract_bracketed_text;
+ $self->_extract_bracketed_text;
}
# TODO: implement it.
@@ -647,7 +650,7 @@ sub _on_ignore ($)
my ($self) = @_;
$self->fixed_warning ('Not yet implemented.');
- $self->extract_bracketed_text;
+ $self->_extract_bracketed_text;
# my @args = split(/\s+|,/,$str);
# foreach (@args)
# {
@@ -662,7 +665,7 @@ sub _on_ignore_signal ($)
my ($self) = @_;
$self->fixed_warning ('Not yet implemented.');
- $self->extract_bracketed_text;
+ $self->_extract_bracketed_text;
# $str = Common::Util::string_trim($str);
# $str = Common::Util::string_unquote($str);
# my @args = split(/\s+|,/,$str);
@@ -676,7 +679,7 @@ sub _on_ignore_signal ($)
sub _on_wrap_method ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -799,7 +802,7 @@ sub _on_wrap_method_docs_only ($)
{
my ($self) = @_;
- $self->extract_bracketed_text;
+ $self->_extract_bracketed_text;
$self->fixed_warning ('Not yet implemented.');
# my $objOutputter = $$self{objOutputter};
@@ -808,7 +811,7 @@ sub _on_wrap_method_docs_only ($)
# my $filename = $$self{filename};
# my $line_num = $$self{line_num};
- # my $str = $self->extract_bracketed_text();
+ # my $str = $self->_extract_bracketed_text();
# my @args = string_split_commas($str);
# my $entity_type = "method";
@@ -863,7 +866,7 @@ sub _on_wrap_method_docs_only ($)
sub _on_wrap_signal ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -954,7 +957,7 @@ sub _on_wrap_signal ($)
sub _on_wrap_property ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -967,7 +970,7 @@ sub _on_wrap_property ($)
# Catch useless parameters.
$self->_handle_get_args_results (Common::Shared::get_args \ args, {});
- if ($prop_c_name =~ /_/ or $prop_c_name !~ /$".*"^/)
+ if ($prop_c_name =~ /_/ or $prop_c_name !~ /^"\w+"$/)
{
$self->fixed_warning ('First parameter should be like C string (in double quotes) with dashes instead of underlines - e.g. "g-name-owner".');
}
@@ -1018,7 +1021,7 @@ sub _on_wrap_property ($)
sub _on_wrap_vfunc ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -1116,7 +1119,7 @@ sub _on_wrap_vfunc ($)
sub _on_wrap_ctor ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -1147,13 +1150,12 @@ sub _on_wrap_ctor ($)
my $c_constructor = Common::CFunctionInfo->new_from_gir ($gir_constructor);
my $c_param_names = $c_constructor->get_param_names;
my $cxx_param_names = $cxx_function->get_param_names;
- my @c_prop_names = ();
+ my $c_params_count = @{$c_param_names};
+ my $cxx_params_count = @{$cxx_param_names};
- die if scalar(@{$c_param_names}) != scalar(@{$cxx_param_names});
- if (@{$c_param_names})
- {
- @c_prop_names = map { $self->get_prop_name ($gir_class, $c_param_names->[$_], $cxx_param_names->[$_]) } 0 .. @{$c_param_names};
- }
+ die if $c_params_count != $cxx_params_count;
+
+ my @c_prop_names = map { $self->_get_prop_name ($gir_class, $c_param_names->[$_], $cxx_param_names->[$_]) } 0 .. ($c_params_count - 1);
Common::Output::Ctor::wrap_ctor $self,
$c_constructor->get_param_types,
@@ -1166,7 +1168,7 @@ sub _on_wrap_ctor ($)
sub _on_wrap_create ($)
{
my ($self) = @_;
- my $params = Common::Shared::parse_params $self->extract_bracketed_text;
+ my $params = Common::Shared::parse_params $self->_extract_bracketed_text;
my $types = [];
my $names = [];
@@ -1186,7 +1188,7 @@ sub _on_wrap_enum ($)
my $module = $self->get_module;
my $repository = $repositories->get_repository ($module);
my $namespace = $repository->get_g_namespace_by_name ($module);
- my @args = Common::Shared::string_split_commas ($self->extract_bracketed_text);
+ my @args = Common::Shared::string_split_commas ($self->_extract_bracketed_text);
if (@args < 2)
{
@@ -1245,7 +1247,7 @@ sub _on_wrap_gerror ($)
my $module = $self->get_module;
my $repository = $repositories->get_repository ($module);
my $namespace = $repository->get_g_namespace_by_name ($module);
- my @args = Common::Shared::string_split_commas ($self->extract_bracketed_text);
+ my @args = Common::Shared::string_split_commas ($self->_extract_bracketed_text);
if (@args < 2)
{
@@ -1306,7 +1308,7 @@ sub _on_wrap_gerror ($)
sub _on_implements_interface ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -1328,7 +1330,7 @@ sub _on_implements_interface ($)
sub _on_class_generic ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args < 2)
{
@@ -1373,7 +1375,7 @@ sub _on_class_generic ($)
sub _on_class_g_object ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 2)
{
@@ -1498,7 +1500,7 @@ sub _on_class_g_object ($)
for my $gir_parent_prefix (@gir_parent_prefixes)
{
my $temp_parent_class_type = $gir_parent_prefix . $gir_parent_type_struct;
- my $gir_parent_class_struct = $namespace->get_g_record_by_name ($temp_parent_class_type);
+ my $gir_parent_class_struct = $parent_namespace->get_g_record_by_name ($temp_parent_class_type);
if (defined $gir_parent_class_struct)
{
@@ -1558,10 +1560,12 @@ sub _on_class_g_object ($)
}
my $type_info_store = $self->get_type_info_store;
+# TODO: write an info about adding mapping when returned value
+# TODO continued: is undefined.
my $cpp_parent_type = $type_info_store->c_to_cpp ($c_parent_type);
- $self->push_gir_class ($gir_class);
- $self->push_c_class ($c_type);
+ $self->_push_gir_class ($gir_class);
+ $self->_push_c_class ($c_type);
Common::Output::GObject::output $self,
$c_type,
@@ -1582,7 +1586,7 @@ sub _on_class_gtk_object ($)
sub _on_class_boxed_type ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 5)
{
@@ -1754,7 +1758,7 @@ sub _on_class_boxed_type ($)
sub _on_class_boxed_type_static ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 2)
{
@@ -1803,7 +1807,7 @@ sub _on_class_boxed_type_static ($)
sub _on_class_interface ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 2)
{
@@ -1953,7 +1957,7 @@ sub _on_class_interface ($)
my $type_info_store = $self->get_type_info_store;
my $cpp_parent_name = $type_info_store->c_to_cpp ($c_parent_name);
- $self->push_gir_class ($gir_class);
+ $self->_push_gir_class ($gir_class);
Common::Output::Interface::output $self,
$c_name,
@@ -1969,7 +1973,7 @@ sub _on_class_interface ($)
sub _on_class_opaque_copyable ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 5)
{
@@ -2135,7 +2139,7 @@ sub _on_class_opaque_copyable ($)
sub _on_class_opaque_refcounted ($)
{
my ($self) = @_;
- my @args = Common::Shared::string_split_commas $self->extract_bracketed_text;
+ my @args = Common::Shared::string_split_commas $self->_extract_bracketed_text;
if (@args > 5)
{
@@ -2307,6 +2311,7 @@ sub _on_namespace_keyword ($)
my $in_s_comment = 0;
my $in_m_comment = 0;
+# TODO: why _extract_token is not used here?
# we need to peek ahead to figure out what type of namespace
# declaration this is.
foreach my $token (@{$tokens})
@@ -2342,8 +2347,10 @@ sub _on_namespace_keyword ($)
my $namespace_levels = $self->get_namespace_levels;
$name = Common::Util::string_trim ($name);
+ push @{$namespaces}, $name;
+ push @{$namespace_levels}, $level + 1;
- unless (@{$namespaces})
+ if (@{$namespaces} == 1)
{
$self->generate_first_namespace_number;
@@ -2352,8 +2359,6 @@ sub _on_namespace_keyword ($)
$section_manager->append_section_to_section ($section, $main_section);
}
- push @{$namespaces}, $name;
- push @{$namespace_levels}, $level + 1;
$done = 1;
}
elsif ($token eq ';')
@@ -2383,7 +2388,7 @@ sub _on_insert_section ($)
my ($self) = @_;
my $section_manager = $self->get_section_manager;
my $main_section = $self->get_main_section;
- my $str = Common::Util::string_trim $self->extract_bracketed_text;
+ my $str = Common::Util::string_trim $self->_extract_bracketed_text;
$section_manager->append_section_to_section ($str, $main_section);
}
@@ -2435,8 +2440,10 @@ sub _on_class_keyword ($)
my $class_levels = $self->get_class_levels;
$name =~ s/\s+//g;
+ push @{$classes}, $name;
+ push @{$class_levels}, $level + 1;
- unless (@{$classes})
+ if (@{$classes} == 1)
{
$self->generate_first_class_number;
@@ -2445,8 +2452,6 @@ sub _on_class_keyword ($)
$section_manager->append_section_to_section ($section, $main_section);
}
- push @{$classes}, $name;
- push @{$class_levels}, $level + 1;
$done = 1;
}
elsif ($token eq ';')
@@ -2477,7 +2482,7 @@ sub _on_class_keyword ($)
sub _on_module ($)
{
my ($self) = @_;
- my $str = Common::Util::string_trim $self->extract_bracketed_text;
+ my $str = Common::Util::string_trim $self->_extract_bracketed_text;
$self->{'module'} = $str;
}
@@ -2486,27 +2491,71 @@ sub _on_module ($)
### HANDLERS ABOVE
###
+sub get_stage_section_tuples ($)
+{
+ my ($self) = @_;
+
+ return $self->{'stage_section_tuples'}
+}
+
+sub set_filename ($$)
+{
+ my ($self, $filename) = @_;
+
+ $self->{'filename'} = $filename;
+}
+
+sub get_filename ($)
+{
+ my ($self) = @_;
+
+ return $self->{'filename'};
+}
+
+sub get_base ($)
+{
+ my ($self) = @_;
+
+ return $self->{'base'};
+}
+
+# TODO: private
sub _switch_to_stage ($$)
{
my ($self, $stage) = @_;
- my $pairs = $self->get_stage_section_pairs;
+ my $pairs = $self->get_stage_section_tuples;
if (exists $pairs->{$stage})
{
+ my $tuple = $pairs->{$stage};
+ my $main_section = $tuple->[0][0];
+ my $tokens = $tuple->[1];
+ my $ext = $tuple->[2];
+ my $filename = join '.', $self->get_base, $ext;
+
$self->set_parsing_stage ($stage);
$self->set_main_section ($pairs->{$stage}[0][0]);
$self->set_tokens ($self->{$pairs->{$stage}[1]});
+ $self->set_filename ($filename);
}
else
{
# TODO: internal error.
+ die;
}
}
+sub get_repositories ($)
+{
+ my ($self) = @_;
+
+ return $self->{'repositories'};
+}
+
# public
-sub new ($$$$$$)
+sub new ($$$$$$$)
{
- my ($type, $tokens_hg, $tokens_ccg, $type_info_store, $repositories, $conversions_store, $mm_module) = @_;
+ my ($type, $tokens_hg, $tokens_ccg, $type_info_store, $repositories, $conversions_store, $mm_module, $base) = @_;
my $class = (ref $type or $type or 'Common::WrapParser');
my $self =
{
@@ -2516,8 +2565,6 @@ sub new ($$$$$$)
'level' => 0,
'classes' => [],
'class_levels' => [],
- 'first_namespace' => '',
- 'first_class' => '',
'namespaces' => [],
'namespace_levels' => [],
'module' => '',
@@ -2529,18 +2576,20 @@ sub new ($$$$$$)
'parsing_stage' => STAGE_INVALID,
'main_section' => Common::Sections::DEV_NULL->[0],
'section_manager' => Common::SectionManager->new,
- 'stage_section_pairs' =>
+ 'stage_section_tuples' =>
{
- STAGE_HG() => [Common::Sections::H, 'tokens_hg'],
- STAGE_CCG() => [Common::Sections::CC, 'tokens_ccg'],
- STAGE_INVALID() => [Common::Sections::DEV_NULL, 'tokens_null']
+ STAGE_HG() => [Common::Sections::H, 'tokens_hg', 'hg'],
+ STAGE_CCG() => [Common::Sections::CC, 'tokens_ccg', 'ccg'],
+ STAGE_INVALID() => [Common::Sections::DEV_NULL, 'tokens_null', 'BAD']
},
'type_info_store' => $type_info_store,
'counter' => 0,
'conversions_store' => Common::ConversionsStore->new_local ($conversions_store),
'gir_stack' => [],
'c_stack' => [],
- 'mm_module' => $mm_module
+ 'mm_module' => $mm_module,
+ 'base' => $base,
+ 'filename' => undef
};
$self = bless $self, $class;
@@ -2590,6 +2639,13 @@ sub new ($$$$$$)
return $self;
}
+sub get_type_info_store ($)
+{
+ my ($self) = @_;
+
+ return $self->{'type_info_store'};
+}
+
sub get_number ($)
{
my ($self) = @_;
@@ -2804,6 +2860,8 @@ sub parse ($)
if (exists $handlers->{$token})
{
+ print 'Currently parsing: ' . $token . "\n";
+
my $pair = $handlers->{$token};
my $object = $pair->[0];
my $handler = $pair->[1];
diff --git a/tools/pm/Gir/Parser.pm b/tools/pm/Gir/Parser.pm
index ef77f52..015f469 100644
--- a/tools/pm/Gir/Parser.pm
+++ b/tools/pm/Gir/Parser.pm
@@ -266,7 +266,7 @@ sub parse_file ($$)
foreach my $girdir (@{$girdirs})
{
- my $maybe_real_filename = File::Spec->catfile (Gir::Config::get_girdir, $filename);
+ my $maybe_real_filename = File::Spec->catfile ($girdir, $filename);
if (-r $maybe_real_filename)
{
@@ -278,7 +278,8 @@ sub parse_file ($$)
unless (defined $real_filename)
{
# TODO: throw a runtime error.
- die; # with horrible death!
+ my $message = join '', 'Could not find ', $filename, ' in followin paths:', "\n", (join "\n", @{$girdirs}), "\n";
+ die $message; # with horrible death!
}
my $xml_parser = $self->_create_xml_parser;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]