Skip to content

Commit

Permalink
Merge pull request OpenDDS#4355 from tmayoff/optional
Browse files Browse the repository at this point in the history
Add warning for @optional annotation
  • Loading branch information
jrw972 authored Nov 21, 2023
2 parents 44395d4 + 02eef86 commit f4ec88a
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ if(OPENDDS_BUILD_TESTS)
add_subdirectory(tests/cmake/Messenger)
endif()
add_subdirectory(tests/cmake/idl_compiler_tests)
add_subdirectory(tests/DCPS/Compiler/optional)
add_subdirectory(tests/cmake/include_subdir)
# TODO: This test always builds shared libraries and linker complains about
# ACE/TAO libs lacking -fPIC when ACE is static.
Expand Down
6 changes: 6 additions & 0 deletions dds/idl/dds_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ dds_visitor::visit_structure(AST_Structure* node)
field_vec.push_back(*i);
}

for (vector<AST_Field*>::iterator it = field_vec.begin(); it != field_vec.end(); ++it) {
if (be_global->is_optional(*it)) {
idl_global->err()->misc_warning("@optional annotation isn't fully supported", *it);
}
}

if (!java_ts_only_) {
error_ |= !gen_target_.gen_struct(node, node->name(), field_vec,
node->size_type(), node->repoID());
Expand Down
14 changes: 14 additions & 0 deletions tests/DCPS/Compiler/optional/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
optional_annotation
optionalC.cpp
optionalC.h
optionalC.inl
optionalS.cpp
optionalS.h
optionalTypeSupport.idl
optionalTypeSupportC.cpp
optionalTypeSupportC.h
optionalTypeSupportC.inl
optionalTypeSupportImpl.cpp
optionalTypeSupportImpl.h
optionalTypeSupportS.cpp
optionalTypeSupportS.h
14 changes: 14 additions & 0 deletions tests/DCPS/Compiler/optional/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.8...3.27)
project(opendds_compiler_optional CXX)
enable_testing()

find_package(OpenDDS REQUIRED)
include(opendds_testing)

add_executable(${PROJECT_NAME} "main.cpp")
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME optional_annotation)
opendds_target_sources(${PROJECT_NAME} PUBLIC "optional.idl" OPENDDS_IDL_OPTIONS "-Lc++11")
target_link_libraries(${PROJECT_NAME} OpenDDS::Dcps)

configure_file(run_test.pl . COPYONLY)
opendds_add_test(COMMAND perl run_test.pl)
16 changes: 16 additions & 0 deletions tests/DCPS/Compiler/optional/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "optionalTypeSupportImpl.h"

#include <dds/DCPS/Serializer.h>
#include <dds/DCPS/TypeSupportImpl.h>
#include <dds/DCPS/FilterEvaluator.h>

#include <ace/ACE.h>
#include <ace/Log_Msg.h>

#include <cstdlib>


int ACE_TMAIN(int, ACE_TCHAR**)
{
return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions tests/DCPS/Compiler/optional/optional.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module optional {

@topic
struct OptionalMembers {
@optional long value;
};

};
17 changes: 17 additions & 0 deletions tests/DCPS/Compiler/optional/optional.mpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project(*): dcps_test, msvc_bigobj {
exename = optional_annotation
exeout = .

Source_Files {
main.cpp
}

TypeSupport_Files {
optional.idl
}

IDL_Files {
optional.idl
optionalTypeSupport.idl
}
}
19 changes: 19 additions & 0 deletions tests/DCPS/Compiler/optional/run_test.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;

use Env (DDS_ROOT);
use lib "$DDS_ROOT/bin";
use Env (ACE_ROOT);
use lib "$ACE_ROOT/bin";
use PerlDDS::Run_Test;
use strict;

my $name = 'optional_annotation';

my $test = new PerlDDS::TestFramework();

$test->process($name, $name);
$test->start_process($name);

exit $test->finish(30);

0 comments on commit f4ec88a

Please sign in to comment.