source: mainline/uspace/app/sbi/src/stree_t.h@ 406d514

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

Update SBI to rev. 291.

  • Property mode set to 100644
File size: 15.8 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#ifndef STREE_T_H_
30#define STREE_T_H_
31
32#include "bigint_t.h"
33#include "list_t.h"
34#include "builtin_t.h"
35
36/*
37 * Arithmetic expressions
38 */
39
40struct stree_expr;
41
42/** Identifier */
43typedef struct {
44 int sid;
45 struct cspan *cspan;
46} stree_ident_t;
47
48/** Name reference */
49typedef struct {
50 /** Expression backlink */
51 struct stree_expr *expr;
52
53 stree_ident_t *name;
54} stree_nameref_t;
55
56/** Boolean literal */
57typedef struct {
58 bool_t value;
59} stree_lit_bool_t;
60
61/** Character literal */
62typedef struct {
63 bigint_t value;
64} stree_lit_char_t;
65
66/** Integer literal */
67typedef struct {
68 bigint_t value;
69} stree_lit_int_t;
70
71/** Reference literal (there is only one: @c nil). */
72typedef struct {
73} stree_lit_ref_t;
74
75/** String literal */
76typedef struct {
77 char *value;
78} stree_lit_string_t;
79
80typedef enum {
81 ltc_bool,
82 ltc_char,
83 ltc_int,
84 ltc_ref,
85 ltc_string
86} literal_class_t;
87
88/** Literal */
89typedef struct {
90 /** Expression backlink */
91 struct stree_expr *expr;
92
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;
102
103/** Reference to currently active object. */
104typedef struct {
105 /** Expression backlink */
106 struct stree_expr *expr;
107} stree_self_ref_t;
108
109/** Binary operation class */
110typedef 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;
123
124/** Unary operation class */
125typedef enum {
126 uo_plus,
127 uo_minus,
128 uo_not
129} unop_class_t;
130
131/** Binary operation */
132typedef struct {
133 /** Expression backlink */
134 struct stree_expr *expr;
135
136 /** Binary operation class */
137 binop_class_t bc;
138
139 /** Arguments */
140 struct stree_expr *arg1, *arg2;
141} stree_binop_t;
142
143/** Unary operation */
144typedef struct {
145 /** Expression backlink */
146 struct stree_expr *expr;
147
148 /** Operation class */
149 unop_class_t uc;
150
151 /** Argument */
152 struct stree_expr *arg;
153} stree_unop_t;
154
155/** New operation */
156typedef struct {
157 /** Expression backlink */
158 struct stree_expr *expr;
159
160 /** Type of object to construct. */
161 struct stree_texpr *texpr;
162
163 /** Constructor arguments */
164 list_t ctor_args; /* of stree_expr_t */
165} stree_new_t;
166
167/** Member access operation */
168typedef struct {
169 /** Expression backlink */
170 struct stree_expr *expr;
171
172 /** Argument */
173 struct stree_expr *arg;
174 /** Name of member being accessed. */
175 stree_ident_t *member_name;
176} stree_access_t;
177
178/** Function call operation */
179typedef struct {
180 /** Expression backlink */
181 struct stree_expr *expr;
182
183 /** Function */
184 struct stree_expr *fun;
185
186 /** Arguments */
187 list_t args; /* of stree_expr_t */
188} stree_call_t;
189
190typedef enum {
191 ac_set,
192 ac_increase
193} assign_class_t;
194
195/** Assignment */
196typedef struct {
197 /** Expression backlink */
198 struct stree_expr *expr;
199
200 assign_class_t ac;
201 struct stree_expr *dest, *src;
202} stree_assign_t;
203
204/** Indexing operation */
205typedef struct {
206 /** Expression backlink */
207 struct stree_expr *expr;
208
209 /** Base */
210 struct stree_expr *base;
211
212 /** Arguments (indices) */
213 list_t args; /* of stree_expr_t */
214} stree_index_t;
215
216/** @c as conversion operation */
217typedef struct {
218 /** Expression backlink */
219 struct stree_expr *expr;
220
221 /** Expression to convert */
222 struct stree_expr *arg;
223
224 /** Destination type of conversion. */
225 struct stree_texpr *dtype;
226} stree_as_t;
227
228/** Boxing of primitive type (pseudo)
229 *
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.
233 */
234typedef struct {
235 /** Expression backlink */
236 struct stree_expr *expr;
237
238 /* Primitive type expression */
239 struct stree_expr *arg;
240} stree_box_t;
241
242/** Arithmetic expression class */
243typedef 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;
257
258/** Arithmetic expression */
259typedef struct stree_expr {
260 expr_class_t ec;
261
262 /** Type of this expression or @c NULL if not typed yet */
263 struct tdata_item *titem;
264
265 /** Coordinate span */
266 struct cspan *cspan;
267
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;
283
284/*
285 * Type expressions
286 */
287
288struct stree_texpr;
289
290/** Type literal class */
291typedef enum {
292 tlc_bool,
293 tlc_char,
294 tlc_int,
295 tlc_resource,
296 tlc_string
297} tliteral_class_t;
298
299/** Type literal */
300typedef struct {
301 /** Type expression backlink */
302 struct stree_texpr *texpr;
303
304 tliteral_class_t tlc;
305} stree_tliteral_t;
306
307/** Type name reference */
308typedef struct {
309 /** Type expression backlink */
310 struct stree_texpr *texpr;
311
312 stree_ident_t *name;
313} stree_tnameref_t;
314
315/** Type member access operation */
316typedef struct {
317 /** Type expression backlink */
318 struct stree_texpr *texpr;
319
320 /** Argument */
321 struct stree_texpr *arg;
322
323 /** Name of member being accessed. */
324 stree_ident_t *member_name;
325} stree_taccess_t;
326
327/** Type application operation */
328typedef struct {
329 /** Type expression backlink */
330 struct stree_texpr *texpr;
331
332 /* Base type */
333 struct stree_texpr *gtype;
334
335 /** (Formal) type arguments */
336 list_t targs; /* of stree_texpr_t */
337} stree_tapply_t;
338
339/** Type index operation */
340typedef struct {
341 /** Type expression backlink */
342 struct stree_texpr *texpr;
343
344 /** Base type */
345 struct stree_texpr *base_type;
346
347 /**
348 * Number of arguments (rank). Needed when only rank is specified
349 * and @c args are not used.
350 */
351 int n_args;
352
353 /** Arguments (extents) */
354 list_t args; /* of stree_expr_t */
355} stree_tindex_t;
356
357/** Type expression class */
358typedef enum {
359 tc_tliteral,
360 tc_tnameref,
361 tc_taccess,
362 tc_tapply,
363 tc_tindex
364} texpr_class_t;
365
366/** Arithmetic expression */
367typedef struct stree_texpr {
368 texpr_class_t tc;
369
370 /** Coordinate span */
371 struct cspan *cspan;
372
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;
381
382/*
383 * Statements, class members and module members.
384 */
385
386/** Statement block */
387typedef struct stree_block {
388 /** List of statements in the block */
389 list_t stats; /* of stree_stat_t */
390} stree_block_t;
391
392/** Variable declaration */
393typedef struct {
394 stree_ident_t *name;
395 stree_texpr_t *type;
396} stree_vdecl_t;
397
398/** @c except clause */
399typedef struct {
400 stree_ident_t *evar;
401 stree_texpr_t *etype;
402 stree_block_t *block;
403} stree_except_t;
404
405/** @c if or @c elif clause */
406typedef struct {
407 stree_expr_t *cond;
408 stree_block_t *block;
409} stree_if_clause_t;
410
411/** If statement */
412typedef struct {
413 /** If and elif clauses */
414 list_t if_clauses; /* of stree_if_clause_t */
415
416 /** Else block */
417 stree_block_t *else_block;
418} stree_if_t;
419
420/** While statement */
421typedef struct {
422 stree_expr_t *cond;
423 stree_block_t *body;
424} stree_while_t;
425
426/** For statement */
427typedef struct {
428 stree_block_t *body;
429} stree_for_t;
430
431/** Raise statement */
432typedef struct {
433 stree_expr_t *expr;
434} stree_raise_t;
435
436/** Break statement */
437typedef struct {
438} stree_break_t;
439
440/** Return statement */
441typedef struct {
442 stree_expr_t *expr;
443} stree_return_t;
444
445/** Expression statement */
446typedef struct {
447 stree_expr_t *expr;
448} stree_exps_t;
449
450/** With-try-except-finally statement (WEF) */
451typedef struct {
452 stree_block_t *with_block;
453 list_t except_clauses; /* of stree_except_t */
454 stree_block_t *finally_block;
455} stree_wef_t;
456
457/** Statement class */
458typedef enum {
459 st_vdecl,
460 st_if,
461 st_while,
462 st_for,
463 st_raise,
464 st_break,
465 st_return,
466 st_exps,
467 st_wef
468} stat_class_t;
469
470/** Statement */
471typedef struct {
472 stat_class_t sc;
473
474 union {
475 stree_vdecl_t *vdecl_s;
476 stree_if_t *if_s;
477 stree_while_t *while_s;
478 stree_for_t *for_s;
479 stree_raise_t *raise_s;
480 stree_break_t *break_s;
481 stree_return_t *return_s;
482 stree_exps_t *exp_s;
483 stree_wef_t *wef_s;
484 } u;
485} stree_stat_t;
486
487/** Argument attribute class */
488typedef enum {
489 /** Packed argument (for variadic functions) */
490 aac_packed
491} arg_attr_class_t;
492
493/** Argument atribute */
494typedef struct {
495 arg_attr_class_t aac;
496} stree_arg_attr_t;
497
498/** Formal function parameter */
499typedef struct {
500 /* Argument name */
501 stree_ident_t *name;
502
503 /* Argument type */
504 stree_texpr_t *type;
505
506 /* Attributes */
507 list_t attr; /* of stree_arg_attr_t */
508} stree_proc_arg_t;
509
510/** Function signature.
511 *
512 * Foormal parameters and return type. This is common to function and delegate
513 * delcarations.
514 */
515typedef struct {
516 /** Formal parameters */
517 list_t args; /* of stree_proc_arg_t */
518
519 /** Variadic argument or @c NULL if none. */
520 stree_proc_arg_t *varg;
521
522 /** Return type */
523 stree_texpr_t *rtype;
524} stree_fun_sig_t;
525
526/** Procedure
527 *
528 * Procedure is the common term for a getter, setter or function body.
529 * A procedure can be invoked. However, the arguments are specified by
530 * the containing symbol.
531 */
532typedef struct stree_proc {
533 /** Symbol (function or property) containing the procedure */
534 struct stree_symbol *outer_symbol;
535
536 /** Main block for regular procedures */
537 stree_block_t *body;
538
539 /** Builtin handler for builtin procedures */
540 builtin_proc_t bi_handler;
541} stree_proc_t;
542
543/** Constructor declaration */
544typedef struct stree_ctor {
545 /** Constructor 'name'. Points to the @c new keyword. */
546 stree_ident_t *name;
547
548 /** Symbol */
549 struct stree_symbol *symbol;
550
551 /** Signature (arguments, return type is always none) */
552 stree_fun_sig_t *sig;
553
554 /** Constructor implementation */
555 stree_proc_t *proc;
556
557 /** Type item describing the constructor */
558 struct tdata_item *titem;
559} stree_ctor_t;
560
561/** Delegate declaration */
562typedef struct stree_deleg {
563 /** Delegate name */
564 stree_ident_t *name;
565
566 /** Symbol */
567 struct stree_symbol *symbol;
568
569 /** Signature (arguments and return type) */
570 stree_fun_sig_t *sig;
571
572 /** Type item describing the delegate */
573 struct tdata_item *titem;
574} stree_deleg_t;
575
576/** Enum member */
577typedef struct stree_embr {
578 /** Enum containing this declaration */
579 struct stree_enum *outer_enum;
580
581 /** Enum member name */
582 stree_ident_t *name;
583} stree_embr_t;
584
585/** Enum declaration */
586typedef struct stree_enum {
587 /** Enum name */
588 stree_ident_t *name;
589
590 /** Symbol */
591 struct stree_symbol *symbol;
592
593 /** List of enum members */
594 list_t members; /* of stree_embr_t */
595
596 /** Type item describing the enum */
597 struct tdata_item *titem;
598} stree_enum_t;
599
600/** Member function declaration */
601typedef struct stree_fun {
602 /** Function name */
603 stree_ident_t *name;
604
605 /** Symbol */
606 struct stree_symbol *symbol;
607
608 /** Signature (arguments and return type) */
609 stree_fun_sig_t *sig;
610
611 /** Function implementation */
612 stree_proc_t *proc;
613
614 /** Type item describing the function */
615 struct tdata_item *titem;
616} stree_fun_t;
617
618/** Member variable declaration */
619typedef struct stree_var {
620 stree_ident_t *name;
621 struct stree_symbol *symbol;
622 stree_texpr_t *type;
623} stree_var_t;
624
625/** Member property declaration */
626typedef struct stree_prop {
627 stree_ident_t *name;
628 struct stree_symbol *symbol;
629 stree_texpr_t *type;
630
631 stree_proc_t *getter;
632
633 stree_proc_t *setter;
634 stree_proc_arg_t *setter_arg;
635
636 /** Formal parameters (for indexed properties) */
637 list_t args; /* of stree_proc_arg_t */
638
639 /** Variadic argument or @c NULL if none. */
640 stree_proc_arg_t *varg;
641
642 /** Type of the property */
643 struct tdata_item *titem;
644} stree_prop_t;
645
646/**
647 * Fake identifiers used with symbols that do not really have one.
648 */
649#define CTOR_IDENT "$ctor"
650#define INDEXER_IDENT "$indexer"
651
652typedef enum {
653 csimbr_csi,
654 csimbr_ctor,
655 csimbr_deleg,
656 csimbr_enum,
657 csimbr_fun,
658 csimbr_var,
659 csimbr_prop
660} csimbr_class_t;
661
662/** Class, struct or interface member */
663typedef struct {
664 csimbr_class_t cc;
665
666 union {
667 struct stree_csi *csi;
668 stree_ctor_t *ctor;
669 stree_deleg_t *deleg;
670 stree_enum_t *enum_d;
671 stree_fun_t *fun;
672 stree_var_t *var;
673 stree_prop_t *prop;
674 } u;
675} stree_csimbr_t;
676
677typedef enum {
678 csi_class,
679 csi_struct,
680 csi_interface
681} csi_class_t;
682
683/** CSI formal type argument */
684typedef struct stree_targ {
685 stree_ident_t *name;
686 struct stree_symbol *symbol;
687} stree_targ_t;
688
689/** Class, struct or interface declaration */
690typedef struct stree_csi {
691 /** Which of class, struct or interface */
692 csi_class_t cc;
693
694 /** Name of this CSI */
695 stree_ident_t *name;
696
697 /** List of type arguments */
698 list_t targ; /* of stree_targ_t */
699
700 /** Symbol for this CSI */
701 struct stree_symbol *symbol;
702
703 /** Type expressions referencing inherited CSIs. */
704 list_t inherit; /* of stree_texpr_t */
705
706 /** Base CSI. Only available when ancr_state == ws_visited. */
707 struct stree_csi *base_csi;
708
709 /** Types of implemented or accumulated interfaces. */
710 list_t impl_if_ti; /* of tdata_item_t */
711
712 /** Node state for ancr walks. */
713 walk_state_t ancr_state;
714
715 /** List of CSI members */
716 list_t members; /* of stree_csimbr_t */
717} stree_csi_t;
718
719typedef enum {
720 /* Class, struct or interface declaration */
721 mc_csi,
722 /* Enum declaration */
723 mc_enum
724} modm_class_t;
725
726/** Module member */
727typedef struct {
728 modm_class_t mc;
729 union {
730 stree_csi_t *csi;
731 stree_enum_t *enum_d;
732 } u;
733} stree_modm_t;
734
735/** Module */
736typedef struct stree_module {
737 /** List of module members */
738 list_t members; /* of stree_modm_t */
739} stree_module_t;
740
741/** Symbol attribute class */
742typedef enum {
743 /** Builtin symbol (interpreter hook) */
744 sac_builtin,
745
746 /** Static symbol */
747 sac_static
748} symbol_attr_class_t;
749
750/** Symbol atribute */
751typedef struct {
752 symbol_attr_class_t sac;
753} stree_symbol_attr_t;
754
755typedef enum {
756 /** CSI (class, struct or interface) */
757 sc_csi,
758 /** Constructor */
759 sc_ctor,
760 /** Member delegate */
761 sc_deleg,
762 /** Enum */
763 sc_enum,
764 /** Member function */
765 sc_fun,
766 /** Member variable */
767 sc_var,
768 /** Member property */
769 sc_prop
770} symbol_class_t;
771
772/** Symbol
773 *
774 * A symbol is a common superclass of different program elements that
775 * allow us to refer to them, print their fully qualified names, etc.
776 */
777typedef struct stree_symbol {
778 symbol_class_t sc;
779
780 union {
781 struct stree_csi *csi;
782 stree_ctor_t *ctor;
783 stree_deleg_t *deleg;
784 stree_enum_t *enum_d;
785 stree_fun_t *fun;
786 stree_var_t *var;
787 stree_prop_t *prop;
788 } u;
789
790 /** Containing CSI (for all symbols) */
791 stree_csi_t *outer_csi;
792
793 /** Containing block (for block-level symbols) */
794 stree_block_t *outer_block;
795
796 /** Symbol attributes. */
797 list_t attr; /* of stree_symbol_attr_t */
798} stree_symbol_t;
799
800/** Program */
801typedef struct stree_program {
802 /** The one and only module in the program */
803 stree_module_t *module;
804
805 /** Builtin symbols binding. */
806 struct builtin *builtin;
807} stree_program_t;
808
809#endif
Note: See TracBrowser for help on using the repository browser.