Skip to content

Latest commit

 

History

History
2770 lines (2377 loc) · 97.2 KB

mojoshader_compiler.c

File metadata and controls

2770 lines (2377 loc) · 97.2 KB
 
Feb 19, 2010
Feb 19, 2010
1
2
3
4
5
6
7
8
9
/**
* MojoShader; generate shader programs from bytecode of compiled
* Direct3D shaders.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Oct 19, 2010
Oct 19, 2010
10
11
12
13
// !!! FIXME: this needs to be split into separate source files:
// !!! FIXME: parse, AST, IR, etc. The problem is we need to deal with the
// !!! FIXME: "Context" struct being passed around everywhere.
Feb 28, 2009
Feb 28, 2009
14
15
#define __MOJOSHADER_INTERNAL__ 1
#include "mojoshader_internal.h"
Aug 23, 2009
Aug 23, 2009
17
18
19
20
#if DEBUG_COMPILER_PARSER
#define LEMON_SUPPORT_TRACING 1
#endif
Oct 13, 2010
Oct 13, 2010
21
22
// !!! FIXME: I'd like to lose this. It's really inefficient. Just keep a
// !!! FIXME: (tail) on these list structures instead?
Feb 23, 2010
Feb 23, 2010
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#define REVERSE_LINKED_LIST(typ, head) { \
if ((head) && (head->next)) { \
typ *tmp = NULL; \
typ *tmp1 = NULL; \
while (head != NULL) { \
tmp = head; \
head = head->next; \
tmp->next = tmp1; \
tmp1 = tmp; \
} \
head = tmp; \
} \
}
Oct 28, 2010
Oct 28, 2010
37
static inline int operator_is_unary(const MOJOSHADER_astNodeType op)
Aug 23, 2009
Aug 23, 2009
38
{
Oct 28, 2010
Oct 28, 2010
39
40
return ( (op > MOJOSHADER_AST_OP_START_RANGE_UNARY) &&
(op < MOJOSHADER_AST_OP_END_RANGE_UNARY) );
Feb 9, 2010
Feb 9, 2010
41
42
} // operator_is_unary
Oct 28, 2010
Oct 28, 2010
43
static inline int operator_is_binary(const MOJOSHADER_astNodeType op)
Feb 9, 2010
Feb 9, 2010
44
{
Oct 28, 2010
Oct 28, 2010
45
46
return ( (op > MOJOSHADER_AST_OP_START_RANGE_BINARY) &&
(op < MOJOSHADER_AST_OP_END_RANGE_BINARY) );
Feb 9, 2010
Feb 9, 2010
47
48
} // operator_is_binary
Oct 28, 2010
Oct 28, 2010
49
static inline int operator_is_ternary(const MOJOSHADER_astNodeType op)
Feb 9, 2010
Feb 9, 2010
50
{
Oct 28, 2010
Oct 28, 2010
51
52
return ( (op > MOJOSHADER_AST_OP_START_RANGE_TERNARY) &&
(op < MOJOSHADER_AST_OP_END_RANGE_TERNARY) );
Feb 9, 2010
Feb 9, 2010
53
54
55
} // operator_is_ternary
Oct 28, 2010
Oct 28, 2010
56
typedef union TokenData
Feb 9, 2010
Feb 9, 2010
57
{
Oct 28, 2010
Oct 28, 2010
58
59
int64 i64;
double dbl;
Feb 9, 2010
Feb 9, 2010
60
const char *string;
Oct 28, 2010
Oct 28, 2010
61
} TokenData;
Feb 19, 2010
Feb 19, 2010
62
63
Oct 19, 2010
Oct 19, 2010
64
// This tracks data types and variables, and notes when they enter/leave scope.
Feb 22, 2010
Feb 22, 2010
65
Oct 19, 2010
Oct 19, 2010
66
typedef struct SymbolScope
Feb 22, 2010
Feb 22, 2010
67
68
69
{
const char *symbol;
const char *datatype;
Oct 19, 2010
Oct 19, 2010
70
71
struct SymbolScope *next;
} SymbolScope;
Feb 22, 2010
Feb 22, 2010
72
Oct 19, 2010
Oct 19, 2010
73
typedef struct SymbolMap
Feb 22, 2010
Feb 22, 2010
74
{
Oct 19, 2010
Oct 19, 2010
75
76
77
HashTable *hash;
SymbolScope *scope;
} SymbolMap;
Feb 22, 2010
Feb 22, 2010
78
79
Feb 19, 2010
Feb 19, 2010
80
81
82
83
84
85
86
87
88
89
90
// Compile state, passed around all over the place.
typedef struct Context
{
int isfail;
int out_of_memory;
MOJOSHADER_malloc malloc;
MOJOSHADER_free free;
void *malloc_data;
int error_count;
ErrorList *errors;
Nov 2, 2010
Nov 2, 2010
91
92
int warning_count;
ErrorList *warnings;
Feb 24, 2010
Feb 24, 2010
93
StringCache *strcache;
Feb 22, 2010
Feb 22, 2010
94
95
const char *sourcefile; // current source file that we're parsing.
unsigned int sourceline; // current line in sourcefile that we're parsing.
Oct 19, 2010
Oct 19, 2010
96
97
SymbolMap usertypes;
SymbolMap variables;
Oct 28, 2010
Oct 28, 2010
98
MOJOSHADER_astNode *ast; // Abstract Syntax Tree
Nov 1, 2010
Nov 1, 2010
99
const char *source_profile;
Oct 19, 2010
Oct 19, 2010
100
101
102
103
104
105
// These are entries allocated in the strcache, so these pointers are
// valid from shortly after we create the cache until we destroy it
// with the rest of the context. This makes it so we can compare common
// strings by pointer without having to hash them every time, so long as
// we're comparing a string pointer we know came from this string cache.
Oct 26, 2010
Oct 26, 2010
106
// The first batch are simplifed datatype strings ("b" == bool, etc).
Oct 19, 2010
Oct 19, 2010
107
108
109
const char *str_b; // "b"
const char *str_f; // "f"
const char *str_i; // "i"
Oct 20, 2010
Oct 20, 2010
110
111
112
113
const char *str_u; // "u"
const char *str_h; // "h"
const char *str_d; // "d"
const char *str_s; // "s"
Oct 26, 2010
Oct 26, 2010
114
115
116
117
118
119
120
121
122
123
124
const char *str_S; // "S"
const char *str_s1; // "s1"
const char *str_s2; // "s2"
const char *str_s3; // "s3"
const char *str_sc; // "sc"
const char *str_ss; // "ss"
const char *str_sS; // "sS"
const char *str_Fs; // "Fs"
const char *str_Fu; // "Fu"
const char *str_ns; // "ns"
const char *str_nu; // "nu"
Feb 19, 2010
Feb 19, 2010
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
} Context;
// Convenience functions for allocators...
static inline void out_of_memory(Context *ctx)
{
ctx->isfail = ctx->out_of_memory = 1;
} // out_of_memory
static inline void *Malloc(Context *ctx, const size_t len)
{
void *retval = ctx->malloc((int) len, ctx->malloc_data);
if (retval == NULL)
out_of_memory(ctx);
return retval;
} // Malloc
static inline char *StrDup(Context *ctx, const char *str)
{
char *retval = (char *) Malloc(ctx, strlen(str) + 1);
if (retval != NULL)
strcpy(retval, str);
return retval;
} // StrDup
static inline void Free(Context *ctx, void *ptr)
{
if (ptr != NULL) // check for NULL in case of dumb free() impl.
ctx->free(ptr, ctx->malloc_data);
} // Free
Nov 1, 2010
Nov 1, 2010
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
static void failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
static void failf(Context *ctx, const char *fmt, ...)
{
const char *fname = ctx->sourcefile;
const unsigned int error_position = ctx->sourceline;
ctx->isfail = 1;
const int MAX_ERROR_COUNT = 128;
if (ctx->error_count == (MAX_ERROR_COUNT-1))
fmt = "Too many errors, not reporting any more.";
else if (ctx->error_count >= MAX_ERROR_COUNT)
return;
ErrorList *error = (ErrorList *) Malloc(ctx, sizeof (ErrorList));
if (error == NULL)
return;
char scratch = 0;
va_list ap;
va_start(ap, fmt);
const int len = vsnprintf(&scratch, sizeof (scratch), fmt, ap);
va_end(ap);
char *failstr = (char *) Malloc(ctx, len + 1);
if (failstr == NULL)
Free(ctx, error);
else
{
va_start(ap, fmt);
vsnprintf(failstr, len + 1, fmt, ap); // rebuild it.
va_end(ap);
error->error.error = failstr;
error->error.filename = fname ? StrDup(ctx, fname) : NULL;
error->error.error_position = error_position;
error->next = NULL;
ErrorList *prev = NULL;
ErrorList *item = ctx->errors;
while (item != NULL)
{
prev = item;
item = item->next;
} // while
if (prev == NULL)
ctx->errors = error;
else
prev->next = error;
ctx->error_count++;
} // else
} // failf
static inline void fail(Context *ctx, const char *reason)
Feb 21, 2010
Feb 21, 2010
213
{
Nov 1, 2010
Nov 1, 2010
214
failf(ctx, "%s", reason);
Feb 21, 2010
Feb 21, 2010
215
} // fail
Feb 19, 2010
Feb 19, 2010
216
Nov 1, 2010
Nov 1, 2010
217
218
219
220
221
static inline int isfail(const Context *ctx)
{
return ctx->isfail;
} // isfail
Feb 22, 2010
Feb 22, 2010
222
Oct 19, 2010
Oct 19, 2010
223
static void symbolmap_nuke(const void *k, const void *v, void *d) {/*no-op*/}
Feb 22, 2010
Feb 22, 2010
224
Oct 19, 2010
Oct 19, 2010
225
static int create_symbolmap(Context *ctx, SymbolMap *map)
Feb 22, 2010
Feb 22, 2010
226
{
Oct 19, 2010
Oct 19, 2010
227
// !!! FIXME: should compare string pointer, with string in cache.
Feb 22, 2010
Feb 22, 2010
228
map->scope = NULL;
Oct 19, 2010
Oct 19, 2010
229
230
231
232
map->hash = hash_create(ctx, hash_hash_string, hash_keymatch_string,
symbolmap_nuke, 1, ctx->malloc, ctx->free,
ctx->malloc_data);
if (!map->hash)
Feb 22, 2010
Feb 22, 2010
233
234
235
236
237
238
{
out_of_memory(ctx);
return 0;
} // if
return 1;
Oct 19, 2010
Oct 19, 2010
239
} // create_symbolmap
Feb 22, 2010
Feb 22, 2010
240
241
Oct 19, 2010
Oct 19, 2010
242
243
244
static void push_symbol(Context *ctx, SymbolMap *map,
const char *sym, const char *datatype)
{
Oct 26, 2010
Oct 26, 2010
245
246
247
// !!! FIXME: decide if this symbol is defined, and if so, if it's in
// !!! FIXME: the current scope.
Oct 19, 2010
Oct 19, 2010
248
SymbolScope *item = (SymbolScope *) Malloc(ctx, sizeof (SymbolScope));
Feb 22, 2010
Feb 22, 2010
249
250
251
252
253
if (item == NULL)
return;
if (sym != NULL)
{
Oct 19, 2010
Oct 19, 2010
254
if (hash_insert(map->hash, sym, datatype) == -1)
Feb 22, 2010
Feb 22, 2010
255
256
257
{
Free(ctx, item);
return;
Oct 26, 2010
Oct 26, 2010
258
} // if
Feb 22, 2010
Feb 22, 2010
259
260
261
262
263
264
} // if
item->symbol = sym; // cached strings, don't copy.
item->datatype = datatype;
item->next = map->scope;
map->scope = item;
Oct 19, 2010
Oct 19, 2010
265
266
267
268
269
} // push_symbol
static inline void push_usertype(Context *ctx, const char *sym, const char *dt)
{
push_symbol(ctx, &ctx->usertypes, sym, dt);
Feb 22, 2010
Feb 22, 2010
270
271
} // push_usertype
Oct 19, 2010
Oct 19, 2010
272
273
274
275
276
277
278
279
280
281
282
283
284
static inline void push_variable(Context *ctx, const char *sym, const char *dt)
{
push_symbol(ctx, &ctx->variables, sym, dt);
} // push_variable
static inline void push_scope(Context *ctx)
{
push_usertype(ctx, NULL, NULL);
push_variable(ctx, NULL, NULL);
} // push_scope
static void pop_symbol(Context *ctx, SymbolMap *map)
Feb 22, 2010
Feb 22, 2010
285
{
Oct 19, 2010
Oct 19, 2010
286
SymbolScope *item = map->scope;
Feb 22, 2010
Feb 22, 2010
287
288
289
if (!item)
return;
if (item->symbol)
Oct 19, 2010
Oct 19, 2010
290
hash_remove(map->hash, item->symbol);
Feb 22, 2010
Feb 22, 2010
291
292
map->scope = item->next;
Free(ctx, item);
Oct 19, 2010
Oct 19, 2010
293
} // pop_symbol
Feb 22, 2010
Feb 22, 2010
294
Oct 19, 2010
Oct 19, 2010
295
static void pop_symbol_scope(Context *ctx, SymbolMap *map)
Feb 22, 2010
Feb 22, 2010
296
297
{
while ((map->scope) && (map->scope->symbol))
Oct 19, 2010
Oct 19, 2010
298
pop_symbol(ctx, map);
Feb 22, 2010
Feb 22, 2010
299
300
301
assert(map->scope != NULL);
assert(map->scope->symbol == NULL);
Oct 19, 2010
Oct 19, 2010
302
303
304
305
306
307
308
pop_symbol(ctx, map);
} // pop_symbol_scope
static inline void pop_scope(Context *ctx)
{
pop_symbol_scope(ctx, &ctx->usertypes);
pop_symbol_scope(ctx, &ctx->variables);
Feb 22, 2010
Feb 22, 2010
309
310
} // push_scope
Oct 26, 2010
Oct 26, 2010
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
static const char *find_symbol(Context *ctx, SymbolMap *map, const char *sym)
{
const void *value = NULL;
hash_find(map->hash, sym, &value);
return (const char *) value;
} // find_symbol
static inline const char *find_usertype(Context *ctx, const char *sym)
{
return find_symbol(ctx, &ctx->usertypes, sym);
} // find_usertype
static inline const char *find_variable(Context *ctx, const char *sym)
{
return find_symbol(ctx, &ctx->variables, sym);
} // find_variable
Oct 19, 2010
Oct 19, 2010
328
static void destroy_symbolmap(Context *ctx, SymbolMap *map)
Feb 22, 2010
Feb 22, 2010
329
330
{
while (map->scope)
Oct 19, 2010
Oct 19, 2010
331
332
333
pop_symbol_scope(ctx, map);
hash_destroy(map->hash);
} // destroy_symbolmap
Feb 22, 2010
Feb 22, 2010
334
335
Feb 19, 2010
Feb 19, 2010
336
337
338
339
340
// These functions are mostly for construction and cleanup of nodes in the
// parse tree. Mostly this is simple allocation and initialization, so we
// can do as little in the lemon code as possible, and then sort it all out
// afterwards.
Feb 22, 2010
Feb 22, 2010
341
#define NEW_AST_NODE(retval, cls, typ) \
Mar 3, 2010
Mar 3, 2010
342
cls *retval = (cls *) Malloc(ctx, sizeof (cls)); \
Feb 22, 2010
Feb 22, 2010
343
344
345
346
347
348
349
350
do { \
if (retval == NULL) { return NULL; } \
retval->ast.type = typ; \
retval->ast.filename = ctx->sourcefile; \
retval->ast.line = ctx->sourceline; \
} while (0)
#define DELETE_AST_NODE(cls) do { \
Feb 19, 2010
Feb 19, 2010
351
352
353
if (!cls) return; \
} while (0)
Oct 28, 2010
Oct 28, 2010
354
355
static void delete_compilation_unit(Context*, MOJOSHADER_astCompilationUnit*);
static void delete_statement(Context *ctx, MOJOSHADER_astStatement *stmt);
Feb 19, 2010
Feb 19, 2010
356
Oct 28, 2010
Oct 28, 2010
357
358
359
static MOJOSHADER_astExpression *new_callfunc_expr(Context *ctx,
MOJOSHADER_astExpression *identifier,
MOJOSHADER_astArguments *args)
Oct 25, 2010
Oct 25, 2010
360
{
Oct 28, 2010
Oct 28, 2010
361
362
NEW_AST_NODE(retval, MOJOSHADER_astExpressionCallFunction,
MOJOSHADER_AST_OP_CALLFUNC);
Oct 25, 2010
Oct 25, 2010
363
364
retval->identifier = identifier;
retval->args = args;
Oct 28, 2010
Oct 28, 2010
365
return (MOJOSHADER_astExpression *) retval;
Oct 25, 2010
Oct 25, 2010
366
367
} // new_callfunc_expr
Oct 28, 2010
Oct 28, 2010
368
369
370
static MOJOSHADER_astExpression *new_constructor_expr(Context *ctx,
const char *datatype,
MOJOSHADER_astArguments *args)
Feb 20, 2010
Feb 20, 2010
371
{
Oct 28, 2010
Oct 28, 2010
372
373
NEW_AST_NODE(retval, MOJOSHADER_astExpressionConstructor,
MOJOSHADER_AST_OP_CONSTRUCTOR);
Feb 20, 2010
Feb 20, 2010
374
375
retval->datatype = datatype;
retval->args = args;
Oct 28, 2010
Oct 28, 2010
376
return (MOJOSHADER_astExpression *) retval;
Feb 20, 2010
Feb 20, 2010
377
378
} // new_constructor_expr
Oct 28, 2010
Oct 28, 2010
379
380
381
static MOJOSHADER_astExpression *new_cast_expr(Context *ctx,
const char *datatype,
MOJOSHADER_astExpression *operand)
Feb 20, 2010
Feb 20, 2010
382
{
Oct 28, 2010
Oct 28, 2010
383
NEW_AST_NODE(retval, MOJOSHADER_astExpressionCast, MOJOSHADER_AST_OP_CAST);
Feb 20, 2010
Feb 20, 2010
384
385
retval->datatype = datatype;
retval->operand = operand;
Oct 28, 2010
Oct 28, 2010
386
return (MOJOSHADER_astExpression *) retval;
Feb 20, 2010
Feb 20, 2010
387
388
} // new_cast_expr
Oct 28, 2010
Oct 28, 2010
389
390
391
static MOJOSHADER_astExpression *new_unary_expr(Context *ctx,
const MOJOSHADER_astNodeType op,
MOJOSHADER_astExpression *operand)
Feb 9, 2010
Feb 9, 2010
392
{
Oct 28, 2010
Oct 28, 2010
393
NEW_AST_NODE(retval, MOJOSHADER_astExpressionUnary, op);
Feb 9, 2010
Feb 9, 2010
394
395
assert(operator_is_unary(op));
retval->operand = operand;
Oct 28, 2010
Oct 28, 2010
396
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
397
398
} // new_unary_expr
Oct 28, 2010
Oct 28, 2010
399
400
401
402
static MOJOSHADER_astExpression *new_binary_expr(Context *ctx,
const MOJOSHADER_astNodeType op,
MOJOSHADER_astExpression *left,
MOJOSHADER_astExpression *right)
Feb 9, 2010
Feb 9, 2010
403
{
Oct 28, 2010
Oct 28, 2010
404
NEW_AST_NODE(retval, MOJOSHADER_astExpressionBinary, op);
Feb 9, 2010
Feb 9, 2010
405
406
407
assert(operator_is_binary(op));
retval->left = left;
retval->right = right;
Oct 28, 2010
Oct 28, 2010
408
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
409
410
} // new_binary_expr
Oct 28, 2010
Oct 28, 2010
411
412
413
414
415
static MOJOSHADER_astExpression *new_ternary_expr(Context *ctx,
const MOJOSHADER_astNodeType op,
MOJOSHADER_astExpression *left,
MOJOSHADER_astExpression *center,
MOJOSHADER_astExpression *right)
Feb 9, 2010
Feb 9, 2010
416
{
Oct 28, 2010
Oct 28, 2010
417
NEW_AST_NODE(retval, MOJOSHADER_astExpressionTernary, op);
Feb 9, 2010
Feb 9, 2010
418
419
420
421
assert(operator_is_ternary(op));
retval->left = left;
retval->center = center;
retval->right = right;
Oct 28, 2010
Oct 28, 2010
422
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
423
424
} // new_ternary_expr
Oct 28, 2010
Oct 28, 2010
425
426
427
static MOJOSHADER_astExpression *new_deref_struct_expr(Context *ctx,
MOJOSHADER_astExpression *identifier,
const char *member)
Oct 26, 2010
Oct 26, 2010
428
{
Oct 28, 2010
Oct 28, 2010
429
430
NEW_AST_NODE(retval, MOJOSHADER_astExpressionDerefStruct,
MOJOSHADER_AST_OP_DEREF_STRUCT);
Oct 26, 2010
Oct 26, 2010
431
432
retval->identifier = identifier;
retval->member = member; // cached; don't copy string.
Oct 28, 2010
Oct 28, 2010
433
return (MOJOSHADER_astExpression *) retval;
Oct 26, 2010
Oct 26, 2010
434
435
} // new_deref_struct_expr
Oct 28, 2010
Oct 28, 2010
436
437
static MOJOSHADER_astExpression *new_identifier_expr(Context *ctx,
const char *string)
Feb 9, 2010
Feb 9, 2010
438
{
Oct 28, 2010
Oct 28, 2010
439
440
NEW_AST_NODE(retval, MOJOSHADER_astExpressionIdentifier,
MOJOSHADER_AST_OP_IDENTIFIER);
Feb 9, 2010
Feb 9, 2010
441
retval->identifier = string; // cached; don't copy string.
Oct 28, 2010
Oct 28, 2010
442
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
443
444
} // new_identifier_expr
Oct 28, 2010
Oct 28, 2010
445
446
static MOJOSHADER_astExpression *new_literal_int_expr(Context *ctx,
const int value)
Feb 9, 2010
Feb 9, 2010
447
{
Oct 28, 2010
Oct 28, 2010
448
449
NEW_AST_NODE(retval, MOJOSHADER_astExpressionIntLiteral,
MOJOSHADER_AST_OP_INT_LITERAL);
Feb 9, 2010
Feb 9, 2010
450
retval->value = value;
Oct 28, 2010
Oct 28, 2010
451
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
452
453
} // new_literal_int_expr
Oct 28, 2010
Oct 28, 2010
454
455
static MOJOSHADER_astExpression *new_literal_float_expr(Context *ctx,
const double dbl)
Feb 9, 2010
Feb 9, 2010
456
{
Oct 28, 2010
Oct 28, 2010
457
458
NEW_AST_NODE(retval, MOJOSHADER_astExpressionFloatLiteral,
MOJOSHADER_AST_OP_FLOAT_LITERAL);
Feb 9, 2010
Feb 9, 2010
459
retval->value = dbl;
Oct 28, 2010
Oct 28, 2010
460
return (MOJOSHADER_astExpression *) retval;
Feb 9, 2010
Feb 9, 2010
461
462
} // new_literal_float_expr
Oct 28, 2010
Oct 28, 2010
463
464
static MOJOSHADER_astExpression *new_literal_string_expr(Context *ctx,
const char *string)
Feb 9, 2010
Feb 9, 2010
465
{
Oct 28, 2010
Oct 28, 2010
466
467
NEW_AST_NODE(retval, MOJOSHADER_astExpressionStringLiteral,
MOJOSHADER_AST_OP_STRING_LITERAL);
Feb 9, 2010
Feb 9, 2010
468
retval->string = string; // cached; don't copy string.
Oct 28, 2010
Oct 28, 2010
469
return (MOJOSHADER_astExpression *) retval;
Oct 20, 2010
Oct 20, 2010
470
471
} // new_literal_string_expr
Oct 28, 2010
Oct 28, 2010
472
473
static MOJOSHADER_astExpression *new_literal_boolean_expr(Context *ctx,
const int value)
Oct 20, 2010
Oct 20, 2010
474
{
Oct 28, 2010
Oct 28, 2010
475
476
NEW_AST_NODE(retval, MOJOSHADER_astExpressionBooleanLiteral,
MOJOSHADER_AST_OP_BOOLEAN_LITERAL);
Oct 20, 2010
Oct 20, 2010
477
retval->value = value;
Oct 28, 2010
Oct 28, 2010
478
return (MOJOSHADER_astExpression *) retval;
Oct 20, 2010
Oct 20, 2010
479
} // new_literal_boolean_expr
Feb 9, 2010
Feb 9, 2010
480
Oct 28, 2010
Oct 28, 2010
481
static void delete_arguments(Context *ctx, MOJOSHADER_astArguments *args);
Oct 25, 2010
Oct 25, 2010
482
Oct 28, 2010
Oct 28, 2010
483
static void delete_expr(Context *ctx, MOJOSHADER_astExpression *_expr)
Feb 19, 2010
Feb 19, 2010
484
{
Oct 28, 2010
Oct 28, 2010
485
486
MOJOSHADER_astNode *expr = (MOJOSHADER_astNode *) _expr;
Feb 19, 2010
Feb 19, 2010
487
DELETE_AST_NODE(expr);
Oct 28, 2010
Oct 28, 2010
488
489
490
491
492
493
494
495
496
497
498
499
500
if (expr->ast.type == MOJOSHADER_AST_OP_CAST)
delete_expr(ctx, expr->cast.operand);
else if (expr->ast.type == MOJOSHADER_AST_OP_CONSTRUCTOR)
delete_arguments(ctx, expr->constructor.args);
else if (expr->ast.type == MOJOSHADER_AST_OP_DEREF_STRUCT)
delete_expr(ctx, expr->derefstruct.identifier);
else if (operator_is_unary(expr->ast.type))
delete_expr(ctx, expr->unary.operand);
Feb 22, 2010
Feb 22, 2010
501
else if (operator_is_binary(expr->ast.type))
Feb 19, 2010
Feb 19, 2010
502
{
Oct 28, 2010
Oct 28, 2010
503
504
delete_expr(ctx, expr->binary.left);
delete_expr(ctx, expr->binary.right);
Feb 19, 2010
Feb 19, 2010
505
} // else if
Oct 28, 2010
Oct 28, 2010
506
Feb 22, 2010
Feb 22, 2010
507
else if (operator_is_ternary(expr->ast.type))
Feb 19, 2010
Feb 19, 2010
508
{
Oct 28, 2010
Oct 28, 2010
509
510
511
delete_expr(ctx, expr->ternary.left);
delete_expr(ctx, expr->ternary.center);
delete_expr(ctx, expr->ternary.right);
Oct 26, 2010
Oct 26, 2010
512
} // else if
Oct 28, 2010
Oct 28, 2010
513
514
else if (expr->ast.type == MOJOSHADER_AST_OP_CALLFUNC)
Oct 25, 2010
Oct 25, 2010
515
{
Oct 28, 2010
Oct 28, 2010
516
517
delete_expr(ctx, expr->callfunc.identifier);
delete_arguments(ctx, expr->callfunc.args);
Feb 20, 2010
Feb 20, 2010
518
} // else if
Feb 22, 2010
Feb 22, 2010
519
520
521
// rest of operators don't have extra data to free.
Feb 19, 2010
Feb 19, 2010
522
523
524
Free(ctx, expr);
} // delete_expr
Oct 28, 2010
Oct 28, 2010
525
526
static MOJOSHADER_astArguments *new_argument(Context *ctx,
MOJOSHADER_astExpression *arg)
Oct 25, 2010
Oct 25, 2010
527
{
Oct 28, 2010
Oct 28, 2010
528
529
NEW_AST_NODE(retval, MOJOSHADER_astArguments, MOJOSHADER_AST_ARGUMENTS);
retval->argument = arg;
Oct 25, 2010
Oct 25, 2010
530
531
532
533
retval->next = NULL;
return retval;
} // new_argument
Oct 28, 2010
Oct 28, 2010
534
static void delete_arguments(Context *ctx, MOJOSHADER_astArguments *args)
Oct 25, 2010
Oct 25, 2010
535
536
537
538
539
540
541
{
DELETE_AST_NODE(args);
delete_arguments(ctx, args->next);
delete_expr(ctx, args->argument);
Free(ctx, args);
} // delete_arguments
Oct 28, 2010
Oct 28, 2010
542
543
544
545
546
547
static MOJOSHADER_astFunctionParameters *new_function_param(Context *ctx,
const MOJOSHADER_astInputModifier inputmod,
const char *datatype, const char *identifier,
const char *semantic,
const MOJOSHADER_astInterpolationModifier interpmod,
MOJOSHADER_astExpression *initializer)
Feb 19, 2010
Feb 19, 2010
548
{
Oct 28, 2010
Oct 28, 2010
549
550
NEW_AST_NODE(retval, MOJOSHADER_astFunctionParameters,
MOJOSHADER_AST_FUNCTION_PARAMS);
Feb 19, 2010
Feb 19, 2010
551
552
553
554
555
556
557
558
retval->input_modifier = inputmod;
retval->datatype = datatype;
retval->identifier = identifier;
retval->semantic = semantic;
retval->interpolation_modifier = interpmod;
retval->initializer = initializer;
retval->next = NULL;
return retval;
Oct 25, 2010
Oct 25, 2010
559
} // new_function_param
Feb 19, 2010
Feb 19, 2010
560
Oct 28, 2010
Oct 28, 2010
561
562
static void delete_function_params(Context *ctx,
MOJOSHADER_astFunctionParameters *params)
Feb 19, 2010
Feb 19, 2010
563
{
Oct 25, 2010
Oct 25, 2010
564
565
566
567
568
DELETE_AST_NODE(params);
delete_function_params(ctx, params->next);
delete_expr(ctx, params->initializer);
Free(ctx, params);
} // delete_function_params
Feb 19, 2010
Feb 19, 2010
569
Oct 28, 2010
Oct 28, 2010
570
571
572
573
static MOJOSHADER_astFunctionSignature *new_function_signature(Context *ctx,
const char *datatype,
const char *identifier,
MOJOSHADER_astFunctionParameters *params)
Feb 19, 2010
Feb 19, 2010
574
{
Oct 28, 2010
Oct 28, 2010
575
576
NEW_AST_NODE(retval, MOJOSHADER_astFunctionSignature,
MOJOSHADER_AST_FUNCTION_SIGNATURE);
Feb 19, 2010
Feb 19, 2010
577
578
retval->datatype = datatype;
retval->identifier = identifier;
Oct 25, 2010
Oct 25, 2010
579
retval->params = params;
Oct 28, 2010
Oct 28, 2010
580
retval->storage_class = MOJOSHADER_AST_FNSTORECLS_NONE;
Feb 19, 2010
Feb 19, 2010
581
582
583
584
retval->semantic = NULL;
return retval;
} // new_function_signature
Oct 28, 2010
Oct 28, 2010
585
586
static void delete_function_signature(Context *ctx,
MOJOSHADER_astFunctionSignature *sig)
Feb 19, 2010
Feb 19, 2010
587
588
{
DELETE_AST_NODE(sig);
Oct 25, 2010
Oct 25, 2010
589
delete_function_params(ctx, sig->params);
Feb 19, 2010
Feb 19, 2010
590
591
592
Free(ctx, sig);
} // delete_function_signature
Oct 28, 2010
Oct 28, 2010
593
594
595
static MOJOSHADER_astCompilationUnit *new_function(Context *ctx,
MOJOSHADER_astFunctionSignature *declaration,
MOJOSHADER_astStatement *definition)
Feb 19, 2010
Feb 19, 2010
596
{
Oct 28, 2010
Oct 28, 2010
597
598
NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitFunction,
MOJOSHADER_AST_COMPUNIT_FUNCTION);
Feb 19, 2010
Feb 19, 2010
599
600
601
retval->next = NULL;
retval->declaration = declaration;
retval->definition = definition;
Oct 28, 2010
Oct 28, 2010
602
return (MOJOSHADER_astCompilationUnit *) retval;
Feb 19, 2010
Feb 19, 2010
603
604
} // new_function
Oct 28, 2010
Oct 28, 2010
605
606
static void delete_function(Context *ctx,
MOJOSHADER_astCompilationUnitFunction *unitfn)
Feb 19, 2010
Feb 19, 2010
607
608
609
610
611
612
613
614
{
DELETE_AST_NODE(unitfn);
delete_compilation_unit(ctx, unitfn->next);
delete_function_signature(ctx, unitfn->declaration);
delete_statement(ctx, unitfn->definition);
Free(ctx, unitfn);
} // delete_function
Oct 28, 2010
Oct 28, 2010
615
616
617
static MOJOSHADER_astScalarOrArray *new_scalar_or_array(Context *ctx,
const char *ident, const int isvec,
MOJOSHADER_astExpression *dim)
Feb 19, 2010
Feb 19, 2010
618
{
Oct 28, 2010
Oct 28, 2010
619
620
NEW_AST_NODE(retval, MOJOSHADER_astScalarOrArray,
MOJOSHADER_AST_SCALAR_OR_ARRAY);
Feb 19, 2010
Feb 19, 2010
621
622
623
624
625
626
retval->identifier = ident;
retval->isarray = isvec;
retval->dimension = dim;
return retval;
} // new_scalar_or_array
Oct 28, 2010
Oct 28, 2010
627
static void delete_scalar_or_array(Context *ctx,MOJOSHADER_astScalarOrArray *s)
Feb 19, 2010
Feb 19, 2010
628
{
Oct 28, 2010
Oct 28, 2010
629
630
631
DELETE_AST_NODE(s);
delete_expr(ctx, s->dimension);
Free(ctx, s);
Feb 19, 2010
Feb 19, 2010
632
633
} // delete_scalar_or_array
Oct 28, 2010
Oct 28, 2010
634
635
636
static MOJOSHADER_astTypedef *new_typedef(Context *ctx, const int isconst,
const char *datatype,
MOJOSHADER_astScalarOrArray *soa)
Feb 19, 2010
Feb 19, 2010
637
{
Oct 26, 2010
Oct 26, 2010
638
// we correct this datatype to the final string during semantic analysis.
Oct 28, 2010
Oct 28, 2010
639
NEW_AST_NODE(retval, MOJOSHADER_astTypedef, MOJOSHADER_AST_TYPEDEF);
Feb 19, 2010
Feb 19, 2010
640
641
642
643
644
645
retval->isconst = isconst;
retval->datatype = datatype;
retval->details = soa;
return retval;
} // new_typedef
Oct 28, 2010
Oct 28, 2010
646
static void delete_typedef(Context *ctx, MOJOSHADER_astTypedef *td)
Feb 19, 2010
Feb 19, 2010
647
648
649
650
651
652
{
DELETE_AST_NODE(td);
delete_scalar_or_array(ctx, td->details);
Free(ctx, td);
} // delete_typedef
Oct 28, 2010
Oct 28, 2010
653
654
static MOJOSHADER_astPackOffset *new_pack_offset(Context *ctx,
const char *a, const char *b)
Feb 19, 2010
Feb 19, 2010
655
{
Oct 28, 2010
Oct 28, 2010
656
NEW_AST_NODE(retval, MOJOSHADER_astPackOffset, MOJOSHADER_AST_PACK_OFFSET);
Feb 19, 2010
Feb 19, 2010
657
658
659
660
661
retval->ident1 = a;
retval->ident2 = b;
return retval;
} // new_pack_offset
Oct 28, 2010
Oct 28, 2010
662
static void delete_pack_offset(Context *ctx, MOJOSHADER_astPackOffset *o)
Feb 19, 2010
Feb 19, 2010
663
664
665
666
667
{
DELETE_AST_NODE(o);
Free(ctx, o);
} // delete_pack_offset
Oct 28, 2010
Oct 28, 2010
668
669
static MOJOSHADER_astVariableLowLevel *new_variable_lowlevel(Context *ctx,
MOJOSHADER_astPackOffset *po,
Feb 19, 2010
Feb 19, 2010
670
671
const char *reg)
{
Oct 28, 2010
Oct 28, 2010
672
673
NEW_AST_NODE(retval, MOJOSHADER_astVariableLowLevel,
MOJOSHADER_AST_VARIABLE_LOWLEVEL);
Feb 19, 2010
Feb 19, 2010
674
675
676
677
678
retval->packoffset = po;
retval->register_name = reg;
return retval;
} // new_variable_lowlevel
Oct 28, 2010
Oct 28, 2010
679
680
static void delete_variable_lowlevel(Context *ctx,
MOJOSHADER_astVariableLowLevel *vll)
Feb 19, 2010
Feb 19, 2010
681
682
683
684
685
686
{
DELETE_AST_NODE(vll);
delete_pack_offset(ctx, vll->packoffset);
Free(ctx, vll);
} // delete_variable_lowlevel
Oct 28, 2010
Oct 28, 2010
687
688
689
static MOJOSHADER_astAnnotations *new_annotation(Context *ctx,
const char *datatype,
MOJOSHADER_astExpression *initializer)
Feb 19, 2010
Feb 19, 2010
690
{
Oct 28, 2010
Oct 28, 2010
691
NEW_AST_NODE(retval, MOJOSHADER_astAnnotations, MOJOSHADER_AST_ANNOTATION);
Feb 19, 2010
Feb 19, 2010
692
693
694
695
696
697
retval->datatype = datatype;
retval->initializer = initializer;
retval->next = NULL;
return retval;
} // new_annotation
Oct 28, 2010
Oct 28, 2010
698
static void delete_annotation(Context *ctx, MOJOSHADER_astAnnotations *annos)
Feb 19, 2010
Feb 19, 2010
699
{
Oct 28, 2010
Oct 28, 2010
700
701
702
703
DELETE_AST_NODE(annos);
delete_annotation(ctx, annos->next);
delete_expr(ctx, annos->initializer);
Free(ctx, annos);
Feb 19, 2010
Feb 19, 2010
704
705
} // delete_annotation
Oct 28, 2010
Oct 28, 2010
706
707
708
709
710
711
static MOJOSHADER_astVariableDeclaration *new_variable_declaration(
Context *ctx, MOJOSHADER_astScalarOrArray *soa,
const char *semantic,
MOJOSHADER_astAnnotations *annotations,
MOJOSHADER_astExpression *init,
MOJOSHADER_astVariableLowLevel *vll)
Feb 19, 2010
Feb 19, 2010
712
{
Oct 28, 2010
Oct 28, 2010
713
714
NEW_AST_NODE(retval, MOJOSHADER_astVariableDeclaration,
MOJOSHADER_AST_VARIABLE_DECLARATION);
Feb 19, 2010
Feb 19, 2010
715
716
717
718
719
720
721
722
723
724
725
726
retval->attributes = 0;
retval->datatype = NULL;
retval->anonymous_datatype = NULL;
retval->details = soa;
retval->semantic = semantic;
retval->annotations = annotations;
retval->initializer = init;
retval->lowlevel = vll;
retval->next = NULL;
return retval;
} // new_variable_declaration
Oct 28, 2010
Oct 28, 2010
727
728
static void delete_variable_declaration(Context *ctx,
MOJOSHADER_astVariableDeclaration *dcl)
Feb 19, 2010
Feb 19, 2010
729
730
731
732
733
734
735
736
737
738
{
DELETE_AST_NODE(dcl);
delete_variable_declaration(ctx, dcl->next);
delete_scalar_or_array(ctx, dcl->details);
delete_annotation(ctx, dcl->annotations);
delete_expr(ctx, dcl->initializer);
delete_variable_lowlevel(ctx, dcl->lowlevel);
Free(ctx, dcl);
} // delete_variable_declaration
Oct 28, 2010
Oct 28, 2010
739
740
static MOJOSHADER_astCompilationUnit *new_global_variable(Context *ctx,
MOJOSHADER_astVariableDeclaration *decl)
Feb 19, 2010
Feb 19, 2010
741
{
Oct 28, 2010
Oct 28, 2010
742
743
NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitVariable,
MOJOSHADER_AST_COMPUNIT_VARIABLE);
Feb 19, 2010
Feb 19, 2010
744
745
retval->next = NULL;
retval->declaration = decl;
Oct 28, 2010
Oct 28, 2010
746
return (MOJOSHADER_astCompilationUnit *) retval;
Feb 19, 2010
Feb 19, 2010
747
748
} // new_global_variable
Oct 28, 2010
Oct 28, 2010
749
750
static void delete_global_variable(Context *ctx,
MOJOSHADER_astCompilationUnitVariable *var)
Feb 19, 2010
Feb 19, 2010
751
752
753
754
755
756
757
{
DELETE_AST_NODE(var);
delete_compilation_unit(ctx, var->next);
delete_variable_declaration(ctx, var->declaration);
Free(ctx, var);
} // delete_global_variable
Oct 28, 2010
Oct 28, 2010
758
759
static MOJOSHADER_astCompilationUnit *new_global_typedef(Context *ctx,
MOJOSHADER_astTypedef *td)
Feb 19, 2010
Feb 19, 2010
760
{
Oct 28, 2010
Oct 28, 2010
761
762
NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitTypedef,
MOJOSHADER_AST_COMPUNIT_TYPEDEF);
Feb 19, 2010
Feb 19, 2010
763
764
retval->next = NULL;
retval->type_info = td;
Oct 28, 2010
Oct 28, 2010
765
return (MOJOSHADER_astCompilationUnit *) retval;
Feb 19, 2010
Feb 19, 2010
766
767
} // new_global_typedef
Oct 28, 2010
Oct 28, 2010
768
769
static void delete_global_typedef(Context *ctx,
MOJOSHADER_astCompilationUnitTypedef *unit)
Feb 19, 2010
Feb 19, 2010
770
771
772
773
774
775
776
{
DELETE_AST_NODE(unit);
delete_compilation_unit(ctx, unit->next);
delete_typedef(ctx, unit->type_info);
Free(ctx, unit);
} // delete_global_typedef
Oct 28, 2010
Oct 28, 2010
777
778
779
static MOJOSHADER_astStructMembers *new_struct_member(Context *ctx,
MOJOSHADER_astScalarOrArray *soa,
const char *semantic)
Feb 19, 2010
Feb 19, 2010
780
{
Oct 28, 2010
Oct 28, 2010
781
782
NEW_AST_NODE(retval, MOJOSHADER_astStructMembers,
MOJOSHADER_AST_STRUCT_MEMBER);
Feb 19, 2010
Feb 19, 2010
783
784
785
retval->datatype = NULL;
retval->semantic = semantic;
retval->details = soa;
Oct 28, 2010
Oct 28, 2010
786
retval->interpolation_mod = MOJOSHADER_AST_INTERPMOD_NONE;
Feb 19, 2010
Feb 19, 2010
787
788
789
790
retval->next = NULL;
return retval;
} // new_struct_member
Oct 28, 2010
Oct 28, 2010
791
792
static void delete_struct_member(Context *ctx,
MOJOSHADER_astStructMembers *member)
Feb 19, 2010
Feb 19, 2010
793
794
795
796
797
798
799
{
DELETE_AST_NODE(member);
delete_struct_member(ctx, member->next);
delete_scalar_or_array(ctx, member->details);
Free(ctx, member);
} // delete_struct_member
Oct 28, 2010
Oct 28, 2010
800
801
802
static MOJOSHADER_astStructDeclaration *new_struct_declaration(Context *ctx,
const char *name,
MOJOSHADER_astStructMembers *members)
Feb 19, 2010
Feb 19, 2010
803
{
Oct 28, 2010
Oct 28, 2010
804
805
NEW_AST_NODE(retval, MOJOSHADER_astStructDeclaration,
MOJOSHADER_AST_STRUCT_DECLARATION);
Feb 19, 2010
Feb 19, 2010
806
807
808
809
810
retval->name = name;
retval->members = members;
return retval;
} // new_struct_declaration
Oct 28, 2010
Oct 28, 2010
811
812
static void delete_struct_declaration(Context *ctx,
MOJOSHADER_astStructDeclaration *decl)
Feb 19, 2010
Feb 19, 2010
813
814
815
816
817
818
{
DELETE_AST_NODE(decl);
delete_struct_member(ctx, decl->members);
Free(ctx, decl);
} // delete_struct_declaration
Oct 28, 2010
Oct 28, 2010
819
820
static MOJOSHADER_astCompilationUnit *new_global_struct(Context *ctx,
MOJOSHADER_astStructDeclaration *sd)
Feb 19, 2010
Feb 19, 2010
821
{
Oct 28, 2010
Oct 28, 2010
822
823
NEW_AST_NODE(retval, MOJOSHADER_astCompilationUnitStruct,
MOJOSHADER_AST_COMPUNIT_STRUCT);
Feb 19, 2010
Feb 19, 2010
824
825
retval->next = NULL;
retval->struct_info = sd;
Oct 28, 2010
Oct 28, 2010
826
return (MOJOSHADER_astCompilationUnit *) retval;
Feb 19, 2010
Feb 19, 2010
827
828
} // new_global_struct
Oct 28, 2010
Oct 28, 2010
829
830
static void delete_global_struct(Context *ctx,
MOJOSHADER_astCompilationUnitStruct *unit)
Feb 19, 2010
Feb 19, 2010
831
832
833
834
835
836
837
{
DELETE_AST_NODE(unit);
delete_compilation_unit(ctx, unit->next);
delete_struct_declaration(ctx, unit->struct_info);
Free(ctx, unit);
} // delete_global_struct
Oct 28, 2010
Oct 28, 2010
838
839
static void delete_compilation_unit(Context *ctx,
MOJOSHADER_astCompilationUnit *unit)
Feb 19, 2010
Feb 19, 2010
840
841
842
843
844
845
846
847
848
849
850
{
if (!unit) return;
// it's important to not recurse too deeply here, since you may have
// thousands of items in this linked list (each line of a massive
// function, for example). To avoid this, we iterate the list here,
// deleting all children and making them think they have no reason
// to recurse in their own delete methods.
// Please note that everyone should _try_ to delete their "next" member,
// just in case, but hopefully this cleaned it out.
Oct 28, 2010
Oct 28, 2010
851
MOJOSHADER_astCompilationUnit *i = unit->next;
Feb 19, 2010
Feb 19, 2010
852
853
854
unit->next = NULL;
while (i)
{
Oct 28, 2010
Oct 28, 2010
855
MOJOSHADER_astCompilationUnit *next = i->next;
Feb 19, 2010
Feb 19, 2010
856
857
858
859
860
i->next = NULL;
delete_compilation_unit(ctx, i);
i = next;
} // while
Feb 22, 2010
Feb 22, 2010
861
switch (unit->ast.type)
Feb 19, 2010
Feb 19, 2010
862
863
{
#define DELETE_UNIT(typ, cls, fn) \
Oct 28, 2010
Oct 28, 2010
864
865
866
867
868
case MOJOSHADER_AST_COMPUNIT_##typ: delete_##fn(ctx, (cls *) unit); break;
DELETE_UNIT(FUNCTION, MOJOSHADER_astCompilationUnitFunction, function);
DELETE_UNIT(TYPEDEF, MOJOSHADER_astCompilationUnitTypedef, global_typedef);
DELETE_UNIT(VARIABLE, MOJOSHADER_astCompilationUnitVariable, global_variable);
DELETE_UNIT(STRUCT, MOJOSHADER_astCompilationUnitStruct, global_struct);
Feb 19, 2010
Feb 19, 2010
869
870
871
872
873
874
875
#undef DELETE_UNIT
default: assert(0 && "missing cleanup code"); break;
} // switch
// don't free (unit) here, the class-specific functions do it.
} // delete_compilation_unit
Oct 28, 2010
Oct 28, 2010
876
877
static MOJOSHADER_astStatement *new_typedef_statement(Context *ctx,
MOJOSHADER_astTypedef *td)
Feb 19, 2010
Feb 19, 2010
878
{
Oct 28, 2010
Oct 28, 2010
879
880
NEW_AST_NODE(retval, MOJOSHADER_astTypedefStatement,
MOJOSHADER_AST_STATEMENT_TYPEDEF);
Feb 19, 2010
Feb 19, 2010
881
882
retval->next = NULL;
retval->type_info = td;
Oct 28, 2010
Oct 28, 2010
883
return (MOJOSHADER_astStatement *) retval;
Feb 19, 2010
Feb 19, 2010
884
885
} // new_typedef_statement
Oct 28, 2010
Oct 28, 2010
886
887
static void delete_typedef_statement(Context *ctx,
MOJOSHADER_astTypedefStatement *stmt)
Feb 19, 2010
Feb 19, 2010
888
889
890
891
892
893
894
{
DELETE_AST_NODE(stmt);
delete_statement(ctx, stmt->next);
delete_typedef(ctx, stmt->type_info);
Free(ctx, stmt);
} // delete_typedef_statement
Oct 28, 2010
Oct 28, 2010
895
896
static MOJOSHADER_astStatement *new_return_statement(Context *ctx,
MOJOSHADER_astExpression *expr)
Feb 19, 2010
Feb 19, 2010
897
{
Oct 28, 2010
Oct 28, 2010
898
899
NEW_AST_NODE(retval, MOJOSHADER_astReturnStatement,
MOJOSHADER_AST_STATEMENT_RETURN);
Feb 19, 2010
Feb 19, 2010
900
901
retval->next = NULL;
retval->expr = expr;
Oct 28, 2010
Oct 28, 2010
902
return (MOJOSHADER_astStatement *) retval;
Feb 19, 2010
Feb 19, 2010
903
904
} // new_return_statement
Oct 28, 2010
Oct 28, 2010
905
906
static void delete_return_statement(Context *ctx,
MOJOSHADER_astReturnStatement *stmt)
Feb 19, 2010
Feb 19, 2010
907
908
909
910
911
912
913
{
DELETE_AST_NODE(stmt);
delete_statement(ctx, stmt->next);
delete_expr(ctx, stmt->expr);
Free(ctx, stmt);
} // delete_return_statement
Oct 28, 2010
Oct 28, 2010
914
915
static MOJOSHADER_astStatement *new_block_statement(Context *ctx,
MOJOSHADER_astStatement *stmts)
Oct 13, 2010
Oct 13, 2010
916
{
Oct 28, 2010
Oct 28, 2010
917
918
NEW_AST_NODE(retval, MOJOSHADER_astBlockStatement,
MOJOSHADER_AST_STATEMENT_BLOCK);
Oct 13, 2010
Oct 13, 2010
919
retval->next = NULL;
Oct 28, 2010
Oct 28, 2010
920
921
retval->statements = stmts;
return (MOJOSHADER_astStatement *) retval;
Oct 13, 2010
Oct 13, 2010
922
923
} // new_block_statement
Oct 28, 2010
Oct 28, 2010
924
925
static void delete_block_statement(Context *ctx,
MOJOSHADER_astBlockStatement *stmt)
Oct 13, 2010
Oct 13, 2010
926
927
928
929
930
931
932
{
DELETE_AST_NODE(stmt);
delete_statement(ctx, stmt->statements);
delete_statement(ctx, stmt->next);
Free(ctx, stmt);
} // delete_statement_block
Oct 28, 2010
Oct 28, 2010
933
934
935
936
937
938
static MOJOSHADER_astStatement *new_for_statement(Context *ctx,
MOJOSHADER_astVariableDeclaration *decl,
MOJOSHADER_astExpression *initializer,
MOJOSHADER_astExpression *looptest,
MOJOSHADER_astExpression *counter,
MOJOSHADER_astStatement *statement)
Feb 19, 2010
Feb 19, 2010
939
{
Oct 28, 2010
Oct 28, 2010
940
941
NEW_AST_NODE(retval, MOJOSHADER_astForStatement,
MOJOSHADER_AST_STATEMENT_FOR);
Feb 19, 2010
Feb 19, 2010
942
943
944
945
946
947
948
retval->next = NULL;
retval->unroll = -1;
retval->var_decl = decl;
retval->initializer = initializer;
retval->looptest = looptest;
retval->counter = counter;
retval->statement = statement;
Oct 28, 2010
Oct 28, 2010
949
return (MOJOSHADER_astStatement *) retval;
Feb 19, 2010
Feb 19, 2010
950
951
} // new_for_statement
Oct 28, 2010
Oct 28, 2010
952
static void delete_for_statement(Context *ctx,MOJOSHADER_astForStatement *stmt)
Feb 19, 2010
Feb 19, 2010
953
954
955
956
957
958
959
960
961
962
963
{
DELETE_AST_NODE(stmt);
delete_statement(ctx, stmt->next);
delete_variable_declaration(ctx, stmt->var_decl);
delete_expr(ctx, stmt->initializer);
delete_expr(ctx, stmt->looptest);
delete_expr(ctx, stmt->counter);
delete_statement(ctx, stmt->statement);
Free(ctx, stmt);
} // delete_for_statement
Oct 28, 2010
Oct 28, 2010
964
965
966
967
static MOJOSHADER_astStatement *new_do_statement(Context *ctx,
const int unroll,
MOJOSHADER_astStatement *stmt,
MOJOSHADER_astExpression *expr)
Feb 19, 2010
Feb 19, 2010
968
{
Oct 28, 2010
Oct 28, 2010
969
NEW_AST_NODE(retval,MOJOSHADER_astDoStatement,MOJOSHADER_AST_STATEMENT_DO);
Feb 19, 2010
Feb 19, 2010
970
971
972
973
retval->next = NULL;
retval->unroll = unroll;
retval->expr = expr;
retval->statement = stmt;
Oct 28, 2010
Oct 28, 2010
974
return (MOJOSHADER_astStatement *) retval;
Feb 19, 2010
Feb 19, 2010
975
976
} // new_do_statement
Oct 28, 2010
Oct 28, 2010
977
static void delete_do_statement(Context *ctx, MOJOSHADER_astDoStatement *stmt)
Feb 19, 2010
Feb 19, 2010
978
979
980
981
982
983
984
985
{
DELETE_AST_NODE(stmt);
delete_statement(ctx, stmt->next);
delete_statement(ctx, stmt->statement);
delete_expr(ctx, stmt->expr);
Free(ctx, stmt);
} // delete_do_statement
Oct 28, 2010
Oct 28, 2010
986
987
988
989
static MOJOSHADER_astStatement *new_while_statement(Context *ctx,
const int unroll,
MOJOSHADER_astExpression *expr,
MOJOSHADER_astStatement *stmt)
Feb 19, 2010
Feb 19, 2010
990
{
Oct 28, 2010
Oct 28, 2010
991
992
NEW_AST_NODE(retval, MOJOSHADER_astWhileStatement,
MOJOSHADER_AST_STATEMENT_WHILE);
Feb 19, 2010
Feb 19, 2010
993
994
995
996
retval->next = NULL;
retval->unroll = unroll;
retval->expr = expr;
retval->statement = stmt;
Oct 28, 2010
Oct 28, 2010
997
return (MOJOSHADER_astStatement *) retval;
Feb 19, 2010
Feb 19, 2010
998
999
} // new_while_statement
Oct 28, 2010
Oct 28, 2010
1000
static void delete_while_statement(Context *ctx,