expr.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
  3. * Released under the terms of the GNU GPL v2.0.
  4. */
  5. #ifndef EXPR_H
  6. #define EXPR_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. #include <stdio.h>
  11. #ifndef __cplusplus
  12. #include <stdbool.h>
  13. #endif
  14. struct file {
  15. struct file *next;
  16. struct file *parent;
  17. #ifdef CML1
  18. struct statement *stmt;
  19. struct statement *last_stmt;
  20. #endif
  21. char *name;
  22. int lineno;
  23. int flags;
  24. };
  25. #define FILE_BUSY 0x0001
  26. #define FILE_SCANNED 0x0002
  27. #define FILE_PRINTED 0x0004
  28. typedef enum tristate {
  29. no, mod, yes
  30. } tristate;
  31. enum expr_type {
  32. E_NONE, E_OR, E_AND, E_NOT, E_EQUAL, E_UNEQUAL, E_CHOICE, E_SYMBOL
  33. };
  34. union expr_data {
  35. struct expr *expr;
  36. struct symbol *sym;
  37. };
  38. struct expr {
  39. #ifdef CML1
  40. int token;
  41. #else
  42. enum expr_type type;
  43. #endif
  44. union expr_data left, right;
  45. };
  46. #define E_TRI(ev) ((ev).tri)
  47. #define E_EXPR(ev) ((ev).expr)
  48. #define E_CALC(ev) (E_TRI(ev) = expr_calc_value(E_EXPR(ev)))
  49. #define E_OR(dep1, dep2) (((dep1)>(dep2))?(dep1):(dep2))
  50. #define E_AND(dep1, dep2) (((dep1)<(dep2))?(dep1):(dep2))
  51. #define E_NOT(dep) (2-(dep))
  52. struct expr_value {
  53. struct expr *expr;
  54. tristate tri;
  55. };
  56. #define S_VAL(sv) ((sv).value)
  57. #define S_TRI(sv) ((sv).tri)
  58. #define S_EQ(sv1, sv2) (S_VAL(sv1) == S_VAL(sv2) || !strcmp(S_VAL(sv1), S_VAL(sv2)))
  59. struct symbol_value {
  60. void *value;
  61. tristate tri;
  62. };
  63. enum symbol_type {
  64. S_UNKNOWN, S_BOOLEAN, S_TRISTATE, S_INT, S_HEX, S_STRING, S_OTHER
  65. };
  66. struct symbol {
  67. struct symbol *next;
  68. char *name;
  69. char *help;
  70. #ifdef CML1
  71. int type;
  72. #else
  73. enum symbol_type type;
  74. #endif
  75. struct symbol_value curr, def;
  76. tristate visible;
  77. int flags;
  78. struct property *prop;
  79. struct expr *dep, *dep2;
  80. struct menu *menu;
  81. };
  82. #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)
  83. #ifdef CML1
  84. #define SYMBOL_UNKNOWN S_UNKNOWN
  85. #define SYMBOL_BOOLEAN S_BOOLEAN
  86. #define SYMBOL_TRISTATE S_TRISTATE
  87. #define SYMBOL_INT S_INT
  88. #define SYMBOL_HEX S_HEX
  89. #define SYMBOL_STRING S_STRING
  90. #define SYMBOL_OTHER S_OTHER
  91. #endif
  92. #define SYMBOL_YES 0x0001
  93. #define SYMBOL_MOD 0x0002
  94. #define SYMBOL_NO 0x0004
  95. #define SYMBOL_CONST 0x0007
  96. #define SYMBOL_CHECK 0x0008
  97. #define SYMBOL_CHOICE 0x0010
  98. #define SYMBOL_CHOICEVAL 0x0020
  99. #define SYMBOL_PRINTED 0x0040
  100. #define SYMBOL_VALID 0x0080
  101. #define SYMBOL_OPTIONAL 0x0100
  102. #define SYMBOL_WRITE 0x0200
  103. #define SYMBOL_CHANGED 0x0400
  104. #define SYMBOL_NEW 0x0800
  105. #define SYMBOL_AUTO 0x1000
  106. #define SYMBOL_MAXLENGTH 256
  107. #define SYMBOL_HASHSIZE 257
  108. #define SYMBOL_HASHMASK 0xff
  109. enum prop_type {
  110. P_UNKNOWN, P_PROMPT, P_COMMENT, P_MENU, P_ROOTMENU, P_DEFAULT, P_CHOICE
  111. };
  112. struct property {
  113. struct property *next;
  114. struct symbol *sym;
  115. #ifdef CML1
  116. int token;
  117. #else
  118. enum prop_type type;
  119. #endif
  120. const char *text;
  121. struct symbol *def;
  122. struct expr_value visible;
  123. struct expr *dep;
  124. struct expr *dep2;
  125. struct menu *menu;
  126. struct file *file;
  127. int lineno;
  128. #ifdef CML1
  129. struct property *next_pos;
  130. #endif
  131. };
  132. #define for_all_properties(sym, st, tok) \
  133. for (st = sym->prop; st; st = st->next) \
  134. if (st->type == (tok))
  135. #define for_all_prompts(sym, st) for_all_properties(sym, st, P_PROMPT)
  136. #define for_all_defaults(sym, st) for_all_properties(sym, st, P_DEFAULT)
  137. #define for_all_choices(sym, st) for_all_properties(sym, st, P_CHOICE)
  138. struct menu {
  139. struct menu *next;
  140. struct menu *parent;
  141. struct menu *list;
  142. struct symbol *sym;
  143. struct property *prompt;
  144. struct expr *dep;
  145. //char *help;
  146. struct file *file;
  147. int lineno;
  148. //void *data;
  149. };
  150. #ifndef SWIG
  151. extern struct file *file_list;
  152. extern struct file *current_file;
  153. struct file *lookup_file(const char *name);
  154. extern struct symbol symbol_yes, symbol_no, symbol_mod;
  155. extern struct symbol *modules_sym;
  156. extern int cdebug;
  157. extern int print_type;
  158. struct expr *expr_alloc_symbol(struct symbol *sym);
  159. #ifdef CML1
  160. struct expr *expr_alloc_one(int token, struct expr *ce);
  161. struct expr *expr_alloc_two(int token, struct expr *e1, struct expr *e2);
  162. struct expr *expr_alloc_comp(int token, struct symbol *s1, struct symbol *s2);
  163. #else
  164. struct expr *expr_alloc_one(enum expr_type type, struct expr *ce);
  165. struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2);
  166. struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2);
  167. #endif
  168. struct expr *expr_alloc_and(struct expr *e1, struct expr *e2);
  169. struct expr *expr_copy(struct expr *org);
  170. void expr_free(struct expr *e);
  171. int expr_eq(struct expr *e1, struct expr *e2);
  172. void expr_eliminate_eq(struct expr **ep1, struct expr **ep2);
  173. tristate expr_calc_value(struct expr *e);
  174. struct expr *expr_eliminate_yn(struct expr *e);
  175. struct expr *expr_trans_bool(struct expr *e);
  176. struct expr *expr_eliminate_dups(struct expr *e);
  177. struct expr *expr_transform(struct expr *e);
  178. int expr_contains_symbol(struct expr *dep, struct symbol *sym);
  179. bool expr_depends_symbol(struct expr *dep, struct symbol *sym);
  180. struct expr *expr_extract_eq_and(struct expr **ep1, struct expr **ep2);
  181. struct expr *expr_extract_eq_or(struct expr **ep1, struct expr **ep2);
  182. void expr_extract_eq(enum expr_type type, struct expr **ep, struct expr **ep1, struct expr **ep2);
  183. struct expr *expr_trans_compare(struct expr *e, enum expr_type type, struct symbol *sym);
  184. void expr_fprint(struct expr *e, FILE *out);
  185. void print_expr(int mask, struct expr *e, int prevtoken);
  186. #ifdef CML1
  187. static inline int expr_is_yes(struct expr *e)
  188. {
  189. return !e || (e->token == WORD && e->left.sym == &symbol_yes);
  190. }
  191. static inline int expr_is_no(struct expr *e)
  192. {
  193. return e && (e->token == WORD && e->left.sym == &symbol_no);
  194. }
  195. #else
  196. static inline int expr_is_yes(struct expr *e)
  197. {
  198. return !e || (e->type == E_SYMBOL && e->left.sym == &symbol_yes);
  199. }
  200. static inline int expr_is_no(struct expr *e)
  201. {
  202. return e && (e->type == E_SYMBOL && e->left.sym == &symbol_no);
  203. }
  204. #endif
  205. #endif
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif /* EXPR_H */