Zigbee Protocol Controller 1.6.0
attribute_mapper_ast_complexity.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
14#include <iostream>
15#include <iomanip>
16#include "attribute.hpp"
18
28namespace ast
29{
31{
32 public:
33 inline int operator()(const nil &x)
34 {
35 return 1;
36 }
37
38 inline int operator()(unsigned int n)
39 {
40 return 1;
41 }
42
43 inline int operator()(float n)
44 {
45 return 1;
46 }
47
48 inline int operator()(const attribute &a);
49 inline int operator()(const signed_ &x)
50 {
51 return boost::apply_visitor(*this, x.operand_) + 1;
52 }
53
54 inline int operator()(const condition &x)
55 {
56 int n = 0;
57 n += boost::apply_visitor(*this, x.cond_value);
58 n += boost::apply_visitor(*this, x.cond_true);
59 n += boost::apply_visitor(*this, x.cond_false);
60 return n;
61 }
62
63 inline int operator()(const operation &x)
64 {
65 return boost::apply_visitor(*this, x.operand_) + 1;
66 }
67
68 inline int operator()(const expression &x)
69 {
70 int n = boost::apply_visitor(*this, x.first);
71 for (const auto &terms: x.rest) {
72 n += (*this)(terms);
73 }
74 return n;
75 }
76
77 inline int operator()(const assignment &a)
78 {
79 int n = 0;
80 n += (*this)(a.lhs);
81 n += (*this)(a.rhs);
82 return n;
83 }
84
85 inline int operator()(const function_invokation &f)
86 {
87 int n = 0;
88 for (auto &argument: f.arguments) {
89 n += (*this)(argument);
90 }
91 return n;
92 }
93
94 inline int operator()(const scope &x)
95 {
96 int n = 0;
97 for (auto &a: x.assignments) {
98 n += (*this)(a);
99 }
100 return n;
101 }
102
103 inline int operator()(const ast_tree ast)
104 {
105 int n = 0;
106 for (const auto &ast_element: ast) {
107 n += boost::apply_visitor(*this, ast_element);
108 }
109 return n;
110 }
111};
112
114{
115 public:
117
118 inline int operator()(const ast::operand &operand)
119 {
120 return boost::apply_visitor(_complexity, operand) + 1;
121 }
122 // hat operator ^ (parent)
123 inline int operator()(const nil &nul)
124 {
125 return 1;
126 }
127 // just given by type id
129 {
130 return 1;
131 }
132
133 // Subscript operator
134 inline int operator()(const attribute_path_subscript &subscript)
135 {
136 int n = 0;
137 n += boost::apply_visitor(_complexity, subscript.identifier);
138 n += boost::apply_visitor(_complexity, subscript.index);
139 return n;
140 }
141 // parse a path list
142 inline int operator()(const std::vector<attribute_path_element> &paths)
143 {
144 int n = 0;
145 for (auto it = paths.begin(); it != paths.end(); it++) {
146 n += boost::apply_visitor(*this, *it);
147 }
148 return n;
149 }
150
151 private:
153};
154
156{
157 path_complexity pc(*this);
158 return pc(a.attribute_path) + 1;
159}
160
161} // namespace ast
162
attribute store C++ wrapper.
Definition: attribute_mapper_ast_complexity.hpp:31
int operator()(const expression &x)
Definition: attribute_mapper_ast_complexity.hpp:68
int operator()(const function_invokation &f)
Definition: attribute_mapper_ast_complexity.hpp:85
int operator()(const ast_tree ast)
Definition: attribute_mapper_ast_complexity.hpp:103
int operator()(float n)
Definition: attribute_mapper_ast_complexity.hpp:43
int operator()(const operation &x)
Definition: attribute_mapper_ast_complexity.hpp:63
int operator()(const nil &x)
Definition: attribute_mapper_ast_complexity.hpp:33
int operator()(const scope &x)
Definition: attribute_mapper_ast_complexity.hpp:94
int operator()(unsigned int n)
Definition: attribute_mapper_ast_complexity.hpp:38
int operator()(const assignment &a)
Definition: attribute_mapper_ast_complexity.hpp:77
int operator()(const condition &x)
Definition: attribute_mapper_ast_complexity.hpp:54
int operator()(const signed_ &x)
Definition: attribute_mapper_ast_complexity.hpp:49
Definition: attribute_mapper_ast_complexity.hpp:114
int operator()(const attribute_path_subscript &subscript)
Definition: attribute_mapper_ast_complexity.hpp:134
int operator()(const ast::operand &operand)
Definition: attribute_mapper_ast_complexity.hpp:118
complexity & _complexity
Definition: attribute_mapper_ast_complexity.hpp:152
int operator()(const std::vector< attribute_path_element > &paths)
Definition: attribute_mapper_ast_complexity.hpp:142
int operator()(const nil &nul)
Definition: attribute_mapper_ast_complexity.hpp:123
path_complexity(complexity &complexity)
Definition: attribute_mapper_ast_complexity.hpp:116
int operator()(attribute_store_type_t type)
Definition: attribute_mapper_ast_complexity.hpp:128
Definition: attribute_mapper_ast.hpp:39
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
Assignment.
Definition: attribute_mapper_ast.hpp:193
ast::attribute lhs
left hand side of the assignment
Definition: attribute_mapper_ast.hpp:199
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
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
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
operand operand_
right hand side operand
Definition: attribute_mapper_ast.hpp:125
Scope.
Definition: attribute_mapper_ast.hpp:234
std::vector< assignment > assignments
Definition: attribute_mapper_ast.hpp:237
Uniary signed operand.
Definition: attribute_mapper_ast.hpp:111
operand operand_
Definition: attribute_mapper_ast.hpp:113