From 9fb7497add9d92af6f58cf0db870e406a3ff829a Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Fri, 10 Jul 2015 14:36:52 +0300 Subject: [PATCH] dsdlc: union tag generation --- .../libuavcan_dsdl_compiler/__init__.py | 3 +++ .../data_type_template.tmpl | 23 +++++++++++++++---- libuavcan/dsdl_compiler/pyuavcan | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py index 85abc2aee4..a7a18bab9f 100644 --- a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py +++ b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py @@ -193,12 +193,15 @@ def generate_one_type(template_expander, t): inject_cpp_types(t.fields) inject_cpp_types(t.constants) t.all_attributes = t.fields + t.constants + t.union = t.union and len(t.fields) else: inject_cpp_types(t.request_fields) inject_cpp_types(t.request_constants) inject_cpp_types(t.response_fields) inject_cpp_types(t.response_constants) t.all_attributes = t.request_fields + t.request_constants + t.response_fields + t.response_constants + t.request_union = t.request_union and len(t.request_fields) + t.response_union = t.response_union and len(t.response_fields) # Constant properties def inject_constant_info(constants): diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl index 4a61f42e0d..c9963fbc98 100644 --- a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl +++ b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl @@ -43,7 +43,7 @@ template % endif struct UAVCAN_EXPORT ${t.cpp_type_name} { - #! type_name, max_bitlen, fields, constants + #! type_name, max_bitlen, fields, constants, union typedef const ${type_name}<_tmpl>& ParameterType; typedef ${type_name}<_tmpl>& ReferenceType; @@ -80,10 +80,23 @@ struct UAVCAN_EXPORT ${t.cpp_type_name} typename ::uavcan::StorageType< typename FieldTypes::${a.name} >::Type ${a.name}; % endfor + % if union: +private: // Union tag definition + typedef IntegerSpec< ::uavcan::IntegerBitLen< ${len(fields)} >::Result, + ::uavcan::SignednessUnsigned, ::uavcan::CastModeTruncate > TagType; + + typename ::uavcan::StorageType< TagType >::Type _tag_; // The name is mangled to avoid clashing with fields + +public: + % endif + ${type_name}() % for idx,a in enumerate(fields): ${':' if idx == 0 else ','} ${a.name}() % endfor + % if union: + , _tag_() + % endif { ::uavcan::StaticAssert<_tmpl == 0>::check(); // Usage check @@ -118,21 +131,23 @@ struct UAVCAN_EXPORT ${t.cpp_type_name} struct Request_ { ${indent(generate_primary_body(type_name='Request_', max_bitlen=t.get_max_bitlen_request(), \ - fields=t.request_fields, constants=t.request_constants))} + fields=t.request_fields, constants=t.request_constants, \ + union=t.request_union))} }; template struct Response_ { ${indent(generate_primary_body(type_name='Response_', max_bitlen=t.get_max_bitlen_response(), \ - fields=t.response_fields, constants=t.response_constants))} + fields=t.response_fields, constants=t.response_constants, \ + union=t.response_union))} }; typedef Request_<0> Request; typedef Response_<0> Response; % else: ${generate_primary_body(type_name=t.cpp_type_name, max_bitlen=t.get_max_bitlen(), \ - fields=t.fields, constants=t.constants)} + fields=t.fields, constants=t.constants, union=t.union)} % endif /* diff --git a/libuavcan/dsdl_compiler/pyuavcan b/libuavcan/dsdl_compiler/pyuavcan index 7dc69a4ad1..36e12969c0 160000 --- a/libuavcan/dsdl_compiler/pyuavcan +++ b/libuavcan/dsdl_compiler/pyuavcan @@ -1 +1 @@ -Subproject commit 7dc69a4ad1ae545334e39ac9f4a6c181be59670e +Subproject commit 36e12969c0bc60956541e487d1a99779cd2f108b