1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/kconfig/expr.h Wed Aug 15 21:24:02 2007 +0000
1.3 @@ -0,0 +1,202 @@
1.4 +/*
1.5 + * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
1.6 + * Released under the terms of the GNU GPL v2.0.
1.7 + */
1.8 +
1.9 +#ifndef EXPR_H
1.10 +#define EXPR_H
1.11 +
1.12 +#ifdef __cplusplus
1.13 +extern "C" {
1.14 +#endif
1.15 +
1.16 +#include <stdio.h>
1.17 +#ifndef __cplusplus
1.18 +#include <stdbool.h>
1.19 +#endif
1.20 +
1.21 +struct file {
1.22 + struct file *next;
1.23 + struct file *parent;
1.24 + char *name;
1.25 + int lineno;
1.26 + int flags;
1.27 +};
1.28 +
1.29 +#define FILE_BUSY 0x0001
1.30 +#define FILE_SCANNED 0x0002
1.31 +#define FILE_PRINTED 0x0004
1.32 +
1.33 +typedef enum tristate {
1.34 + no, mod, yes
1.35 +} tristate;
1.36 +
1.37 +enum expr_type {
1.38 + E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_CHOICE, E_SYMBOL, E_RANGE
1.39 +};
1.40 +
1.41 +union expr_data {
1.42 + struct expr *expr;
1.43 + struct symbol *sym;
1.44 +};
1.45 +
1.46 +struct expr {
1.47 + enum expr_type type;
1.48 + union expr_data left, right;
1.49 +};
1.50 +
1.51 +#define E_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
1.52 +#define E_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
1.53 +#define E_NOT(dep) (2-(dep))
1.54 +
1.55 +struct expr_value {
1.56 + struct expr *expr;
1.57 + tristate tri;
1.58 +};
1.59 +
1.60 +struct symbol_value {
1.61 + void *val;
1.62 + tristate tri;
1.63 +};
1.64 +
1.65 +enum symbol_type {
1.66 + S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
1.67 +};
1.68 +
1.69 +enum {
1.70 + S_DEF_USER, /* main user value */
1.71 + S_DEF_AUTO,
1.72 +};
1.73 +
1.74 +struct symbol {
1.75 + struct symbol *next;
1.76 + char *name;
1.77 + char *help;
1.78 + enum symbol_type type;
1.79 + struct symbol_value curr;
1.80 + struct symbol_value def[4];
1.81 + tristate visible;
1.82 + int flags;
1.83 + struct property *prop;
1.84 + struct expr *dep, *dep2;
1.85 + struct expr_value rev_dep;
1.86 +};
1.87 +
1.88 +#define for_all_symbols(i, sym) for (i = 0; i < 257; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
1.89 +
1.90 +#define SYMBOL_CONST 0x0001
1.91 +#define SYMBOL_CHECK 0x0008
1.92 +#define SYMBOL_CHOICE 0x0010
1.93 +#define SYMBOL_CHOICEVAL 0x0020
1.94 +#define SYMBOL_PRINTED 0x0040
1.95 +#define SYMBOL_VALID 0x0080
1.96 +#define SYMBOL_OPTIONAL 0x0100
1.97 +#define SYMBOL_WRITE 0x0200
1.98 +#define SYMBOL_CHANGED 0x0400
1.99 +#define SYMBOL_AUTO 0x1000
1.100 +#define SYMBOL_CHECKED 0x2000
1.101 +#define SYMBOL_WARNED 0x8000
1.102 +#define SYMBOL_DEF 0x10000
1.103 +#define SYMBOL_DEF_USER 0x10000
1.104 +#define SYMBOL_DEF_AUTO 0x20000
1.105 +#define SYMBOL_DEF3 0x40000
1.106 +#define SYMBOL_DEF4 0x80000
1.107 +
1.108 +#define SYMBOL_MAXLENGTH 256
1.109 +#define SYMBOL_HASHSIZE 257
1.110 +#define SYMBOL_HASHMASK 0xff
1.111 +
1.112 +enum prop_type {
1.113 + P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_DEFAULT, P_CHOICE, P_SELECT, P_RANGE
1.114 +};
1.115 +
1.116 +struct property {
1.117 + struct property *next;
1.118 + struct symbol *sym;
1.119 + enum prop_type type;
1.120 + const char *text;
1.121 + struct expr_value visible;
1.122 + struct expr *expr;
1.123 + struct menu *menu;
1.124 + struct file *file;
1.125 + int lineno;
1.126 +};
1.127 +
1.128 +#define for_all_properties(sym, st, tok) \
1.129 + for (st = sym->prop; st; st = st->next) \
1.130 + if (st->type == (tok))
1.131 +#define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
1.132 +#define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
1.133 +#define for_all_prompts(sym, st) \
1.134 + for (st = sym->prop; st; st = st->next) \
1.135 + if (st->text)
1.136 +
1.137 +struct menu {
1.138 + struct menu *next;
1.139 + struct menu *parent;
1.140 + struct menu *list;
1.141 + struct symbol *sym;
1.142 + struct property *prompt;
1.143 + struct expr *dep;
1.144 + unsigned int flags;
1.145 + //char *help;
1.146 + struct file *file;
1.147 + int lineno;
1.148 + void *data;
1.149 +};
1.150 +
1.151 +#define MENU_CHANGED 0x0001
1.152 +#define MENU_ROOT 0x0002
1.153 +
1.154 +#ifndef SWIG
1.155 +
1.156 +extern struct file *file_list;
1.157 +extern struct file *current_file;
1.158 +struct file *lookup_file(const char *name);
1.159 +
1.160 +extern struct symbol symbol_yes, symbol_no, symbol_mod;
1.161 +extern struct symbol *modules_sym;
1.162 +extern struct symbol *sym_defconfig_list;
1.163 +extern int cdebug;
1.164 +struct expr *expr_alloc_symbol(struct symbol *sym);
1.165 +struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
1.166 +struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
1.167 +struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
1.168 +struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
1.169 +struct expr *expr_alloc_or(struct expr *e1, struct expr *e2);
1.170 +struct expr *expr_copy(struct expr *org);
1.171 +void expr_free(struct expr *e);
1.172 +int expr_eq(struct expr *e1, struct expr *e2);
1.173 +void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
1.174 +tristate expr_calc_value(struct expr *e);
1.175 +struct expr *expr_eliminate_yn(struct expr *e);
1.176 +struct expr *expr_trans_bool(struct expr *e);
1.177 +struct expr *expr_eliminate_dups(struct expr *e);
1.178 +struct expr *expr_transform(struct expr *e);
1.179 +int expr_contains_symbol(struct expr *dep, struct symbol *sym);
1.180 +bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
1.181 +struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
1.182 +struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
1.183 +void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
1.184 +struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
1.185 +
1.186 +void expr_fprint(struct expr *e, FILE *out);
1.187 +struct gstr; /* forward */
1.188 +void expr_gstr_print(struct expr *e, struct gstr *gs);
1.189 +
1.190 +static inline int expr_is_yes(struct expr *e)
1.191 +{
1.192 + return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
1.193 +}
1.194 +
1.195 +static inline int expr_is_no(struct expr *e)
1.196 +{
1.197 + return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
1.198 +}
1.199 +#endif
1.200 +
1.201 +#ifdef __cplusplus
1.202 +}
1.203 +#endif
1.204 +
1.205 +#endif /* EXPR_H */