Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
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 /* enum values are used as index to symbol.def[] */
0069 enum {
0070     S_DEF_USER,     /* main user value */
0071     S_DEF_AUTO,     /* values read from auto.conf */
0072     S_DEF_DEF3,     /* Reserved for UI usage */
0073     S_DEF_DEF4,     /* Reserved for UI usage */
0074     S_DEF_COUNT
0075 };
0076 
0077 /*
0078  * Represents a configuration symbol.
0079  *
0080  * Choices are represented as a special kind of symbol and have the
0081  * SYMBOL_CHOICE bit set in 'flags'.
0082  */
0083 struct symbol {
0084     /* The next symbol in the same bucket in the symbol hash table */
0085     struct symbol *next;
0086 
0087     /* The name of the symbol, e.g. "FOO" for 'config FOO' */
0088     char *name;
0089 
0090     /* S_BOOLEAN, S_TRISTATE, ... */
0091     enum symbol_type type;
0092 
0093     /*
0094      * The calculated value of the symbol. The SYMBOL_VALID bit is set in
0095      * 'flags' when this is up to date. Note that this value might differ
0096      * from the user value set in e.g. a .config file, due to visibility.
0097      */
0098     struct symbol_value curr;
0099 
0100     /*
0101      * Values for the symbol provided from outside. def[S_DEF_USER] holds
0102      * the .config value.
0103      */
0104     struct symbol_value def[S_DEF_COUNT];
0105 
0106     /*
0107      * An upper bound on the tristate value the user can set for the symbol
0108      * if it is a boolean or tristate. Calculated from prompt dependencies,
0109      * which also inherit dependencies from enclosing menus, choices, and
0110      * ifs. If 'n', the user value will be ignored.
0111      *
0112      * Symbols lacking prompts always have visibility 'n'.
0113      */
0114     tristate visible;
0115 
0116     /* SYMBOL_* flags */
0117     int flags;
0118 
0119     /* List of properties. See prop_type. */
0120     struct property *prop;
0121 
0122     /* Dependencies from enclosing menus, choices, and ifs */
0123     struct expr_value dir_dep;
0124 
0125     /* Reverse dependencies through being selected by other symbols */
0126     struct expr_value rev_dep;
0127 
0128     /*
0129      * "Weak" reverse dependencies through being implied by other symbols
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  /* symbol is const */
0137 #define SYMBOL_CHECK      0x0008  /* used during dependency checking */
0138 #define SYMBOL_CHOICE     0x0010  /* start of a choice block (null name) */
0139 #define SYMBOL_CHOICEVAL  0x0020  /* used as a value in a choice block */
0140 #define SYMBOL_VALID      0x0080  /* set when symbol.curr is calculated */
0141 #define SYMBOL_OPTIONAL   0x0100  /* choice is optional - values can be 'n' */
0142 #define SYMBOL_WRITE      0x0200  /* write symbol to file (KCONFIG_CONFIG) */
0143 #define SYMBOL_CHANGED    0x0400  /* ? */
0144 #define SYMBOL_WRITTEN    0x0800  /* track info to avoid double-write to .config */
0145 #define SYMBOL_NO_WRITE   0x1000  /* Symbol for internal use only; it will not be written */
0146 #define SYMBOL_CHECKED    0x2000  /* used during dependency checking */
0147 #define SYMBOL_WARNED     0x8000  /* warning has been issued */
0148 
0149 /* Set when symbol.def[] is used */
0150 #define SYMBOL_DEF        0x10000  /* First bit of SYMBOL_DEF */
0151 #define SYMBOL_DEF_USER   0x10000  /* symbol.def[S_DEF_USER] is valid */
0152 #define SYMBOL_DEF_AUTO   0x20000  /* symbol.def[S_DEF_AUTO] is valid */
0153 #define SYMBOL_DEF3       0x40000  /* symbol.def[S_DEF_3] is valid */
0154 #define SYMBOL_DEF4       0x80000  /* symbol.def[S_DEF_4] is valid */
0155 
0156 /* choice values need to be set before calculating this symbol value */
0157 #define SYMBOL_NEED_SET_CHOICE_VALUES  0x100000
0158 
0159 #define SYMBOL_MAXLENGTH    256
0160 #define SYMBOL_HASHSIZE     9973
0161 
0162 /* A property represent the config options that can be associated
0163  * with a config "symbol".
0164  * Sample:
0165  * config FOO
0166  *         default y
0167  *         prompt "foo prompt"
0168  *         select BAR
0169  * config BAZ
0170  *         int "BAZ Value"
0171  *         range 1..255
0172  *
0173  * Please, also check parser.y:print_symbol() when modifying the
0174  * list of property types!
0175  */
0176 enum prop_type {
0177     P_UNKNOWN,
0178     P_PROMPT,   /* prompt "foo prompt" or "BAZ Value" */
0179     P_COMMENT,  /* text associated with a comment */
0180     P_MENU,     /* prompt associated with a menu or menuconfig symbol */
0181     P_DEFAULT,  /* default y */
0182     P_CHOICE,   /* choice value */
0183     P_SELECT,   /* select BAR */
0184     P_IMPLY,    /* imply BAR */
0185     P_RANGE,    /* range 7..100 (for a symbol) */
0186     P_SYMBOL,   /* where a symbol is defined */
0187 };
0188 
0189 struct property {
0190     struct property *next;     /* next property - null if last */
0191     enum prop_type type;       /* type of property */
0192     const char *text;          /* the prompt value - P_PROMPT, P_MENU, P_COMMENT */
0193     struct expr_value visible;
0194     struct expr *expr;         /* the optional conditional part of the property */
0195     struct menu *menu;         /* the menu the property are associated with
0196                                 * valid for: P_SELECT, P_RANGE, P_CHOICE,
0197                                 * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */
0198     struct file *file;         /* what file was this property defined */
0199     int lineno;                /* what lineno was this property defined */
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  * Represents a node in the menu tree, as seen in e.g. menuconfig (though used
0213  * for all front ends). Each symbol, menu, etc. defined in the Kconfig files
0214  * gets a node. A symbol defined in multiple locations gets one node at each
0215  * location.
0216  */
0217 struct menu {
0218     /* The next menu node at the same level */
0219     struct menu *next;
0220 
0221     /* The parent menu node, corresponding to e.g. a menu or choice */
0222     struct menu *parent;
0223 
0224     /* The first child menu node, for e.g. menus and choices */
0225     struct menu *list;
0226 
0227     /*
0228      * The symbol associated with the menu node. Choices are implemented as
0229      * a special kind of symbol. NULL for menus, comments, and ifs.
0230      */
0231     struct symbol *sym;
0232 
0233     /*
0234      * The prompt associated with the node. This holds the prompt for a
0235      * symbol as well as the text for a menu or comment, along with the
0236      * type (P_PROMPT, P_MENU, etc.)
0237      */
0238     struct property *prompt;
0239 
0240     /*
0241      * 'visible if' dependencies. If more than one is given, they will be
0242      * ANDed together.
0243      */
0244     struct expr *visibility;
0245 
0246     /*
0247      * Ordinary dependencies from e.g. 'depends on' and 'if', ANDed
0248      * together
0249      */
0250     struct expr *dep;
0251 
0252     /* MENU_* flags */
0253     unsigned int flags;
0254 
0255     /* Any help text associated with the node */
0256     char *help;
0257 
0258     /* The location where the menu node appears in the Kconfig files */
0259     struct file *file;
0260     int lineno;
0261 
0262     /* For use by front ends that need to store auxiliary data */
0263     void *data;
0264 };
0265 
0266 /*
0267  * Set on a menu node when the corresponding symbol changes state in some way.
0268  * Can be checked by front ends.
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; /* forward */
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 /* EXPR_H */