Skip to content

Commit cf370ec

Browse files
Merge pull request #4117 from iguessthislldo/igtd/dynamic-data-adapter
Fix Warnings and Typedef of Typedef Build Issues
2 parents b6ff722 + 865a7f0 commit cf370ec

File tree

11 files changed

+109
-35
lines changed

11 files changed

+109
-35
lines changed

dds/DCPS/Definitions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
# define OPENDDS_HAS_EXPLICIT_INTS 0
8484
#endif
8585

86+
#if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined __clang__)
87+
# define OPENDDS_GCC_HAS_DIAG_PUSHPOP 1
88+
#else
89+
# define OPENDDS_GCC_HAS_DIAG_PUSHPOP 0
90+
#endif
91+
8692
OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
8793

8894
namespace OpenDDS {

dds/DCPS/DirentWrapper.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef OPENDDS_DCPS_DIRENTWRAPPER_H
22
#define OPENDDS_DCPS_DIRENTWRAPPER_H
33

4-
#if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5) || defined __clang__)
5-
# define OPENDDS_GCC_HAS_DIAG_PUSHPOP
4+
#include "Definitions.h"
5+
6+
#if OPENDDS_GCC_HAS_DIAG_PUSHPOP
67
# pragma GCC diagnostic push
78
# if defined(__has_warning)
89
# if __has_warning("-Wdeprecated-declarations")
@@ -13,7 +14,7 @@
1314
# endif
1415
#endif
1516
#include <ace/Dirent.h>
16-
#ifdef OPENDDS_GCC_HAS_DIAG_PUSHPOP
17+
#if OPENDDS_GCC_HAS_DIAG_PUSHPOP
1718
# pragma GCC diagnostic pop
1819
#endif
1920

dds/DCPS/XTypes/DynamicDataAdapter.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ class OpenDDS_Dcps_Export DynamicDataAdapter : public DynamicDataBase {
527527
return rc;
528528
}
529529

530+
/*
531+
* It's possible to call this function with incorrectly matched types and
532+
* GCC could warn about this when the source value from set_*_value is
533+
* smaller than T in get_raw_value. This isn't actually a problem because
534+
* check_member requires tk to match the member's type.
535+
*/
536+
# if OPENDDS_GCC_HAS_DIAG_PUSHPOP
537+
# pragma GCC diagnostic push
538+
# pragma GCC diagnostic ignored "-Warray-bounds"
539+
# endif
530540
template <typename T>
531541
DDS::ReturnCode_t set_simple_raw_value(
532542
const char* method, T& dest, DDS::MemberId id, const void* source, DDS::TypeKind tk)
@@ -537,6 +547,9 @@ class OpenDDS_Dcps_Export DynamicDataAdapter : public DynamicDataBase {
537547
}
538548
return rc;
539549
}
550+
# if OPENDDS_GCC_HAS_DIAG_PUSHPOP
551+
# pragma GCC diagnostic pop
552+
# endif
540553

541554
// A reference to a std::vector<bool> element isn't a bool&, so it's a special
542555
// case.

