annotate lwlib/lw_expr.h @ 342:7b4123dce741

Added basic symbol registration
author lost@starbug
date Wed, 24 Mar 2010 21:30:31 -0600
parents 04c80c51b16a
children a82c55070624
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
f2173d18c73f Checkpoint
lost
parents:
diff changeset
25
f2173d18c73f Checkpoint
lost
parents:
diff changeset
26 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
27 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
28 lw_expr_type_oper, // operator term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
29 lw_expr_type_int, // integer
f2173d18c73f Checkpoint
lost
parents:
diff changeset
30 lw_expr_type_var, // a "variable" (string for the name)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
31 lw_expr_type_special // a "special" reference (user defined)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
32 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
33
f2173d18c73f Checkpoint
lost
parents:
diff changeset
34 enum
f2173d18c73f Checkpoint
lost
parents:
diff changeset
35 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
36 lw_expr_oper_plus = 1, // addition
f2173d18c73f Checkpoint
lost
parents:
diff changeset
37 lw_expr_oper_minus, // subtraction
f2173d18c73f Checkpoint
lost
parents:
diff changeset
38 lw_expr_oper_times, // multiplication
f2173d18c73f Checkpoint
lost
parents:
diff changeset
39 lw_expr_oper_divide, // division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
40 lw_expr_oper_mod, // modulus
f2173d18c73f Checkpoint
lost
parents:
diff changeset
41 lw_expr_oper_intdiv, // integer division
f2173d18c73f Checkpoint
lost
parents:
diff changeset
42 lw_expr_oper_bwand, // bitwise and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
43 lw_expr_oper_bwor, // bitwise or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
44 lw_expr_oper_bwxor, // bitwise xor
f2173d18c73f Checkpoint
lost
parents:
diff changeset
45 lw_expr_oper_and, // boolean and
f2173d18c73f Checkpoint
lost
parents:
diff changeset
46 lw_expr_oper_or, // boolean or
f2173d18c73f Checkpoint
lost
parents:
diff changeset
47 lw_expr_oper_neg, // unary negation, 2's complement
f2173d18c73f Checkpoint
lost
parents:
diff changeset
48 lw_expr_oper_com // unary 1's complement
f2173d18c73f Checkpoint
lost
parents:
diff changeset
49 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
50
f2173d18c73f Checkpoint
lost
parents:
diff changeset
51 #ifdef ___lw_expr_c_seen___
f2173d18c73f Checkpoint
lost
parents:
diff changeset
52
f2173d18c73f Checkpoint
lost
parents:
diff changeset
53 typedef struct lw_expr_priv * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
54
f2173d18c73f Checkpoint
lost
parents:
diff changeset
55 struct lw_expr_opers
f2173d18c73f Checkpoint
lost
parents:
diff changeset
56 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
57 lw_expr_t p;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
58 struct lw_expr_opers *next;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
59 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
60
f2173d18c73f Checkpoint
lost
parents:
diff changeset
61 struct lw_expr_priv
f2173d18c73f Checkpoint
lost
parents:
diff changeset
62 {
f2173d18c73f Checkpoint
lost
parents:
diff changeset
63 int type; // type of term
f2173d18c73f Checkpoint
lost
parents:
diff changeset
64 int value; // integer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
65 void *value2; // misc pointer value
f2173d18c73f Checkpoint
lost
parents:
diff changeset
66 struct lw_expr_opers *operands; // ptr to list of operands (for operators)
f2173d18c73f Checkpoint
lost
parents:
diff changeset
67 };
f2173d18c73f Checkpoint
lost
parents:
diff changeset
68
342
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
69 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
70 typedef lw_expr_t lw_expr_fn2_t(char *var);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
71
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
72
f2173d18c73f Checkpoint
lost
parents:
diff changeset
73 #else /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
74
f2173d18c73f Checkpoint
lost
parents:
diff changeset
75 typedef void * lw_expr_t;
f2173d18c73f Checkpoint
lost
parents:
diff changeset
76
f2173d18c73f Checkpoint
lost
parents:
diff changeset
77 extern lw_expr_t lwexpr_create(void);
337
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
78 extern void lw_expr_destroy(lw_expr_t E);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
79 extern lw_expr_t lw_expr_copy(lw_expr_t E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
80 extern void lw_expr_add_operand(lw_expr_t E, lw_expr_t O);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
81 extern lw_expr_t lw_expr_build(int exprtype, ...);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
82 extern void lw_expr_print(lw_expr_t E);
f2173d18c73f Checkpoint
lost
parents:
diff changeset
83 extern int lw_expr_compare(lw_expr_t E1, lw_expr_t E2);
335
9f58e3bca6e3 checkpoint
lost
parents: 334
diff changeset
84 extern void lw_expr_simplify(lw_expr_t E);
337
04c80c51b16a Checkpoint development
lost
parents: 335
diff changeset
85
342
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
86 typedef lw_expr_t lw_expr_fn_t(int t, void *ptr);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
87 typedef lw_expr_t lw_expr_fn2_t(char *var);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
88
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
89 extern void lw_expr_set_special_handler(lw_expr_fn_t *fn);
7b4123dce741 Added basic symbol registration
lost@starbug
parents: 337
diff changeset
90 extern void lw_expr_set_var_handler(lw_expr_fn2_t *fn);
334
f2173d18c73f Checkpoint
lost
parents:
diff changeset
91
f2173d18c73f Checkpoint
lost
parents:
diff changeset
92 #endif /* def ___lw_expr_c_seen___ */
f2173d18c73f Checkpoint
lost
parents:
diff changeset
93
f2173d18c73f Checkpoint
lost
parents:
diff changeset
94 #endif /* ___lw_expr_h_seen___ */