Lines Matching refs:e
15 static struct expr *expr_eliminate_yn(struct expr *e);
19 struct expr *e = xcalloc(1, sizeof(*e)); in expr_alloc_symbol() local
20 e->type = E_SYMBOL; in expr_alloc_symbol()
21 e->left.sym = sym; in expr_alloc_symbol()
22 return e; in expr_alloc_symbol()
27 struct expr *e = xcalloc(1, sizeof(*e)); in expr_alloc_one() local
28 e->type = type; in expr_alloc_one()
29 e->left.expr = ce; in expr_alloc_one()
30 return e; in expr_alloc_one()
35 struct expr *e = xcalloc(1, sizeof(*e)); in expr_alloc_two() local
36 e->type = type; in expr_alloc_two()
37 e->left.expr = e1; in expr_alloc_two()
38 e->right.expr = e2; in expr_alloc_two()
39 return e; in expr_alloc_two()
44 struct expr *e = xcalloc(1, sizeof(*e)); in expr_alloc_comp() local
45 e->type = type; in expr_alloc_comp()
46 e->left.sym = s1; in expr_alloc_comp()
47 e->right.sym = s2; in expr_alloc_comp()
48 return e; in expr_alloc_comp()
67 struct expr *e; in expr_copy() local
72 e = xmalloc(sizeof(*org)); in expr_copy()
73 memcpy(e, org, sizeof(*org)); in expr_copy()
76 e->left = org->left; in expr_copy()
79 e->left.expr = expr_copy(org->left.expr); in expr_copy()
87 e->left.sym = org->left.sym; in expr_copy()
88 e->right.sym = org->right.sym; in expr_copy()
93 e->left.expr = expr_copy(org->left.expr); in expr_copy()
94 e->right.expr = expr_copy(org->right.expr); in expr_copy()
97 printf("can't copy type %d\n", e->type); in expr_copy()
98 free(e); in expr_copy()
99 e = NULL; in expr_copy()
103 return e; in expr_copy()
106 void expr_free(struct expr *e) in expr_free() argument
108 if (!e) in expr_free()
111 switch (e->type) { in expr_free()
115 expr_free(e->left.expr); in expr_free()
126 expr_free(e->left.expr); in expr_free()
127 expr_free(e->right.expr); in expr_free()
130 printf("how to free type %d?\n", e->type); in expr_free()
133 free(e); in expr_free()
253 static struct expr *expr_eliminate_yn(struct expr *e) in expr_eliminate_yn() argument
257 if (e) switch (e->type) { in expr_eliminate_yn()
259 e->left.expr = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
260 e->right.expr = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
261 if (e->left.expr->type == E_SYMBOL) { in expr_eliminate_yn()
262 if (e->left.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
263 expr_free(e->left.expr); in expr_eliminate_yn()
264 expr_free(e->right.expr); in expr_eliminate_yn()
265 e->type = E_SYMBOL; in expr_eliminate_yn()
266 e->left.sym = &symbol_no; in expr_eliminate_yn()
267 e->right.expr = NULL; in expr_eliminate_yn()
268 return e; in expr_eliminate_yn()
269 } else if (e->left.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
270 free(e->left.expr); in expr_eliminate_yn()
271 tmp = e->right.expr; in expr_eliminate_yn()
272 *e = *(e->right.expr); in expr_eliminate_yn()
274 return e; in expr_eliminate_yn()
277 if (e->right.expr->type == E_SYMBOL) { in expr_eliminate_yn()
278 if (e->right.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
279 expr_free(e->left.expr); in expr_eliminate_yn()
280 expr_free(e->right.expr); in expr_eliminate_yn()
281 e->type = E_SYMBOL; in expr_eliminate_yn()
282 e->left.sym = &symbol_no; in expr_eliminate_yn()
283 e->right.expr = NULL; in expr_eliminate_yn()
284 return e; in expr_eliminate_yn()
285 } else if (e->right.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
286 free(e->right.expr); in expr_eliminate_yn()
287 tmp = e->left.expr; in expr_eliminate_yn()
288 *e = *(e->left.expr); in expr_eliminate_yn()
290 return e; in expr_eliminate_yn()
295 e->left.expr = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
296 e->right.expr = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
297 if (e->left.expr->type == E_SYMBOL) { in expr_eliminate_yn()
298 if (e->left.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
299 free(e->left.expr); in expr_eliminate_yn()
300 tmp = e->right.expr; in expr_eliminate_yn()
301 *e = *(e->right.expr); in expr_eliminate_yn()
303 return e; in expr_eliminate_yn()
304 } else if (e->left.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
305 expr_free(e->left.expr); in expr_eliminate_yn()
306 expr_free(e->right.expr); in expr_eliminate_yn()
307 e->type = E_SYMBOL; in expr_eliminate_yn()
308 e->left.sym = &symbol_yes; in expr_eliminate_yn()
309 e->right.expr = NULL; in expr_eliminate_yn()
310 return e; in expr_eliminate_yn()
313 if (e->right.expr->type == E_SYMBOL) { in expr_eliminate_yn()
314 if (e->right.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
315 free(e->right.expr); in expr_eliminate_yn()
316 tmp = e->left.expr; in expr_eliminate_yn()
317 *e = *(e->left.expr); in expr_eliminate_yn()
319 return e; in expr_eliminate_yn()
320 } else if (e->right.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
321 expr_free(e->left.expr); in expr_eliminate_yn()
322 expr_free(e->right.expr); in expr_eliminate_yn()
323 e->type = E_SYMBOL; in expr_eliminate_yn()
324 e->left.sym = &symbol_yes; in expr_eliminate_yn()
325 e->right.expr = NULL; in expr_eliminate_yn()
326 return e; in expr_eliminate_yn()
333 return e; in expr_eliminate_yn()
339 struct expr *expr_trans_bool(struct expr *e) in expr_trans_bool() argument
341 if (!e) in expr_trans_bool()
343 switch (e->type) { in expr_trans_bool()
347 e->left.expr = expr_trans_bool(e->left.expr); in expr_trans_bool()
348 e->right.expr = expr_trans_bool(e->right.expr); in expr_trans_bool()
352 if (e->left.sym->type == S_TRISTATE) { in expr_trans_bool()
353 if (e->right.sym == &symbol_no) { in expr_trans_bool()
354 e->type = E_SYMBOL; in expr_trans_bool()
355 e->right.sym = NULL; in expr_trans_bool()
362 return e; in expr_trans_bool()
578 struct expr *expr_eliminate_dups(struct expr *e) in expr_eliminate_dups() argument
581 if (!e) in expr_eliminate_dups()
582 return e; in expr_eliminate_dups()
587 switch (e->type) { in expr_eliminate_dups()
589 expr_eliminate_dups1(e->type, &e, &e); in expr_eliminate_dups()
595 e = expr_eliminate_yn(e); in expr_eliminate_dups()
598 return e; in expr_eliminate_dups()
601 struct expr *expr_transform(struct expr *e) in expr_transform() argument
605 if (!e) in expr_transform()
607 switch (e->type) { in expr_transform()
618 e->left.expr = expr_transform(e->left.expr); in expr_transform()
619 e->right.expr = expr_transform(e->right.expr); in expr_transform()
622 switch (e->type) { in expr_transform()
624 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
626 if (e->right.sym == &symbol_no) { in expr_transform()
627 e->type = E_NOT; in expr_transform()
628 e->left.expr = expr_alloc_symbol(e->left.sym); in expr_transform()
629 e->right.sym = NULL; in expr_transform()
632 if (e->right.sym == &symbol_mod) { in expr_transform()
633 printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e->left.sym->name); in expr_transform()
634 e->type = E_SYMBOL; in expr_transform()
635 e->left.sym = &symbol_no; in expr_transform()
636 e->right.sym = NULL; in expr_transform()
639 if (e->right.sym == &symbol_yes) { in expr_transform()
640 e->type = E_SYMBOL; in expr_transform()
641 e->right.sym = NULL; in expr_transform()
646 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
648 if (e->right.sym == &symbol_no) { in expr_transform()
649 e->type = E_SYMBOL; in expr_transform()
650 e->right.sym = NULL; in expr_transform()
653 if (e->right.sym == &symbol_mod) { in expr_transform()
654 printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e->left.sym->name); in expr_transform()
655 e->type = E_SYMBOL; in expr_transform()
656 e->left.sym = &symbol_yes; in expr_transform()
657 e->right.sym = NULL; in expr_transform()
660 if (e->right.sym == &symbol_yes) { in expr_transform()
661 e->type = E_NOT; in expr_transform()
662 e->left.expr = expr_alloc_symbol(e->left.sym); in expr_transform()
663 e->right.sym = NULL; in expr_transform()
668 switch (e->left.expr->type) { in expr_transform()
671 tmp = e->left.expr->left.expr; in expr_transform()
672 free(e->left.expr); in expr_transform()
673 free(e); in expr_transform()
674 e = tmp; in expr_transform()
675 e = expr_transform(e); in expr_transform()
680 tmp = e->left.expr; in expr_transform()
681 free(e); in expr_transform()
682 e = tmp; in expr_transform()
683 e->type = e->type == E_EQUAL ? E_UNEQUAL : E_EQUAL; in expr_transform()
688 tmp = e->left.expr; in expr_transform()
689 free(e); in expr_transform()
690 e = tmp; in expr_transform()
691 e->type = e->type == E_LEQ ? E_GTH : E_LTH; in expr_transform()
696 tmp = e->left.expr; in expr_transform()
697 free(e); in expr_transform()
698 e = tmp; in expr_transform()
699 e->type = e->type == E_LTH ? E_GEQ : E_LEQ; in expr_transform()
703 tmp = e->left.expr; in expr_transform()
704 e->type = E_AND; in expr_transform()
705 e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); in expr_transform()
708 e = expr_transform(e); in expr_transform()
712 tmp = e->left.expr; in expr_transform()
713 e->type = E_OR; in expr_transform()
714 e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); in expr_transform()
717 e = expr_transform(e); in expr_transform()
720 if (e->left.expr->left.sym == &symbol_yes) { in expr_transform()
722 tmp = e->left.expr; in expr_transform()
723 free(e); in expr_transform()
724 e = tmp; in expr_transform()
725 e->type = E_SYMBOL; in expr_transform()
726 e->left.sym = &symbol_no; in expr_transform()
729 if (e->left.expr->left.sym == &symbol_mod) { in expr_transform()
731 tmp = e->left.expr; in expr_transform()
732 free(e); in expr_transform()
733 e = tmp; in expr_transform()
734 e->type = E_SYMBOL; in expr_transform()
735 e->left.sym = &symbol_mod; in expr_transform()
738 if (e->left.expr->left.sym == &symbol_no) { in expr_transform()
740 tmp = e->left.expr; in expr_transform()
741 free(e); in expr_transform()
742 e = tmp; in expr_transform()
743 e->type = E_SYMBOL; in expr_transform()
744 e->left.sym = &symbol_yes; in expr_transform()
755 return e; in expr_transform()
815 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym) in expr_trans_compare() argument
819 if (!e) { in expr_trans_compare()
820 e = expr_alloc_symbol(sym); in expr_trans_compare()
822 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
823 return e; in expr_trans_compare()
825 switch (e->type) { in expr_trans_compare()
827 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
828 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
830 e = expr_alloc_two(E_AND, e1, e2); in expr_trans_compare()
832 e = expr_alloc_two(E_OR, e1, e2); in expr_trans_compare()
834 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
835 return e; in expr_trans_compare()
837 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
838 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
840 e = expr_alloc_two(E_OR, e1, e2); in expr_trans_compare()
842 e = expr_alloc_two(E_AND, e1, e2); in expr_trans_compare()
844 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
845 return e; in expr_trans_compare()
847 return expr_trans_compare(e->left.expr, type == E_EQUAL ? E_UNEQUAL : E_EQUAL, sym); in expr_trans_compare()
856 return expr_copy(e); in expr_trans_compare()
860 return expr_alloc_one(E_NOT, expr_copy(e)); in expr_trans_compare()
863 return expr_alloc_one(E_NOT, expr_copy(e)); in expr_trans_compare()
867 return expr_copy(e); in expr_trans_compare()
871 return expr_alloc_comp(type, e->left.sym, sym); in expr_trans_compare()
924 tristate expr_calc_value(struct expr *e) in expr_calc_value() argument
932 if (!e) in expr_calc_value()
935 switch (e->type) { in expr_calc_value()
937 sym_calc_value(e->left.sym); in expr_calc_value()
938 return e->left.sym->curr.tri; in expr_calc_value()
940 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
941 val2 = expr_calc_value(e->right.expr); in expr_calc_value()
944 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
945 val2 = expr_calc_value(e->right.expr); in expr_calc_value()
948 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
958 printf("expr_calc_value: %d?\n", e->type); in expr_calc_value()
962 sym_calc_value(e->left.sym); in expr_calc_value()
963 sym_calc_value(e->right.sym); in expr_calc_value()
964 str1 = sym_get_string_value(e->left.sym); in expr_calc_value()
965 str2 = sym_get_string_value(e->right.sym); in expr_calc_value()
967 if (e->left.sym->type != S_STRING || e->right.sym->type != S_STRING) { in expr_calc_value()
968 k1 = expr_parse_string(str1, e->left.sym->type, &lval); in expr_calc_value()
969 k2 = expr_parse_string(str2, e->right.sym->type, &rval); in expr_calc_value()
975 if (e->type != E_EQUAL && e->type != E_UNEQUAL) { in expr_calc_value()
985 switch(e->type) { in expr_calc_value()
999 printf("expr_calc_value: relation %d?\n", e->type); in expr_calc_value()
1039 expr_get_leftmost_symbol(const struct expr *e) in expr_get_leftmost_symbol() argument
1042 if (e == NULL) in expr_get_leftmost_symbol()
1045 while (e->type != E_SYMBOL) in expr_get_leftmost_symbol()
1046 e = e->left.expr; in expr_get_leftmost_symbol()
1048 return expr_copy(e); in expr_get_leftmost_symbol()
1065 struct expr *e; in expr_simplify_unmet_dep() local
1066 e = expr_alloc_and(expr_copy(e1), expr_copy(e2)); in expr_simplify_unmet_dep()
1067 e = expr_eliminate_dups(e); in expr_simplify_unmet_dep()
1068 ret = (!expr_eq(e, e1)) ? e1 : NULL; in expr_simplify_unmet_dep()
1069 expr_free(e); in expr_simplify_unmet_dep()
1080 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int … in expr_print() argument
1082 if (!e) { in expr_print()
1087 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1089 switch (e->type) { in expr_print()
1091 if (e->left.sym->name) in expr_print()
1092 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1098 expr_print(e->left.expr, fn, data, E_NOT); in expr_print()
1101 if (e->left.sym->name) in expr_print()
1102 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1106 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1110 if (e->left.sym->name) in expr_print()
1111 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1114 fn(data, NULL, e->type == E_LEQ ? "<=" : "<"); in expr_print()
1115 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1119 if (e->left.sym->name) in expr_print()
1120 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1123 fn(data, NULL, e->type == E_GEQ ? ">=" : ">"); in expr_print()
1124 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1127 if (e->left.sym->name) in expr_print()
1128 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1132 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1135 expr_print(e->left.expr, fn, data, E_OR); in expr_print()
1137 expr_print(e->right.expr, fn, data, E_OR); in expr_print()
1140 expr_print(e->left.expr, fn, data, E_AND); in expr_print()
1142 expr_print(e->right.expr, fn, data, E_AND); in expr_print()
1145 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1146 if (e->left.expr) { in expr_print()
1148 expr_print(e->left.expr, fn, data, E_LIST); in expr_print()
1153 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1155 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1161 sprintf(buf, "<unknown type %d>", e->type); in expr_print()
1166 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1175 void expr_fprint(struct expr *e, FILE *out) in expr_fprint() argument
1177 expr_print(e, expr_print_file_helper, out, E_NONE); in expr_fprint()
1210 void expr_gstr_print(struct expr *e, struct gstr *gs) in expr_gstr_print() argument
1212 expr_print(e, expr_print_gstr_helper, gs, E_NONE); in expr_gstr_print()