Lines Matching refs:e
17 struct expr *e = malloc(sizeof(*e)); in expr_alloc_symbol() local
18 memset(e, 0, sizeof(*e)); in expr_alloc_symbol()
19 e->type = E_SYMBOL; in expr_alloc_symbol()
20 e->left.sym = sym; in expr_alloc_symbol()
21 return e; in expr_alloc_symbol()
26 struct expr *e = malloc(sizeof(*e)); in expr_alloc_one() local
27 memset(e, 0, sizeof(*e)); in expr_alloc_one()
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 = malloc(sizeof(*e)); in expr_alloc_two() local
36 memset(e, 0, sizeof(*e)); in expr_alloc_two()
37 e->type = type; in expr_alloc_two()
38 e->left.expr = e1; in expr_alloc_two()
39 e->right.expr = e2; in expr_alloc_two()
40 return e; in expr_alloc_two()
45 struct expr *e = malloc(sizeof(*e)); in expr_alloc_comp() local
46 memset(e, 0, sizeof(*e)); in expr_alloc_comp()
47 e->type = type; in expr_alloc_comp()
48 e->left.sym = s1; in expr_alloc_comp()
49 e->right.sym = s2; in expr_alloc_comp()
50 return e; in expr_alloc_comp()
69 struct expr *e; in expr_copy() local
74 e = malloc(sizeof(*org)); in expr_copy()
75 memcpy(e, org, sizeof(*org)); in expr_copy()
78 e->left = org->left; in expr_copy()
81 e->left.expr = expr_copy(org->left.expr); in expr_copy()
85 e->left.sym = org->left.sym; in expr_copy()
86 e->right.sym = org->right.sym; in expr_copy()
91 e->left.expr = expr_copy(org->left.expr); in expr_copy()
92 e->right.expr = expr_copy(org->right.expr); in expr_copy()
95 printf("can't copy type %d\n", e->type); in expr_copy()
96 free(e); in expr_copy()
97 e = NULL; in expr_copy()
101 return e; in expr_copy()
104 void expr_free(struct expr *e) in expr_free() argument
106 if (!e) in expr_free()
109 switch (e->type) { in expr_free()
113 expr_free(e->left.expr); in expr_free()
120 expr_free(e->left.expr); in expr_free()
121 expr_free(e->right.expr); in expr_free()
124 printf("how to free type %d?\n", e->type); in expr_free()
127 free(e); in expr_free()
236 struct expr *expr_eliminate_yn(struct expr *e) in expr_eliminate_yn() argument
240 if (e) switch (e->type) { in expr_eliminate_yn()
242 e->left.expr = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
243 e->right.expr = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
244 if (e->left.expr->type == E_SYMBOL) { in expr_eliminate_yn()
245 if (e->left.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
246 expr_free(e->left.expr); in expr_eliminate_yn()
247 expr_free(e->right.expr); in expr_eliminate_yn()
248 e->type = E_SYMBOL; in expr_eliminate_yn()
249 e->left.sym = &symbol_no; in expr_eliminate_yn()
250 e->right.expr = NULL; in expr_eliminate_yn()
251 return e; in expr_eliminate_yn()
252 } else if (e->left.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
253 free(e->left.expr); in expr_eliminate_yn()
254 tmp = e->right.expr; in expr_eliminate_yn()
255 *e = *(e->right.expr); in expr_eliminate_yn()
257 return e; in expr_eliminate_yn()
260 if (e->right.expr->type == E_SYMBOL) { in expr_eliminate_yn()
261 if (e->right.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
262 expr_free(e->left.expr); in expr_eliminate_yn()
263 expr_free(e->right.expr); in expr_eliminate_yn()
264 e->type = E_SYMBOL; in expr_eliminate_yn()
265 e->left.sym = &symbol_no; in expr_eliminate_yn()
266 e->right.expr = NULL; in expr_eliminate_yn()
267 return e; in expr_eliminate_yn()
268 } else if (e->right.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
269 free(e->right.expr); in expr_eliminate_yn()
270 tmp = e->left.expr; in expr_eliminate_yn()
271 *e = *(e->left.expr); in expr_eliminate_yn()
273 return e; in expr_eliminate_yn()
278 e->left.expr = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
279 e->right.expr = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
280 if (e->left.expr->type == E_SYMBOL) { in expr_eliminate_yn()
281 if (e->left.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
282 free(e->left.expr); in expr_eliminate_yn()
283 tmp = e->right.expr; in expr_eliminate_yn()
284 *e = *(e->right.expr); in expr_eliminate_yn()
286 return e; in expr_eliminate_yn()
287 } else if (e->left.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
288 expr_free(e->left.expr); in expr_eliminate_yn()
289 expr_free(e->right.expr); in expr_eliminate_yn()
290 e->type = E_SYMBOL; in expr_eliminate_yn()
291 e->left.sym = &symbol_yes; in expr_eliminate_yn()
292 e->right.expr = NULL; in expr_eliminate_yn()
293 return e; in expr_eliminate_yn()
296 if (e->right.expr->type == E_SYMBOL) { in expr_eliminate_yn()
297 if (e->right.expr->left.sym == &symbol_no) { in expr_eliminate_yn()
298 free(e->right.expr); in expr_eliminate_yn()
299 tmp = e->left.expr; in expr_eliminate_yn()
300 *e = *(e->left.expr); in expr_eliminate_yn()
302 return e; in expr_eliminate_yn()
303 } else if (e->right.expr->left.sym == &symbol_yes) { in expr_eliminate_yn()
304 expr_free(e->left.expr); in expr_eliminate_yn()
305 expr_free(e->right.expr); in expr_eliminate_yn()
306 e->type = E_SYMBOL; in expr_eliminate_yn()
307 e->left.sym = &symbol_yes; in expr_eliminate_yn()
308 e->right.expr = NULL; in expr_eliminate_yn()
309 return e; in expr_eliminate_yn()
316 return e; in expr_eliminate_yn()
322 struct expr *expr_trans_bool(struct expr *e) in expr_trans_bool() argument
324 if (!e) in expr_trans_bool()
326 switch (e->type) { in expr_trans_bool()
330 e->left.expr = expr_trans_bool(e->left.expr); in expr_trans_bool()
331 e->right.expr = expr_trans_bool(e->right.expr); in expr_trans_bool()
335 if (e->left.sym->type == S_TRISTATE) { in expr_trans_bool()
336 if (e->right.sym == &symbol_no) { in expr_trans_bool()
337 e->type = E_SYMBOL; in expr_trans_bool()
338 e->right.sym = NULL; in expr_trans_bool()
345 return e; in expr_trans_bool()
617 struct expr *expr_eliminate_dups(struct expr *e) in expr_eliminate_dups() argument
620 if (!e) in expr_eliminate_dups()
621 return e; in expr_eliminate_dups()
626 switch (e->type) { in expr_eliminate_dups()
628 expr_eliminate_dups1(e->type, &e, &e); in expr_eliminate_dups()
629 expr_eliminate_dups2(e->type, &e, &e); in expr_eliminate_dups()
635 e = expr_eliminate_yn(e); in expr_eliminate_dups()
638 return e; in expr_eliminate_dups()
641 struct expr *expr_transform(struct expr *e) in expr_transform() argument
645 if (!e) in expr_transform()
647 switch (e->type) { in expr_transform()
654 e->left.expr = expr_transform(e->left.expr); in expr_transform()
655 e->right.expr = expr_transform(e->right.expr); in expr_transform()
658 switch (e->type) { in expr_transform()
660 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
662 if (e->right.sym == &symbol_no) { in expr_transform()
663 e->type = E_NOT; in expr_transform()
664 e->left.expr = expr_alloc_symbol(e->left.sym); in expr_transform()
665 e->right.sym = NULL; in expr_transform()
668 if (e->right.sym == &symbol_mod) { in expr_transform()
669 printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e->left.sym->name); in expr_transform()
670 e->type = E_SYMBOL; in expr_transform()
671 e->left.sym = &symbol_no; in expr_transform()
672 e->right.sym = NULL; in expr_transform()
675 if (e->right.sym == &symbol_yes) { in expr_transform()
676 e->type = E_SYMBOL; in expr_transform()
677 e->right.sym = NULL; in expr_transform()
682 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
684 if (e->right.sym == &symbol_no) { in expr_transform()
685 e->type = E_SYMBOL; in expr_transform()
686 e->right.sym = NULL; in expr_transform()
689 if (e->right.sym == &symbol_mod) { in expr_transform()
690 printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e->left.sym->name); in expr_transform()
691 e->type = E_SYMBOL; in expr_transform()
692 e->left.sym = &symbol_yes; in expr_transform()
693 e->right.sym = NULL; in expr_transform()
696 if (e->right.sym == &symbol_yes) { in expr_transform()
697 e->type = E_NOT; in expr_transform()
698 e->left.expr = expr_alloc_symbol(e->left.sym); in expr_transform()
699 e->right.sym = NULL; in expr_transform()
704 switch (e->left.expr->type) { in expr_transform()
707 tmp = e->left.expr->left.expr; in expr_transform()
708 free(e->left.expr); in expr_transform()
709 free(e); in expr_transform()
710 e = tmp; in expr_transform()
711 e = expr_transform(e); in expr_transform()
716 tmp = e->left.expr; in expr_transform()
717 free(e); in expr_transform()
718 e = tmp; in expr_transform()
719 e->type = e->type == E_EQUAL ? E_UNEQUAL : E_EQUAL; in expr_transform()
723 tmp = e->left.expr; in expr_transform()
724 e->type = E_AND; in expr_transform()
725 e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); in expr_transform()
728 e = expr_transform(e); in expr_transform()
732 tmp = e->left.expr; in expr_transform()
733 e->type = E_OR; in expr_transform()
734 e->right.expr = expr_alloc_one(E_NOT, tmp->right.expr); in expr_transform()
737 e = expr_transform(e); in expr_transform()
740 if (e->left.expr->left.sym == &symbol_yes) { in expr_transform()
742 tmp = e->left.expr; in expr_transform()
743 free(e); in expr_transform()
744 e = tmp; in expr_transform()
745 e->type = E_SYMBOL; in expr_transform()
746 e->left.sym = &symbol_no; in expr_transform()
749 if (e->left.expr->left.sym == &symbol_mod) { in expr_transform()
751 tmp = e->left.expr; in expr_transform()
752 free(e); in expr_transform()
753 e = tmp; in expr_transform()
754 e->type = E_SYMBOL; in expr_transform()
755 e->left.sym = &symbol_mod; in expr_transform()
758 if (e->left.expr->left.sym == &symbol_no) { in expr_transform()
760 tmp = e->left.expr; in expr_transform()
761 free(e); in expr_transform()
762 e = tmp; in expr_transform()
763 e->type = E_SYMBOL; in expr_transform()
764 e->left.sym = &symbol_yes; in expr_transform()
775 return e; in expr_transform()
882 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym) in expr_trans_compare() argument
886 if (!e) { in expr_trans_compare()
887 e = expr_alloc_symbol(sym); in expr_trans_compare()
889 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
890 return e; in expr_trans_compare()
892 switch (e->type) { in expr_trans_compare()
894 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
895 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
897 e = expr_alloc_two(E_AND, e1, e2); in expr_trans_compare()
899 e = expr_alloc_two(E_OR, e1, e2); in expr_trans_compare()
901 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
902 return e; in expr_trans_compare()
904 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
905 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
907 e = expr_alloc_two(E_OR, e1, e2); in expr_trans_compare()
909 e = expr_alloc_two(E_AND, e1, e2); in expr_trans_compare()
911 e = expr_alloc_one(E_NOT, e); in expr_trans_compare()
912 return e; in expr_trans_compare()
914 return expr_trans_compare(e->left.expr, type == E_EQUAL ? E_UNEQUAL : E_EQUAL, sym); in expr_trans_compare()
919 return expr_copy(e); in expr_trans_compare()
923 return expr_alloc_one(E_NOT, expr_copy(e)); in expr_trans_compare()
926 return expr_alloc_one(E_NOT, expr_copy(e)); in expr_trans_compare()
930 return expr_copy(e); in expr_trans_compare()
934 return expr_alloc_comp(type, e->left.sym, sym); in expr_trans_compare()
943 tristate expr_calc_value(struct expr *e) in expr_calc_value() argument
948 if (!e) in expr_calc_value()
951 switch (e->type) { in expr_calc_value()
953 sym_calc_value(e->left.sym); in expr_calc_value()
954 return e->left.sym->curr.tri; in expr_calc_value()
956 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
957 val2 = expr_calc_value(e->right.expr); in expr_calc_value()
960 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
961 val2 = expr_calc_value(e->right.expr); in expr_calc_value()
964 val1 = expr_calc_value(e->left.expr); in expr_calc_value()
967 sym_calc_value(e->left.sym); in expr_calc_value()
968 sym_calc_value(e->right.sym); in expr_calc_value()
969 str1 = sym_get_string_value(e->left.sym); in expr_calc_value()
970 str2 = sym_get_string_value(e->right.sym); in expr_calc_value()
973 sym_calc_value(e->left.sym); in expr_calc_value()
974 sym_calc_value(e->right.sym); in expr_calc_value()
975 str1 = sym_get_string_value(e->left.sym); in expr_calc_value()
976 str2 = sym_get_string_value(e->right.sym); in expr_calc_value()
979 printf("expr_calc_value: %d?\n", e->type); in expr_calc_value()
1016 void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int … in expr_print() argument
1018 if (!e) { in expr_print()
1023 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1025 switch (e->type) { in expr_print()
1027 if (e->left.sym->name) in expr_print()
1028 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1034 expr_print(e->left.expr, fn, data, E_NOT); in expr_print()
1037 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1039 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1042 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1044 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1047 expr_print(e->left.expr, fn, data, E_OR); in expr_print()
1049 expr_print(e->right.expr, fn, data, E_OR); in expr_print()
1052 expr_print(e->left.expr, fn, data, E_AND); in expr_print()
1054 expr_print(e->right.expr, fn, data, E_AND); in expr_print()
1057 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1058 if (e->left.expr) { in expr_print()
1060 expr_print(e->left.expr, fn, data, E_CHOICE); in expr_print()
1065 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1067 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1073 sprintf(buf, "<unknown type %d>", e->type); in expr_print()
1078 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1087 void expr_fprint(struct expr *e, FILE *out) in expr_fprint() argument
1089 expr_print(e, expr_print_file_helper, out, E_NONE); in expr_fprint()
1097 void expr_gstr_print(struct expr *e, struct gstr *gs) in expr_gstr_print() argument
1099 expr_print(e, expr_print_gstr_helper, gs, E_NONE); in expr_gstr_print()