-
Notifications
You must be signed in to change notification settings - Fork 13
/
exprtree.h
299 lines (269 loc) · 7.5 KB
/
exprtree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* exprtree.h
*
* MathMap
*
* Copyright (C) 1997-2009 Mark Probst
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __EXPRTREE_H__
#define __EXPRTREE_H__
#include "vars.h"
#include "builtins/builtins.h"
#include "internals.h"
#include "macros.h"
#include "scanner.h"
extern char error_string[];
extern scanner_region_t error_region;
#define LIMITS_INT 1
#define LIMITS_FLOAT 2
/* This is only used during parsing. */
typedef struct
{
int type;
scanner_region_t region;
union
{
struct
{
int min;
int max;
} integer;
struct
{
float min;
float max;
} floating;
} v;
} limits_t;
typedef struct _option_t
{
char *name;
struct _option_t *suboptions;
struct _option_t *next;
} option_t;
#define ARG_TYPE_INT 1
#define ARG_TYPE_FLOAT 2
#define ARG_TYPE_BOOL 3
#define ARG_TYPE_COLOR 4
#define ARG_TYPE_GRADIENT 5
#define ARG_TYPE_CURVE 6
#define ARG_TYPE_FILTER 7
#define ARG_TYPE_IMAGE 8
typedef struct _arg_decl_t
{
char *name;
int type;
char *docstring;
option_t *options;
scanner_region_t region;
union
{
struct
{
int have_limits;
int min;
int max;
int default_value;
} integer;
struct
{
int have_limits;
float min;
float max;
float default_value;
} floating;
struct
{
struct _arg_decl_t *args;
} filter;
struct
{
int default_value;
} boolean;
} v;
struct _arg_decl_t *next;
} arg_decl_t;
struct _overload_entry_t;
struct _userval_t;
struct _filter_t;
#define EXPR_INT_CONST 1
#define EXPR_FLOAT_CONST 2
#define EXPR_TUPLE_CONST 3
#define EXPR_FUNC 4
#define EXPR_INTERNAL 5
#define EXPR_SEQUENCE 6
#define EXPR_ASSIGNMENT 7
#define EXPR_VARIABLE 8
#define EXPR_IF_THEN 9
#define EXPR_IF_THEN_ELSE 10
#define EXPR_WHILE 11
#define EXPR_DO_WHILE 12
#define EXPR_TUPLE 13
#define EXPR_SELECT 14
#define EXPR_CAST 15
#define EXPR_CONVERT 16
#define EXPR_SUB_ASSIGNMENT 17
#define EXPR_USERVAL 18
#define EXPR_FILTER_CLOSURE 19
typedef struct _exprtree
{
int type;
tuple_info_t result;
int tmpvarnum;
scanner_region_t region;
union
{
tuple_t *tuple_const;
variable_t *var;
internal_t *internal;
int int_const;
float float_const;
struct
{
struct _userval_info_t *info;
} userval;
struct
{
int length;
struct _exprtree *elems;
} tuple;
struct
{
struct _exprtree *tuple;
struct _exprtree *subscripts;
} select;
struct
{
int tagnum;
struct _exprtree *tuple;
} cast;
struct
{
int tagnum;
struct _exprtree *tuple;
} convert;
struct
{
struct _overload_entry_t *entry;
struct _exprtree *args;
} func;
struct
{
struct _exprtree *left;
struct _exprtree *right;
} op;
struct
{
variable_t *var;
struct _exprtree *value;
} assignment;
struct
{
variable_t *var;
struct _exprtree *subscripts;
struct _exprtree *value;
} sub_assignment;
struct
{
struct _exprtree *condition;
struct _exprtree *consequent;
struct _exprtree *alternative;
int label1;
int label2;
} ifExpr;
struct
{
struct _exprtree *invariant;
struct _exprtree *body;
int label1;
int label2;
} whileExpr;
struct
{
macro_function_t macro;
struct _exprtree *args;
} macro;
struct
{
struct _filter_t *filter;
struct _exprtree *args;
} filter_closure;
} val;
struct _exprtree *next;
} exprtree;
#define TOP_LEVEL_FILTER 1
#define TOP_LEVEL_FUNCTION 2
typedef struct _top_level_decl_t
{
int type;
char *name;
char *docstring;
scanner_region_t region;
union
{
struct
{
arg_decl_t *args;
option_t *options;
exprtree *body;
} filter;
} v;
} top_level_decl_t;
extern top_level_decl_t *the_top_level_decls;
top_level_decl_t* make_filter_decl (scanner_ident_t *name, scanner_ident_t *docstring, arg_decl_t *args, option_t *options);
void free_top_level_decl (top_level_decl_t *list);
struct _filter_t* lookup_filter (struct _filter_t *filters, const char *name);
option_t* make_option (scanner_ident_t *name, option_t *suboptions);
option_t* options_append (option_t *o1, option_t *o2);
option_t* find_option_with_name (option_t *options, const char *name);
arg_decl_t* make_simple_arg_decl (int type, scanner_ident_t *name, scanner_ident_t *docstring, option_t *options);
arg_decl_t* make_filter_arg_decl (scanner_ident_t *name, arg_decl_t *args, scanner_ident_t *docstring, option_t *options);
arg_decl_t* arg_decl_list_append (arg_decl_t *list1, arg_decl_t *list2);
void free_arg_decls (arg_decl_t *list);
limits_t* make_int_limits (exprtree *min, exprtree *max);
limits_t* make_float_limits (exprtree *min, exprtree *max);
void free_limits (limits_t *limits);
void apply_limits_to_arg_decl (arg_decl_t *arg_decl, limits_t *limits);
void apply_default_to_arg_decl (arg_decl_t *arg_decl, exprtree *exprtree);
exprtree* make_int_number (int num, scanner_region_t region);
exprtree* make_float_number (float num, scanner_region_t region);
exprtree* make_range (exprtree *first_expr, exprtree *last_expr);
exprtree* make_var (scanner_ident_t *name); /* should use variable_t instead */
exprtree* make_var_from_string (const char *name);
exprtree* make_tuple_exprtree (exprtree *elems);
exprtree* make_select (exprtree *tuple, exprtree *subscripts);
exprtree* make_cast (scanner_ident_t *tagname, exprtree *tuple); /* should use tag number instead */
exprtree* make_convert (scanner_ident_t *tagname, exprtree *tuple); /* ditto */
exprtree* make_function (scanner_ident_t *name, exprtree *args);
exprtree* make_function_from_string (const char *name, exprtree *args, scanner_region_t name_region);
exprtree* make_operator_function (scanner_ident_t *name, exprtree *left, exprtree *right);
exprtree* make_unary_operator_function (scanner_ident_t *name, exprtree *arg);
exprtree* make_sequence (exprtree *left, exprtree *right);
exprtree* make_assignment (scanner_ident_t *name, exprtree *value); /* should use variable_t instead */
exprtree* make_sub_assignment (scanner_ident_t *name, exprtree *subscripts, exprtree *value);
exprtree* make_if_then (exprtree *condition, exprtree *consequent);
exprtree* make_if_then_else (exprtree *condition, exprtree *consequent, exprtree *alternative);
exprtree* make_while (exprtree *invariant, exprtree *body);
exprtree* make_do_while (exprtree *body, exprtree *invariant);
void check_for_start (exprtree *start);
exprtree* make_for (scanner_ident_t *name, exprtree *counter_init,
exprtree *start, exprtree *end, exprtree *body);
void free_exprtree (exprtree *tree);
int exprlist_length (exprtree *list);
exprtree* exprlist_append (exprtree *list1, exprtree *list2);
int is_exprtree_single_const (exprtree *tree, int *int_val, float *float_val);
#endif