-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_callbackfunction_execute.py
executable file
·61 lines (47 loc) · 2.09 KB
/
gen_callbackfunction_execute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
# Copyright (C) 2019, Jaguar Land Rover
# This program is licensed under the terms and conditions of the
# Mozilla Public License, version 2.0. The full text of the
# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
#
# Author:Steven Martin (smarti24@jaguarlandrover.com)
num_expressions_to_generate = 16
indent = " "
function_indent = " "
nl = "\n "
comma = ","
end_bracket = "}"
else_txt = "else "
function_start = "void execute(uint8_t* payload, uint16_t payload_len) override {"
conditional_expression = "if constexpr (sizeof...(Types) == {}) {{"
function_call_start = "_function("
empty_function = "return _function();"
define_arg = "auto arg{} = utils::getArgType{}<Types...>(&payload);"
get_args_expr = "arg{}"
function_call_end = ");"
end = "static_assert (sizeof...(Types) <= {}, \"Currently only up to {} paramater for callbacks in supported, although this can be expanded\");"
arg_delete_expression="\n{}{}{}{}if constexpr (isVarPointer(arg{})) delete[] arg{};"
function_text = nl
function_text += function_start
function_text += nl + indent + conditional_expression.format(0)
function_text += nl + indent + indent + empty_function + nl + indent + end_bracket
for idx in range(num_expressions_to_generate):
function_text += nl + indent
function_text += else_txt
function_text += conditional_expression.format(idx + 1) + nl
for idx2 in range(idx + 1):
function_text += indent + indent + define_arg.format(idx2, idx2) + nl
function_text += indent + indent + function_call_start
for idx2 in range(idx + 1):
function_text += get_args_expr.format(idx2)
if (idx2 == (idx)):
function_text += function_call_end
else:
function_text += comma + " "
for idx2 in range(idx + 1):
function_text += arg_delete_expression.format(
indent, indent, indent, indent, idx2, idx2
)
function_text += nl + indent + end_bracket
function_text += nl + indent + end.format(num_expressions_to_generate, num_expressions_to_generate) + nl + end_bracket
print (function_text)