Skip to content

Commit

Permalink
Generated code linters
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Dominguez <mariodominguez@eprosima.com>
  • Loading branch information
Mario-DL authored and MiguelCompany committed Apr 7, 2024
1 parent 2d05445 commit 61072ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
23 changes: 11 additions & 12 deletions rosidl_typesupport_fastrtps_c/resource/msg__type_support_c.cpp.em
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ def generate_member_for_cdr_serialize(member, suffix):
strlist.append(' for (size_t i = 0; i < size; ++i) {')
strlist.append(' const rosidl_runtime_c__U16String * str = &array_ptr[i];')
strlist.append(' if (str->capacity == 0 || str->capacity <= str->size) {')
strlist.append(' fprintf(stderr, \"string capacity not greater than size\\n\");')
strlist.append(' return false;')
strlist.append(' fprintf(stderr, \"string capacity not greater than size\\n\");')
strlist.append(' return false;')
strlist.append(' }')
strlist.append(' if (str->data[str->size] != \'\\0\') {')
strlist.append(' fprintf(stderr, \"string not null-terminated\\n\");')
Expand All @@ -268,14 +268,14 @@ def generate_member_for_cdr_serialize(member, suffix):
elif isinstance(member.type.value_type, BasicType) and member.type.value_type.typename == 'wchar':
strlist.append(' for (size_t i = 0; i < size; ++i) {')
strlist.append(' cdr_serialize%s_%s(' % (suffix, ('__'.join(member.type.value_type.namespaced_name()))))
strlist.append(' static_cast<wchar_t *>(&array_ptr[i]), cdr);')
strlist.append(' static_cast<wchar_t *>(&array_ptr[i]), cdr);')
strlist.append(' }')
elif isinstance(member.type.value_type, BasicType):
strlist.append(' cdr.serialize_array(array_ptr, size);')
else :
strlist.append(' for (size_t i = 0; i < size; ++i) {')
strlist.append(' cdr_serialize%s_%s(' % (suffix, ('__'.join(member.type.value_type.namespaced_name()))))
strlist.append(' &array_ptr[i], cdr);')
strlist.append(' &array_ptr[i], cdr);')
strlist.append(' }')
elif isinstance(member.type, AbstractString):
strlist.append(' const rosidl_runtime_c__String * str = &ros_message->%s;' % (member.name))
Expand All @@ -297,8 +297,8 @@ def generate_member_for_cdr_serialize(member, suffix):
elif isinstance(member.type, BasicType):
strlist.append(' cdr << ros_message->%s;' % (member.name))
else:
strlist.append(' cdr_serialize%s_%s(' % (suffix, ('__'.join(member.type.namespaced_name()))))
strlist.append(' &ros_message->%s, cdr);' % (member.name))
strlist.append(' cdr_serialize%s_%s(' % (suffix, ('__'.join(member.type.namespaced_name()))))
strlist.append(' &ros_message->%s, cdr);' % (member.name))
strlist.append('}')

return strlist
Expand Down Expand Up @@ -488,7 +488,7 @@ def generate_member_for_get_serialized_size(member, suffix):
if isinstance(member.type.value_type, AbstractGenericString):
strlist.append(' for (size_t index = 0; index < array_size; ++index) {')
strlist.append(' current_alignment += padding +')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + ')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +')
if isinstance(member.type.value_type, AbstractWString):
strlist.append(' wchar_size *')
strlist.append(' (array_ptr[index].size + 1);')
Expand Down Expand Up @@ -518,7 +518,7 @@ def generate_member_for_get_serialized_size(member, suffix):
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, item_size);')
strlist.append('}')
else:
strlist.append(' current_alignment += get_serialized_size%s_%s(' % (suffix, ('__'.join(member.type.namespaced_name()))))
strlist.append('current_alignment += get_serialized_size%s_%s(' % (suffix, ('__'.join(member.type.namespaced_name()))))
strlist.append(' &(ros_message->%s), current_alignment);' % (member.name))
return strlist
}@
Expand All @@ -538,7 +538,7 @@ size_t get_serialized_size_@('__'.join([package_name] + list(interface_path.pare
(void)wchar_size;

@[for member in message.structure.members]@
@[ for line in generate_member_for_get_serialized_size(member, '')]@
@[ for line in generate_member_for_get_serialized_size(member, '')]@
@(line)
@[ end for]@

Expand Down Expand Up @@ -592,11 +592,11 @@ def generate_member_for_max_serialized_size(member, suffix):
strlist.append(' is_plain = false;')
strlist.append(' for (size_t index = 0; index < array_size; ++index) {')
strlist.append(' current_alignment += padding +')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + ')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +')
if type_.has_maximum_size():
if isinstance(type_, AbstractWString):
strlist.append(' wchar_size *')
strlist.append(' %d +' % (type_.maximum_size))
strlist.append(' %d +' % (type_.maximum_size))
if isinstance(type_, AbstractWString):
strlist.append(' wchar_size *')
strlist.append(' 1;')
Expand Down Expand Up @@ -823,7 +823,6 @@ static message_type_support_key_callbacks_t __key_callbacks_@(message.structure.
_@(message.structure.namespaced_type.name)__cdr_serialize_key
};
@[ end if]@

@
@# // Collect the callback functions and provide a function to get the type support struct.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ def generate_member_for_cdr_serialize(member, suffix):
strlist.append(' ros_message.%s[i],' % (member.name))
strlist.append(' cdr);')
strlist.append(' }')
strlist.append(' }')
strlist.append('}')
elif isinstance(member.type, BasicType) and member.type.typename == 'boolean':
strlist.append(' cdr << (ros_message.%s ? true : false);' % (member.name))
strlist.append('cdr << (ros_message.%s ? true : false);' % (member.name))
elif isinstance(member.type, BasicType) and member.type.typename == 'wchar':
strlist.append(' cdr << static_cast<wchar_t>(ros_message.%s);' % (member.name))
strlist.append('cdr << static_cast<wchar_t>(ros_message.%s);' % (member.name))
elif isinstance(member.type, AbstractWString):
strlist.append('{')
strlist.append(' rosidl_typesupport_fastrtps_cpp::cdr_serialize(cdr, ros_message.%s);' % (member.name))
strlist.append(' rosidl_typesupport_fastrtps_cpp::cdr_serialize(cdr, ros_message.%s);' % (member.name))
strlist.append('}')
elif not isinstance(member.type, NamespacedType):
strlist.append('cdr << ros_message.%s;' % (member.name))
Expand All @@ -191,7 +191,7 @@ cdr_serialize(
eprosima::fastcdr::Cdr & cdr)
{
@[for member in message.structure.members]@
@[ for line in generate_member_for_cdr_serialize(member, '')]@
@[ for line in generate_member_for_cdr_serialize(member, '')]@
@(line)
@[ end for]@

Expand Down Expand Up @@ -436,11 +436,11 @@ def generate_member_for_max_serialized_size(member, suffix):
strlist.append(' is_plain = false;')
strlist.append(' for (size_t index = 0; index < array_size; ++index) {')
strlist.append(' current_alignment += padding +')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) + ')
strlist.append(' eprosima::fastcdr::Cdr::alignment(current_alignment, padding) +')
if type_.has_maximum_size():
if isinstance(type_, AbstractWString):
strlist.append(' wchar_size *')
strlist.append(' %d +' % (type_.maximum_size))
strlist.append(' %d +' % (type_.maximum_size))
if isinstance(type_, AbstractWString):
strlist.append(' wchar_size *')
strlist.append(' 1;')
Expand Down

0 comments on commit 61072ed

Please sign in to comment.