61 #include <amxc/amxc.h>
71 amxc_var_set_type(value, AMXC_VAR_ID_LIST);
72 amxc_llist_for_each(it, args) {
75 amxc_var_set_index(value, -1, v, AMXC_VAR_FLAG_DEFAULT);
81 const char*
string[] = {
101 (*node)->
type = type;
105 when_null(node, exit);
106 when_null(*node, exit);
108 amxc_llist_it_take(&(*node)->it);
109 switch((*node)->type) {
120 if((amxc_var_type_of((*node)->left.value) == AMXC_VAR_ID_LIST) ||
121 ((*node)->left.value == NULL)) {
124 amxc_var_delete(&(*node)->left.value);
128 free((*node)->left.func_name);
129 (*node)->left.func_name = NULL;
130 amxc_var_delete(&(*node)->value);
134 free((*node)->left.field);
135 amxc_var_delete(&(*node)->value);
145 amxc_lstack_push(stack, &node->
it);
150 amxc_lstack_it_t* it = amxc_lstack_pop(stack);
161 amxc_llist_it_take(&left->
it);
166 amxc_llist_it_take(&right->
it);
191 amxc_llist_it_t* it = amxc_llist_get_first(&expr->
nodes);
201 amxc_var_t* value = NULL;
205 (amxc_var_type_of(node->
left.
value) == AMXC_VAR_ID_LIST)) {
210 amxc_llist_clean(&value->data.vl, NULL);
217 if(node->
value == NULL) {
218 amxc_var_new(&node->
value);
224 amxc_var_set_type(node->
value, AMXC_VAR_ID_NULL);
230 amxc_var_init(&args);
232 if(node->
value == NULL) {
233 amxc_var_new(&node->
value);
236 amxc_llist_clean(&args.data.vl, NULL);
249 when_null(node, exit);
259 result = (left && right);
270 result = (left || right);
280 if(!amxc_var_is_null(left_value) && !amxc_var_is_null(right_value)) {
288 if(amxc_var_type_of(node->
left.
value) != AMXC_VAR_ID_BOOL) {
292 result = amxc_var_constcast(
bool, node->
left.
value);
296 if(node->
value == NULL) {
297 amxc_var_new(&node->
value);
303 result = amxc_var_constcast(
bool, node->
value);
308 amxc_var_init(&args);
311 amxc_llist_clean(&args.data.vl, NULL);
323 static uint32_t
id = 0;
324 uint32_t current_id = 0;
326 when_null(node, exit);
329 amxc_string_t expr_txt;
330 amxc_string_init(&expr_txt, 0);
331 amxc_string_setf(&expr_txt,
"%s", expr->
expression);
332 amxc_string_replace(&expr_txt,
"\"",
"\\\"", UINT32_MAX);
333 printf(
"digraph D {\n");
334 printf(
"graph [ordering=\"out\"];\n");
335 printf(
"label = \"%s\";\n", amxc_string_get(&expr_txt, 0));
336 printf(
"labelloc = \"t\";\n");
339 amxc_string_clean(&expr_txt);
346 printf(
"node_%d", current_id);
354 printf(
"[shape=\"box\" label=\"AND\"];\n");
359 printf(
"[shape=\"box\" label=\"OR\"];\n");
364 printf(
"[shape=\"box\" label=\"NOT\"];\n");
368 char* value = amxc_var_dyncast(cstring_t, node->
left.
value);
369 printf(
"[shape=\"record\" label=\"{VALUE|%s}\"];\n", value);
374 printf(
"[shape=\"record\" label=\"{VALUE FUNCTION|%s}\"];\n", node->
left.
func_name);
377 printf(
"[shape=\"record\" label=\"{BOOL FUNCTION|%s}\"];\n", node->
left.
func_name);
380 printf(
"[shape=\"record\" label=\"{FIELD|%s}\"];\n", node->
left.
field);
385 printf(
"node_%d -> node_%d;\n", parent_id, current_id);
enum _amxp_expr_node_type amxp_expr_node_type_t
PRIVATE void PRIVATE int PRIVATE bool amxp_expr_compare(amxp_expr_t *expr, amxc_var_t *lvalue, amxc_var_t *rvalue, amxp_expr_comp_t comperator)
enum _amxp_expr_comp amxp_expr_comp_t
PRIVATE amxp_expr_status_t amxp_expr_call_value_func(amxp_expr_t *expr, const char *func, amxc_var_t *args, amxc_var_t *ret)
PRIVATE amxp_expr_status_t amxp_expr_get_field(amxp_expr_t *expr, amxc_var_t *var, const char *path)
PRIVATE bool amxp_expr_call_bool_func(amxp_expr_t *expr, const char *func, amxc_var_t *args)
amxp_expr_node_t * amxp_expr_get_node(amxp_expr_t *expr)
bool amxp_expr_node_eval(amxp_expr_t *expr, amxp_expr_node_t *node)
void amxp_expr_node_set_compop(amxp_expr_node_t *node, amxp_expr_comp_t comop)
void amxp_expr_node_add_value(amxp_expr_node_t *node, amxp_expr_node_t *value)
static const char * amxp_expr_compop2string(amxp_expr_comp_t op)
amxp_expr_node_t * amxp_expr_node_pop(amxc_lstack_t *stack)
static void amxp_expr_node_clean_args(amxc_llist_it_t *it)
void amxp_expr_node_push(amxc_lstack_t *stack, amxp_expr_node_t *node)
void amxp_expr_node_set_left(amxp_expr_node_t *node, amxp_expr_node_t *left)
static void amxp_expr_node_build_args(amxp_expr_t *expr, amxc_var_t *value, amxc_llist_t *args)
void amxp_expr_node_new(amxp_expr_node_t **node, amxp_expr_node_type_t type)
void amxp_expr_node_set_value(amxp_expr_node_t *node, amxc_var_t *value)
void amxp_expr_node_set_right(amxp_expr_node_t *node, amxp_expr_node_t *right)
void amxp_expr_node_delete(amxp_expr_node_t **node)
void amxp_expr_node_set_function(amxp_expr_node_t *node, char *func_name)
void amxp_expr_node_dump(amxp_expr_t *expr, amxp_expr_node_t *node, uint32_t level, uint32_t parent_id)
amxc_var_t * amxp_expr_node_get_value(amxp_expr_t *expr, amxp_expr_node_t *node)
void amxp_expr_node_set_field(amxp_expr_node_t *node, char *field)
@ amxp_expr_status_invalid_value
union _amxp_expr_node::@0 left
union _amxp_expr_node::@1 right
amxp_expr_node_type_t type
amxp_expr_status_t status