Skip to content

Commit

Permalink
Merge pull request #331 from jwillemsen/jwi-idl4optional
Browse files Browse the repository at this point in the history
Beta support for IDL optional annotation
  • Loading branch information
jwillemsen authored Dec 1, 2023
2 parents 932f81f + 148ffbc commit c58fb9c
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/taox11_tests.lst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ tests/idl4/explicit_ints/run_illegal_idl3_test.pl:
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_inheritance/run_test.pl:
tests/idl4/struct_inheritance/run_illegal_idl3_test.pl:
tests/idl4/union/run_test.pl:
Expand Down
5 changes: 5 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,12 @@ struct formatter<<%= scoped_cxxtype %>, OStrm_>
<< "object}"
% end
% else
% unless _m.optional?
<< "<%= _sep %><%= _m.cxxname %>=" << IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ())
% else
%# TODO
%# << "<%= _sep %><%= _m.cxxname %>=" << (val_.<%= _m.cxxname() %> ().has_value () ? IDL::traits<<%= _m.scoped_cxxtype %>>::write(val_.<%= _m.cxxname %> ().value ()) : "<empty>")
% 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
"IDL::optional<#{cxx_return_type}>"
end
end

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

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

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

def cxx_member_type
unless optional?
super
else
"IDL::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('tao/x11/optional_t.h') 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
44 changes: 44 additions & 0 deletions tao/x11/optional_t.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// -*- C++ -*-
/**
* @file optional_t.h
* @author Johnny Willemsen
*
* @brief template for IDL4 optional annotaiton
*
* @copyright Copyright (c) Remedy IT Expertise BV
*/

#if !defined (__IDL__OPTIONAL_T_H_INCLUDED__)
#define __IDL__OPTIONAL_T_H_INCLUDED__

#include <optional>
#include "tao/x11/versioned_x11_namespace.h"

#if defined (ACE_HAS_CPP17)

namespace TAOX11_NAMESPACE
{
namespace IDL
{
template<typename T>
using optional = std::optional<T>;
} // namespace IDL
} // namespace TAOX11_NAMESPACE

#else

namespace TAOX11_NAMESPACE
{
namespace IDL
{
template<typename T>
class optional
{
public:
T value_;
};
}
}
#endif

#endif // __IDL__OPTIONAL_T_H_INCLUDED__
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 c58fb9c

Please sign in to comment.