diff options
Diffstat (limited to 'scripts/kconfig/expr.c')
-rw-r--r-- | scripts/kconfig/expr.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c index d83f2322893..001003452f6 100644 --- a/scripts/kconfig/expr.c +++ b/scripts/kconfig/expr.c | |||
@@ -64,7 +64,7 @@ struct expr *expr_alloc_or(struct expr *e1, struct expr *e2) | |||
64 | return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; | 64 | return e2 ? expr_alloc_two(E_OR, e1, e2) : e1; |
65 | } | 65 | } |
66 | 66 | ||
67 | struct expr *expr_copy(struct expr *org) | 67 | struct expr *expr_copy(const struct expr *org) |
68 | { | 68 | { |
69 | struct expr *e; | 69 | struct expr *e; |
70 | 70 | ||
@@ -1013,6 +1013,48 @@ int expr_compare_type(enum expr_type t1, enum expr_type t2) | |||
1013 | #endif | 1013 | #endif |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | static inline struct expr * | ||
1017 | expr_get_leftmost_symbol(const struct expr *e) | ||
1018 | { | ||
1019 | |||
1020 | if (e == NULL) | ||
1021 | return NULL; | ||
1022 | |||
1023 | while (e->type != E_SYMBOL) | ||
1024 | e = e->left.expr; | ||
1025 | |||
1026 | return expr_copy(e); | ||
1027 | } | ||
1028 | |||
1029 | /* | ||
1030 | * Given expression `e1' and `e2', returns the leaf of the longest | ||
1031 | * sub-expression of `e1' not containing 'e2. | ||
1032 | */ | ||
1033 | struct expr *expr_simplify_unmet_dep(struct expr *e1, struct expr *e2) | ||
1034 | { | ||
1035 | struct expr *ret; | ||
1036 | |||
1037 | switch (e1->type) { | ||
1038 | case E_OR: | ||
1039 | return expr_alloc_and( | ||
1040 | expr_simplify_unmet_dep(e1->left.expr, e2), | ||
1041 | expr_simplify_unmet_dep(e1->right.expr, e2)); | ||
1042 | case E_AND: { | ||
1043 | struct expr *e; | ||
1044 | e = expr_alloc_and(expr_copy(e1), expr_copy(e2)); | ||
1045 | e = expr_eliminate_dups(e); | ||
1046 | ret = (!expr_eq(e, e1)) ? e1 : NULL; | ||
1047 | expr_free(e); | ||
1048 | break; | ||
1049 | } | ||
1050 | default: | ||
1051 | ret = e1; | ||
1052 | break; | ||
1053 | } | ||
1054 | |||
1055 | return expr_get_leftmost_symbol(ret); | ||
1056 | } | ||
1057 | |||
1016 | void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken) | 1058 | void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken) |
1017 | { | 1059 | { |
1018 | if (!e) { | 1060 | if (!e) { |
@@ -1087,7 +1129,7 @@ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char * | |||
1087 | 1129 | ||
1088 | static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) | 1130 | static void expr_print_file_helper(void *data, struct symbol *sym, const char *str) |
1089 | { | 1131 | { |
1090 | fwrite(str, strlen(str), 1, data); | 1132 | xfwrite(str, strlen(str), 1, data); |
1091 | } | 1133 | } |
1092 | 1134 | ||
1093 | void expr_fprint(struct expr *e, FILE *out) | 1135 | void expr_fprint(struct expr *e, FILE *out) |
@@ -1121,7 +1163,7 @@ static void expr_print_gstr_helper(void *data, struct symbol *sym, const char *s | |||
1121 | } | 1163 | } |
1122 | 1164 | ||
1123 | str_append(gs, str); | 1165 | str_append(gs, str); |
1124 | if (sym) | 1166 | if (sym && sym->type != S_UNKNOWN) |
1125 | str_printf(gs, " [=%s]", sym_str); | 1167 | str_printf(gs, " [=%s]", sym_str); |
1126 | } | 1168 | } |
1127 | 1169 | ||