barectf.c.j2: only declare `ts` variable when needed
[barectf.git] / barectf / templates / c / barectf.c-macros.j2
CommitLineData
fdbf8740
PP
1{#
2 # The MIT License (MIT)
3 #
4 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #}
25
d6483c83
PP
26{% import 'common.j2' as common %}
27
28{% set prefix = common.prefix %}
29{% set ucprefix = common.ucprefix %}
30{% set cg_opts = cfg.options.code_generation_options %}
31
32{#
33 # Generates the preamble of the packet opening/closing functions for
e8f0d548 34 # the data stream type `dst`.
d6483c83 35 #}
f5c70e1e 36{% macro open_close_func_preamble(dst, ts_feature) %}
e18cf9d6 37struct {{ prefix }}ctx * const ctx = &sctx->parent;
f5c70e1e 38{% if dst.default_clock_type and ts_feature %}
e8f0d548 39const {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} ts = ctx->use_cur_last_event_ts ?
d6483c83 40 sctx->cur_last_event_ts :
e8f0d548 41 ctx->cbs.{{ dst.default_clock_type.name }}_clock_get_value(ctx->data);
d6483c83
PP
42{% endif %}
43const int saved_in_tracing_section = ctx->in_tracing_section;
44{%- endmacro %}
45
46{#
47 # Generates a list of function call parameters for the members of
48 # the structure field type `ft`.
49 #
50 # Each parameter has the prefix `param_prefix`.
51 #
52 # The list always starts with a comma (if there's at least one member).
53 #
54 # Example:
55 #
a7e54146 56 # , cc_peer_id, sc_addr, p_msg_id, p_msg
d6483c83 57 #}
b622b24f 58{% macro ft_call_params(param_prefix, ft, only_dyn=false) %}
d6483c83 59{% if ft %}
b622b24f 60 {% for member_name, member in ft.members.items() %}
be9f12dc 61 {% if not only_dyn or member.field_type.size_is_dynamic or member.field_type._is_len %}
d6483c83 62, {{ param_prefix }}_{{ member_name }}
b622b24f
PP
63 {%- endif %}
64 {% endfor %}
d6483c83
PP
65{% endif %}
66{% endmacro %}
This page took 0.025748 seconds and 4 git commands to generate.