0001
0002
0003
0004
0005
0006 #ifndef EXPR_H
0007 #define EXPR_H
0008
0009 #ifdef __cplusplus
0010 extern "C" {
0011 #endif
0012
0013 #include <assert.h>
0014 #include <stdio.h>
0015 #include "list.h"
0016 #ifndef __cplusplus
0017 #include <stdbool.h>
0018 #endif
0019
0020 struct file {
0021 struct file *next;
0022 struct file *parent;
0023 const char *name;
0024 int lineno;
0025 };
0026
0027 typedef enum tristate {
0028 no, mod, yes
0029 } tristate;
0030
0031 enum expr_type {
0032 E_NONE, E_OR, E_AND, E_NOT,
0033 E_EQUAL, E_UNEQUAL, E_LTH, E_LEQ, E_GTH, E_GEQ,
0034 E_LIST, E_SYMBOL, E_RANGE
0035 };
0036
0037 union expr_data {
0038 struct expr *expr;
0039 struct symbol *sym;
0040 };
0041
0042 struct expr {
0043 enum expr_type type;
0044 union expr_data left, right;
0045 };
0046
0047 #define EXPR_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
0048 #define EXPR_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
0049 #define EXPR_NOT(dep) (2-(dep))
0050
0051 #define expr_list_for_each_sym(l, e, s) \
0052 for (e = (l); e && (s = e->right.sym); e = e->left.expr)
0053
0054 struct expr_value {
0055 struct expr *expr;
0056 tristate tri;
0057 };
0058
0059 struct symbol_value {
0060 void *val;
0061 tristate tri;
0062 };
0063
0064 enum symbol_type {
0065 S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING
0066 };
0067
0068
0069 enum {
0070 S_DEF_USER,
0071 S_DEF_AUTO,
0072 S_DEF_DEF3,
0073 S_DEF_DEF4,
0074 S_DEF_COUNT
0075 };
0076
0077
0078
0079
0080
0081
0082
0083 struct symbol {
0084
0085 struct symbol *next;
0086
0087
0088 char *name;
0089
0090
0091 enum symbol_type type;
0092
0093
0094
0095
0096
0097
0098 struct symbol_value curr;
0099
0100
0101
0102
0103
0104 struct symbol_value def[S_DEF_COUNT];
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 tristate visible;
0115
0116
0117 int flags;
0118
0119
0120 struct property *prop;
0121
0122
0123 struct expr_value dir_dep;
0124
0125
0126 struct expr_value rev_dep;
0127
0128
0129
0130
0131 struct expr_value implied;
0132 };
0133
0134 #define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next)
0135
0136 #define SYMBOL_CONST 0x0001
0137 #define SYMBOL_CHECK 0x0008
0138 #define SYMBOL_CHOICE 0x0010
0139 #define SYMBOL_CHOICEVAL 0x0020
0140 #define SYMBOL_VALID 0x0080
0141 #define SYMBOL_OPTIONAL 0x0100
0142 #define SYMBOL_WRITE 0x0200
0143 #define SYMBOL_CHANGED 0x0400
0144 #define SYMBOL_WRITTEN 0x0800
0145 #define SYMBOL_NO_WRITE 0x1000
0146 #define SYMBOL_CHECKED 0x2000
0147 #define SYMBOL_WARNED 0x8000
0148
0149
0150 #define SYMBOL_DEF 0x10000
0151 #define SYMBOL_DEF_USER 0x10000
0152 #define SYMBOL_DEF_AUTO 0x20000
0153 #define SYMBOL_DEF3 0x40000
0154 #define SYMBOL_DEF4 0x80000
0155
0156
0157 #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000
0158
0159 #define SYMBOL_MAXLENGTH 256
0160 #define SYMBOL_HASHSIZE 9973
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 enum prop_type {
0177 P_UNKNOWN,
0178 P_PROMPT,
0179 P_COMMENT,
0180 P_MENU,
0181 P_DEFAULT,
0182 P_CHOICE,
0183 P_SELECT,
0184 P_IMPLY,
0185 P_RANGE,
0186 P_SYMBOL,
0187 };
0188
0189 struct property {
0190 struct property *next;
0191 enum prop_type type;
0192 const char *text;
0193 struct expr_value visible;
0194 struct expr *expr;
0195 struct menu *menu;
0196
0197
0198 struct file *file;
0199 int lineno;
0200 };
0201
0202 #define for_all_properties(sym, st, tok) \
0203 for (st = sym->prop; st; st = st->next) \
0204 if (st->type == (tok))
0205 #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
0206 #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
0207 #define for_all_prompts(sym, st) \
0208 for (st = sym->prop; st; st = st->next) \
0209 if (st->text)
0210
0211
0212
0213
0214
0215
0216
0217 struct menu {
0218
0219 struct menu *next;
0220
0221
0222 struct menu *parent;
0223
0224
0225 struct menu *list;
0226
0227
0228
0229
0230
0231 struct symbol *sym;
0232
0233
0234
0235
0236
0237
0238 struct property *prompt;
0239
0240
0241
0242
0243
0244 struct expr *visibility;
0245
0246
0247
0248
0249
0250 struct expr *dep;
0251
0252
0253 unsigned int flags;
0254
0255
0256 char *help;
0257
0258
0259 struct file *file;
0260 int lineno;
0261
0262
0263 void *data;
0264 };
0265
0266
0267
0268
0269
0270 #define MENU_CHANGED 0x0001
0271
0272 #define MENU_ROOT 0x0002
0273
0274 struct jump_key {
0275 struct list_head entries;
0276 size_t offset;
0277 struct menu *target;
0278 int index;
0279 };
0280
0281 extern struct file *file_list;
0282 extern struct file *current_file;
0283 struct file *lookup_file(const char *name);
0284
0285 extern struct symbol symbol_yes, symbol_no, symbol_mod;
0286 extern struct symbol *modules_sym;
0287 extern int cdebug;
0288 struct expr *expr_alloc_symbol(struct symbol *sym);
0289 struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
0290 struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
0291 struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
0292 struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
0293 struct expr *expr_alloc_or(struct expr *e1, struct expr *e2);
0294 struct expr *expr_copy(const struct expr *org);
0295 void expr_free(struct expr *e);
0296 void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
0297 int expr_eq(struct expr *e1, struct expr *e2);
0298 tristate expr_calc_value(struct expr *e);
0299 struct expr *expr_trans_bool(struct expr *e);
0300 struct expr *expr_eliminate_dups(struct expr *e);
0301 struct expr *expr_transform(struct expr *e);
0302 int expr_contains_symbol(struct expr *dep, struct symbol *sym);
0303 bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
0304 struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
0305
0306 void expr_fprint(struct expr *e, FILE *out);
0307 struct gstr;
0308 void expr_gstr_print(struct expr *e, struct gstr *gs);
0309 void expr_gstr_print_revdep(struct expr *e, struct gstr *gs,
0310 tristate pr_type, const char *title);
0311
0312 static inline int expr_is_yes(struct expr *e)
0313 {
0314 return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
0315 }
0316
0317 static inline int expr_is_no(struct expr *e)
0318 {
0319 return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
0320 }
0321
0322 #ifdef __cplusplus
0323 }
0324 #endif
0325
0326 #endif