From d470cf1fb44a971d38f21c3d2d8babc58bd98155 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Thu, 6 Mar 2014 17:55:37 +0400 Subject: [PATCH] Added workarounds for name clashing in generated messages --- .../dsdl_compiler/data_type_template.hpp | 19 +++++++----- libuavcan/dsdl_compiler/dsdlc.py | 1 + libuavcan/test/dsdl_test/dsdl_test.cpp | 3 +- .../dsdl_test/dsdl_uavcan_compilability.cpp | 31 +++++++++++++++++++ libuavcan/test/dsdl_test/root_ns_b/T.uavcan | 2 ++ 5 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp create mode 100644 libuavcan/test/dsdl_test/root_ns_b/T.uavcan diff --git a/libuavcan/dsdl_compiler/data_type_template.hpp b/libuavcan/dsdl_compiler/data_type_template.hpp index 58c4e67841..4ff5fb75dd 100644 --- a/libuavcan/dsdl_compiler/data_type_template.hpp +++ b/libuavcan/dsdl_compiler/data_type_template.hpp @@ -44,7 +44,7 @@ namespace UAVCAN_PACKED_BEGIN #endif -struct ${t.short_name} +struct ${t.cpp_type_name} { <%def name="generate_primary_body(type_name, max_bitlen, fields, constants)" buffered="True"> typedef const ${type_name}& ParameterType; @@ -53,6 +53,9 @@ struct ${t.short_name} <%def name="expand_attr_types(group_name, attrs)"> struct ${group_name} { +% for a in attrs: + #undef ${a.name} +% endfor % for a in attrs: typedef ${a.cpp_type} ${a.name}; % endfor @@ -130,7 +133,7 @@ ${'::uavcan::TailArrayOptDisabled' if (idx + 1) < len(fields) else 'tao_mode'}); ${generate_primary_body('Response', t.get_max_bitlen_response(), t.response_fields, t.response_constants) | indent} }; % else: - ${generate_primary_body(t.short_name, t.get_max_bitlen(), t.fields, t.constants)} + ${generate_primary_body(t.cpp_type_name, t.get_max_bitlen(), t.fields, t.constants)} % endif /* @@ -172,7 +175,7 @@ ${'::uavcan::TailArrayOptDisabled' if (idx + 1) < len(fields) else 'tao_mode'}); % if t.kind == t.KIND_SERVICE: private: - ${t.short_name}(); // Don't create objects of this type. Use Request/Response instead. + ${t.cpp_type_name}(); // Don't create objects of this type. Use Request/Response instead. % endif }; @@ -185,10 +188,10 @@ const typename ::uavcan::StorageType< ${scope_prefix}::ConstantTypes::${a.name} % endfor % if t.kind == t.KIND_SERVICE: -${define_out_of_line_constants(t.short_name + '::Request', t.request_constants)} -${define_out_of_line_constants(t.short_name + '::Response', t.response_constants)} +${define_out_of_line_constants(t.cpp_type_name + '::Request', t.request_constants)} +${define_out_of_line_constants(t.cpp_type_name + '::Response', t.response_constants)} % else: -${define_out_of_line_constants(t.short_name, t.constants)} +${define_out_of_line_constants(t.cpp_type_name, t.constants)} % endif #if UAVCAN_PACK_STRUCTS @@ -198,11 +201,13 @@ UAVCAN_PACKED_END // TODO Stream operator % if t.has_default_dtid: -const ::uavcan::DefaultDataTypeRegistrator< ${t.short_name} > _uavcan_gdtr_registrator_${t.short_name}; +const ::uavcan::DefaultDataTypeRegistrator< ${t.cpp_type_name} > _uavcan_gdtr_registrator_${t.cpp_type_name}; % else: // No default registration % endif +typedef ${t.cpp_type_name} ${t.short_name}; + } // Anonymous namespace % for nsc in t.cpp_namespace_components: } // Namespace ${nsc} diff --git a/libuavcan/dsdl_compiler/dsdlc.py b/libuavcan/dsdl_compiler/dsdlc.py index 8cec28e638..9616e36a41 100755 --- a/libuavcan/dsdl_compiler/dsdlc.py +++ b/libuavcan/dsdl_compiler/dsdlc.py @@ -118,6 +118,7 @@ def type_to_cpp_type(t): def generate_one_type(t): t.short_name = t.full_name.split('.')[-1] + t.cpp_type_name = t.short_name + '_' # Dependencies (no duplicates) def fields_includes(fields): diff --git a/libuavcan/test/dsdl_test/dsdl_test.cpp b/libuavcan/test/dsdl_test/dsdl_test.cpp index 0b1270cb49..970a105f1b 100644 --- a/libuavcan/test/dsdl_test/dsdl_test.cpp +++ b/libuavcan/test/dsdl_test/dsdl_test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include TEST(Dsdl, EmptyServices) @@ -92,13 +93,11 @@ TEST(Dsdl, Registration) GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindMessage, mask); ASSERT_TRUE(mask[8]); mask[8] = false; - ASSERT_FALSE(mask.any()); GlobalDataTypeRegistry::instance().getDataTypeIDMask(uavcan::DataTypeKindService, mask); ASSERT_TRUE(mask[1]); ASSERT_TRUE(mask[3]); mask[1] = mask[3] = false; - ASSERT_FALSE(mask.any()); /* * Reset diff --git a/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp new file mode 100644 index 0000000000..d15307e191 --- /dev/null +++ b/libuavcan/test/dsdl_test/dsdl_uavcan_compilability.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 Pavel Kirienko + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/libuavcan/test/dsdl_test/root_ns_b/T.uavcan b/libuavcan/test/dsdl_test/root_ns_b/T.uavcan new file mode 100644 index 0000000000..ef22364940 --- /dev/null +++ b/libuavcan/test/dsdl_test/root_ns_b/T.uavcan @@ -0,0 +1,2 @@ +bool T = true +bool F = false \ No newline at end of file