Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to include <cstdint> when using fixed width ints #234

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ def __init__(self, name, **kwargs):
self.array_type = kwargs.pop('array_type', None)
self.array_size = kwargs.pop('array_size', None)

self.includes = set()

if kwargs:
raise ValueError("Unused kwargs in MemberVariable: {}".format(list(kwargs.keys())))

if self.array_type is not None and self.array_size is not None:
self.is_array = True
self.full_type = r'std::array<{}, {}>'.format(self.array_type, self.array_size)
self.is_builtin_array = self.array_type in BUILTIN_TYPES
self.includes.add('#include <array>')

self.is_builtin = self.full_type in BUILTIN_TYPES
# We still have to check if this type is a valid fixed width type that we
Expand All @@ -123,6 +126,7 @@ def __init__(self, name, **kwargs):
# "Normalize" the name by prepending it with the std namespace if necessary
if not self.full_type.startswith('std::'):
self.full_type = f'std::{self.full_type}'
self.includes.add('#include <cstdint>')

# For usage in constructor signatures
self.signature = self.full_type + ' ' + self.name
Expand Down
10 changes: 4 additions & 6 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ def _fill_templates(self, template_base, data):
def _process_component(self, name, component):
"""Process one component"""
includes = set()
if any(m.is_array for m in component['Members']):
includes.add('#include <array>')
includes.update(*(m.includes for m in component['Members']))

for member in component['Members']:
if member.full_type in self.reader.components or member.array_type in self.reader.components:
Expand Down Expand Up @@ -370,11 +369,10 @@ def _preprocess_datatype(self, name, definition):
def _get_member_includes(self, members):
"""Process all members and gather the necessary includes"""
includes = set()
includes.update(*(m.includes for m in members))
for member in members:
if member.is_array:
includes.add("#include <array>")
if not member.is_builtin_array:
includes.add(self._build_include(member.array_bare_type))
if member.is_array and not member.is_builtin_array:
includes.add(self._build_include(member.array_bare_type))

for stl_type in ClassDefinitionValidator.allowed_stl_types:
if member.full_type == 'std::' + stl_type:
Expand Down