annotate lwlib/lw_expr.h @ 430:4bcb763bddde

Adjusted output in list so that 8 space tabs line up right in output
author lost@l-w.ca
date Sun, 24 Oct 2010 19:06:00 -0600
parents a741d2e4869f
children 5cccf90bf838
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
1 /*
f2173d18c73f Checkpoint
lost
parents:
diff changeset
2 lwexpr.h
f2173d18c73f Checkpoint
lost
parents:
diff changeset
3
f2173d18c73f Checkpoint
lost
parents:
diff changeset
4 Copyright © 2010 William Astle
f2173d18c73f Checkpoint
lost
parents:
diff changeset
5
f2173d18c73f Checkpoint
lost
parents:
diff changeset
6 This file is part of LWTOOLS.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
7
f2173d18c73f Checkpoint
lost
parents:
diff changeset
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
f2173d18c73f Checkpoint
lost
parents:
diff changeset
9 terms of the GNU General Public License as published by the Free Software
f2173d18c73f Checkpoint
lost
parents:
diff changeset
10 Foundation, either version 3 of the License, or (at your option) any later
f2173d18c73f Checkpoint
lost
parents:
diff changeset
11 version.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
12
f2173d18c73f Checkpoint
lost
parents:
diff changeset
13 This program is distributed in the hope that it will be useful, but WITHOUT
f2173d18c73f Checkpoint
lost
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
f2173d18c73f Checkpoint
lost
parents:
diff changeset
16 more details.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
17
f2173d18c73f Checkpoint
lost
parents:
diff changeset
18 You should have received a copy of the GNU General Public License along with
f2173d18c73f Checkpoint
lost
parents:
diff changeset
19 this program. If not, see <http://www.gnu.org/licenses/>.
f2173d18c73f Checkpoint
lost
parents:
diff changeset
20 */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
21
f2173d18c73f Checkpoint
lost
parents:
diff changeset
22 #ifndef ___lw_expr_h_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
23 #define ___lw_expr_h_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
24
370
6b33faa21a0a Debugging output and bugfixing pass 0
lost@starbug
parents: 367
diff changeset
25 #include <stdio.h>
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
26
f2173d18c73f Checkpoint
lost
parents:
diff changeset
27 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
28 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
29 lw_expr_type_oper, // operator term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
30 lw_expr_type_int, // integer
f2173d18c73f Checkpoint
lost
parents:
diff changeset
31 lw_expr_type_var, // a "variable" (string for the name)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
32 lw_expr_type_special // a "special" reference (user defined)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
33 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
34
f2173d18c73f Checkpoint
lost
parents:
diff changeset
35 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
36 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
37 lw_expr_oper_plus = 1, // addition
f2173d18c73f Checkpoint
lost
parents:
diff changeset
38 lw_expr_oper_minus, // subtraction
f2173d18c73f Checkpoint
lost
parents:
diff changeset
39 lw_expr_oper_times, // multiplication
f2173d18c73f Checkpoint
lost
parents:
diff changeset
40 lw_expr_oper_divide, // division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
41 lw_expr_oper_mod, // modulus
f2173d18c73f Checkpoint
lost
parents:
diff changeset
42 lw_expr_oper_intdiv, // integer division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
43 lw_expr_oper_bwand, // bitwise and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
44 lw_expr_oper_bwor, // bitwise or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
45 lw_expr_oper_bwxor, // bitwise xor
f2173d18c73f Checkpoint
lost
parents:
diff changeset
46 lw_expr_oper_and, // boolean and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
47 lw_expr_oper_or, // boolean or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
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
f2173d18c73f Checkpoint
lost
parents:
diff changeset
51 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
52
f2173d18c73f Checkpoint
lost
parents:
diff changeset
53 #ifdef ___lw_expr_c_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
54
f2173d18c73f Checkpoint
lost
parents:
diff changeset
55 typedef struct lw_expr_priv * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
56
f2173d18c73f Checkpoint
lost
parents:
diff changeset
57 struct lw_expr_opers
f2173d18c73f Checkpoint
lost
parents:
diff changeset
58 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
59 lw_expr_t p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
60 struct lw_expr_opers *next;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
61 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
62
f2173d18c73f Checkpoint
lost
parents:
diff changeset
63 struct lw_expr_priv
f2173d18c73f Checkpoint
lost
parents:
diff changeset
64 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
65 int type; // type of term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
66 int value; // integer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
67 void *value2; // misc pointer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
68 struct lw_expr_opers *operands; // ptr to list of operands (for operators)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
69 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
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
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
74 typedef int lw_expr_testfn_t(lw_expr_t e, void *priv);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
75
f2173d18c73f Checkpoint
lost
parents:
diff changeset
76 #else /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
77
f2173d18c73f Checkpoint
lost
parents:
diff changeset
78 typedef void * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
79
f2173d18c73f Checkpoint
lost
parents:
diff changeset
80 extern lw_expr_t lwexpr_create(void);
337
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
81 extern void lw_expr_destroy(lw_expr_t E);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
82 extern lw_expr_t lw_expr_copy(lw_expr_t E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
83 extern void lw_expr_add_operand(lw_expr_t E, lw_expr_t O);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
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
f2173d18c73f Checkpoint
lost
parents:
diff changeset
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
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
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
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
92
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
93 extern void lw_expr_set_special_handler(lw_expr_fn_t *fn);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
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
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents: 346
diff changeset
98 extern int lw_expr_istype(lw_expr_t e, int t);
1649bc7bda5a Some data oriented pseudo ops added
lost@starbug
parents: 346
diff changeset
99 extern int lw_expr_intval(lw_expr_t e);
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
100 extern int lw_expr_specint(lw_expr_t e);
376
91c0fe026940 Output incomplete references in object target
lost@starbug
parents: 372
diff changeset
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
91c0fe026940 Output incomplete references in object target
lost@starbug
parents: 372
diff changeset
103
91c0fe026940 Output incomplete references in object target
lost@starbug
parents: 372
diff changeset
104 extern int lw_expr_type(lw_expr_t e);
367
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
105
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
106 typedef int lw_expr_testfn_t(lw_expr_t e, void *priv);
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
107
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
108 // run a function on all terms in an expression; if the function
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
109 // returns non-zero for any term, return non-zero, else return
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
110 // zero
34dfc9747f23 Reduction passes complete
lost@starbug
parents: 347
diff changeset
111 extern int lw_expr_testterms(lw_expr_t e, lw_expr_testfn_t *fn, void *priv);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
112
f2173d18c73f Checkpoint
lost
parents:
diff changeset
113 #endif /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
114
f2173d18c73f Checkpoint
lost
parents:
diff changeset
115 #endif /* ___lw_expr_h_seen___ */