Skip to content

Commit

Permalink
First beta support for IDL optional annotation, needs more cleanup an…
Browse files Browse the repository at this point in the history
…d support for ostream insertion

    * tests/idl4/optional/client.cpp:
    * tests/idl4/optional/run_test.pl:
    * tests/idl4/optional/test.idl:
    * tests/idl4/optional/test.mpc:
      Added.

    * ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb:
    * ridlbe/c++11/visitors/struct.rb:
    * ridlbe/c++11/writers/stubheader.rb:
  • Loading branch information
jwillemsen committed Oct 31, 2023
1 parent 1a5c5ff commit 6e2be8c
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ridlbe/c++11/templates/cli/hdr/struct_idl_traits_def.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_>
<< "object}"
% end
% else
% unless _m.optional?
%# TODO Add optional support
<< "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ())
% end
% end
% _sep = ',' unless _sep
% end
Expand Down
60 changes: 60 additions & 0 deletions ridlbe/c++11/visitors/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,66 @@ def value_initializer
_resolved_idltype.zero_initializer
end
end

def optional?
!node.annotations[:optional].first.nil?
end

def is_reference?
if optional?
false
else
super
end
end

def is_pod?
if optional?
false
else
super
end
end

def cxx_byval_type
unless optional?
super
else
"std::optional<#{cxx_return_type}>"
end
end

def cxx_out_type
unless optional?
super
else
"std::optional<#{cxx_return_type}>&"
end
end

def cxx_in_type
unless optional?
super
else
"const std::optional<#{super}>&"
end
end

def cxx_move_type
unless optional?
super
else
"std::optional<#{cxx_return_type}>&&"
end
end

def cxx_member_type
unless optional?
super
else
"std::optional<#{super}>"
end
end
end
end
end
5 changes: 5 additions & 0 deletions ridlbe/c++11/writers/stubheader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def visit_valuebox(node)

def enter_struct(node)
node.members.each { |m| check_idl_type(m.idltype) }
node.members.each { |m| add_post_include('optional') if member_optional(m) }
end

def enter_union(node)
Expand Down Expand Up @@ -446,6 +447,10 @@ def visit_typedef(node)

private

def member_optional(node)
!node.annotations[:optional].first.nil?
end

def check_idl_type(idl_type)
idl_type = idl_type.resolved_type
case idl_type
Expand Down
20 changes: 20 additions & 0 deletions tests/idl4/optional/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @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*/[])
{
int retval {};
bar mybar;

TAOX11_TEST_INFO << "mybar: " << mybar << std::endl;
return retval;
}
31 changes: 31 additions & 0 deletions tests/idl4/optional/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: const returned $server\n";
$status = 1;
}

$target->GetStderrLog();

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

struct bar
{
short x;
string y;
@optional short z;
};

20 changes: 20 additions & 0 deletions tests/idl4/optional/test.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// -*- MPC -*-

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

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

0 comments on commit 6e2be8c

Please sign in to comment.