dds/idl/dds_generator.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ NestedForLoops::~NestedForLoops()
322322
string type_to_default_array(const std::string& indent, AST_Type* type, const string& name,
323323
bool is_anonymous, bool is_union, bool use_cxx11, Classification fld_cls)
324324
{
325+
// TODO: Most of what's in here looks like it could be replaced with RefWrapper
325326
string val;
326327
string temp = name;
327328
if (temp.size() > 2 && temp.substr(temp.size() - 2, 2) == "()") {
@@ -332,7 +333,7 @@ string type_to_default_array(const std::string& indent, AST_Type* type, const st
332333
replace(temp.begin(), temp.end(), '[', '_');
333334
replace(temp.begin(), temp.end(), ']', '_');
334335
if (use_cxx11) {
335-
string n = scoped(type->name());
336+
string n = scoped(deepest_named_type(type)->name());
336337
if (is_anonymous) {
337338
n = n.substr(0, n.rfind("::") + 2) + "AnonymousType_" + type->local_name()->get_string();
338339
n = (fld_cls == AST_Decl::NT_sequence) ? (n + "_seq") : n;
@@ -423,14 +424,28 @@ string type_to_default(const std::string& indent, AST_Type* type, const string&
423424

424425
std::string field_type_name(AST_Field* field, AST_Type* field_type)
425426
{
426-
std::string name;
427+
if (!field_type) {
428+
field_type = field->field_type();
429+
}
427430
const Classification cls = classify(field_type);
428-
name = (cls & CL_STRING) ? string_type(cls) : scoped(field_type->name());
431+
const std::string name = (cls & CL_STRING) ?
432+
string_type(cls) : scoped(deepest_named_type(field_type)->name());
429433
if (field) {
430434
FieldInfo af(*field);
431435
if (af.as_base_ && af.type_->anonymous()) {
432-
name = af.scoped_type_;
436+
return af.scoped_type_;
433437
}
434438
}
435439
return name;
436440
}
441+
442+
AST_Type* deepest_named_type(AST_Type* type)
443+
{
444+
AST_Type* consider = type;
445+
AST_Type* named_type = type;
446+
while (consider->node_type() == AST_Decl::NT_typedef) {
447+
named_type = consider;
448+
consider = dynamic_cast<AST_Typedef*>(named_type)->base_type();
449+
}
450+
return named_type;
451+
}

dds/idl/dds_generator.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,15 @@ struct Intro {
786786
}
787787
};
788788

789-
std::string field_type_name(AST_Field* field, AST_Type* field_type);
789+
std::string field_type_name(AST_Field* field, AST_Type* field_type = 0);
790+
791+
/**
792+
* For the some situations, like a tag name, the type name we need is the
793+
* deepest named type, not the actual type. This will be the name of the
794+
* deepest typedef if it's an array or sequence, otherwise the name of the
795+
* type.
796+
*/
797+
AST_Type* deepest_named_type(AST_Type* type);
790798

791799
typedef std::string (*CommonFn)(
792800
const std::string& indent, AST_Decl* node,
@@ -834,7 +842,7 @@ void generateCaseBody(
834842
rhs = use_cxx11 ? "tmp" : "tmp.out()";
835843
} else if (use_cxx11 && (br_cls & (CL_ARRAY | CL_SEQUENCE))) { //array or seq C++11
836844
rhs = "IDL::DistinctType<" + brType + ", "
837-
+ dds_generator::get_tag_name(dds_generator::scoped_helper(branch->field_type()->name(), "::"))
845+
+ dds_generator::get_tag_name(brType)
838846
+ ">(tmp)";
839847
} else if (br_cls & CL_ARRAY) { //array classic
840848
forany = " " + brType + "_forany fa = tmp;\n";

dds/idl/dynamic_data_adapter_generator.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,7 @@ namespace {
249249
" }\n";
250250
} else if (seq_node || array_node) {
251251
AST_Type* const base_type = seq_node ? seq_node->base_type() : array_node->base_type();
252-
253-
// For the type name we need the deepest named type, not the actual type.
254-
// This will be the name of the deepest typedef if it's an array or
255-
// sequence, otherwise the name of the type.
256-
AST_Type* consider = base_type;
257-
AST_Type* named_type = base_type;
258-
while (consider->node_type() == AST_Decl::NT_typedef) {
259-
named_type = consider;
260-
consider = dynamic_cast<AST_Typedef*>(named_type)->base_type();
261-
}
252+
AST_Type* const named_type = deepest_named_type(base_type);
262253

263254
std::string op_type;
264255
std::string extra_access;

dds/idl/marshal_generator.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ namespace {
453453
}
454454
} else {
455455
Intro intro;
456-
RefWrapper wrapper(seq->base_type(), scoped(seq->base_type()->name()),
456+
RefWrapper wrapper(seq->base_type(), scoped(deepest_named_type(seq->base_type())->name()),
457457
classic_array_copy ? tempvar : stream_to, false);
458458
wrapper.classic_array_copy_ = classic_array_copy;
459459
wrapper.done(&intro);
@@ -523,7 +523,7 @@ namespace {
523523
}
524524

525525
const std::string cxx_elem =
526-
anonymous ? anonymous->scoped_elem_ : scoped(seq->base_type()->name());
526+
anonymous ? anonymous->scoped_elem_ : scoped(deepest_named_type(seq->base_type())->name());
527527
const bool use_cxx11 = be_global->language_mapping() == BE_GlobalData::LANGMAP_CXX11;
528528

529529
RefWrapper(base_wrapper).done().generate_tag();
@@ -804,7 +804,7 @@ namespace {
804804
std::string classic_array_copy;
805805
if (!use_cxx11 && (elem_cls & CL_ARRAY)) {
806806
RefWrapper classic_array_wrapper(
807-
seq->base_type(), scoped(seq->base_type()->name()), elem_access);
807+
seq->base_type(), scoped(deepest_named_type(seq->base_type())->name()), elem_access);
808808
classic_array_wrapper.classic_array_copy_ = true;
809809
classic_array_wrapper.done(&intro);
810810
classic_array_copy = classic_array_wrapper.classic_array_copy();
@@ -932,7 +932,7 @@ namespace {
932932
be_global->add_referenced(elem->file_name().c_str());
933933
}
934934
const std::string cxx_elem =
935-
anonymous ? anonymous->scoped_elem_ : scoped(arr->base_type()->name());
935+
anonymous ? anonymous->scoped_elem_ : scoped(deepest_named_type(arr->base_type())->name());
936936
const ACE_CDR::ULong n_elems = array_element_count(arr);
937937

938938
RefWrapper(base_wrapper).done().generate_tag();
@@ -1077,7 +1077,8 @@ namespace {
10771077
std::string classic_array_copy;
10781078
if (!use_cxx11 && (elem_cls & CL_ARRAY)) {
10791079
RefWrapper classic_array_wrapper(
1080-
arr->base_type(), scoped(arr->base_type()->name()), wrapper.value_access() + nfl.index_);
1080+
arr->base_type(), scoped(deepest_named_type(arr->base_type())->name()),
1081+
wrapper.value_access() + nfl.index_);
10811082
classic_array_wrapper.classic_array_copy_ = true;
10821083
classic_array_wrapper.done(&intro);
10831084
classic_array_copy = classic_array_wrapper.classic_array_copy();
@@ -3130,7 +3131,6 @@ marshal_generator::gen_field_getValueFromSerialized(AST_Structure* node, const s
31303131
for (Fields::Iterator i = fields.begin(); i != fields_end; ++i) {
31313132
AST_Field* const field = *i;
31323133
size_t size = 0;
3133-
const std::string field_name = field->local_name()->get_string();
31343134
const std::string idl_name = canonical_name(field);
31353135
AST_Type* const field_type = resolveActualType(field->field_type());
31363136
Classification fld_cls = classify(field_type);
@@ -3183,7 +3183,7 @@ marshal_generator::gen_field_getValueFromSerialized(AST_Structure* node, const s
31833183
" return getMetaStruct<" + scoped(field_type->name()) + ">().getValue(strm, subfield.c_str());\n"
31843184
" } else {\n"
31853185
" if (!gen_skip_over(strm, static_cast<" + scoped(field_type->name()) + "*>(0))) {\n"
3186-
" throw std::runtime_error(\"Field '" + field_name + "' could not be skipped\");\n"
3186+
" throw std::runtime_error(\"Field '" + idl_name + "' could not be skipped\");\n"
31873187
" }\n"
31883188
" }\n";
31893189
} else { // array, sequence, union:
@@ -3192,10 +3192,10 @@ marshal_generator::gen_field_getValueFromSerialized(AST_Structure* node, const s
31923192
post = "_forany";
31933193
} else if (use_cxx11 && (fld_cls & (CL_ARRAY | CL_SEQUENCE))) {
31943194
pre = "IDL::DistinctType<";
3195-
post = ", " + dds_generator::get_tag_name(scoped(field->field_type()->name())) + ">";
3195+
post = ", " + dds_generator::get_tag_name(scoped(deepest_named_type(field->field_type())->name())) + ">";
31963196
}
31973197
const std::string ptr = field->field_type()->anonymous() ?
3198-
FieldInfo(*field).ptr_ : (pre + scoped(field->field_type()->name()) + post + '*');
3198+
FieldInfo(*field).ptr_ : (pre + field_type_name(field) + post + '*');
31993199
expr +=
32003200
" if (!gen_skip_over(strm, static_cast<" + ptr + ">(0))) {\n"
32013201
" throw std::runtime_error(\"Field \" + OPENDDS_STRING(field) + \" could not be skipped\");\n"
@@ -3733,7 +3733,6 @@ bool marshal_generator::gen_union(AST_Union* node, UTL_ScopedName* name,
37333733
be_global->impl_ <<
37343734
" " << scoped(discriminator->name()) << " disc;\n" <<
37353735
streamAndCheck(">> " + getWrapper("disc", discriminator, WD_INPUT));
3736-
be_global->impl_ << "/* HERE */\n";
37373736
if (generateSwitchForUnion(node, "disc", streamCommon, branches,
37383737
discriminator, "", ">> ", cxx.c_str())) {
37393738
be_global->impl_ <<

dds/idl/metaclass_generator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void generate_anon_fields(AST_Structure* node)
475475
post = "_forany";
476476
} else if (use_cxx11 && (elem_cls & (CL_ARRAY | CL_SEQUENCE))) {
477477
pre = "IDL::DistinctType<";
478-
post = ", " + dds_generator::get_tag_name(dds_generator::scoped_helper(elem_orig->name(), "_")) + ">";
478+
post = ", " + dds_generator::get_tag_name(dds_generator::scoped_helper(deepest_named_type(elem_orig)->name(), "_")) + ">";
479479
}
480480
be_global->impl_ <<
481481
" if (!gen_skip_over(ser, static_cast<" << pre << cxx_elem << post
@@ -597,7 +597,7 @@ metaclass_generator::gen_typedef(AST_Typedef*, UTL_ScopedName* name,
597597
post = "_forany";
598598
} else if (use_cxx11 && (elem_cls & (CL_ARRAY | CL_SEQUENCE))) {
599599
pre = "IDL::DistinctType<";
600-
post = ", " + dds_generator::get_tag_name(scoped_helper(elem_orig->name(), "::")) + ">";
600+
post = ", " + dds_generator::get_tag_name(scoped_helper(deepest_named_type(elem_orig)->name(), "::")) + ">";
601601
}
602602
be_global->impl_ <<
603603
" if (!gen_skip_over(ser, static_cast<" << pre << cxx_elem << post
@@ -637,7 +637,7 @@ std::string gen_union_branch(const std::string&, AST_Decl* branch, const std::st
637637
post = "_forany";
638638
} else if (use_cxx11 && (br_cls & (CL_ARRAY | CL_SEQUENCE))) {
639639
pre = "IDL::DistinctType<";
640-
post = ", " + dds_generator::get_tag_name(dds_generator::scoped_helper(br_type->name(), "::")) + ">";
640+
post = ", " + dds_generator::get_tag_name(dds_generator::scoped_helper(deepest_named_type(br_type)->name(), "::")) + ">";
641641
}
642642
ss <<
643643
" if (!gen_skip_over(ser, static_cast<" << pre

tests/DCPS/Compiler/idl_test3_lib/FooDef.idl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ module Xyz {
5858
typedef sequence<SeqOfLong,4> SeqOfSeqOfLong;
5959
typedef sequence<SeqOfAnEnum,4> SeqOfSeqOfAnEnum;
6060

61+
// typedefs of typedefs
62+
typedef ArrayOfLong TypedefOfArrayOfLong;
63+
typedef SeqOfArrayOfLong TypedefOfSeqOfArrayOfLong;
64+
typedef sequence<TypedefOfArrayOfLong, 3> SeqOfTypedefOfArrayOfLong;
65+
typedef TypedefOfSeqOfArrayOfLong ArrayOfTypedefOfSeqOfArrayOfLong[2];
66+
67+
@topic
68+
struct StructOfTypedefsOfTypedefs {
69+
TypedefOfArrayOfLong typedef_of_array_of_long;
70+
TypedefOfSeqOfArrayOfLong typedef_of_seq_of_array_of_long;
71+
SeqOfTypedefOfArrayOfLong seq_of_typedef_of_array_of_long;
72+
ArrayOfTypedefOfSeqOfArrayOfLong array_of_typedef_of_seq_of_array_of_long;
73+
};
74+
75+
union UnionOfTypedefsOfTypedefs switch (int32) {
76+
case 0:
77+
TypedefOfArrayOfLong typedef_of_array_of_long;
78+
case 1:
79+
TypedefOfSeqOfArrayOfLong typedef_of_seq_of_array_of_long;
80+
case 2:
81+
SeqOfTypedefOfArrayOfLong seq_of_typedef_of_array_of_long;
82+
default:
83+
ArrayOfTypedefOfSeqOfArrayOfLong array_of_typedef_of_seq_of_array_of_long;
84+
};
85+
6186
// typedef of a "special" scalar type
6287
typedef octet OctetTypedef;
6388

tests/unit-tests/dds/DCPS/XTypes/DynamicDataAdapter.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ void test_collection_struct(T& col_struct)
188188
EXPECT_EQ(col_struct.f32[1], 0.11f);
189189
EXPECT_EQ(col_struct.f64[0], 0.20);
190190
EXPECT_EQ(col_struct.f64[1], 0.22);
191-
EXPECT_EQ(col_struct.f128[0], 0.30);
192-
EXPECT_EQ(col_struct.f128[1], 0.33);
191+
EXPECT_EQ(static_cast<double>(col_struct.f128[0]), 0.30);
192+
EXPECT_EQ(static_cast<double>(col_struct.f128[1]), 0.33);
193193
EXPECT_EQ(col_struct.c8[0], '1');
194194
EXPECT_EQ(col_struct.c8[1], '2');
195195
EXPECT_EQ(col_struct.c16[0], L'1');
@@ -240,6 +240,11 @@ TEST_F(dds_DCPS_XTypes_DynamicDataAdapter, test_struct)
240240
set_collection_struct(x.anon_seqs);
241241
set_collection_struct(x.arrays);
242242
set_collection_struct(x.anon_arrays);
243+
x.typedef_of_seq_typedef.length(2);
244+
x.typedef_of_seq_typedef[0] = 1;
245+
x.typedef_of_seq_typedef[1] = 2;
246+
x.typedef_of_array_typedef[0] = 1;
247+
x.typedef_of_array_typedef[1] = 2;
243248

244249
DDS::DynamicData_var dda = get_dynamic_data_adapter<TestStruct>(dt, x);
245250
ASSERT_RC_OK(copy(ddi, dda));
@@ -261,7 +266,7 @@ TEST_F(dds_DCPS_XTypes_DynamicDataAdapter, test_struct)
261266
EXPECT_EQ(y.u64, 8u);
262267
EXPECT_EQ(y.f32, 0.1f);
263268
EXPECT_EQ(y.f64, 0.2);
264-
EXPECT_EQ(y.f128, 0.3);
269+
EXPECT_EQ(static_cast<double>(y.f128), 0.3);
265270
EXPECT_EQ(y.c8, '!');
266271
EXPECT_EQ(y.c16, L'@');
267272
EXPECT_STREQ(y.s8, "Hello");
@@ -275,6 +280,11 @@ TEST_F(dds_DCPS_XTypes_DynamicDataAdapter, test_struct)
275280
test_collection_struct(y.anon_seqs);
276281
test_collection_struct(y.arrays);
277282
test_collection_struct(y.anon_arrays);
283+
ASSERT_EQ(y.typedef_of_seq_typedef.length(), 2u);
284+
EXPECT_EQ(y.typedef_of_seq_typedef[0], 1);
285+
EXPECT_EQ(y.typedef_of_seq_typedef[1], 2);
286+
EXPECT_EQ(y.typedef_of_array_typedef[0], 1);
287+
EXPECT_EQ(y.typedef_of_array_typedef[1], 2);
278288
}
279289
}
280290

0 commit comments

Comments
 (0)