Lines Matching +full:left +full:-
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
24 * expr_lookup - return the expression with the given type and sub-nodes
25 * This looks up an expression with the specified type and sub-nodes. If such
29 * @l: left node
41 if (e->type == type && e->left._initdata == l && in expr_lookup()
42 e->right._initdata == r) in expr_lookup()
47 e->type = type; in expr_lookup()
48 e->left._initdata = l; in expr_lookup()
49 e->right._initdata = r; in expr_lookup()
50 e->val_is_valid = false; in expr_lookup()
52 hash_add(expr_hashtable, &e->node, hash); in expr_lookup()
107 if ((*ep1)->type == type) { in __expr_eliminate_eq()
108 l = (*ep1)->left.expr; in __expr_eliminate_eq()
109 r = (*ep1)->right.expr; in __expr_eliminate_eq()
115 if ((*ep2)->type == type) { in __expr_eliminate_eq()
116 l = (*ep2)->left.expr; in __expr_eliminate_eq()
117 r = (*ep2)->right.expr; in __expr_eliminate_eq()
126 if ((*ep1)->type == E_SYMBOL && (*ep2)->type == E_SYMBOL && in __expr_eliminate_eq()
127 (*ep1)->left.sym == (*ep2)->left.sym && in __expr_eliminate_eq()
128 ((*ep1)->left.sym == &symbol_yes || (*ep1)->left.sym == &symbol_no)) in __expr_eliminate_eq()
154 * ep1: A && B -> ep1: y
155 * ep2: A && B && C -> ep2: C
157 * ep1: A || B -> ep1: n
158 * ep2: A || B || C -> ep2: C
160 * ep1: A && (B && FOO) -> ep1: FOO
161 * ep2: (BAR && B) && A -> ep2: BAR
163 * ep1: A && (B || C) -> ep1: y
164 * ep2: (C || B) && A -> ep2: y
170 * - 'e1', 'e2 || e3', and 'e4 || e5', against each other
171 * - e2 against e3
172 * - e4 against e5
183 switch ((*ep1)->type) { in expr_eliminate_eq()
186 __expr_eliminate_eq((*ep1)->type, ep1, ep2); in expr_eliminate_eq()
190 if ((*ep1)->type != (*ep2)->type) switch ((*ep2)->type) { in expr_eliminate_eq()
193 __expr_eliminate_eq((*ep2)->type, ep1, ep2); in expr_eliminate_eq()
219 if (e1->type != e2->type) in expr_eq()
221 switch (e1->type) { in expr_eq()
228 return e1->left.sym == e2->left.sym && e1->right.sym == e2->right.sym; in expr_eq()
230 return e1->left.sym == e2->left.sym; in expr_eq()
232 return expr_eq(e1->left.expr, e2->left.expr); in expr_eq()
237 res = (e1->type == E_SYMBOL && e2->type == E_SYMBOL && in expr_eq()
238 e1->left.sym == e2->left.sym); in expr_eq()
260 * expr && n -> n
261 * expr && y -> expr
262 * expr || n -> expr
263 * expr || y -> y
271 if (e) switch (e->type) { in expr_eliminate_yn()
273 l = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
274 r = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
275 if (l->type == E_SYMBOL) { in expr_eliminate_yn()
276 if (l->left.sym == &symbol_no) in expr_eliminate_yn()
278 else if (l->left.sym == &symbol_yes) in expr_eliminate_yn()
281 if (r->type == E_SYMBOL) { in expr_eliminate_yn()
282 if (r->left.sym == &symbol_no) in expr_eliminate_yn()
284 else if (r->left.sym == &symbol_yes) in expr_eliminate_yn()
289 l = expr_eliminate_yn(e->left.expr); in expr_eliminate_yn()
290 r = expr_eliminate_yn(e->right.expr); in expr_eliminate_yn()
291 if (l->type == E_SYMBOL) { in expr_eliminate_yn()
292 if (l->left.sym == &symbol_no) in expr_eliminate_yn()
294 else if (l->left.sym == &symbol_yes) in expr_eliminate_yn()
297 if (r->type == E_SYMBOL) { in expr_eliminate_yn()
298 if (r->left.sym == &symbol_no) in expr_eliminate_yn()
300 else if (r->left.sym == &symbol_yes) in expr_eliminate_yn()
311 * e1 || e2 -> ?
320 if (e1->type != E_EQUAL && e1->type != E_UNEQUAL && e1->type != E_SYMBOL && e1->type != E_NOT) in expr_join_or()
322 if (e2->type != E_EQUAL && e2->type != E_UNEQUAL && e2->type != E_SYMBOL && e2->type != E_NOT) in expr_join_or()
324 if (e1->type == E_NOT) { in expr_join_or()
325 tmp = e1->left.expr; in expr_join_or()
326 if (tmp->type != E_EQUAL && tmp->type != E_UNEQUAL && tmp->type != E_SYMBOL) in expr_join_or()
328 sym1 = tmp->left.sym; in expr_join_or()
330 sym1 = e1->left.sym; in expr_join_or()
331 if (e2->type == E_NOT) { in expr_join_or()
332 if (e2->left.expr->type != E_SYMBOL) in expr_join_or()
334 sym2 = e2->left.expr->left.sym; in expr_join_or()
336 sym2 = e2->left.sym; in expr_join_or()
339 if (sym1->type != S_BOOLEAN && sym1->type != S_TRISTATE) in expr_join_or()
341 if (sym1->type == S_TRISTATE) { in expr_join_or()
342 if (e1->type == E_EQUAL && e2->type == E_EQUAL && in expr_join_or()
343 ((e1->right.sym == &symbol_yes && e2->right.sym == &symbol_mod) || in expr_join_or()
344 (e1->right.sym == &symbol_mod && e2->right.sym == &symbol_yes))) { in expr_join_or()
345 // (a='y') || (a='m') -> (a!='n') in expr_join_or()
348 if (e1->type == E_EQUAL && e2->type == E_EQUAL && in expr_join_or()
349 ((e1->right.sym == &symbol_yes && e2->right.sym == &symbol_no) || in expr_join_or()
350 (e1->right.sym == &symbol_no && e2->right.sym == &symbol_yes))) { in expr_join_or()
351 // (a='y') || (a='n') -> (a!='m') in expr_join_or()
354 if (e1->type == E_EQUAL && e2->type == E_EQUAL && in expr_join_or()
355 ((e1->right.sym == &symbol_mod && e2->right.sym == &symbol_no) || in expr_join_or()
356 (e1->right.sym == &symbol_no && e2->right.sym == &symbol_mod))) { in expr_join_or()
357 // (a='m') || (a='n') -> (a!='y') in expr_join_or()
361 if (sym1->type == S_BOOLEAN) { in expr_join_or()
362 // a || !a -> y in expr_join_or()
363 if ((e1->type == E_NOT && e1->left.expr->type == E_SYMBOL && e2->type == E_SYMBOL) || in expr_join_or()
364 (e2->type == E_NOT && e2->left.expr->type == E_SYMBOL && e1->type == E_SYMBOL)) in expr_join_or()
385 if (e1->type != E_EQUAL && e1->type != E_UNEQUAL && e1->type != E_SYMBOL && e1->type != E_NOT) in expr_join_and()
387 if (e2->type != E_EQUAL && e2->type != E_UNEQUAL && e2->type != E_SYMBOL && e2->type != E_NOT) in expr_join_and()
389 if (e1->type == E_NOT) { in expr_join_and()
390 tmp = e1->left.expr; in expr_join_and()
391 if (tmp->type != E_EQUAL && tmp->type != E_UNEQUAL && tmp->type != E_SYMBOL) in expr_join_and()
393 sym1 = tmp->left.sym; in expr_join_and()
395 sym1 = e1->left.sym; in expr_join_and()
396 if (e2->type == E_NOT) { in expr_join_and()
397 if (e2->left.expr->type != E_SYMBOL) in expr_join_and()
399 sym2 = e2->left.expr->left.sym; in expr_join_and()
401 sym2 = e2->left.sym; in expr_join_and()
404 if (sym1->type != S_BOOLEAN && sym1->type != S_TRISTATE) in expr_join_and()
407 if ((e1->type == E_SYMBOL && e2->type == E_EQUAL && e2->right.sym == &symbol_yes) || in expr_join_and()
408 (e2->type == E_SYMBOL && e1->type == E_EQUAL && e1->right.sym == &symbol_yes)) in expr_join_and()
409 // (a) && (a='y') -> (a='y') in expr_join_and()
412 if ((e1->type == E_SYMBOL && e2->type == E_UNEQUAL && e2->right.sym == &symbol_no) || in expr_join_and()
413 (e2->type == E_SYMBOL && e1->type == E_UNEQUAL && e1->right.sym == &symbol_no)) in expr_join_and()
414 // (a) && (a!='n') -> (a) in expr_join_and()
417 if ((e1->type == E_SYMBOL && e2->type == E_UNEQUAL && e2->right.sym == &symbol_mod) || in expr_join_and()
418 (e2->type == E_SYMBOL && e1->type == E_UNEQUAL && e1->right.sym == &symbol_mod)) in expr_join_and()
419 // (a) && (a!='m') -> (a='y') in expr_join_and()
422 if (sym1->type == S_TRISTATE) { in expr_join_and()
423 if (e1->type == E_EQUAL && e2->type == E_UNEQUAL) { in expr_join_and()
424 // (a='b') && (a!='c') -> 'b'='c' ? 'n' : a='b' in expr_join_and()
425 sym2 = e1->right.sym; in expr_join_and()
426 if ((e2->right.sym->flags & SYMBOL_CONST) && (sym2->flags & SYMBOL_CONST)) in expr_join_and()
427 return sym2 != e2->right.sym ? expr_alloc_comp(E_EQUAL, sym1, sym2) in expr_join_and()
430 if (e1->type == E_UNEQUAL && e2->type == E_EQUAL) { in expr_join_and()
431 // (a='b') && (a!='c') -> 'b'='c' ? 'n' : a='b' in expr_join_and()
432 sym2 = e2->right.sym; in expr_join_and()
433 if ((e1->right.sym->flags & SYMBOL_CONST) && (sym2->flags & SYMBOL_CONST)) in expr_join_and()
434 return sym2 != e1->right.sym ? expr_alloc_comp(E_EQUAL, sym1, sym2) in expr_join_and()
437 if (e1->type == E_UNEQUAL && e2->type == E_UNEQUAL && in expr_join_and()
438 ((e1->right.sym == &symbol_yes && e2->right.sym == &symbol_no) || in expr_join_and()
439 (e1->right.sym == &symbol_no && e2->right.sym == &symbol_yes))) in expr_join_and()
440 // (a!='y') && (a!='n') -> (a='m') in expr_join_and()
443 if (e1->type == E_UNEQUAL && e2->type == E_UNEQUAL && in expr_join_and()
444 ((e1->right.sym == &symbol_yes && e2->right.sym == &symbol_mod) || in expr_join_and()
445 (e1->right.sym == &symbol_mod && e2->right.sym == &symbol_yes))) in expr_join_and()
446 // (a!='y') && (a!='m') -> (a='n') in expr_join_and()
449 if (e1->type == E_UNEQUAL && e2->type == E_UNEQUAL && in expr_join_and()
450 ((e1->right.sym == &symbol_mod && e2->right.sym == &symbol_no) || in expr_join_and()
451 (e1->right.sym == &symbol_no && e2->right.sym == &symbol_mod))) in expr_join_and()
452 // (a!='m') && (a!='n') -> (a='m') in expr_join_and()
455 if ((e1->type == E_SYMBOL && e2->type == E_EQUAL && e2->right.sym == &symbol_mod) || in expr_join_and()
456 (e2->type == E_SYMBOL && e1->type == E_EQUAL && e1->right.sym == &symbol_mod) || in expr_join_and()
457 (e1->type == E_SYMBOL && e2->type == E_UNEQUAL && e2->right.sym == &symbol_yes) || in expr_join_and()
458 (e2->type == E_SYMBOL && e1->type == E_UNEQUAL && e1->right.sym == &symbol_yes)) in expr_join_and()
485 if ((*ep1)->type == type) { in expr_eliminate_dups1()
486 l = (*ep1)->left.expr; in expr_eliminate_dups1()
487 r = (*ep1)->right.expr; in expr_eliminate_dups1()
493 if ((*ep2)->type == type) { in expr_eliminate_dups1()
494 l = (*ep2)->left.expr; in expr_eliminate_dups1()
495 r = (*ep2)->right.expr; in expr_eliminate_dups1()
527 * Rewrites 'e' in-place to remove ("join") duplicate and other redundant
532 * A || B || A -> A || B
533 * A && B && A=y -> A=y && B
548 switch (e->type) { in expr_eliminate_dups()
550 l = expr_eliminate_dups(e->left.expr); in expr_eliminate_dups()
551 r = expr_eliminate_dups(e->right.expr); in expr_eliminate_dups()
552 expr_eliminate_dups1(e->type, &l, &r); in expr_eliminate_dups()
553 e = expr_alloc_two(e->type, l, r); in expr_eliminate_dups()
568 * A=n -> !A
569 * A=m -> n
570 * A=y -> A
571 * A!=n -> A
572 * A!=m -> y
573 * A!=y -> !A
576 * !!A -> A
577 * !(A=B) -> A!=B
578 * !(A!=B) -> A=B
579 * !(A<=B) -> A>B
580 * !(A>=B) -> A<B
581 * !(A<B) -> A>=B
582 * !(A>B) -> A<=B
583 * !(A || B) -> !A && !B
584 * !(A && B) -> !A || !B
587 * !y -> n
588 * !m -> m
589 * !n -> y
597 switch (e->type) { in expr_transform()
607 e = expr_alloc_two(e->type, in expr_transform()
608 expr_transform(e->left.expr), in expr_transform()
609 expr_transform(e->right.expr)); in expr_transform()
612 switch (e->type) { in expr_transform()
614 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
616 if (e->right.sym == &symbol_no) { in expr_transform()
617 // A=n -> !A in expr_transform()
618 e = expr_alloc_one(E_NOT, expr_alloc_symbol(e->left.sym)); in expr_transform()
621 if (e->right.sym == &symbol_mod) { in expr_transform()
622 // A=m -> n in expr_transform()
623 printf("boolean symbol %s tested for 'm'? test forced to 'n'\n", e->left.sym->name); in expr_transform()
627 if (e->right.sym == &symbol_yes) { in expr_transform()
628 // A=y -> A in expr_transform()
629 e = expr_alloc_symbol(e->left.sym); in expr_transform()
634 if (e->left.sym->type != S_BOOLEAN) in expr_transform()
636 if (e->right.sym == &symbol_no) { in expr_transform()
637 // A!=n -> A in expr_transform()
638 e = expr_alloc_symbol(e->left.sym); in expr_transform()
641 if (e->right.sym == &symbol_mod) { in expr_transform()
642 // A!=m -> y in expr_transform()
643 printf("boolean symbol %s tested for 'm'? test forced to 'y'\n", e->left.sym->name); in expr_transform()
647 if (e->right.sym == &symbol_yes) { in expr_transform()
648 // A!=y -> !A in expr_transform()
649 e = expr_alloc_one(E_NOT, e->left.expr); in expr_transform()
654 switch (e->left.expr->type) { in expr_transform()
656 // !!A -> A in expr_transform()
657 e = e->left.expr->left.expr; in expr_transform()
661 // !(A=B) -> A!=B in expr_transform()
662 e = expr_alloc_comp(e->left.expr->type == E_EQUAL ? E_UNEQUAL : E_EQUAL, in expr_transform()
663 e->left.expr->left.sym, in expr_transform()
664 e->left.expr->right.sym); in expr_transform()
668 // !(A<=B) -> A>B in expr_transform()
669 e = expr_alloc_comp(e->left.expr->type == E_LEQ ? E_GTH : E_LTH, in expr_transform()
670 e->left.expr->left.sym, in expr_transform()
671 e->left.expr->right.sym); in expr_transform()
675 // !(A<B) -> A>=B in expr_transform()
676 e = expr_alloc_comp(e->left.expr->type == E_LTH ? E_GEQ : E_LEQ, in expr_transform()
677 e->left.expr->left.sym, in expr_transform()
678 e->left.expr->right.sym); in expr_transform()
681 // !(A || B) -> !A && !B in expr_transform()
682 e = expr_alloc_and(expr_alloc_one(E_NOT, e->left.expr->left.expr), in expr_transform()
683 expr_alloc_one(E_NOT, e->left.expr->right.expr)); in expr_transform()
687 // !(A && B) -> !A || !B in expr_transform()
688 e = expr_alloc_or(expr_alloc_one(E_NOT, e->left.expr->left.expr), in expr_transform()
689 expr_alloc_one(E_NOT, e->left.expr->right.expr)); in expr_transform()
693 if (e->left.expr->left.sym == &symbol_yes) in expr_transform()
694 // !'y' -> 'n' in expr_transform()
696 else if (e->left.expr->left.sym == &symbol_mod) in expr_transform()
697 // !'m' -> 'm' in expr_transform()
699 else if (e->left.expr->left.sym == &symbol_no) in expr_transform()
700 // !'n' -> 'y' in expr_transform()
718 switch (dep->type) { in expr_contains_symbol()
721 return expr_contains_symbol(dep->left.expr, sym) || in expr_contains_symbol()
722 expr_contains_symbol(dep->right.expr, sym); in expr_contains_symbol()
724 return dep->left.sym == sym; in expr_contains_symbol()
731 return dep->left.sym == sym || in expr_contains_symbol()
732 dep->right.sym == sym; in expr_contains_symbol()
734 return expr_contains_symbol(dep->left.expr, sym); in expr_contains_symbol()
746 switch (dep->type) { in expr_depends_symbol()
748 return expr_depends_symbol(dep->left.expr, sym) || in expr_depends_symbol()
749 expr_depends_symbol(dep->right.expr, sym); in expr_depends_symbol()
751 return dep->left.sym == sym; in expr_depends_symbol()
753 if (dep->left.sym == sym) { in expr_depends_symbol()
754 if (dep->right.sym == &symbol_yes || dep->right.sym == &symbol_mod) in expr_depends_symbol()
759 if (dep->left.sym == sym) { in expr_depends_symbol()
760 if (dep->right.sym == &symbol_no) in expr_depends_symbol()
776 * A -> A!=n
777 * !A -> A=n
778 * A && B -> !(A=n || B=n)
779 * A || B -> !(A=n && B=n)
780 * A && (B || C) -> !(A=n || (B=n && C=n))
794 switch (e->type) { in expr_trans_compare()
796 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
797 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
806 e1 = expr_trans_compare(e->left.expr, E_EQUAL, sym); in expr_trans_compare()
807 e2 = expr_trans_compare(e->right.expr, E_EQUAL, sym); in expr_trans_compare()
816 return expr_trans_compare(e->left.expr, type == E_EQUAL ? E_UNEQUAL : E_EQUAL, sym); in expr_trans_compare()
840 return expr_alloc_comp(type, e->left.sym, sym); in expr_trans_compare()
870 val->s = !strcmp(str, "n") ? 0 : in expr_parse_string()
872 !strcmp(str, "y") ? 2 : -1; in expr_parse_string()
875 val->s = strtoll(str, &tail, 10); in expr_parse_string()
879 val->u = strtoull(str, &tail, 16); in expr_parse_string()
883 val->s = strtoll(str, &tail, 0); in expr_parse_string()
887 return !errno && !*tail && tail > str && isxdigit(tail[-1]) in expr_parse_string()
899 switch (e->type) { in __expr_calc_value()
901 sym_calc_value(e->left.sym); in __expr_calc_value()
902 return e->left.sym->curr.tri; in __expr_calc_value()
904 val1 = expr_calc_value(e->left.expr); in __expr_calc_value()
905 val2 = expr_calc_value(e->right.expr); in __expr_calc_value()
908 val1 = expr_calc_value(e->left.expr); in __expr_calc_value()
909 val2 = expr_calc_value(e->right.expr); in __expr_calc_value()
912 val1 = expr_calc_value(e->left.expr); in __expr_calc_value()
922 printf("expr_calc_value: %d?\n", e->type); in __expr_calc_value()
926 sym_calc_value(e->left.sym); in __expr_calc_value()
927 sym_calc_value(e->right.sym); in __expr_calc_value()
928 str1 = sym_get_string_value(e->left.sym); in __expr_calc_value()
929 str2 = sym_get_string_value(e->right.sym); in __expr_calc_value()
931 if (e->left.sym->type != S_STRING || e->right.sym->type != S_STRING) { in __expr_calc_value()
932 k1 = expr_parse_string(str1, e->left.sym->type, &lval); in __expr_calc_value()
933 k2 = expr_parse_string(str2, e->right.sym->type, &rval); in __expr_calc_value()
939 res = (lval.u > rval.u) - (lval.u < rval.u); in __expr_calc_value()
941 res = (lval.s > rval.s) - (lval.s < rval.s); in __expr_calc_value()
943 switch(e->type) { in __expr_calc_value()
957 printf("expr_calc_value: relation %d?\n", e->type); in __expr_calc_value()
963 * expr_calc_value - return the tristate value of the given expression
972 if (!e->val_is_valid) { in expr_calc_value()
973 e->val = __expr_calc_value(e); in expr_calc_value()
974 e->val_is_valid = true; in expr_calc_value()
977 return e->val; in expr_calc_value()
981 * expr_invalidate_all - invalidate all cached expression values
988 e->val_is_valid = false; in expr_invalidate_all()
1031 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1033 switch (e->type) { in expr_print()
1035 if (e->left.sym->name) in expr_print()
1036 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1042 expr_print(e->left.expr, fn, data, E_NOT); in expr_print()
1045 if (e->left.sym->name) in expr_print()
1046 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1050 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1054 if (e->left.sym->name) in expr_print()
1055 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1058 fn(data, NULL, e->type == E_LEQ ? "<=" : "<"); in expr_print()
1059 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1063 if (e->left.sym->name) in expr_print()
1064 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1067 fn(data, NULL, e->type == E_GEQ ? ">=" : ">"); in expr_print()
1068 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1071 if (e->left.sym->name) in expr_print()
1072 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1076 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1079 expr_print(e->left.expr, fn, data, E_OR); in expr_print()
1081 expr_print(e->right.expr, fn, data, E_OR); in expr_print()
1084 expr_print(e->left.expr, fn, data, E_AND); in expr_print()
1086 expr_print(e->right.expr, fn, data, E_AND); in expr_print()
1090 fn(data, e->left.sym, e->left.sym->name); in expr_print()
1092 fn(data, e->right.sym, e->right.sym->name); in expr_print()
1098 sprintf(buf, "<unknown type %d>", e->type); in expr_print()
1103 if (expr_compare_type(prevtoken, e->type) > 0) in expr_print()
1125 if (gs->max_width) { in expr_print_gstr_helper()
1127 const char *last_cr = strrchr(gs->s, '\n'); in expr_print_gstr_helper()
1134 last_cr = gs->s; in expr_print_gstr_helper()
1136 last_line_length = strlen(gs->s) - (last_cr - gs->s); in expr_print_gstr_helper()
1138 if ((last_line_length + extra_length) > gs->max_width) in expr_print_gstr_helper()
1143 if (sym && sym->type != S_UNKNOWN) in expr_print_gstr_helper()
1161 if (e->type == E_OR) { in expr_print_revdep()
1162 expr_print_revdep(e->left.expr, fn, data, pr_type, title); in expr_print_revdep()
1163 expr_print_revdep(e->right.expr, fn, data, pr_type, title); in expr_print_revdep()
1170 fn(data, NULL, " - "); in expr_print_revdep()