mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 15:57:35 +08:00
Removed enum constants from generated types
This commit is contained in:
@@ -8,7 +8,6 @@ import sys, os, logging, errno
|
||||
from mako.template import Template
|
||||
from pyuavcan import dsdl
|
||||
|
||||
MAX_BITLEN_FOR_ENUM = 31
|
||||
OUTPUT_FILE_EXTENSION = 'hpp'
|
||||
OUTPUT_FILE_PERMISSIONS = 0o444 # Read only for all
|
||||
TEMPLATE_FILENAME = os.path.join(os.path.dirname(__file__), 'data_type_template.tmpl')
|
||||
@@ -167,12 +166,10 @@ def generate_one_type(t):
|
||||
def inject_constant_info(constants):
|
||||
for c in constants:
|
||||
if c.type.kind == c.type.KIND_FLOAT:
|
||||
c.cpp_use_enum = False
|
||||
float(c.string_value) # Making sure that this is a valid float literal
|
||||
c.cpp_value = c.string_value
|
||||
else:
|
||||
int(c.string_value) # Making sure that this is a valid integer literal
|
||||
c.cpp_use_enum = c.value >= 0 and c.type.bitlen <= MAX_BITLEN_FOR_ENUM
|
||||
c.cpp_value = c.string_value
|
||||
if c.type.kind == c.type.KIND_UNSIGNED_INT:
|
||||
c.cpp_value += 'U'
|
||||
|
||||
@@ -83,11 +83,7 @@ struct UAVCAN_EXPORT ${t.cpp_type_name}
|
||||
|
||||
// Constants
|
||||
% for a in constants:
|
||||
% if a.cpp_use_enum:
|
||||
enum { ${a.name} = ${a.cpp_value} }; // ${a.init_expression}
|
||||
% else:
|
||||
static const typename ::uavcan::StorageType< typename ConstantTypes::${a.name} >::Type ${a.name}; // ${a.init_expression}
|
||||
%endif
|
||||
% endfor
|
||||
|
||||
// Fields
|
||||
@@ -257,12 +253,10 @@ ${extend_signature_per_field('', t.fields)}
|
||||
*/
|
||||
<%def name="define_out_of_line_constants(scope_prefix, constants)">
|
||||
% for a in constants:
|
||||
% if not a.cpp_use_enum:
|
||||
template <int _tmpl>
|
||||
const typename ::uavcan::StorageType< typename ${scope_prefix}<_tmpl>::ConstantTypes::${a.name} >::Type
|
||||
${scope_prefix}<_tmpl>::${a.name} = ${a.cpp_value}; // ${a.init_expression}
|
||||
|
||||
%endif
|
||||
% endfor
|
||||
</%def>
|
||||
% if t.kind == t.KIND_SERVICE:
|
||||
|
||||
Reference in New Issue
Block a user