-rw-r--r-- | scripts/kconfig/expr.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index d1af2a5..3f15ae8 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c | |||
@@ -50,16 +50,23 @@ struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symb | |||
50 | 50 | ||
51 | struct expr *expr_alloc_and(struct expr *e1, struct expr *e2) | 51 | struct expr *expr_alloc_and(struct expr *e1, struct expr *e2) |
52 | { | 52 | { |
53 | if (!e1) | 53 | if (!e1) |
54 | return e2; | 54 | return e2; |
55 | return e2 ? expr_alloc_two(E_AND, e1, e2) : e1; | 55 | return e2 ? expr_alloc_two(E_AND, e1, e2) : e1; |
56 | } | 56 | } |
57 | 57 | ||
58 | struct expr *expr_alloc_or(struct expr *e1, struct expr *e2) | ||
59 | { | ||
60 | if (!e1) | ||
61 | return e2; | ||
62 | return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; | ||
63 | } | ||
64 | |||
58 | struct expr *expr_copy(struct expr *org) | 65 | struct expr *expr_copy(struct expr *org) |
59 | { | 66 | { |
60 | struct expr *e; | 67 | struct expr *e; |
61 | 68 | ||
62 | if (!org) | 69 | if (!org) |
63 | return NULL; | 70 | return NULL; |
64 | 71 | ||
65 | e = malloc(sizeof(*org)); | 72 | e = malloc(sizeof(*org)); |
@@ -153,19 +160,32 @@ static void __expr_eliminate_eq(enum expr_type type, struct expr **ep1, struct e | |||
153 | break; | 160 | break; |
154 | default: | 161 | default: |
155 | ; | 162 | ; |
156 | } | 163 | } |
157 | } | 164 | } |
158 | 165 | ||
159 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2) | 166 | void expr_eliminate_eq(struct expr **ep1, struct expr **ep2) |
160 | { | 167 | { |
161 | if (!e1 || !e2 || e1->type != e2->type) | 168 | if (!e1 || !e2) |
162 | return; | 169 | return; |
163 | __expr_eliminate_eq(e1->type, ep1, ep2); | 170 | switch (e1->type) { |
171 | case E_OR: | ||
172 | case E_AND: | ||
173 | __expr_eliminate_eq(e1->type, ep1, ep2); | ||
174 | default: | ||
175 | ; | ||
176 | } | ||
177 | if (e1->type != e2->type) switch (e2->type) { | ||
178 | case E_OR: | ||
179 | case E_AND: | ||
180 | __expr_eliminate_eq(e2->type, ep1, ep2); | ||
181 | default: | ||
182 | ; | ||
183 | } | ||
164 | e1 = expr_eliminate_yn(e1); | 184 | e1 = expr_eliminate_yn(e1); |
165 | e2 = expr_eliminate_yn(e2); | 185 | e2 = expr_eliminate_yn(e2); |
166 | } | 186 | } |
167 | 187 | ||
168 | #undef e1 | 188 | #undef e1 |
169 | #undef e2 | 189 | #undef e2 |
170 | 190 | ||
171 | int expr_eq(struct expr *e1, struct expr *e2) | 191 | int expr_eq(struct expr *e1, struct expr *e2) |
@@ -190,16 +210,17 @@ int expr_eq(struct expr *e1, struct expr *e2) | |||
190 | expr_eliminate_eq(&e1, &e2); | 210 | expr_eliminate_eq(&e1, &e2); |
191 | res = (e1->type == E_SYMBOL && e2->type == E_SYMBOL && | 211 | res = (e1->type == E_SYMBOL && e2->type == E_SYMBOL && |
192 | e1->left.sym == e2->left.sym); | 212 | e1->left.sym == e2->left.sym); |
193 | expr_free(e1); | 213 | expr_free(e1); |
194 | expr_free(e2); | 214 | expr_free(e2); |
195 | trans_count = old_count; | 215 | trans_count = old_count; |
196 | return res; | 216 | return res; |
197 | case E_CHOICE: | 217 | case E_CHOICE: |
218 | case E_RANGE: | ||
198 | case E_NONE: | 219 | case E_NONE: |
199 | /* panic */; | 220 | /* panic */; |
200 | } | 221 | } |
201 | 222 | ||
202 | print_expr(0, e1, 0); | 223 | print_expr(0, e1, 0); |
203 | printf(" = "); | 224 | printf(" = "); |
204 | print_expr(0, e2, 0); | 225 | print_expr(0, e2, 0); |
205 | printf(" ?\n"); | 226 | printf(" ?\n"); |
@@ -892,16 +913,17 @@ struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symb | |||
892 | return expr_alloc_symbol(&symbol_yes); | 913 | return expr_alloc_symbol(&symbol_yes); |
893 | if (sym == &symbol_no) | 914 | if (sym == &symbol_no) |
894 | return expr_copy(e); | 915 | return expr_copy(e); |
895 | } | 916 | } |
896 | break; | 917 | break; |
897 | case E_SYMBOL: | 918 | case E_SYMBOL: |
898 | return expr_alloc_comp(type, e->left.sym, sym); | 919 | return expr_alloc_comp(type, e->left.sym, sym); |
899 | case E_CHOICE: | 920 | case E_CHOICE: |
921 | case E_RANGE: | ||
900 | case E_NONE: | 922 | case E_NONE: |
901 | /* panic */; | 923 | /* panic */; |
902 | } | 924 | } |
903 | return NULL; | 925 | return NULL; |
904 | } | 926 | } |
905 | 927 | ||
906 | tristate expr_calc_value(struct expr *e) | 928 | tristate expr_calc_value(struct expr *e) |
907 | { | 929 | { |
@@ -909,17 +931,17 @@ tristate expr_calc_value(struct expr *e) | |||
909 | const char *str1, *str2; | 931 | const char *str1, *str2; |
910 | 932 | ||
911 | if (!e) | 933 | if (!e) |
912 | return yes; | 934 | return yes; |
913 | 935 | ||
914 | switch (e->type) { | 936 | switch (e->type) { |
915 | case E_SYMBOL: | 937 | case E_SYMBOL: |
916 | sym_calc_value(e->left.sym); | 938 | sym_calc_value(e->left.sym); |
917 | return S_TRI(e->left.sym->curr); | 939 | return e->left.sym->curr.tri; |
918 | case E_AND: | 940 | case E_AND: |
919 | val1 = expr_calc_value(e->left.expr); | 941 | val1 = expr_calc_value(e->left.expr); |
920 | val2 = expr_calc_value(e->right.expr); | 942 | val2 = expr_calc_value(e->right.expr); |
921 | return E_AND(val1, val2); | 943 | return E_AND(val1, val2); |
922 | case E_OR: | 944 | case E_OR: |
923 | val1 = expr_calc_value(e->left.expr); | 945 | val1 = expr_calc_value(e->left.expr); |
924 | val2 = expr_calc_value(e->right.expr); | 946 | val2 = expr_calc_value(e->right.expr); |
925 | return E_OR(val1, val2); | 947 | return E_OR(val1, val2); |
@@ -1012,21 +1034,28 @@ void expr_print(struct expr *e, void (*fn)(void *, const char *), void *data, in | |||
1012 | expr_print(e->right.expr, fn, data, E_OR); | 1034 | expr_print(e->right.expr, fn, data, E_OR); |
1013 | break; | 1035 | break; |
1014 | case E_AND: | 1036 | case E_AND: |
1015 | expr_print(e->left.expr, fn, data, E_AND); | 1037 | expr_print(e->left.expr, fn, data, E_AND); |
1016 | fn(data, " && "); | 1038 | fn(data, " && "); |
1017 | expr_print(e->right.expr, fn, data, E_AND); | 1039 | expr_print(e->right.expr, fn, data, E_AND); |
1018 | break; | 1040 | break; |
1019 | case E_CHOICE: | 1041 | case E_CHOICE: |
1042 | fn(data, e->right.sym->name); | ||
1020 | if (e->left.expr) { | 1043 | if (e->left.expr) { |
1021 | expr_print(e->left.expr, fn, data, E_CHOICE); | ||
1022 | fn(data, " ^ "); | 1044 | fn(data, " ^ "); |
1045 | expr_print(e->left.expr, fn, data, E_CHOICE); | ||
1023 | } | 1046 | } |
1047 | break; | ||
1048 | case E_RANGE: | ||
1049 | fn(data, "["); | ||
1050 | fn(data, e->left.sym->name); | ||
1051 | fn(data, " "); | ||
1024 | fn(data, e->right.sym->name); | 1052 | fn(data, e->right.sym->name); |
1053 | fn(data, "]"); | ||
1025 | break; | 1054 | break; |
1026 | default: | 1055 | default: |
1027 | { | 1056 | { |
1028 | char buf[32]; | 1057 | char buf[32]; |
1029 | sprintf(buf, "<unknown type %d>", e->type); | 1058 | sprintf(buf, "<unknown type %d>", e->type); |
1030 | fn(data, buf); | 1059 | fn(data, buf); |
1031 | break; | 1060 | break; |
1032 | } | 1061 | } |