Skip to content

Commit

Permalink
Merge pull request #408 from jwillemsen/jwi-structmapping
Browse files Browse the repository at this point in the history
Add first test and code for cpp_mapping annotation
  • Loading branch information
jwillemsen authored Oct 23, 2024
2 parents 4ce6321 + 6094278 commit 06ab14c
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 5 deletions.
1 change: 1 addition & 0 deletions bin/taox11_tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ tests/idl4/illegal_idl/run_test.pl:
tests/idl4/map/run_test.pl:
tests/idl4/map/run_illegal_idl3_test.pl:
tests/idl4/optional/run_test.pl:
tests/idl4/struct_cppmapping/run_test.pl:
tests/idl4/struct_inheritance/run_test.pl:
tests/idl4/struct_inheritance/run_illegal_idl3_test.pl:
tests/idl4/union/run_test.pl:
Expand Down
2 changes: 1 addition & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_>
% elsif _m.external?
%# TODO
% else
<< "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ())
<< "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %><%= member_accessor %>)
% end
% end
% _sep = ',' unless _sep
Expand Down
14 changes: 13 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_post.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// generated from <%= ridl_template_path %>
%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
<%= cxxname %> () = default;
~<%= cxxname %> () = default;
% unless base.nil?
Expand Down Expand Up @@ -43,9 +44,20 @@
inline void swap (<%= cxx_inout_type %> s);

private:
%end
% members.each do |_m|
<%= _m.cxx_member_type %> <%= _m.cxxname %>_<%= _m.value_initializer %>;
<%= _m.cxx_member_type %> <%= _m.cxxname %><%= member_postfix %><%= _m.value_initializer %>;
% end
};// <%= cxxname %>

%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2) { m1.swap (m2); }
%else
inline void swap (<%= scoped_cxx_out_type %> m1, <%= scoped_cxx_out_type %> m2)
{
%# Add support for base
% members.each do |_m|
std::swap (m1.<%= _m.cxxname %>, m2.<%= _m.cxxname %>);
% end
}
%end
4 changes: 3 additions & 1 deletion ridlbe/c++11/templates/cli/hdr/struct_pre.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

// generated from <%= ridl_template_path %>
/// @copydoc <%= doc_scoped_name %>
class <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %>
<%= class_struct %> <%= stub_export_macro %><%= cxxname %><% unless base.nil? %> : public <%= base.cxxname %><% end %>
{
%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
public:
%end
2 changes: 2 additions & 0 deletions ridlbe/c++11/templates/cli/inl/struct_inl.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
%if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'

// generated from <%= ridl_template_path %>
%#
Expand Down Expand Up @@ -40,3 +41,4 @@ inline void <%= scoped_cxxtype %>::swap (<%= scoped_cxx_out_type %><% if member_
std::swap (this-><%= _m.cxxname %>_, s.<%= _m.cxxname %>_);
% end
}
%end
4 changes: 2 additions & 2 deletions ridlbe/c++11/templates/cli/src/struct_cdr.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TAO_CORBA::Boolean operator<< (TAO_OutputCDR &<% if member_count > 0 || !base.ni
% if _m.optional?
(taox11_optional_cdr_in<<%= _m.cxx_member_type%><%= !_m.cdr_from_helper_type.nil? ? ', ' : '' %><%= _m.cdr_from_helper_type %>>::insert (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %>
% else
(strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n ) ? ' &&' : ';') %>
(strm << <%= _m.cdr_from_fmt % "_tao_aggregate.#{_m.cxxname}#{member_accessor}" %>)<%= ((_i < _n ) ? ' &&' : ';') %>
% end
% end
% else
Expand All @@ -32,7 +32,7 @@ TAO_CORBA::Boolean operator>> (TAO_InputCDR &<% if member_count > 0 || !base.nil
% if _m.optional?
(taox11_optional_cdr_out<<%= _m.cxx_member_type%><%= !_m.cdr_to_helper_type.nil? ? ', ' : '' %><%= _m.cdr_to_helper_type %>>::extract (strm, _tao_aggregate.<%= _m.cxxname %> ()))<%= ((_i < _n ) ? ' &&' : ';') %>
% else
(strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname} ()" %>)<%= ((_i < _n) ? ' &&' : ';') %>
(strm >> <%= _m.cdr_to_fmt % "_tao_aggregate.#{_m.cxxname}#{member_accessor}" %>)<%= ((_i < _n) ? ' &&' : ';') %>
% end
% end
% else
Expand Down
24 changes: 24 additions & 0 deletions ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ def base
node.base
end

# Which cpp_mapping we should use, default to class with methods
def cpp_mapping
return 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS' if node.annotations[:cpp_mapping].first.nil?
node.annotations[:cpp_mapping].first.fields[:value]
end

# How can we access a struct member, directly or through a method call
def member_accessor
return ' ()' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
''
end

# Possible postfix for all members in C++
def member_postfix
return '_' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
''
end

# Do we map to a C++ class or struct
def class_struct
return 'class' if cpp_mapping == 'CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS'
'struct'
end

# template mapping

map_template :typecode, :typecode
Expand Down
22 changes: 22 additions & 0 deletions tests/idl4/struct_cppmapping/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file client.cpp
* @author Johnny Willemsen
*
* @brief CORBA C++11 client application
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#include "testC.h"
#include "testlib/taox11_testlog.h"

int main (int /*argc*/, char* /*argv*/[])
{
bar_struct bs1;
bar_class bc1;

// Just compilation test
TAOX11_TEST_INFO << "bs1: " << bs1 << std::endl;

return 0;
}
31 changes: 31 additions & 0 deletions tests/idl4/struct_cppmapping/run_test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#---------------------------------------------------------------------
# @file run_test.pl
# @author Marcel Smit
#
# @copyright Copyright (c) Remedy IT Expertise BV
#---------------------------------------------------------------------
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;

# -*- perl -*-

use lib "$ENV{ACE_ROOT}/bin";
use PerlACE::TestTarget;

my $target = PerlACE::TestTarget::create_target(2) || die "Create target 2 failed\n";

$status = 0;

$SV = $target->CreateProcess ("client");

$server = $SV->SpawnWaitKill ($target->ProcessStartWaitInterval());

if ($server != 0) {
print STDERR "ERROR: client returned $server\n";
$status = 1;
}

$target->GetStderrLog();

exit $status;
16 changes: 16 additions & 0 deletions tests/idl4/struct_cppmapping/test.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file test.idl
* @author Johnny Willemsen
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

@cpp_mapping(STRUCT_WITH_PUBLIC_MEMBERS)
struct bar_struct {
short b;
};

@cpp_mapping(CLASS_WITH_PUBLIC_ACCESSORS_AND_MODIFIERS)
struct bar_class {
short b;
};
20 changes: 20 additions & 0 deletions tests/idl4/struct_cppmapping/test.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// -*- MPC -*-

project(*structmap_gen_idl): ridl_ostream_defaults {
IDL_Files {
test.idl
idlflags += --idl-version=4
}
custom_only = 1
}

project(*structmap_client): taox11_client {
after += *structmap_gen_idl
Source_Files {
client.cpp
}
Source_Files {
testC.cpp
}
}

0 comments on commit 06ab14c

Please sign in to comment.