| 1 | /* |
| 2 | Authors: |
| 3 | Tomas Halman <[email protected]> |
| 4 | |
| 5 | Copyright (C) 2019 Red Hat |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <stdbool.h> |
| 24 | #include <string.h> |
| 25 | #include <ctype.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include "evaluator.h"cxx . . $ `<file>/src/lib/util/evaluator.h`/ |
| 29 | #include "lib/util/string_array.h"cxx . . $ `<file>/src/lib/util/string_array.h`/ |
| 30 | #include "common/common.h"cxx . . $ `<file>/src/common/common.h`/ |
| 31 | |
| 32 | enum e_statecxx . . $ e_state# { |
| 33 | E_STATE_INVALIDcxx . . $ E_STATE_INVALID. = 0, |
| 34 | E_STATE_BEGINcxx . . $ E_STATE_BEGIN., |
| 35 | E_STATE_STRINGcxx . . $ E_STATE_STRING., |
| 36 | E_STATE_SUBEXPRESSIONcxx . . $ E_STATE_SUBEXPRESSION., |
| 37 | E_STATE_OPERATORcxx . . $ E_STATE_OPERATOR., |
| 38 | E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT., |
| 39 | E_STATE_ENDcxx . . $ E_STATE_END., |
| 40 | }; |
| 41 | |
| 42 | enum e_operatorcxx . . $ e_operator# { |
| 43 | E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID. = 0, |
| 44 | E_OPERATOR_ANDcxx . . $ E_OPERATOR_AND., |
| 45 | E_OPERATOR_ORcxx . . $ E_OPERATOR_OR., |
| 46 | E_OPERATOR_NOTcxx . . $ E_OPERATOR_NOT. |
| 47 | }; |
| 48 | |
| 49 | struct evaluatorcxx . . $ evaluator# { |
| 50 | const char *expressioncxx . . $ evaluator#expression.; |
| 51 | const char *cursorcxx . . $ evaluator#cursor.; |
| 52 | char *tokencxx . . $ evaluator#token.; |
| 53 | size_tcxx . . $ size_t# tokensizecxx . . $ evaluator#tokensize.; |
| 54 | int depthcxx . . $ evaluator#depth.; |
| 55 | enum e_statecxx . . $ e_state# statecxx . . $ evaluator#state.; |
| 56 | }; |
| 57 | |
| 58 | struct e_mapcxx . . $ e_map# { |
| 59 | char *namecxx . . $ e_map#name.; |
| 60 | enum e_operatorcxx . . $ e_operator# valuecxx . . $ e_map#value.; |
| 61 | }; |
| 62 | |
| 63 | static struct e_mapcxx . . $ e_map# operatorscxx . . $ operators.[] = { |
| 64 | {"and", E_OPERATOR_ANDcxx . . $ E_OPERATOR_AND.}, |
| 65 | {"or", E_OPERATOR_ORcxx . . $ E_OPERATOR_OR.}, |
| 66 | {"not", E_OPERATOR_NOTcxx . . $ E_OPERATOR_NOT.}, |
| 67 | {NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.} |
| 68 | }; |
| 69 | |
| 70 | static errno_tcxx . . $ errno_t# evaluator_state_machinecxx . . $ evaluator_state_machine(ec3b0d9a86be5486).(struct evaluatorcxx . . $ evaluator# *self, |
| 71 | int depth, |
| 72 | const char **features, |
| 73 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_result); |
| 74 | |
| 75 | /* |
| 76 | * This function reads new item/token from expression. |
| 77 | * It is then stored in self->token. Expected tokens are |
| 78 | * '(', ')', group of letters (used for operators) or |
| 79 | * strings (characters enclosed by quotation marks). |
| 80 | * |
| 81 | * Strings are copied into self->token with quotation |
| 82 | * marks and they are used for feature's names. |
| 83 | * |
| 84 | */ |
| 85 | static errno_tcxx . . $ errno_t# evaluator_next_tokencxx . . $ evaluator_next_token(1f329120e9aca934).(struct evaluatorcxx . . $ evaluator# *self) |
| 86 | { |
| 87 | const char *p; |
| 88 | |
| 89 | while (isblankcxx . . $ `<external>/17904084882347303253/ctype.h:201:12`!(*self->cursor)) { |
| 90 | self->cursorcxx . . $ evaluator#cursor.++; |
| 91 | } |
| 92 | |
| 93 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(self->tokencxx . . $ evaluator#token., 0, self->tokensizecxx . . $ evaluator#tokensize.); |
| 94 | switch(tolowercxx . . $ `<external>/17904084882347303253/ctype.h:220:11`!(*self->cursor)) { |
| 95 | case '(': |
| 96 | case ')': |
| 97 | strncpycxx . . $ strncpy(255158a415b673b0).(self->tokencxx . . $ evaluator#token., self->cursorcxx . . $ evaluator#cursor., 1); |
| 98 | self->cursorcxx . . $ evaluator#cursor.++; |
| 99 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 100 | case '"': |
| 101 | p = strchrcxx . . $ strchr(2050848944e00d54).(&(self->cursorcxx . . $ evaluator#cursor.[1]), '"'); |
| 102 | if (p != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 103 | strncpycxx . . $ strncpy(255158a415b673b0).(self->tokencxx . . $ evaluator#token., self->cursorcxx . . $ evaluator#cursor., p - self->cursorcxx . . $ evaluator#cursor. + 1); |
| 104 | self->cursorcxx . . $ evaluator#cursor. = ++p; |
| 105 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 106 | } |
| 107 | self->cursorcxx . . $ evaluator#cursor. = &self->expressioncxx . . $ evaluator#expression.[self->tokensizecxx . . $ evaluator#tokensize. - 1]; |
| 108 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 109 | case '\0': |
| 110 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 111 | default: |
| 112 | p = self->cursorcxx . . $ evaluator#cursor.; |
| 113 | while (isalphacxx . . $ `<external>/17904084882347303253/ctype.h:190:10`!(*p)) { |
| 114 | ++p; |
| 115 | } |
| 116 | strncpycxx . . $ strncpy(255158a415b673b0).(self->tokencxx . . $ evaluator#token., self->cursorcxx . . $ evaluator#cursor., p - self->cursorcxx . . $ evaluator#cursor.); |
| 117 | self->cursorcxx . . $ evaluator#cursor. = p; |
| 118 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 119 | } |
| 120 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 121 | } |
| 122 | |
| 123 | static enum e_operatorcxx . . $ e_operator# evaluator_operatorcxx . . $ evaluator_operator(2dafef0c71c09bf4).(const char *token) |
| 124 | { |
| 125 | int i; |
| 126 | |
| 127 | if (token == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 128 | return E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.; |
| 129 | } |
| 130 | |
| 131 | for (i = 0; operatorscxx . . $ operators.[i].namecxx . . $ e_map#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; ++i) { |
| 132 | if (strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(token, operatorscxx . . $ operators.[i].namecxx . . $ e_map#name.) == 0) { |
| 133 | return operatorscxx . . $ operators.[i].valuecxx . . $ e_map#value.; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | return E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * This function return the state in which the |
| 142 | * state should change by evaluating self->token |
| 143 | * |
| 144 | * '"feature"' -> E_STATE_STRING -- i. e. feature name |
| 145 | * '(' -> E_STATE_SUBEXPRESSION -- sub expression |
| 146 | * ')' -> E_STATE_END -- end of subexpression |
| 147 | * 'letters' -> this should be an operator, find which one |
| 148 | * state might be E_STATE_OPERATOR or |
| 149 | * E_STATE_UNARY_NOT then |
| 150 | */ |
| 151 | static enum e_statecxx . . $ e_state# evaluator_token_to_statecxx . . $ evaluator_token_to_state(72aa860286bd5157).(const char *token) |
| 152 | { |
| 153 | enum e_operatorcxx . . $ e_operator# operator; |
| 154 | |
| 155 | switch (tolowercxx . . $ `<external>/17904084882347303253/ctype.h:220:11`!(token[0])) { |
| 156 | case '"': |
| 157 | return E_STATE_STRINGcxx . . $ E_STATE_STRING.; |
| 158 | case '(': |
| 159 | return E_STATE_SUBEXPRESSIONcxx . . $ E_STATE_SUBEXPRESSION.; |
| 160 | case ')': |
| 161 | return E_STATE_ENDcxx . . $ E_STATE_END.; |
| 162 | default: |
| 163 | operator = evaluator_operatorcxx . . $ evaluator_operator(2dafef0c71c09bf4).(token); |
| 164 | if (operator != E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.) { |
| 165 | if (operator == E_OPERATOR_NOTcxx . . $ E_OPERATOR_NOT.) { |
| 166 | return E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT.; |
| 167 | } |
| 168 | return E_STATE_OPERATORcxx . . $ E_STATE_OPERATOR.; |
| 169 | } |
| 170 | } |
| 171 | return E_STATE_INVALIDcxx . . $ E_STATE_INVALID.; |
| 172 | } |
| 173 | |
| 174 | static errno_tcxx . . $ errno_t# evaluator_get_featurecxx . . $ evaluator_get_feature(46899b4d75686a).(const char *token, |
| 175 | const char **features, |
| 176 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_result) |
| 177 | { |
| 178 | char *feature_name; |
| 179 | int len; |
| 180 | |
| 181 | *_result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 182 | if (features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || token == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 183 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 184 | } |
| 185 | |
| 186 | len = strlencxx . . $ strlen(751346f8406fd082).(token) - 2; |
| 187 | feature_name = formatcxx . . $ format(a849077ff1b8d812).("%.*s", len, &token[1]); |
| 188 | if (feature_name == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 189 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 190 | } |
| 191 | |
| 192 | *_result = string_array_has_valuecxx . . $ string_array_has_value(20870b8b3d19c175).((char **)features, feature_name); |
| 193 | freecxx . . $ free(5d22bdacc48458e8).(feature_name); |
| 194 | |
| 195 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 196 | } |
| 197 | |
| 198 | /* |
| 199 | * Handle state machine in E_STATE_BEGIN state |
| 200 | */ |
| 201 | static errno_tcxx . . $ errno_t# evaluator_handle_begin_statecxx . . $ evaluator_handle_begin_state(c73681c524d235ba).(struct evaluatorcxx . . $ evaluator# *self, |
| 202 | int depth, |
| 203 | const char **features, |
| 204 | enum e_statecxx . . $ e_state# nextstate, |
| 205 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *result, |
| 206 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *negation, |
| 207 | enum e_operatorcxx . . $ e_operator# *operator) |
| 208 | { |
| 209 | |
| 210 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! sub_result; |
| 211 | errno_tcxx . . $ errno_t# ret; |
| 212 | |
| 213 | switch (nextstate) { |
| 214 | case E_STATE_STRINGcxx . . $ E_STATE_STRING.: |
| 215 | return evaluator_get_featurecxx . . $ evaluator_get_feature(46899b4d75686a).(self->tokencxx . . $ evaluator#token., features, result); |
| 216 | case E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT.: |
| 217 | *negation = !*negation; |
| 218 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 219 | case E_STATE_SUBEXPRESSIONcxx . . $ E_STATE_SUBEXPRESSION.: |
| 220 | ret = evaluator_state_machinecxx . . $ evaluator_state_machine(ec3b0d9a86be5486).(self, depth + 1, features, |
| 221 | &sub_result); |
| 222 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 223 | return ret; |
| 224 | } |
| 225 | switch(*operator) { |
| 226 | case E_OPERATOR_ANDcxx . . $ E_OPERATOR_AND.: |
| 227 | *result = *result && (*negation ? !sub_result : sub_result); |
| 228 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 229 | break; |
| 230 | case E_OPERATOR_ORcxx . . $ E_OPERATOR_OR.: |
| 231 | *result = *result || (*negation ? !sub_result : sub_result); |
| 232 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 233 | break; |
| 234 | case E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.: /* no operator yet */ |
| 235 | *result = (*negation ? !sub_result : sub_result); |
| 236 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 237 | break; |
| 238 | default: |
| 239 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 240 | } |
| 241 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 242 | default: |
| 243 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Handle state machine in E_STATE_OPERATOR and E_STATE_UNARY_NOT state |
| 249 | * when the next state is going to be E_STATE_STRING |
| 250 | */ |
| 251 | static errno_tcxx . . $ errno_t# evaluator_handle_operator_state_stringcxx . . $ evaluator_handle_operator_state_string(f1d3ca753f98491f).(struct evaluatorcxx . . $ evaluator# *self, |
| 252 | const char **features, |
| 253 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *result, |
| 254 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *negation, |
| 255 | enum e_operatorcxx . . $ e_operator# *operator) |
| 256 | { |
| 257 | errno_tcxx . . $ errno_t# ret; |
| 258 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! sub_result; |
| 259 | |
| 260 | switch(*operator) { |
| 261 | case E_OPERATOR_ANDcxx . . $ E_OPERATOR_AND.: |
| 262 | ret = evaluator_get_featurecxx . . $ evaluator_get_feature(46899b4d75686a).(self->tokencxx . . $ evaluator#token., features, &sub_result); |
| 263 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 264 | return ret; |
| 265 | } |
| 266 | |
| 267 | *result = *result && (*negation ? !sub_result : sub_result); |
| 268 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 269 | break; |
| 270 | case E_OPERATOR_ORcxx . . $ E_OPERATOR_OR.: |
| 271 | ret = evaluator_get_featurecxx . . $ evaluator_get_feature(46899b4d75686a).(self->tokencxx . . $ evaluator#token., features, &sub_result); |
| 272 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | *result = *result || (*negation ? !sub_result : sub_result); |
| 277 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 278 | break; |
| 279 | case E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.: /* no operator yet */ |
| 280 | ret = evaluator_get_featurecxx . . $ evaluator_get_feature(46899b4d75686a).(self->tokencxx . . $ evaluator#token., features, &sub_result); |
| 281 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 282 | return ret; |
| 283 | } |
| 284 | |
| 285 | *result = *negation ? !sub_result : sub_result; |
| 286 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 287 | break; |
| 288 | default: |
| 289 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 290 | } |
| 291 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Handle state machine in E_STATE_OPERATOR and E_STATE_UNARY_NOT state |
| 296 | * when the next state is going to be E_STATE_SUBEXPRESSION |
| 297 | */ |
| 298 | static errno_tcxx . . $ errno_t# evaluator_handle_operator_state_subexpressioncxx . . $ evaluator_handle_operator_state_subexpression(dc02c6410df8df38).(struct evaluatorcxx . . $ evaluator# *self, |
| 299 | int depth, |
| 300 | const char **features, |
| 301 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *result, |
| 302 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *negation, |
| 303 | enum e_operatorcxx . . $ e_operator# *operator) |
| 304 | { |
| 305 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! sub_result; |
| 306 | errno_tcxx . . $ errno_t# ret; |
| 307 | |
| 308 | ret = evaluator_state_machinecxx . . $ evaluator_state_machine(ec3b0d9a86be5486).(self, depth + 1, features, &sub_result); |
| 309 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 310 | return ret; |
| 311 | } |
| 312 | |
| 313 | switch(*operator) { |
| 314 | case E_OPERATOR_ANDcxx . . $ E_OPERATOR_AND.: |
| 315 | *result = *result && (*negation ? !sub_result : sub_result); |
| 316 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 317 | break; |
| 318 | case E_OPERATOR_ORcxx . . $ E_OPERATOR_OR.: |
| 319 | *result = *result || (*negation ? !sub_result : sub_result); |
| 320 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 321 | break; |
| 322 | case E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.: /* no operator yet */ |
| 323 | *result = (*negation ? !sub_result : sub_result); |
| 324 | *negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 325 | break; |
| 326 | default: |
| 327 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 328 | } |
| 329 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Handle state machine in E_STATE_OPERATOR and E_STATE_UNARY_NOT state |
| 334 | */ |
| 335 | static errno_tcxx . . $ errno_t# evaluator_handle_operator_statecxx . . $ evaluator_handle_operator_state(c73681c524d235ba).(struct evaluatorcxx . . $ evaluator# *self, |
| 336 | int depth, |
| 337 | const char **features, |
| 338 | enum e_statecxx . . $ e_state# nextstate, |
| 339 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *result, |
| 340 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *negation, |
| 341 | enum e_operatorcxx . . $ e_operator# *operator) |
| 342 | { |
| 343 | switch (nextstate) { |
| 344 | case E_STATE_STRINGcxx . . $ E_STATE_STRING.: |
| 345 | return evaluator_handle_operator_state_stringcxx . . $ evaluator_handle_operator_state_string(f1d3ca753f98491f).(self, features, result, negation, operator); |
| 346 | case E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT.: |
| 347 | *negation = !*negation; |
| 348 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 349 | case E_STATE_SUBEXPRESSIONcxx . . $ E_STATE_SUBEXPRESSION.: |
| 350 | return evaluator_handle_operator_state_subexpressioncxx . . $ evaluator_handle_operator_state_subexpression(dc02c6410df8df38).(self, depth, features, result, negation, operator); |
| 351 | case E_STATE_ENDcxx . . $ E_STATE_END.: |
| 352 | if (depth == 0) { |
| 353 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; /* too many ) */ |
| 354 | } |
| 355 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 356 | default: |
| 357 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * Handle state machine in E_STATE_SUBEXPRESSION and E_STATE_STRING state |
| 363 | */ |
| 364 | static errno_tcxx . . $ errno_t# evaluator_handle_expression_statecxx . . $ evaluator_handle_expression_state(c73681c524d235ba).(struct evaluatorcxx . . $ evaluator# *self, |
| 365 | int depth, |
| 366 | const char **features, |
| 367 | enum e_statecxx . . $ e_state# nextstate, |
| 368 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *result, |
| 369 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *negation, |
| 370 | enum e_operatorcxx . . $ e_operator# *operator) |
| 371 | { |
| 372 | switch (nextstate) { |
| 373 | case E_STATE_OPERATORcxx . . $ E_STATE_OPERATOR.: |
| 374 | *operator = evaluator_operatorcxx . . $ evaluator_operator(2dafef0c71c09bf4).(self->tokencxx . . $ evaluator#token.); |
| 375 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 376 | case E_STATE_ENDcxx . . $ E_STATE_END.: |
| 377 | if (depth == 0) { |
| 378 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; /* too many ) */ |
| 379 | } |
| 380 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 381 | default: |
| 382 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static errno_tcxx . . $ errno_t# evaluator_state_machinecxx . . $ evaluator_state_machine(ec3b0d9a86be5486).(struct evaluatorcxx . . $ evaluator# *self, |
| 387 | int depth, |
| 388 | const char **features, |
| 389 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_result) |
| 390 | { |
| 391 | if (self == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || _result == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 392 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 393 | } |
| 394 | |
| 395 | enum e_statecxx . . $ e_state# state = E_STATE_BEGINcxx . . $ E_STATE_BEGIN.; |
| 396 | enum e_statecxx . . $ e_state# nextstate; |
| 397 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! result = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 398 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! negation = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 399 | enum e_operatorcxx . . $ e_operator# operator = E_OPERATOR_INVALIDcxx . . $ E_OPERATOR_INVALID.; |
| 400 | errno_tcxx . . $ errno_t# ret; |
| 401 | |
| 402 | do { |
| 403 | ret = evaluator_next_tokencxx . . $ evaluator_next_token(1f329120e9aca934).(self); |
| 404 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | if (self->tokencxx . . $ evaluator#token.[0] != '\0') { |
| 409 | nextstate = evaluator_token_to_statecxx . . $ evaluator_token_to_state(72aa860286bd5157).(self->tokencxx . . $ evaluator#token.); |
| 410 | switch(state) { |
| 411 | case E_STATE_BEGINcxx . . $ E_STATE_BEGIN.: |
| 412 | ret = evaluator_handle_begin_statecxx . . $ evaluator_handle_begin_state(c73681c524d235ba).(self, depth, features, |
| 413 | nextstate, &result, |
| 414 | &negation, &operator); |
| 415 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 416 | return ret; |
| 417 | } |
| 418 | break; |
| 419 | case E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT.: |
| 420 | case E_STATE_OPERATORcxx . . $ E_STATE_OPERATOR.: |
| 421 | ret = evaluator_handle_operator_statecxx . . $ evaluator_handle_operator_state(c73681c524d235ba).(self, depth, features, |
| 422 | nextstate, &result, |
| 423 | &negation, &operator); |
| 424 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 425 | return ret; |
| 426 | } |
| 427 | break; |
| 428 | case E_STATE_SUBEXPRESSIONcxx . . $ E_STATE_SUBEXPRESSION.: |
| 429 | case E_STATE_STRINGcxx . . $ E_STATE_STRING.: |
| 430 | ret = evaluator_handle_expression_statecxx . . $ evaluator_handle_expression_state(c73681c524d235ba).(self, depth, features, |
| 431 | nextstate, &result, |
| 432 | &negation, &operator); |
| 433 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 434 | return ret; |
| 435 | } |
| 436 | if (nextstate == E_STATE_ENDcxx . . $ E_STATE_END.) { |
| 437 | *_result = result; |
| 438 | return ret; |
| 439 | } |
| 440 | break; |
| 441 | case E_STATE_ENDcxx . . $ E_STATE_END.: |
| 442 | if (depth == 0) { |
| 443 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; /* too many ) */ |
| 444 | } |
| 445 | break; |
| 446 | case E_STATE_INVALIDcxx . . $ E_STATE_INVALID.: |
| 447 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 448 | } |
| 449 | state = nextstate; |
| 450 | } |
| 451 | } while (self->tokencxx . . $ evaluator#token.[0] != '\0'); |
| 452 | |
| 453 | if (depth != 0) { |
| 454 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; /* too many ) */ |
| 455 | } |
| 456 | |
| 457 | if (state == E_STATE_OPERATORcxx . . $ E_STATE_OPERATOR. || |
| 458 | state == E_STATE_UNARY_NOTcxx . . $ E_STATE_UNARY_NOT. || |
| 459 | state == E_STATE_BEGINcxx . . $ E_STATE_BEGIN.) { |
| 460 | |
| 461 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; /* expression can't end in this state */ |
| 462 | } |
| 463 | |
| 464 | *_result = result; |
| 465 | |
| 466 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 467 | } |
| 468 | |
| 469 | /* |
| 470 | * Set an expression to be evaluated. |
| 471 | * Returns EOK or an error on failure (ENOMEM). |
| 472 | */ |
| 473 | static errno_tcxx . . $ errno_t# evaluator_set_expressioncxx . . $ evaluator_set_expression(c409f8b4f3df5d8b).(struct evaluatorcxx . . $ evaluator# *self, |
| 474 | const char *expression) |
| 475 | { |
| 476 | if (self == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || expression == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 477 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 478 | } |
| 479 | |
| 480 | self->expressioncxx . . $ evaluator#expression. = expression; |
| 481 | self->cursorcxx . . $ evaluator#cursor. = self->expressioncxx . . $ evaluator#expression.; |
| 482 | self->tokensizecxx . . $ evaluator#tokensize. = strlencxx . . $ strlen(751346f8406fd082).(expression) + 1; |
| 483 | if (self->tokencxx . . $ evaluator#token. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 484 | freecxx . . $ free(5d22bdacc48458e8).(self->tokencxx . . $ evaluator#token.); |
| 485 | } |
| 486 | |
| 487 | self->tokencxx . . $ evaluator#token. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(self->tokensizecxx . . $ evaluator#tokensize.); |
| 488 | if (self->tokencxx . . $ evaluator#token. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 489 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 490 | } |
| 491 | |
| 492 | return EOKcxx . . $ `src/common/errno_t.h:34:9`!; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * Evaluate expression with set of features |
| 497 | * Result is stored in _result variable. |
| 498 | * Returns EOK or an error on failure. |
| 499 | */ |
| 500 | static errno_tcxx . . $ errno_t# evaluator_evaluatecxx . . $ evaluator_evaluate(7c0781a206ee835c).(struct evaluatorcxx . . $ evaluator# *self, |
| 501 | const char **features, |
| 502 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_result) |
| 503 | { |
| 504 | if (self == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || features == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || _result == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 505 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 506 | } |
| 507 | |
| 508 | self->cursorcxx . . $ evaluator#cursor. = self->expressioncxx . . $ evaluator#expression.; |
| 509 | return evaluator_state_machinecxx . . $ evaluator_state_machine(ec3b0d9a86be5486).(self, 0, features, _result); |
| 510 | } |
| 511 | |
| 512 | |
| 513 | errno_tcxx . . $ errno_t# evaluatecxx . . $ evaluate(46899b4d75686a).(const char *expression, const char *features[], boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *_result) |
| 514 | { |
| 515 | struct evaluatorcxx . . $ evaluator# *evaluator; |
| 516 | errno_tcxx . . $ errno_t# ret; |
| 517 | |
| 518 | evaluator = malloc_zerocxx . . $ `src/common/common.h:38:9`!(struct evaluator); |
| 519 | if (evaluator == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 520 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 521 | } |
| 522 | |
| 523 | ret = evaluator_set_expressioncxx . . $ evaluator_set_expression(c409f8b4f3df5d8b).(evaluator, expression); |
| 524 | if (ret != EOKcxx . . $ `src/common/errno_t.h:34:9`!) { |
| 525 | goto done; |
| 526 | } |
| 527 | |
| 528 | ret = evaluator_evaluatecxx . . $ evaluator_evaluate(7c0781a206ee835c).(evaluator, features, _result); |
| 529 | |
| 530 | done: |
| 531 | if (evaluator->tokencxx . . $ evaluator#token. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 532 | freecxx . . $ free(5d22bdacc48458e8).(evaluator->tokencxx . . $ evaluator#token.); |
| 533 | } |
| 534 | |
| 535 | freecxx . . $ free(5d22bdacc48458e8).(evaluator); |
| 536 | return ret; |
| 537 | } |