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

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

Update SBI to rev. 291.

  • Property mode set to 100644
File size: 20.5 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
39/** Allocate new module.
40 *
41 * @return New module
42 */
43stree_module_t *stree_module_new(void)
44{
45 stree_module_t *module;
46
47 module = calloc(1, sizeof(stree_module_t));
48 if (module == NULL) {
49 printf("Memory allocation failed.\n");
50 exit(1);
51 }
52
53 list_init(&module->members);
54 return module;
55}
56
57/** Allocate new module member.
58 *
59 * @param mc Module member class
60 * @return New module member
61 */
62stree_modm_t *stree_modm_new(modm_class_t mc)
63{
64 stree_modm_t *modm;
65
66 modm = calloc(1, sizeof(stree_modm_t));
67 if (modm == NULL) {
68 printf("Memory allocation failed.\n");
69 exit(1);
70 }
71
72 modm->mc = mc;
73 return modm;
74}
75
76/** Allocate new CSI.
77 *
78 * @param cc CSI class
79 * @return New CSI
80 */
81stree_csi_t *stree_csi_new(csi_class_t cc)
82{
83 stree_csi_t *csi;
84
85 csi = calloc(1, sizeof(stree_csi_t));
86 if (csi == NULL) {
87 printf("Memory allocation failed.\n");
88 exit(1);
89 }
90
91 csi->cc = cc;
92 csi->ancr_state = ws_unvisited;
93 csi->name = NULL;
94 csi->base_csi = NULL;
95 list_init(&csi->inherit);
96 list_init(&csi->impl_if_ti);
97 list_init(&csi->members);
98
99 return csi;
100}
101
102/** Allocate new CSI member.
103 *
104 * @param cc CSI member class
105 * @return New CSI member
106 */
107stree_csimbr_t *stree_csimbr_new(csimbr_class_t cc)
108{
109 stree_csimbr_t *csimbr;
110
111 csimbr = calloc(1, sizeof(stree_csimbr_t));
112 if (csimbr == NULL) {
113 printf("Memory allocation failed.\n");
114 exit(1);
115 }
116
117 csimbr->cc = cc;
118 return csimbr;
119}
120
121/** Allocate new constructor.
122 *
123 * @return New constructor
124 */
125stree_ctor_t *stree_ctor_new(void)
126{
127 stree_ctor_t *ctor;
128
129 ctor = calloc(1, sizeof(stree_ctor_t));
130 if (ctor == NULL) {
131 printf("Memory allocation failed.\n");
132 exit(1);
133 }
134
135 return ctor;
136}
137
138/** Allocate new member delegate.
139 *
140 * @return New member delegate
141 */
142stree_deleg_t *stree_deleg_new(void)
143{
144 stree_deleg_t *deleg;
145
146 deleg = calloc(1, sizeof(stree_deleg_t));
147 if (deleg == NULL) {
148 printf("Memory allocation failed.\n");
149 exit(1);
150 }
151
152 return deleg;
153}
154
155/** Allocate new enum.
156 *
157 * @return New enum
158 */
159stree_enum_t *stree_enum_new(void)
160{
161 stree_enum_t *enum_d;
162
163 enum_d = calloc(1, sizeof(stree_enum_t));
164 if (enum_d == NULL) {
165 printf("Memory allocation failed.\n");
166 exit(1);
167 }
168
169 return enum_d;
170}
171
172/** Allocate new enum member.
173 *
174 * @return New enum member
175 */
176stree_embr_t *stree_embr_new(void)
177{
178 stree_embr_t *embr;
179
180 embr = calloc(1, sizeof(stree_embr_t));
181 if (embr == NULL) {
182 printf("Memory allocation failed.\n");
183 exit(1);
184 }
185
186 return embr;
187}
188
189/** Allocate new member function.
190 *
191 * @return New member function
192 */
193stree_fun_t *stree_fun_new(void)
194{
195 stree_fun_t *fun;
196
197 fun = calloc(1, sizeof(stree_fun_t));
198 if (fun == NULL) {
199 printf("Memory allocation failed.\n");
200 exit(1);
201 }
202
203 return fun;
204}
205
206/** Allocate new member variable.
207 *
208 * @return New member variable
209 */
210stree_var_t *stree_var_new(void)
211{
212 stree_var_t *var;
213
214 var = calloc(1, sizeof(stree_var_t));
215 if (var == NULL) {
216 printf("Memory allocation failed.\n");
217 exit(1);
218 }
219
220 return var;
221}
222
223/** Allocate new property.
224 *
225 * @return New property
226 */
227stree_prop_t *stree_prop_new(void)
228{
229 stree_prop_t *prop;
230
231 prop = calloc(1, sizeof(stree_prop_t));
232 if (prop == NULL) {
233 printf("Memory allocation failed.\n");
234 exit(1);
235 }
236
237 return prop;
238}
239
240/** Allocate new type argument.
241 *
242 * @return New type argument
243 */
244stree_targ_t *stree_targ_new(void)
245{
246 stree_targ_t *targ;
247
248 targ = calloc(1, sizeof(stree_targ_t));
249 if (targ == NULL) {
250 printf("Memory allocation failed.\n");
251 exit(1);
252 }
253
254 return targ;
255}
256
257/** Allocate new symbol attribute.
258 *
259 * @param sac Symbol attribute class
260 * @return New symbol attribute
261 */
262stree_symbol_attr_t *stree_symbol_attr_new(symbol_attr_class_t sac)
263{
264 stree_symbol_attr_t *symbol_attr;
265
266 symbol_attr = calloc(1, sizeof(stree_symbol_attr_t));
267 if (symbol_attr == NULL) {
268 printf("Memory allocation failed.\n");
269 exit(1);
270 }
271
272 symbol_attr->sac = sac;
273 return symbol_attr;
274}
275
276/** Allocate new procedure.
277 *
278 * @return New procedure
279 */
280stree_proc_t *stree_proc_new(void)
281{
282 stree_proc_t *proc;
283
284 proc = calloc(1, sizeof(stree_proc_t));
285 if (proc == NULL) {
286 printf("Memory allocation failed.\n");
287 exit(1);
288 }
289
290 return proc;
291}
292
293/** Allocate new procedure argument.
294 *
295 * @return New procedure argument
296 */
297stree_proc_arg_t *stree_proc_arg_new(void)
298{
299 stree_proc_arg_t *proc_arg;
300
301 proc_arg = calloc(1, sizeof(stree_proc_arg_t));
302 if (proc_arg == NULL) {
303 printf("Memory allocation failed.\n");
304 exit(1);
305 }
306
307 return proc_arg;
308}
309
310/** Allocate new function signature.
311 *
312 * @return New procedure argument
313 */
314stree_fun_sig_t *stree_fun_sig_new(void)
315{
316 stree_fun_sig_t *fun_sig;
317
318 fun_sig = calloc(1, sizeof(stree_fun_sig_t));
319 if (fun_sig == NULL) {
320 printf("Memory allocation failed.\n");
321 exit(1);
322 }
323
324 return fun_sig;
325}
326
327/** Allocate new procedure argument attribute.
328 *
329 * @param Argument attribute class
330 * @return New procedure argument attribute
331 */
332stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac)
333{
334 stree_arg_attr_t *arg_attr;
335
336 arg_attr = calloc(1, sizeof(stree_arg_attr_t));
337 if (arg_attr == NULL) {
338 printf("Memory allocation failed.\n");
339 exit(1);
340 }
341
342 arg_attr->aac = aac;
343 return arg_attr;
344}
345
346/** Allocate new statement.
347 *
348 * @param sc Statement class
349 * @return New statement
350 */
351stree_stat_t *stree_stat_new(stat_class_t sc)
352{
353 stree_stat_t *stat;
354
355 stat = calloc(1, sizeof(stree_stat_t));
356 if (stat == NULL) {
357 printf("Memory allocation failed.\n");
358 exit(1);
359 }
360
361 stat->sc = sc;
362 return stat;
363}
364
365/** Allocate new local variable declaration.
366 *
367 * @return New local variable declaration
368 */
369stree_vdecl_t *stree_vdecl_new(void)
370{
371 stree_vdecl_t *vdecl_s;
372
373 vdecl_s = calloc(1, sizeof(stree_vdecl_t));
374 if (vdecl_s == NULL) {
375 printf("Memory allocation failed.\n");
376 exit(1);
377 }
378
379 return vdecl_s;
380}
381
382/** Allocate new @c if statement.
383 *
384 * @return New @c if statement
385 */
386stree_if_t *stree_if_new(void)
387{
388 stree_if_t *if_s;
389
390 if_s = calloc(1, sizeof(stree_if_t));
391 if (if_s == NULL) {
392 printf("Memory allocation failed.\n");
393 exit(1);
394 }
395
396 return if_s;
397}
398
399/** Allocate new @c while statement.
400 *
401 * @return New @c while statement
402 */
403stree_while_t *stree_while_new(void)
404{
405 stree_while_t *while_s;
406
407 while_s = calloc(1, sizeof(stree_while_t));
408 if (while_s == NULL) {
409 printf("Memory allocation failed.\n");
410 exit(1);
411 }
412
413 return while_s;
414}
415
416/** Allocate new @c for statement.
417 *
418 * @return New @c for statement
419 */
420stree_for_t *stree_for_new(void)
421{
422 stree_for_t *for_s;
423
424 for_s = calloc(1, sizeof(stree_for_t));
425 if (for_s == NULL) {
426 printf("Memory allocation failed.\n");
427 exit(1);
428 }
429
430 return for_s;
431}
432
433/** Allocate new @c raise statement.
434 *
435 * @return New @c raise statement
436 */
437stree_raise_t *stree_raise_new(void)
438{
439 stree_raise_t *raise_s;
440
441 raise_s = calloc(1, sizeof(stree_raise_t));
442 if (raise_s == NULL) {
443 printf("Memory allocation failed.\n");
444 exit(1);
445 }
446
447 return raise_s;
448}
449
450/** Allocate new @c break statement.
451 *
452 * @return New @c break statement
453 */
454stree_break_t *stree_break_new(void)
455{
456 stree_break_t *break_s;
457
458 break_s = calloc(1, sizeof(stree_break_t));
459 if (break_s == NULL) {
460 printf("Memory allocation failed.\n");
461 exit(1);
462 }
463
464 return break_s;
465}
466
467/** Allocate new @c return statement.
468 *
469 * @return New @c return statement
470 */
471stree_return_t *stree_return_new(void)
472{
473 stree_return_t *return_s;
474
475 return_s = calloc(1, sizeof(stree_return_t));
476 if (return_s == NULL) {
477 printf("Memory allocation failed.\n");
478 exit(1);
479 }
480
481 return return_s;
482}
483
484/** Allocate new with-except-finally statement.
485 *
486 * @return New with-except-finally statement.
487 */
488stree_wef_t *stree_wef_new(void)
489{
490 stree_wef_t *wef_s;
491
492 wef_s = calloc(1, sizeof(stree_wef_t));
493 if (wef_s == NULL) {
494 printf("Memory allocation failed.\n");
495 exit(1);
496 }
497
498 return wef_s;
499}
500
501/** Allocate new expression statement.
502 *
503 * @return New expression statement
504 */
505stree_exps_t *stree_exps_new(void)
506{
507 stree_exps_t *exp_s;
508
509 exp_s = calloc(1, sizeof(stree_exps_t));
510 if (exp_s == NULL) {
511 printf("Memory allocation failed.\n");
512 exit(1);
513 }
514
515 return exp_s;
516}
517
518/** Allocate new @c except clause.
519 *
520 * @return New @c except clause
521 */
522stree_except_t *stree_except_new(void)
523{
524 stree_except_t *except_c;
525
526 except_c = calloc(1, sizeof(stree_except_t));
527 if (except_c == NULL) {
528 printf("Memory allocation failed.\n");
529 exit(1);
530 }
531
532 return except_c;
533}
534
535/** Allocate new @c if/elif clause.
536 *
537 * @return New @c if/elif clause
538 */
539stree_if_clause_t *stree_if_clause_new(void)
540{
541 stree_if_clause_t *if_clause;
542
543 if_clause = calloc(1, sizeof(stree_if_clause_t));
544 if (if_clause == NULL) {
545 printf("Memory allocation failed.\n");
546 exit(1);
547 }
548
549 return if_clause;
550}
551
552/** Allocate new statement block.
553 *
554 * @return New statement block
555 */
556stree_block_t *stree_block_new(void)
557{
558 stree_block_t *block;
559
560 block = calloc(1, sizeof(stree_block_t));
561 if (block == NULL) {
562 printf("Memory allocation failed.\n");
563 exit(1);
564 }
565
566 return block;
567}
568
569/** Allocate new expression.
570 *
571 * @param ec Expression class
572 * @return New expression
573 */
574stree_expr_t *stree_expr_new(expr_class_t ec)
575{
576 stree_expr_t *expr;
577
578 expr = calloc(1, sizeof(stree_expr_t));
579 if (expr == NULL) {
580 printf("Memory allocation failed.\n");
581 exit(1);
582 }
583
584 expr->ec = ec;
585 return expr;
586}
587
588/** Allocate new assignment.
589 *
590 * @param ac Assignment class
591 * @return New assignment
592 */
593stree_assign_t *stree_assign_new(assign_class_t ac)
594{
595 stree_assign_t *assign;
596
597 assign = calloc(1, sizeof(stree_assign_t));
598 if (assign == NULL) {
599 printf("Memory allocation failed.\n");
600 exit(1);
601 }
602
603 assign->ac = ac;
604 return assign;
605}
606
607/** Allocate new binary operation.
608 *
609 * @return New binary operation
610 */
611stree_binop_t *stree_binop_new(binop_class_t bc)
612{
613 stree_binop_t *binop;
614
615 binop = calloc(1, sizeof(stree_binop_t));
616 if (binop == NULL) {
617 printf("Memory allocation failed.\n");
618 exit(1);
619 }
620
621 binop->bc = bc;
622 return binop;
623}
624
625/** Allocate new unary operation.
626 *
627 * @param uc Unary operation class
628 * @return New unary operation
629 */
630stree_unop_t *stree_unop_new(unop_class_t uc)
631{
632 stree_unop_t *unop;
633
634 unop = calloc(1, sizeof(stree_unop_t));
635 if (unop == NULL) {
636 printf("Memory allocation failed.\n");
637 exit(1);
638 }
639
640 unop->uc = uc;
641 return unop;
642}
643
644/** Allocate new @c new operation.
645 *
646 * @return New @c new operation
647 */
648stree_new_t *stree_new_new(void)
649{
650 stree_new_t *new_op;
651
652 new_op = calloc(1, sizeof(stree_new_t));
653 if (new_op == NULL) {
654 printf("Memory allocation failed.\n");
655 exit(1);
656 }
657
658 return new_op;
659}
660
661/** Allocate new .
662 *
663 * @return New
664 */
665stree_access_t *stree_access_new(void)
666{
667 stree_access_t *access;
668
669 access = calloc(1, sizeof(stree_access_t));
670 if (access == NULL) {
671 printf("Memory allocation failed.\n");
672 exit(1);
673 }
674
675 return access;
676}
677
678/** Allocate new function call operation.
679 *
680 * @return New function call operation
681 */
682stree_call_t *stree_call_new(void)
683{
684 stree_call_t *call;
685
686 call = calloc(1, sizeof(stree_call_t));
687 if (call == NULL) {
688 printf("Memory allocation failed.\n");
689 exit(1);
690 }
691
692 return call;
693}
694
695/** Allocate new indexing operation.
696 *
697 * @return New indexing operation
698 */
699stree_index_t *stree_index_new(void)
700{
701 stree_index_t *index;
702
703 index = calloc(1, sizeof(stree_index_t));
704 if (index == NULL) {
705 printf("Memory allocation failed.\n");
706 exit(1);
707 }
708
709 return index;
710}
711
712/** Allocate new as conversion.
713 *
714 * @return New as conversion
715 */
716stree_as_t *stree_as_new(void)
717{
718 stree_as_t *as_expr;
719
720 as_expr = calloc(1, sizeof(stree_as_t));
721 if (as_expr == NULL) {
722 printf("Memory allocation failed.\n");
723 exit(1);
724 }
725
726 return as_expr;
727}
728
729/** Allocate new boxing operation.
730 *
731 * @return New boxing operation
732 */
733stree_box_t *stree_box_new(void)
734{
735 stree_box_t *box_expr;
736
737 box_expr = calloc(1, sizeof(stree_box_t));
738 if (box_expr == NULL) {
739 printf("Memory allocation failed.\n");
740 exit(1);
741 }
742
743 return box_expr;
744}
745
746/** Allocate new name reference operation.
747 *
748 * @return New name reference operation
749 */
750stree_nameref_t *stree_nameref_new(void)
751{
752 stree_nameref_t *nameref;
753
754 nameref = calloc(1, sizeof(stree_nameref_t));
755 if (nameref == NULL) {
756 printf("Memory allocation failed.\n");
757 exit(1);
758 }
759
760 return nameref;
761}
762
763/** Allocate new identifier.
764 *
765 * @return New identifier
766 */
767stree_ident_t *stree_ident_new(void)
768{
769 stree_ident_t *ident;
770
771 ident = calloc(1, sizeof(stree_ident_t));
772 if (ident == NULL) {
773 printf("Memory allocation failed.\n");
774 exit(1);
775 }
776
777 return ident;
778}
779
780/** Allocate new literal.
781 *
782 * @param ltc Literal class
783 * @return New literal
784 */
785stree_literal_t *stree_literal_new(literal_class_t ltc)
786{
787 stree_literal_t *literal;
788
789 literal = calloc(1, sizeof(stree_literal_t));
790 if (literal == NULL) {
791 printf("Memory allocation failed.\n");
792 exit(1);
793 }
794
795 literal->ltc = ltc;
796 return literal;
797}
798
799/** Allocate new @c self reference.
800 *
801 * @return New @c self reference
802 */
803stree_self_ref_t *stree_self_ref_new(void)
804{
805 stree_self_ref_t *self_ref;
806
807 self_ref = calloc(1, sizeof(stree_self_ref_t));
808 if (self_ref == NULL) {
809 printf("Memory allocation failed.\n");
810 exit(1);
811 }
812
813 return self_ref;
814}
815
816/** Allocate new type expression
817 *
818 * @return New type expression
819 */
820stree_texpr_t *stree_texpr_new(texpr_class_t tc)
821{
822 stree_texpr_t *texpr;
823
824 texpr = calloc(1, sizeof(stree_texpr_t));
825 if (texpr == NULL) {
826 printf("Memory allocation failed.\n");
827 exit(1);
828 }
829
830 texpr->tc = tc;
831 return texpr;
832}
833
834/** Allocate new type access operation.
835 *
836 * @return New type access operation
837 */
838stree_taccess_t *stree_taccess_new(void)
839{
840 stree_taccess_t *taccess;
841
842 taccess = calloc(1, sizeof(stree_taccess_t));
843 if (taccess == NULL) {
844 printf("Memory allocation failed.\n");
845 exit(1);
846 }
847
848 return taccess;
849}
850
851/** Allocate new type application operation.
852 *
853 * @return New type application operation
854 */
855stree_tapply_t *stree_tapply_new(void)
856{
857 stree_tapply_t *tapply;
858
859 tapply = calloc(1, sizeof(stree_tapply_t));
860 if (tapply == NULL) {
861 printf("Memory allocation failed.\n");
862 exit(1);
863 }
864
865 return tapply;
866}
867
868/** Allocate new type indexing operation.
869 *
870 * @return New type indexing operation
871 */
872stree_tindex_t *stree_tindex_new(void)
873{
874 stree_tindex_t *tindex;
875
876 tindex = calloc(1, sizeof(stree_tindex_t));
877 if (tindex == NULL) {
878 printf("Memory allocation failed.\n");
879 exit(1);
880 }
881
882 return tindex;
883}
884
885/** Allocate new type literal.
886 *
887 * @return New type literal
888 */
889stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc)
890{
891 stree_tliteral_t *tliteral;
892
893 tliteral = calloc(1, sizeof(stree_tliteral_t));
894 if (tliteral == NULL) {
895 printf("Memory allocation failed.\n");
896 exit(1);
897 }
898
899 tliteral->tlc = tlc;
900 return tliteral;
901}
902
903/** Allocate new type name reference.
904 *
905 * @return New type name reference
906 */
907stree_tnameref_t *stree_tnameref_new(void)
908{
909 stree_tnameref_t *tnameref;
910
911 tnameref = calloc(1, sizeof(stree_tnameref_t));
912 if (tnameref == NULL) {
913 printf("Memory allocation failed.\n");
914 exit(1);
915 }
916
917 return tnameref;
918}
919
920/** Allocate new symbol.
921 *
922 * @return New symbol
923 */
924stree_symbol_t *stree_symbol_new(symbol_class_t sc)
925{
926 stree_symbol_t *symbol;
927
928 symbol = calloc(1, sizeof(stree_symbol_t));
929 if (symbol == NULL) {
930 printf("Memory allocation failed.\n");
931 exit(1);
932 }
933
934 symbol->sc = sc;
935 list_init(&symbol->attr);
936
937 return symbol;
938}
939
940/** Allocate new program.
941 *
942 * @return New program
943 */
944stree_program_t *stree_program_new(void)
945{
946 stree_program_t *program;
947
948 program = calloc(1, sizeof(stree_program_t));
949 if (program == NULL) {
950 printf("Memory allocation failed.\n");
951 exit(1);
952 }
953
954 return program;
955}
956
957/** Determine if @a symbol has attribute of class @a sac.
958 *
959 * @param symbol Symbol
960 * @param sac Symbol attribute class
961 * @return @c b_true if yes, @c b_false if no
962 */
963bool_t stree_symbol_has_attr(stree_symbol_t *symbol, symbol_attr_class_t sac)
964{
965 list_node_t *node;
966 stree_symbol_attr_t *attr;
967
968 node = list_first(&symbol->attr);
969 while (node != NULL) {
970 attr = list_node_data(node, stree_symbol_attr_t *);
971 if (attr->sac == sac)
972 return b_true;
973
974 node = list_next(&symbol->attr, node);
975 }
976
977 return b_false;
978}
979
980/** Determine if argument @a arg has attribute of class @a aac.
981 *
982 * @param arg Formal procedure argument
983 * @param aac Argument attribute class
984 * @return @c b_true if yes, @c b_false if no.
985 */
986bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac)
987{
988 list_node_t *node;
989 stree_arg_attr_t *attr;
990
991 node = list_first(&arg->attr);
992 while (node != NULL) {
993 attr = list_node_data(node, stree_arg_attr_t *);
994 if (attr->aac == aac)
995 return b_true;
996
997 node = list_next(&arg->attr, node);
998 }
999
1000 return b_false;
1001}
1002
1003/** Determine wheter @a a is derived (transitively) from @a b.
1004 *
1005 * XXX This does not work right with generics.
1006 *
1007 * @param a Derived CSI.
1008 * @param b Base CSI.
1009 * @return @c b_true if @a a is equal to or directly or indirectly
1010 * derived from @a b.
1011 */
1012bool_t stree_is_csi_derived_from_csi(stree_csi_t *a, stree_csi_t *b)
1013{
1014 stree_csi_t *csi;
1015
1016 csi = a;
1017 while (csi != NULL) {
1018 if (csi == b)
1019 return b_true;
1020
1021 csi = csi->base_csi;
1022 }
1023
1024 /* We went all the way to the root and did not find b. */
1025 return b_false;
1026}
1027
1028/** Determine if @a symbol is static.
1029 *
1030 * @param symbol Symbol
1031 * @return @c b_true if symbol is static, @c b_false otherwise
1032 */
1033bool_t stree_symbol_is_static(stree_symbol_t *symbol)
1034{
1035 /* Module-wide symbols are static. */
1036 if (symbol->outer_csi == NULL)
1037 return b_true;
1038
1039 /* Symbols with @c static attribute are static. */
1040 if (stree_symbol_has_attr(symbol, sac_static))
1041 return b_true;
1042
1043 switch (symbol->sc) {
1044 case sc_csi:
1045 case sc_deleg:
1046 case sc_enum:
1047 return b_true;
1048 case sc_ctor:
1049 case sc_fun:
1050 case sc_var:
1051 case sc_prop:
1052 break;
1053 }
1054
1055 return b_false;
1056}
1057
1058/** Search for CSI type argument of the given name.
1059 *
1060 * @param csi CSI to look in
1061 * @param ident Identifier of the type argument
1062 * @return Type argument declaration or @c NULL if not found
1063 */
1064stree_targ_t *stree_csi_find_targ(stree_csi_t *csi, stree_ident_t *ident)
1065{
1066 list_node_t *targ_n;
1067 stree_targ_t *targ;
1068
1069 targ_n = list_first(&csi->targ);
1070 while (targ_n != NULL) {
1071 targ = list_node_data(targ_n, stree_targ_t *);
1072 if (targ->name->sid == ident->sid)
1073 return targ;
1074
1075 targ_n = list_next(&csi->targ, targ_n);
1076 }
1077
1078 /* No match */
1079 return NULL;
1080}
1081
1082/** Search for enum member of the given name.
1083 *
1084 * @param enum_d Enum to look in
1085 * @param ident Identifier of the enum member
1086 * @return Enum member declaration or @c NULL if not found
1087 */
1088stree_embr_t *stree_enum_find_mbr(stree_enum_t *enum_d, stree_ident_t *ident)
1089{
1090 list_node_t *embr_n;
1091 stree_embr_t *embr;
1092
1093 embr_n = list_first(&enum_d->members);
1094 while (embr_n != NULL) {
1095 embr = list_node_data(embr_n, stree_embr_t *);
1096 if (embr->name->sid == ident->sid)
1097 return embr;
1098
1099 embr_n = list_next(&enum_d->members, embr_n);
1100 }
1101
1102 /* No match */
1103 return NULL;
1104}
1105
1106/** Get CSI member name.
1107 *
1108 * @param csimbr CSI member
1109 * @return Member name
1110 */
1111stree_ident_t *stree_csimbr_get_name(stree_csimbr_t *csimbr)
1112{
1113 stree_ident_t *mbr_name;
1114
1115 /* Keep compiler happy. */
1116 mbr_name = NULL;
1117
1118 switch (csimbr->cc) {
1119 case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
1120 case csimbr_ctor: mbr_name = csimbr->u.ctor->name; break;
1121 case csimbr_deleg: mbr_name = csimbr->u.deleg->name; break;
1122 case csimbr_enum: mbr_name = csimbr->u.enum_d->name; break;
1123 case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
1124 case csimbr_var: mbr_name = csimbr->u.var->name; break;
1125 case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
1126 }
1127
1128 return mbr_name;
1129}
Note: See TracBrowser for help on using the repository browser.