import barectf.config as barectf_config
import collections
import copy
+import re
from typing import List, Optional, Mapping, Callable, Any, Set, Tuple
import typing
from barectf.typing import Count, Alignment
return typing.cast(_Op, ret_op)
stream_ops = create_stream_ops()
- return self._create_file_template('barectf.c.j2').render(header_file_name=header_file_name,
- bitfield_header_file_name=bitfield_header_file_name,
- root_ft_prefixes=_RootFtPrefixes,
- root_ft_prefix_names=_ROOT_FT_PREFIX_NAMES,
- stream_ops=stream_ops,
- stream_op_pkt_ctx_op=stream_op_pkt_ctx_op)
+ c_src = self._create_file_template('barectf.c.j2').render(header_file_name=header_file_name,
+ bitfield_header_file_name=bitfield_header_file_name,
+ root_ft_prefixes=_RootFtPrefixes,
+ root_ft_prefix_names=_ROOT_FT_PREFIX_NAMES,
+ stream_ops=stream_ops,
+ stream_op_pkt_ctx_op=stream_op_pkt_ctx_op)
+
+ # Jinja 2 makes it hard to have multiple contiguous blocks
+ # delimited with empty lines when using a for loop, while not
+ # also having an empty line at the end.
+ #
+ # Therefore, we often get this rendered pattern:
+ #
+ # /* ... */
+ # ...;
+ # ...;
+ #
+ # /* ... */
+ # ...;
+ # ...;
+ # ...;
+ #
+ # }
+ #
+ # It's ugly, so fix it here.
+ return re.sub(r'(\n)\s*\n(\s*})', r'\1\2', c_src)