source: mainline/uspace/app/sbi/src/stree.c@ 39e8406

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 39e8406 was 39e8406, checked in by Jiri Svoboda <jiri@…>, 15 years ago

Update SBI to rev. 128.

  • Property mode set to 100644
File size: 11.0 KB
Line 
1/*
2 * Copyright (c) 2010 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Stree (syntax tree) intermediate representation. */
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <assert.h>
34#include "list.h"
35#include "mytypes.h"
36
37#include "stree.h"
38
39stree_module_t *stree_module_new(void)
40{
41 stree_module_t *module;
42
43 module = calloc(1, sizeof(stree_module_t));
44 if (module == NULL) {
45 printf("Memory allocation failed.\n");
46 exit(1);
47 }
48
49 list_init(&module->members);
50 return module;
51}
52
53stree_modm_t *stree_modm_new(modm_class_t mc)
54{
55 stree_modm_t *modm;
56
57 modm = calloc(1, sizeof(stree_modm_t));
58 if (modm == NULL) {
59 printf("Memory allocation failed.\n");
60 exit(1);
61 }
62
63 modm->mc = mc;
64 return modm;
65}
66
67stree_csi_t *stree_csi_new(csi_class_t cc)
68{
69 stree_csi_t *csi;
70
71 csi = calloc(1, sizeof(stree_csi_t));
72 if (csi == NULL) {
73 printf("Memory allocation failed.\n");
74 exit(1);
75 }
76
77 csi->cc = cc;
78 csi->ancr_state = ws_unvisited;
79 csi->name = NULL;
80 csi->base_csi_ref = NULL;
81 list_init(&csi->members);
82 return csi;
83}
84
85stree_csimbr_t *stree_csimbr_new(csimbr_class_t cc)
86{
87 stree_csimbr_t *csimbr;
88
89 csimbr = calloc(1, sizeof(stree_csimbr_t));
90 if (csimbr == NULL) {
91 printf("Memory allocation failed.\n");
92 exit(1);
93 }
94
95 csimbr->cc = cc;
96 return csimbr;
97}
98
99stree_fun_t *stree_fun_new(void)
100{
101 stree_fun_t *fun;
102
103 fun = calloc(1, sizeof(stree_fun_t));
104 if (fun == NULL) {
105 printf("Memory allocation failed.\n");
106 exit(1);
107 }
108
109 return fun;
110}
111
112stree_var_t *stree_var_new(void)
113{
114 stree_var_t *var;
115
116 var = calloc(1, sizeof(stree_var_t));
117 if (var == NULL) {
118 printf("Memory allocation failed.\n");
119 exit(1);
120 }
121
122 return var;
123}
124
125stree_prop_t *stree_prop_new(void)
126{
127 stree_prop_t *prop;
128
129 prop = calloc(1, sizeof(stree_prop_t));
130 if (prop == NULL) {
131 printf("Memory allocation failed.\n");
132 exit(1);
133 }
134
135 return prop;
136}
137
138stree_proc_t *stree_proc_new(void)
139{
140 stree_proc_t *proc;
141
142 proc = calloc(1, sizeof(stree_proc_t));
143 if (proc == NULL) {
144 printf("Memory allocation failed.\n");
145 exit(1);
146 }
147
148 return proc;
149}
150
151stree_proc_arg_t *stree_proc_arg_new(void)
152{
153 stree_proc_arg_t *proc_arg;
154
155 proc_arg = calloc(1, sizeof(stree_proc_arg_t));
156 if (proc_arg == NULL) {
157 printf("Memory allocation failed.\n");
158 exit(1);
159 }
160
161 return proc_arg;
162}
163
164stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac)
165{
166 stree_arg_attr_t *arg_attr;
167
168 arg_attr = calloc(1, sizeof(stree_arg_attr_t));
169 if (arg_attr == NULL) {
170 printf("Memory allocation failed.\n");
171 exit(1);
172 }
173
174 arg_attr->aac = aac;
175 return arg_attr;
176}
177
178stree_stat_t *stree_stat_new(stat_class_t sc)
179{
180 stree_stat_t *stat;
181
182 stat = calloc(1, sizeof(stree_stat_t));
183 if (stat == NULL) {
184 printf("Memory allocation failed.\n");
185 exit(1);
186 }
187
188 stat->sc = sc;
189 return stat;
190}
191
192stree_vdecl_t *stree_vdecl_new(void)
193{
194 stree_vdecl_t *vdecl_s;
195
196 vdecl_s = calloc(1, sizeof(stree_vdecl_t));
197 if (vdecl_s == NULL) {
198 printf("Memory allocation failed.\n");
199 exit(1);
200 }
201
202 return vdecl_s;
203}
204
205stree_if_t *stree_if_new(void)
206{
207 stree_if_t *if_s;
208
209 if_s = calloc(1, sizeof(stree_if_t));
210 if (if_s == NULL) {
211 printf("Memory allocation failed.\n");
212 exit(1);
213 }
214
215 return if_s;
216}
217
218stree_while_t *stree_while_new(void)
219{
220 stree_while_t *while_s;
221
222 while_s = calloc(1, sizeof(stree_while_t));
223 if (while_s == NULL) {
224 printf("Memory allocation failed.\n");
225 exit(1);
226 }
227
228 return while_s;
229}
230
231stree_for_t *stree_for_new(void)
232{
233 stree_for_t *for_s;
234
235 for_s = calloc(1, sizeof(stree_for_t));
236 if (for_s == NULL) {
237 printf("Memory allocation failed.\n");
238 exit(1);
239 }
240
241 return for_s;
242}
243
244stree_raise_t *stree_raise_new(void)
245{
246 stree_raise_t *raise_s;
247
248 raise_s = calloc(1, sizeof(stree_raise_t));
249 if (raise_s == NULL) {
250 printf("Memory allocation failed.\n");
251 exit(1);
252 }
253
254 return raise_s;
255}
256
257stree_return_t *stree_return_new(void)
258{
259 stree_return_t *return_s;
260
261 return_s = calloc(1, sizeof(stree_return_t));
262 if (return_s == NULL) {
263 printf("Memory allocation failed.\n");
264 exit(1);
265 }
266
267 return return_s;
268}
269
270stree_wef_t *stree_wef_new(void)
271{
272 stree_wef_t *wef_s;
273
274 wef_s = calloc(1, sizeof(stree_wef_t));
275 if (wef_s == NULL) {
276 printf("Memory allocation failed.\n");
277 exit(1);
278 }
279
280 return wef_s;
281}
282
283stree_exps_t *stree_exps_new(void)
284{
285 stree_exps_t *exp_s;
286
287 exp_s = calloc(1, sizeof(stree_exps_t));
288 if (exp_s == NULL) {
289 printf("Memory allocation failed.\n");
290 exit(1);
291 }
292
293 return exp_s;
294}
295
296stree_except_t *stree_except_new(void)
297{
298 stree_except_t *except_c;
299
300 except_c = calloc(1, sizeof(stree_except_t));
301 if (except_c == NULL) {
302 printf("Memory allocation failed.\n");
303 exit(1);
304 }
305
306 return except_c;
307}
308
309stree_block_t *stree_block_new(void)
310{
311 stree_block_t *block;
312
313 block = calloc(1, sizeof(stree_block_t));
314 if (block == NULL) {
315 printf("Memory allocation failed.\n");
316 exit(1);
317 }
318
319 return block;
320}
321
322stree_expr_t *stree_expr_new(expr_class_t ec)
323{
324 stree_expr_t *expr;
325
326 expr = calloc(1, sizeof(stree_expr_t));
327 if (expr == NULL) {
328 printf("Memory allocation failed.\n");
329 exit(1);
330 }
331
332 expr->ec = ec;
333 return expr;
334}
335
336stree_assign_t *stree_assign_new(assign_class_t ac)
337{
338 stree_assign_t *assign;
339
340 assign = calloc(1, sizeof(stree_assign_t));
341 if (assign == NULL) {
342 printf("Memory allocation failed.\n");
343 exit(1);
344 }
345
346 assign->ac = ac;
347 return assign;
348}
349
350stree_binop_t *stree_binop_new(binop_class_t bc)
351{
352 stree_binop_t *binop;
353
354 binop = calloc(1, sizeof(stree_binop_t));
355 if (binop == NULL) {
356 printf("Memory allocation failed.\n");
357 exit(1);
358 }
359
360 binop->bc = bc;
361 return binop;
362}
363
364stree_new_t *stree_new_new(void)
365{
366 stree_new_t *new_op;
367
368 new_op = calloc(1, sizeof(stree_new_t));
369 if (new_op == NULL) {
370 printf("Memory allocation failed.\n");
371 exit(1);
372 }
373
374 return new_op;
375}
376
377stree_access_t *stree_access_new(void)
378{
379 stree_access_t *access;
380
381 access = calloc(1, sizeof(stree_access_t));
382 if (access == NULL) {
383 printf("Memory allocation failed.\n");
384 exit(1);
385 }
386
387 return access;
388}
389
390stree_call_t *stree_call_new(void)
391{
392 stree_call_t *call;
393
394 call = calloc(1, sizeof(stree_call_t));
395 if (call == NULL) {
396 printf("Memory allocation failed.\n");
397 exit(1);
398 }
399
400 return call;
401}
402
403stree_index_t *stree_index_new(void)
404{
405 stree_index_t *index;
406
407 index = calloc(1, sizeof(stree_index_t));
408 if (index == NULL) {
409 printf("Memory allocation failed.\n");
410 exit(1);
411 }
412
413 return index;
414}
415
416stree_nameref_t *stree_nameref_new(void)
417{
418 stree_nameref_t *nameref;
419
420 nameref = calloc(1, sizeof(stree_nameref_t));
421 if (nameref == NULL) {
422 printf("Memory allocation failed.\n");
423 exit(1);
424 }
425
426 return nameref;
427}
428
429stree_ident_t *stree_ident_new(void)
430{
431 stree_ident_t *ident;
432
433 ident = calloc(1, sizeof(stree_ident_t));
434 if (ident == NULL) {
435 printf("Memory allocation failed.\n");
436 exit(1);
437 }
438
439 return ident;
440}
441
442stree_literal_t *stree_literal_new(literal_class_t ltc)
443{
444 stree_literal_t *literal;
445
446 literal = calloc(1, sizeof(stree_literal_t));
447 if (literal == NULL) {
448 printf("Memory allocation failed.\n");
449 exit(1);
450 }
451
452 literal->ltc = ltc;
453 return literal;
454}
455
456stree_self_ref_t *stree_self_ref_new(void)
457{
458 stree_self_ref_t *self_ref;
459
460 self_ref = calloc(1, sizeof(stree_self_ref_t));
461 if (self_ref == NULL) {
462 printf("Memory allocation failed.\n");
463 exit(1);
464 }
465
466 return self_ref;
467}
468
469stree_texpr_t *stree_texpr_new(texpr_class_t tc)
470{
471 stree_texpr_t *texpr;
472
473 texpr = calloc(1, sizeof(stree_texpr_t));
474 if (texpr == NULL) {
475 printf("Memory allocation failed.\n");
476 exit(1);
477 }
478
479 texpr->tc = tc;
480 return texpr;
481}
482
483stree_taccess_t *stree_taccess_new(void)
484{
485 stree_taccess_t *taccess;
486
487 taccess = calloc(1, sizeof(stree_taccess_t));
488 if (taccess == NULL) {
489 printf("Memory allocation failed.\n");
490 exit(1);
491 }
492
493 return taccess;
494}
495
496stree_tapply_t *stree_tapply_new(void)
497{
498 stree_tapply_t *tapply;
499
500 tapply = calloc(1, sizeof(stree_tapply_t));
501 if (tapply == NULL) {
502 printf("Memory allocation failed.\n");
503 exit(1);
504 }
505
506 return tapply;
507}
508
509stree_tindex_t *stree_tindex_new(void)
510{
511 stree_tindex_t *tindex;
512
513 tindex = calloc(1, sizeof(stree_tindex_t));
514 if (tindex == NULL) {
515 printf("Memory allocation failed.\n");
516 exit(1);
517 }
518
519 return tindex;
520}
521
522stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc)
523{
524 stree_tliteral_t *tliteral;
525
526 tliteral = calloc(1, sizeof(stree_tliteral_t));
527 if (tliteral == NULL) {
528 printf("Memory allocation failed.\n");
529 exit(1);
530 }
531
532 tliteral->tlc = tlc;
533 return tliteral;
534}
535
536stree_tnameref_t *stree_tnameref_new(void)
537{
538 stree_tnameref_t *tnameref;
539
540 tnameref = calloc(1, sizeof(stree_tnameref_t));
541 if (tnameref == NULL) {
542 printf("Memory allocation failed.\n");
543 exit(1);
544 }
545
546 return tnameref;
547}
548
549stree_symbol_t *stree_symbol_new(symbol_class_t sc)
550{
551 stree_symbol_t *symbol;
552
553 symbol = calloc(1, sizeof(stree_symbol_t));
554 if (symbol == NULL) {
555 printf("Memory allocation failed.\n");
556 exit(1);
557 }
558
559 symbol->sc = sc;
560 return symbol;
561}
562
563stree_program_t *stree_program_new(void)
564{
565 stree_program_t *program;
566
567 program = calloc(1, sizeof(stree_program_t));
568 if (program == NULL) {
569 printf("Memory allocation failed.\n");
570 exit(1);
571 }
572
573 return program;
574}
575
576/** Determine if argument @a arg has attribute of class @a aac. */
577bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac)
578{
579 list_node_t *node;
580 stree_arg_attr_t *attr;
581
582 node = list_first(&arg->attr);
583 while (node != NULL) {
584 attr = list_node_data(node, stree_arg_attr_t *);
585 if (attr->aac == aac)
586 return b_true;
587
588 node = list_next(&arg->attr, node);
589 }
590
591 return b_false;
592}
593
594/** Determine wheter @a a is derived (transitively) from @a b.
595 *
596 * @param a Derived CSI.
597 * @param b Base CSI.
598 * @return @c b_true if @a a is equal to or directly or indirectly
599 * derived from @a b.
600 */
601bool_t stree_is_csi_derived_from_csi(stree_csi_t *a, stree_csi_t *b)
602{
603 stree_csi_t *csi;
604
605 csi = a;
606 while (csi != NULL) {
607 if (csi == b)
608 return b_true;
609
610 csi = csi->base_csi;
611 }
612
613 /* We went all the way to the root and did not find b. */
614 return b_false;
615}
Note: See TracBrowser for help on using the repository browser.