Zigbee Protocol Controller 1.6.0
attribute_mapper_ast.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
26#ifndef ATTRIBUTE_MAPPER_AST_HPP
27#define ATTRIBUTE_MAPPER_AST_HPP
28
29#include <vector>
30#include <list>
31#include <boost/spirit/home/x3.hpp>
32#include <boost/spirit/home/x3/support/ast/variant.hpp>
33#include <boost/fusion/include/adapt_struct.hpp>
34#include <boost/spirit/include/qi_optional.hpp>
35
36using result_type_t = float;
37
38namespace ast
39{
40namespace x3 = boost::spirit::x3;
41
42struct nil {};
43struct signed_;
44struct expression;
45struct condition;
46struct attribute;
48struct assignment;
50struct scope;
51
52using ast_node = boost::variant<ast::scope>;
53struct ast_tree : public std::vector<ast_node> {};
54
77};
78
88using operand = x3::variant<ast::nil,
90 float,
91 x3::forward_ast<attribute>,
92 x3::forward_ast<signed_>,
93 x3::forward_ast<expression>,
94 x3::forward_ast<condition>,
95 x3::forward_ast<function_invokation>>;
104 = boost::variant<ast::nil, ast::operand, uint32_t, attribute_path_subscript>;
105
111struct signed_ {
112 char sign;
114};
115
123struct operation {
126};
127
136 std::list<operation> rest;
137};
138
147struct condition {
151};
152
163};
164
177struct attribute {
179 std::vector<attribute_path_element> attribute_path;
180};
181
194 // Type of assignment.
195 // 0 - regular assignment
196 // 1 - instance assignment
197 // 2 - clearance assignment
198 int type;
201};
202
204
210 std::string function_name; // Function name to invoke.
211 std::vector<expression> arguments; // Arguments for the function
212};
213
219 std::string setting_name;
220 boost::optional<unsigned int> setting_value;
221};
222
226using scope_settings_t = std::vector<scope_setting>;
227
234struct scope {
237 std::vector<assignment> assignments;
238};
239
240bool operator==(const nil &a, const nil &b);
241bool operator==(const operand &a, const operand &b);
242bool operator==(const signed_ &a, const signed_ &b);
243bool operator==(const operation &a, const operation &b);
244bool operator==(const expression &a, const expression &b);
245bool operator==(const condition &a, const condition &b);
246bool operator==(const attribute &a, const attribute &b);
248 const attribute_path_subscript &b);
249bool operator==(const assignment &a, const assignment &b);
250bool operator==(const scope_setting &a, const scope_setting &b);
252
253} // namespace ast
254
263BOOST_FUSION_ADAPT_STRUCT(ast::signed_, sign, operand_)
264BOOST_FUSION_ADAPT_STRUCT(ast::operation, operator_, operand_)
265BOOST_FUSION_ADAPT_STRUCT(ast::expression, first, rest)
266BOOST_FUSION_ADAPT_STRUCT(ast::assignment, type, lhs, rhs)
267BOOST_FUSION_ADAPT_STRUCT(ast::condition, cond_value, cond_true, cond_false)
268BOOST_FUSION_ADAPT_STRUCT(ast::attribute, value_type, attribute_path)
269BOOST_FUSION_ADAPT_STRUCT(ast::attribute_path_subscript, identifier, index)
270BOOST_FUSION_ADAPT_STRUCT(ast::function_invokation, function_name, arguments)
271BOOST_FUSION_ADAPT_STRUCT(ast::scope_setting,
272 (std::string, setting_name),
273 (boost::optional<unsigned int>, setting_value))
274BOOST_FUSION_ADAPT_STRUCT(ast::scope, priority, settings, assignments)
275
276#endif //ATTRIBUTE_MAPPER_AST_HPP
277
float result_type_t
Definition: attribute_mapper_ast.hpp:36
Definition: attribute_mapper_ast.hpp:39
boost::variant< ast::scope > ast_node
Definition: attribute_mapper_ast.hpp:52
boost::variant< ast::nil, ast::operand, uint32_t, attribute_path_subscript > attribute_path_element
Attribute path element.
Definition: attribute_mapper_ast.hpp:104
operator_ids
Definitions of operators When the parser encounters the string representation of operators,...
Definition: attribute_mapper_ast.hpp:60
@ operator_modulo
Definition: attribute_mapper_ast.hpp:72
@ operator_div
Definition: attribute_mapper_ast.hpp:65
@ operator_bitand
Definition: attribute_mapper_ast.hpp:66
@ operator_bitxor
Definition: attribute_mapper_ast.hpp:68
@ operator_minus
Definition: attribute_mapper_ast.hpp:62
@ operator_bitor
Definition: attribute_mapper_ast.hpp:67
@ operator_mult
Definition: attribute_mapper_ast.hpp:64
@ operator_or
Definition: attribute_mapper_ast.hpp:71
@ operator_less_than_or_eq
Definition: attribute_mapper_ast.hpp:75
@ operator_exponent
Definition: attribute_mapper_ast.hpp:73
@ operator_greater_than_or_eq
Definition: attribute_mapper_ast.hpp:76
@ operator_greater_than
Definition: attribute_mapper_ast.hpp:70
@ operator_plus
Definition: attribute_mapper_ast.hpp:61
@ operator_less_than
Definition: attribute_mapper_ast.hpp:69
@ operator_equals
Definition: attribute_mapper_ast.hpp:63
@ operator_neq
Definition: attribute_mapper_ast.hpp:74
bool operator==(const nil &a, const nil &b)
AssignmentType
Definition: attribute_mapper_ast.hpp:203
@ REGULAR
Definition: attribute_mapper_ast.hpp:203
@ INSTANCE
Definition: attribute_mapper_ast.hpp:203
@ CLEARANCE
Definition: attribute_mapper_ast.hpp:203
x3::variant< ast::nil, uint32_t, float, x3::forward_ast< attribute >, x3::forward_ast< signed_ >, x3::forward_ast< expression >, x3::forward_ast< condition >, x3::forward_ast< function_invokation > > operand
Operands.
Definition: attribute_mapper_ast.hpp:95
std::vector< scope_setting > scope_settings_t
Type for Scope settings list.
Definition: attribute_mapper_ast.hpp:226
Assignment.
Definition: attribute_mapper_ast.hpp:193
ast::attribute lhs
left hand side of the assignment
Definition: attribute_mapper_ast.hpp:199
int type
Definition: attribute_mapper_ast.hpp:198
expression rhs
right hand side of the assignment
Definition: attribute_mapper_ast.hpp:200
Definition: attribute_mapper_ast.hpp:53
Attribute path subscript.
Definition: attribute_mapper_ast.hpp:160
operand identifier
Definition: attribute_mapper_ast.hpp:161
operand index
Definition: attribute_mapper_ast.hpp:162
Attribute.
Definition: attribute_mapper_ast.hpp:177
std::vector< attribute_path_element > attribute_path
Definition: attribute_mapper_ast.hpp:179
char value_type
Definition: attribute_mapper_ast.hpp:178
Condition.
Definition: attribute_mapper_ast.hpp:147
operand cond_true
Truth value.
Definition: attribute_mapper_ast.hpp:149
operand cond_false
False value.
Definition: attribute_mapper_ast.hpp:150
operand cond_value
Selector value.
Definition: attribute_mapper_ast.hpp:148
Expression.
Definition: attribute_mapper_ast.hpp:134
operand first
Definition: attribute_mapper_ast.hpp:135
std::list< operation > rest
Definition: attribute_mapper_ast.hpp:136
Built-in function invokation Example : fn_min_value(r'3, 5, d'5 or 20)
Definition: attribute_mapper_ast.hpp:209
std::vector< expression > arguments
Definition: attribute_mapper_ast.hpp:211
std::string function_name
Definition: attribute_mapper_ast.hpp:210
Definition: attribute_mapper_ast.hpp:42
Operation An operation consists of an operator and an right hand side operand. When operations are ev...
Definition: attribute_mapper_ast.hpp:123
operator_ids operator_
+,-,*,/ etc.
Definition: attribute_mapper_ast.hpp:124
operand operand_
right hand side operand
Definition: attribute_mapper_ast.hpp:125
Scope setting A scope setting consists of a setting name and an associated value.
Definition: attribute_mapper_ast.hpp:218
boost::optional< unsigned int > setting_value
Definition: attribute_mapper_ast.hpp:220
std::string setting_name
Definition: attribute_mapper_ast.hpp:219
Scope.
Definition: attribute_mapper_ast.hpp:234
std::vector< assignment > assignments
Definition: attribute_mapper_ast.hpp:237
scope_settings_t settings
Definition: attribute_mapper_ast.hpp:236
int priority
Definition: attribute_mapper_ast.hpp:235
Uniary signed operand.
Definition: attribute_mapper_ast.hpp:111
char sign
Definition: attribute_mapper_ast.hpp:112
operand operand_
Definition: attribute_mapper_ast.hpp:113