Mercurial > hg-old > index.cgi
annotate lwlib/lw_expr.h @ 415:2d7255509130
Fixed error with indexed posbytes
author | lost@l-w.ca |
---|---|
date | Tue, 10 Aug 2010 21:59:49 -0600 |
parents | a741d2e4869f |
children | 5cccf90bf838 |
rev | line source |
---|---|
334 | 1 /* |
2 lwexpr.h | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #ifndef ___lw_expr_h_seen___ | |
23 #define ___lw_expr_h_seen___ | |
24 | |
370 | 25 #include <stdio.h> |
334 | 26 |
27 enum | |
28 { | |
29 lw_expr_type_oper, // operator term | |
30 lw_expr_type_int, // integer | |
31 lw_expr_type_var, // a "variable" (string for the name) | |
32 lw_expr_type_special // a "special" reference (user defined) | |
33 }; | |
34 | |
35 enum | |
36 { | |
37 lw_expr_oper_plus = 1, // addition | |
38 lw_expr_oper_minus, // subtraction | |
39 lw_expr_oper_times, // multiplication | |
40 lw_expr_oper_divide, // division | |
41 lw_expr_oper_mod, // modulus | |
42 lw_expr_oper_intdiv, // integer division | |
43 lw_expr_oper_bwand, // bitwise and | |
44 lw_expr_oper_bwor, // bitwise or | |
45 lw_expr_oper_bwxor, // bitwise xor | |
46 lw_expr_oper_and, // boolean and | |
47 lw_expr_oper_or, // boolean or | |
48 lw_expr_oper_neg, // unary negation, 2's complement | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
49 lw_expr_oper_com, // unary 1's complement |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
50 lw_expr_oper_none = 0 |
334 | 51 }; |
52 | |
53 #ifdef ___lw_expr_c_seen___ | |
54 | |
55 typedef struct lw_expr_priv * lw_expr_t; | |
56 | |
57 struct lw_expr_opers | |
58 { | |
59 lw_expr_t p; | |
60 struct lw_expr_opers *next; | |
61 }; | |
62 | |
63 struct lw_expr_priv | |
64 { | |
65 int type; // type of term | |
66 int value; // integer value | |
67 void *value2; // misc pointer value | |
68 struct lw_expr_opers *operands; // ptr to list of operands (for operators) | |
69 }; | |
70 | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
71 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr, void *priv); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
72 typedef lw_expr_t lw_expr_fn2_t(char *var, void *priv); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
73 typedef lw_expr_t lw_expr_fn3_t(char **p, void *priv); |
367 | 74 typedef int lw_expr_testfn_t(lw_expr_t e, void *priv); |
334 | 75 |
76 #else /* def ___lw_expr_c_seen___ */ | |
77 | |
78 typedef void * lw_expr_t; | |
79 | |
80 extern lw_expr_t lwexpr_create(void); | |
337 | 81 extern void lw_expr_destroy(lw_expr_t E); |
334 | 82 extern lw_expr_t lw_expr_copy(lw_expr_t E); |
83 extern void lw_expr_add_operand(lw_expr_t E, lw_expr_t O); | |
84 extern lw_expr_t lw_expr_build(int exprtype, ...); | |
372
90de73ba0cac
Created a useful debug framework and adjusted lw_expr_print() to return a "static" dynamic string
lost@starbug
parents:
370
diff
changeset
|
85 extern char *lw_expr_print(lw_expr_t E); |
334 | 86 extern int lw_expr_compare(lw_expr_t E1, lw_expr_t E2); |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
87 extern void lw_expr_simplify(lw_expr_t E, void *priv); |
337 | 88 |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
89 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr, void *priv); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
90 typedef lw_expr_t lw_expr_fn2_t(char *var, void *priv); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
91 typedef lw_expr_t lw_expr_fn3_t(char **p, void *priv); |
342 | 92 |
93 extern void lw_expr_set_special_handler(lw_expr_fn_t *fn); | |
94 extern void lw_expr_set_var_handler(lw_expr_fn2_t *fn); | |
346
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
95 extern void lw_expr_set_term_parser(lw_expr_fn3_t *fn); |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
96 |
a82c55070624
Added expression parsing infrastructure and misc fixes
lost@starbug
parents:
342
diff
changeset
|
97 extern lw_expr_t lw_expr_parse(char **p, void *priv); |
347 | 98 extern int lw_expr_istype(lw_expr_t e, int t); |
99 extern int lw_expr_intval(lw_expr_t e); | |
367 | 100 extern int lw_expr_specint(lw_expr_t e); |
376 | 101 extern void *lw_expr_specptr(lw_expr_t e); |
387
a741d2e4869f
Various bugfixes; fixed lwobjdump to display symbols with unprintable characters more sensibly; start of a (nonfunctional for now) testing framework
lost@l-w.ca
parents:
376
diff
changeset
|
102 extern int lw_expr_whichop(lw_expr_t e); |
376 | 103 |
104 extern int lw_expr_type(lw_expr_t e); | |
367 | 105 |
106 typedef int lw_expr_testfn_t(lw_expr_t e, void *priv); | |
107 | |
108 // run a function on all terms in an expression; if the function | |
109 // returns non-zero for any term, return non-zero, else return | |
110 // zero | |
111 extern int lw_expr_testterms(lw_expr_t e, lw_expr_testfn_t *fn, void *priv); | |
334 | 112 |
113 #endif /* def ___lw_expr_c_seen___ */ | |
114 | |
115 #endif /* ___lw_expr_h_seen___ */ |