Array of strings sys_dirs must be NULL-terminated
[helenos.git] / uspace / app / sbi / src / stree_t.h
blob93aefda046fa59f834125693fbd1785b68a5c4ee
1 /*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
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.
29 #ifndef STREE_T_H_
30 #define STREE_T_H_
32 #include "bigint_t.h"
33 #include "list_t.h"
34 #include "builtin_t.h"
37 * Arithmetic expressions
40 struct stree_expr;
42 /** Identifier */
43 typedef struct {
44 int sid;
45 struct cspan *cspan;
46 } stree_ident_t;
48 /** Name reference */
49 typedef struct {
50 /** Expression backlink */
51 struct stree_expr *expr;
53 stree_ident_t *name;
54 } stree_nameref_t;
56 /** Boolean literal */
57 typedef struct {
58 bool_t value;
59 } stree_lit_bool_t;
61 /** Character literal */
62 typedef struct {
63 bigint_t value;
64 } stree_lit_char_t;
66 /** Integer literal */
67 typedef struct {
68 bigint_t value;
69 } stree_lit_int_t;
71 /** Reference literal (there is only one: @c nil). */
72 typedef struct {
73 } stree_lit_ref_t;
75 /** String literal */
76 typedef struct {
77 char *value;
78 } stree_lit_string_t;
80 typedef enum {
81 ltc_bool,
82 ltc_char,
83 ltc_int,
84 ltc_ref,
85 ltc_string
86 } literal_class_t;
88 /** Literal */
89 typedef struct {
90 /** Expression backlink */
91 struct stree_expr *expr;
93 literal_class_t ltc;
94 union {
95 stree_lit_bool_t lit_bool;
96 stree_lit_char_t lit_char;
97 stree_lit_int_t lit_int;
98 stree_lit_ref_t lit_ref;
99 stree_lit_string_t lit_string;
100 } u;
101 } stree_literal_t;
103 /** Reference to currently active object. */
104 typedef struct {
105 /** Expression backlink */
106 struct stree_expr *expr;
107 } stree_self_ref_t;
109 /** Binary operation class */
110 typedef enum {
111 bo_equal,
112 bo_notequal,
113 bo_lt,
114 bo_gt,
115 bo_lt_equal,
116 bo_gt_equal,
117 bo_plus,
118 bo_minus,
119 bo_mult,
120 bo_and,
121 bo_or
122 } binop_class_t;
124 /** Unary operation class */
125 typedef enum {
126 uo_plus,
127 uo_minus,
128 uo_not
129 } unop_class_t;
131 /** Binary operation */
132 typedef struct {
133 /** Expression backlink */
134 struct stree_expr *expr;
136 /** Binary operation class */
137 binop_class_t bc;
139 /** Arguments */
140 struct stree_expr *arg1, *arg2;
141 } stree_binop_t;
143 /** Unary operation */
144 typedef struct {
145 /** Expression backlink */
146 struct stree_expr *expr;
148 /** Operation class */
149 unop_class_t uc;
151 /** Argument */
152 struct stree_expr *arg;
153 } stree_unop_t;
155 /** New operation */
156 typedef struct {
157 /** Expression backlink */
158 struct stree_expr *expr;
160 /** Type of object to construct. */
161 struct stree_texpr *texpr;
163 /** Constructor arguments */
164 list_t ctor_args; /* of stree_expr_t */
165 } stree_new_t;
167 /** Member access operation */
168 typedef struct {
169 /** Expression backlink */
170 struct stree_expr *expr;
172 /** Argument */
173 struct stree_expr *arg;
174 /** Name of member being accessed. */
175 stree_ident_t *member_name;
176 } stree_access_t;
178 /** Function call operation */
179 typedef struct {
180 /** Expression backlink */
181 struct stree_expr *expr;
183 /** Function */
184 struct stree_expr *fun;
186 /** Arguments */
187 list_t args; /* of stree_expr_t */
188 } stree_call_t;
190 typedef enum {
191 ac_set,
192 ac_increase
193 } assign_class_t;
195 /** Assignment */
196 typedef struct {
197 /** Expression backlink */
198 struct stree_expr *expr;
200 assign_class_t ac;
201 struct stree_expr *dest, *src;
202 } stree_assign_t;
204 /** Indexing operation */
205 typedef struct {
206 /** Expression backlink */
207 struct stree_expr *expr;
209 /** Base */
210 struct stree_expr *base;
212 /** Arguments (indices) */
213 list_t args; /* of stree_expr_t */
214 } stree_index_t;
216 /** @c as conversion operation */
217 typedef struct {
218 /** Expression backlink */
219 struct stree_expr *expr;
221 /** Expression to convert */
222 struct stree_expr *arg;
224 /** Destination type of conversion. */
225 struct stree_texpr *dtype;
226 } stree_as_t;
228 /** Boxing of primitive type (pseudo)
230 * This pseudo-node is used internally to box a value of primitive type.
231 * It is implicitly inserted by stype_convert(). It does not correspond
232 * to a an explicit program construct.
234 typedef struct {
235 /** Expression backlink */
236 struct stree_expr *expr;
238 /* Primitive type expression */
239 struct stree_expr *arg;
240 } stree_box_t;
242 /** Arithmetic expression class */
243 typedef enum {
244 ec_nameref,
245 ec_literal,
246 ec_self_ref,
247 ec_binop,
248 ec_unop,
249 ec_new,
250 ec_access,
251 ec_call,
252 ec_assign,
253 ec_index,
254 ec_as,
255 ec_box
256 } expr_class_t;
258 /** Arithmetic expression */
259 typedef struct stree_expr {
260 expr_class_t ec;
262 /** Type of this expression or @c NULL if not typed yet */
263 struct tdata_item *titem;
265 /** Coordinate span */
266 struct cspan *cspan;
268 union {
269 stree_nameref_t *nameref;
270 stree_literal_t *literal;
271 stree_self_ref_t *self_ref;
272 stree_binop_t *binop;
273 stree_unop_t *unop;
274 stree_new_t *new_op;
275 stree_access_t *access;
276 stree_call_t *call;
277 stree_index_t *index;
278 stree_assign_t *assign;
279 stree_as_t *as_op;
280 stree_box_t *box;
281 } u;
282 } stree_expr_t;
285 * Type expressions
288 struct stree_texpr;
290 /** Type literal class */
291 typedef enum {
292 tlc_bool,
293 tlc_char,
294 tlc_int,
295 tlc_resource,
296 tlc_string
297 } tliteral_class_t;
299 /** Type literal */
300 typedef struct {
301 /** Type expression backlink */
302 struct stree_texpr *texpr;
304 tliteral_class_t tlc;
305 } stree_tliteral_t;
307 /** Type name reference */
308 typedef struct {
309 /** Type expression backlink */
310 struct stree_texpr *texpr;
312 stree_ident_t *name;
313 } stree_tnameref_t;
315 /** Type member access operation */
316 typedef struct {
317 /** Type expression backlink */
318 struct stree_texpr *texpr;
320 /** Argument */
321 struct stree_texpr *arg;
323 /** Name of member being accessed. */
324 stree_ident_t *member_name;
325 } stree_taccess_t;
327 /** Type application operation */
328 typedef struct {
329 /** Type expression backlink */
330 struct stree_texpr *texpr;
332 /* Base type */
333 struct stree_texpr *gtype;
335 /** (Formal) type arguments */
336 list_t targs; /* of stree_texpr_t */
337 } stree_tapply_t;
339 /** Type index operation */
340 typedef struct {
341 /** Type expression backlink */
342 struct stree_texpr *texpr;
344 /** Base type */
345 struct stree_texpr *base_type;
348 * Number of arguments (rank). Needed when only rank is specified
349 * and @c args are not used.
351 int n_args;
353 /** Arguments (extents) */
354 list_t args; /* of stree_expr_t */
355 } stree_tindex_t;
357 /** Type expression class */
358 typedef enum {
359 tc_tliteral,
360 tc_tnameref,
361 tc_taccess,
362 tc_tapply,
363 tc_tindex
364 } texpr_class_t;
366 /** Type expression */
367 typedef struct stree_texpr {
368 texpr_class_t tc;
370 /** Coordinate span */
371 struct cspan *cspan;
373 union {
374 stree_tliteral_t *tliteral;
375 stree_tnameref_t *tnameref;
376 stree_taccess_t *taccess;
377 stree_tapply_t *tapply;
378 stree_tindex_t *tindex;
379 } u;
380 } stree_texpr_t;
383 * Statements, class members and module members.
386 /** Statement block */
387 typedef struct stree_block {
388 /** List of statements in the block */
389 list_t stats; /* of stree_stat_t */
390 } stree_block_t;
392 /** Variable declaration */
393 typedef struct {
394 stree_ident_t *name;
395 stree_texpr_t *type;
397 /** Type of this variable or @c NULL if not typed yet */
398 struct tdata_item *titem;
399 } stree_vdecl_t;
401 /** @c except clause */
402 typedef struct {
403 stree_ident_t *evar;
404 stree_texpr_t *etype;
405 stree_block_t *block;
407 /** Evaluated etype or @c NULL if not typed yet */
408 struct tdata_item *titem;
409 } stree_except_t;
411 /** @c if or @c elif clause */
412 typedef struct {
413 stree_expr_t *cond;
414 stree_block_t *block;
415 } stree_if_clause_t;
417 /** If statement */
418 typedef struct {
419 /** If and elif clauses */
420 list_t if_clauses; /* of stree_if_clause_t */
422 /** Else block */
423 stree_block_t *else_block;
424 } stree_if_t;
426 /** @c when clause */
427 typedef struct {
428 /** List of expressions -- cases -- for this clause */
429 list_t exprs; /* of stree_expr_t */
430 stree_block_t *block;
431 } stree_when_t;
433 /** Switch statement */
434 typedef struct {
435 /** Switch expression */
436 stree_expr_t *expr;
438 /** When clauses */
439 list_t when_clauses; /* of stree_when_t */
441 /** Else block */
442 stree_block_t *else_block;
443 } stree_switch_t;
445 /** While statement */
446 typedef struct {
447 stree_expr_t *cond;
448 stree_block_t *body;
449 } stree_while_t;
451 /** For statement */
452 typedef struct {
453 stree_block_t *body;
454 } stree_for_t;
456 /** Raise statement */
457 typedef struct {
458 stree_expr_t *expr;
459 } stree_raise_t;
461 /** Break statement */
462 typedef struct {
463 } stree_break_t;
465 /** Return statement */
466 typedef struct {
467 stree_expr_t *expr;
468 } stree_return_t;
470 /** Expression statement */
471 typedef struct {
472 stree_expr_t *expr;
473 } stree_exps_t;
475 /** With-try-except-finally (WEF) statement */
476 typedef struct {
477 stree_block_t *with_block;
478 list_t except_clauses; /* of stree_except_t */
479 stree_block_t *finally_block;
480 } stree_wef_t;
482 /** Statement class */
483 typedef enum {
484 st_vdecl,
485 st_if,
486 st_switch,
487 st_while,
488 st_for,
489 st_raise,
490 st_break,
491 st_return,
492 st_exps,
493 st_wef
494 } stat_class_t;
496 /** Statement */
497 typedef struct {
498 stat_class_t sc;
500 union {
501 stree_vdecl_t *vdecl_s;
502 stree_if_t *if_s;
503 stree_switch_t *switch_s;
504 stree_while_t *while_s;
505 stree_for_t *for_s;
506 stree_raise_t *raise_s;
507 stree_break_t *break_s;
508 stree_return_t *return_s;
509 stree_exps_t *exp_s;
510 stree_wef_t *wef_s;
511 } u;
512 } stree_stat_t;
514 /** Argument attribute class */
515 typedef enum {
516 /** Packed argument (for variadic functions) */
517 aac_packed
518 } arg_attr_class_t;
520 /** Argument atribute */
521 typedef struct {
522 arg_attr_class_t aac;
523 } stree_arg_attr_t;
525 /** Formal function parameter */
526 typedef struct {
527 /* Argument name */
528 stree_ident_t *name;
530 /* Argument type */
531 stree_texpr_t *type;
533 /* Attributes */
534 list_t attr; /* of stree_arg_attr_t */
535 } stree_proc_arg_t;
537 /** Function signature.
539 * Formal parameters and return type. This is common to function and delegate
540 * delcarations.
542 typedef struct {
543 /** Formal parameters */
544 list_t args; /* of stree_proc_arg_t */
546 /** Variadic argument or @c NULL if none. */
547 stree_proc_arg_t *varg;
549 /** Return type */
550 stree_texpr_t *rtype;
551 } stree_fun_sig_t;
553 /** Procedure
555 * Procedure is the common term for a getter, setter or function body.
556 * A procedure can be invoked. However, the arguments are specified by
557 * the containing symbol.
559 typedef struct stree_proc {
560 /** Symbol (function or property) containing the procedure */
561 struct stree_symbol *outer_symbol;
563 /** Main block for regular procedures */
564 stree_block_t *body;
566 /** Builtin handler for builtin procedures */
567 builtin_proc_t bi_handler;
568 } stree_proc_t;
570 /** Constructor declaration */
571 typedef struct stree_ctor {
572 /** Constructor 'name'. Points to the @c new keyword. */
573 stree_ident_t *name;
575 /** Symbol */
576 struct stree_symbol *symbol;
578 /** Signature (arguments, return type is always none) */
579 stree_fun_sig_t *sig;
581 /** Constructor implementation */
582 stree_proc_t *proc;
584 /** Type item describing the constructor */
585 struct tdata_item *titem;
586 } stree_ctor_t;
588 /** Delegate declaration */
589 typedef struct stree_deleg {
590 /** Delegate name */
591 stree_ident_t *name;
593 /** Symbol */
594 struct stree_symbol *symbol;
596 /** Signature (arguments and return type) */
597 stree_fun_sig_t *sig;
599 /** Type item describing the delegate */
600 struct tdata_item *titem;
601 } stree_deleg_t;
603 /** Enum member */
604 typedef struct stree_embr {
605 /** Enum containing this declaration */
606 struct stree_enum *outer_enum;
608 /** Enum member name */
609 stree_ident_t *name;
610 } stree_embr_t;
612 /** Enum declaration */
613 typedef struct stree_enum {
614 /** Enum name */
615 stree_ident_t *name;
617 /** Symbol */
618 struct stree_symbol *symbol;
620 /** List of enum members */
621 list_t members; /* of stree_embr_t */
623 /** Type item describing the enum */
624 struct tdata_item *titem;
625 } stree_enum_t;
627 /** Member function declaration */
628 typedef struct stree_fun {
629 /** Function name */
630 stree_ident_t *name;
632 /** Symbol */
633 struct stree_symbol *symbol;
635 /** Signature (arguments and return type) */
636 stree_fun_sig_t *sig;
638 /** Function implementation */
639 stree_proc_t *proc;
641 /** Type item describing the function */
642 struct tdata_item *titem;
643 } stree_fun_t;
645 /** Member variable declaration */
646 typedef struct stree_var {
647 stree_ident_t *name;
648 struct stree_symbol *symbol;
649 stree_texpr_t *type;
650 } stree_var_t;
652 /** Member property declaration */
653 typedef struct stree_prop {
654 stree_ident_t *name;
655 struct stree_symbol *symbol;
656 stree_texpr_t *type;
658 stree_proc_t *getter;
660 stree_proc_t *setter;
661 stree_proc_arg_t *setter_arg;
663 /** Formal parameters (for indexed properties) */
664 list_t args; /* of stree_proc_arg_t */
666 /** Variadic argument or @c NULL if none. */
667 stree_proc_arg_t *varg;
669 /** Type of the property */
670 struct tdata_item *titem;
671 } stree_prop_t;
674 * Fake identifiers used with symbols that do not really have one.
676 #define CTOR_IDENT "$ctor"
677 #define INDEXER_IDENT "$indexer"
679 typedef enum {
680 csimbr_csi,
681 csimbr_ctor,
682 csimbr_deleg,
683 csimbr_enum,
684 csimbr_fun,
685 csimbr_var,
686 csimbr_prop
687 } csimbr_class_t;
689 /** Class, struct or interface member */
690 typedef struct {
691 csimbr_class_t cc;
693 union {
694 struct stree_csi *csi;
695 stree_ctor_t *ctor;
696 stree_deleg_t *deleg;
697 stree_enum_t *enum_d;
698 stree_fun_t *fun;
699 stree_var_t *var;
700 stree_prop_t *prop;
701 } u;
702 } stree_csimbr_t;
704 typedef enum {
705 csi_class,
706 csi_struct,
707 csi_interface
708 } csi_class_t;
710 /** CSI formal type argument */
711 typedef struct stree_targ {
712 stree_ident_t *name;
713 struct stree_symbol *symbol;
714 } stree_targ_t;
716 /** Class, struct or interface declaration */
717 typedef struct stree_csi {
718 /** Which of class, struct or interface */
719 csi_class_t cc;
721 /** Name of this CSI */
722 stree_ident_t *name;
724 /** List of type arguments */
725 list_t targ; /* of stree_targ_t */
727 /** Symbol for this CSI */
728 struct stree_symbol *symbol;
730 /** Type expressions referencing inherited CSIs. */
731 list_t inherit; /* of stree_texpr_t */
733 /** Base CSI. Only available when ancr_state == ws_visited. */
734 struct stree_csi *base_csi;
736 /** Types of implemented or accumulated interfaces. */
737 list_t impl_if_ti; /* of tdata_item_t */
739 /** Node state for ancr walks. */
740 walk_state_t ancr_state;
742 /** List of CSI members */
743 list_t members; /* of stree_csimbr_t */
744 } stree_csi_t;
746 typedef enum {
747 /* Class, struct or interface declaration */
748 mc_csi,
749 /* Enum declaration */
750 mc_enum
751 } modm_class_t;
753 /** Module member */
754 typedef struct {
755 modm_class_t mc;
756 union {
757 stree_csi_t *csi;
758 stree_enum_t *enum_d;
759 } u;
760 } stree_modm_t;
762 /** Module */
763 typedef struct stree_module {
764 /** List of module members */
765 list_t members; /* of stree_modm_t */
766 } stree_module_t;
768 /** Symbol attribute class */
769 typedef enum {
770 /** Builtin symbol (interpreter hook) */
771 sac_builtin,
773 /** Static symbol */
774 sac_static
775 } symbol_attr_class_t;
777 /** Symbol atribute */
778 typedef struct {
779 symbol_attr_class_t sac;
780 } stree_symbol_attr_t;
782 typedef enum {
783 /** CSI (class, struct or interface) */
784 sc_csi,
785 /** Constructor */
786 sc_ctor,
787 /** Member delegate */
788 sc_deleg,
789 /** Enum */
790 sc_enum,
791 /** Member function */
792 sc_fun,
793 /** Member variable */
794 sc_var,
795 /** Member property */
796 sc_prop
797 } symbol_class_t;
799 /** Symbol
801 * A symbol is a common superclass of different program elements that
802 * allow us to refer to them, print their fully qualified names, etc.
804 typedef struct stree_symbol {
805 symbol_class_t sc;
807 union {
808 struct stree_csi *csi;
809 stree_ctor_t *ctor;
810 stree_deleg_t *deleg;
811 stree_enum_t *enum_d;
812 stree_fun_t *fun;
813 stree_var_t *var;
814 stree_prop_t *prop;
815 } u;
817 /** Containing CSI */
818 stree_csi_t *outer_csi;
820 /** Symbol attributes */
821 list_t attr; /* of stree_symbol_attr_t */
822 } stree_symbol_t;
824 /** Program */
825 typedef struct stree_program {
826 /** The one and only module in the program */
827 stree_module_t *module;
829 /** Builtin symbols binding. */
830 struct builtin *builtin;
831 } stree_program_t;
833 #endif