source: mainline/uspace/app/sbi/src/stree_t.h@ 37c9fc8

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

Update SBI to rev. 207.

  • Property mode set to 100644
File size: 13.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#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} stree_ident_t;
46
47/** Name reference */
48typedef struct {
49 stree_ident_t *name;
50} stree_nameref_t;
51
52/** Reference to currently active object. */
53typedef struct {
54} stree_self_ref_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 literal_class_t ltc;
91 union {
92 stree_lit_bool_t lit_bool;
93 stree_lit_char_t lit_char;
94 stree_lit_int_t lit_int;
95 stree_lit_ref_t lit_ref;
96 stree_lit_string_t lit_string;
97 } u;
98} stree_literal_t;
99
100/** Binary operation class */
101typedef enum {
102 bo_equal,
103 bo_notequal,
104 bo_lt,
105 bo_gt,
106 bo_lt_equal,
107 bo_gt_equal,
108 bo_plus,
109 bo_minus,
110 bo_mult
111} binop_class_t;
112
113/** Unary operation class */
114typedef enum {
115 uo_plus,
116 uo_minus,
117} unop_class_t;
118
119/** Binary operation */
120typedef struct {
121 /** Binary operation class */
122 binop_class_t bc;
123
124 /** Arguments */
125 struct stree_expr *arg1, *arg2;
126} stree_binop_t;
127
128/** Unary operation */
129typedef struct {
130 /** Operation class */
131 unop_class_t uc;
132
133 /** Argument */
134 struct stree_expr *arg;
135} stree_unop_t;
136
137/** New operation */
138typedef struct {
139 /** Type of object to construct. */
140 struct stree_texpr *texpr;
141} stree_new_t;
142
143/** Member access operation */
144typedef struct {
145 /** Argument */
146 struct stree_expr *arg;
147 /** Name of member being accessed. */
148 stree_ident_t *member_name;
149} stree_access_t;
150
151/** Function call operation */
152typedef struct {
153 /** Function */
154 struct stree_expr *fun;
155
156 /** Arguments */
157 list_t args; /* of stree_expr_t */
158} stree_call_t;
159
160typedef enum {
161 ac_set,
162 ac_increase
163} assign_class_t;
164
165/** Assignment */
166typedef struct {
167 assign_class_t ac;
168 struct stree_expr *dest, *src;
169} stree_assign_t;
170
171/** Indexing operation */
172typedef struct {
173 /** Base */
174 struct stree_expr *base;
175
176 /** Arguments (indices) */
177 list_t args; /* of stree_expr_t */
178} stree_index_t;
179
180/** @c as conversion operation */
181typedef struct {
182 /** Expression to convert */
183 struct stree_expr *arg;
184 /** Destination type of conversion. */
185 struct stree_texpr *dtype;
186} stree_as_t;
187
188/** Boxing of primitive type (pseudo)
189 *
190 * This pseudo-node is used internally to box a value of primitive type.
191 * It is implicitly inserted by stype_convert(). It does not correspond
192 * to a an explicit program construct.
193 */
194typedef struct {
195 /* Primitive type expression */
196 struct stree_expr *arg;
197} stree_box_t;
198
199/** Arithmetic expression class */
200typedef enum {
201 ec_nameref,
202 ec_literal,
203 ec_self_ref,
204 ec_binop,
205 ec_unop,
206 ec_new,
207 ec_access,
208 ec_call,
209 ec_assign,
210 ec_index,
211 ec_as,
212 ec_box
213} expr_class_t;
214
215/** Arithmetic expression */
216typedef struct stree_expr {
217 expr_class_t ec;
218
219 struct tdata_item *titem;
220
221 union {
222 stree_nameref_t *nameref;
223 stree_literal_t *literal;
224 stree_self_ref_t *self_ref;
225 stree_binop_t *binop;
226 stree_unop_t *unop;
227 stree_new_t *new_op;
228 stree_access_t *access;
229 stree_call_t *call;
230 stree_index_t *index;
231 stree_assign_t *assign;
232 stree_as_t *as_op;
233 stree_box_t *box;
234 } u;
235} stree_expr_t;
236
237/*
238 * Type expressions
239 */
240
241struct stree_texpr;
242
243/** Type literal class */
244typedef enum {
245 tlc_bool,
246 tlc_char,
247 tlc_int,
248 tlc_resource,
249 tlc_string
250} tliteral_class_t;
251
252/** Type literal */
253typedef struct {
254 tliteral_class_t tlc;
255} stree_tliteral_t;
256
257/** Type name reference */
258typedef struct {
259 stree_ident_t *name;
260} stree_tnameref_t;
261
262/** Type member access operation */
263typedef struct {
264 /** Argument */
265 struct stree_texpr *arg;
266 /** Name of member being accessed. */
267 stree_ident_t *member_name;
268} stree_taccess_t;
269
270/** Type application operation */
271typedef struct {
272 /* Base type */
273 struct stree_texpr *gtype;
274
275 /** (Formal) type arguments */
276 list_t targs; /* of stree_texpr_t */
277} stree_tapply_t;
278
279/** Type index operation */
280typedef struct {
281 /** Base type */
282 struct stree_texpr *base_type;
283
284 /**
285 * Number of arguments (rank). Needed when only rank is specified
286 * and @c args are not used.
287 */
288 int n_args;
289
290 /** Arguments (extents) */
291 list_t args; /* of stree_expr_t */
292} stree_tindex_t;
293
294/** Type expression class */
295typedef enum {
296 tc_tliteral,
297 tc_tnameref,
298 tc_taccess,
299 tc_tapply,
300 tc_tindex
301} texpr_class_t;
302
303/** Arithmetic expression */
304typedef struct stree_texpr {
305 texpr_class_t tc;
306
307 union {
308 stree_tliteral_t *tliteral;
309 stree_tnameref_t *tnameref;
310 stree_taccess_t *taccess;
311 stree_tapply_t *tapply;
312 stree_tindex_t *tindex;
313 } u;
314} stree_texpr_t;
315
316/*
317 * Statements, class members and module members.
318 */
319
320/** Statement block */
321typedef struct stree_block {
322 /** List of statements in the block */
323 list_t stats; /* of stree_stat_t */
324} stree_block_t;
325
326/** Variable declaration */
327typedef struct {
328 stree_ident_t *name;
329 stree_texpr_t *type;
330} stree_vdecl_t;
331
332/** @c except clause */
333typedef struct {
334 stree_ident_t *evar;
335 stree_texpr_t *etype;
336 stree_block_t *block;
337} stree_except_t;
338
339/** If statement */
340typedef struct {
341 stree_expr_t *cond;
342 stree_block_t *if_block;
343 stree_block_t *else_block;
344} stree_if_t;
345
346/** While statement */
347typedef struct {
348 stree_expr_t *cond;
349 stree_block_t *body;
350} stree_while_t;
351
352/** For statement */
353typedef struct {
354 stree_block_t *body;
355} stree_for_t;
356
357/** Raise statement */
358typedef struct {
359 stree_expr_t *expr;
360} stree_raise_t;
361
362/** Return statement */
363typedef struct {
364 stree_expr_t *expr;
365} stree_return_t;
366
367/** Expression statement */
368typedef struct {
369 stree_expr_t *expr;
370} stree_exps_t;
371
372/** With-try-except-finally statement (WEF) */
373typedef struct {
374 stree_block_t *with_block;
375 list_t except_clauses; /* of stree_except_t */
376 stree_block_t *finally_block;
377} stree_wef_t;
378
379/** Statement class */
380typedef enum {
381 st_vdecl,
382 st_if,
383 st_while,
384 st_for,
385 st_raise,
386 st_return,
387 st_exps,
388 st_wef
389} stat_class_t;
390
391/** Statement */
392typedef struct {
393 stat_class_t sc;
394
395 union {
396 stree_vdecl_t *vdecl_s;
397 stree_if_t *if_s;
398 stree_while_t *while_s;
399 stree_for_t *for_s;
400 stree_raise_t *raise_s;
401 stree_return_t *return_s;
402 stree_exps_t *exp_s;
403 stree_wef_t *wef_s;
404 } u;
405} stree_stat_t;
406
407/** Argument attribute class */
408typedef enum {
409 /** Packed argument (for variadic functions) */
410 aac_packed
411} arg_attr_class_t;
412
413/** Argument atribute */
414typedef struct {
415 arg_attr_class_t aac;
416} stree_arg_attr_t;
417
418/** Formal function parameter */
419typedef struct {
420 /* Argument name */
421 stree_ident_t *name;
422
423 /* Argument type */
424 stree_texpr_t *type;
425
426 /* Attributes */
427 list_t attr; /* of stree_arg_attr_t */
428} stree_proc_arg_t;
429
430/** Function signature.
431 *
432 * Foormal parameters and return type. This is common to function and delegate
433 * delcarations.
434 */
435typedef struct {
436 /** Formal parameters */
437 list_t args; /* of stree_proc_arg_t */
438
439 /** Variadic argument or @c NULL if none. */
440 stree_proc_arg_t *varg;
441
442 /** Return type */
443 stree_texpr_t *rtype;
444} stree_fun_sig_t;
445
446/** Procedure
447 *
448 * Procedure is the common term for a getter, setter or function body.
449 * A procedure can be invoked. However, the arguments are specified by
450 * the containing symbol.
451 */
452typedef struct stree_proc {
453 /** Symbol (function or property) containing the procedure */
454 struct stree_symbol *outer_symbol;
455
456 /** Main block for regular procedures */
457 stree_block_t *body;
458
459 /** Builtin handler for builtin procedures */
460 builtin_proc_t bi_handler;
461} stree_proc_t;
462
463/** Delegate declaration */
464typedef struct stree_deleg {
465 /** Delegate name */
466 stree_ident_t *name;
467
468 /** Symbol */
469 struct stree_symbol *symbol;
470
471 /** Signature (arguments and return type) */
472 stree_fun_sig_t *sig;
473
474 /** Type item describing the delegate */
475 struct tdata_item *titem;
476} stree_deleg_t;
477
478/** Member function declaration */
479typedef struct stree_fun {
480 /** Function name */
481 stree_ident_t *name;
482
483 /** Symbol */
484 struct stree_symbol *symbol;
485
486 /** Signature (arguments and return type) */
487 stree_fun_sig_t *sig;
488
489 /** Function implementation */
490 stree_proc_t *proc;
491
492 /** Type item describing the function */
493 struct tdata_item *titem;
494} stree_fun_t;
495
496/** Member variable declaration */
497typedef struct stree_var {
498 stree_ident_t *name;
499 struct stree_symbol *symbol;
500 stree_texpr_t *type;
501} stree_var_t;
502
503/** Member property declaration */
504typedef struct stree_prop {
505 stree_ident_t *name;
506 struct stree_symbol *symbol;
507 stree_texpr_t *type;
508
509 stree_proc_t *getter;
510
511 stree_proc_t *setter;
512 stree_proc_arg_t *setter_arg;
513
514 /** Formal parameters (for indexed properties) */
515 list_t args; /* of stree_proc_arg_t */
516
517 /** Variadic argument or @c NULL if none. */
518 stree_proc_arg_t *varg;
519} stree_prop_t;
520
521/**
522 * Fake identifiers used with symbols that do not really have one.
523 * (Mostly for error messages.)
524 */
525#define INDEXER_IDENT "$indexer"
526
527typedef enum {
528 csimbr_csi,
529 csimbr_deleg,
530 csimbr_fun,
531 csimbr_var,
532 csimbr_prop
533} csimbr_class_t;
534
535/** Class, struct or interface member */
536typedef struct {
537 csimbr_class_t cc;
538
539 union {
540 struct stree_csi *csi;
541 stree_deleg_t *deleg;
542 stree_fun_t *fun;
543 stree_var_t *var;
544 stree_prop_t *prop;
545 } u;
546} stree_csimbr_t;
547
548typedef enum {
549 csi_class,
550 csi_struct,
551 csi_interface
552} csi_class_t;
553
554/** CSI formal type argument */
555typedef struct stree_targ {
556 stree_ident_t *name;
557 struct stree_symbol *symbol;
558} stree_targ_t;
559
560/** Class, struct or interface declaration */
561typedef struct stree_csi {
562 /** Which of class, struct or interface */
563 csi_class_t cc;
564
565 /** Name of this CSI */
566 stree_ident_t *name;
567
568 /** List of type arguments */
569 list_t targ; /* of stree_targ_t */
570
571 /** Symbol for this CSI */
572 struct stree_symbol *symbol;
573
574 /** Type expression referencing base CSI. */
575 stree_texpr_t *base_csi_ref;
576
577 /** Base CSI. Only available when ancr_state == ws_visited. */
578 struct stree_csi *base_csi;
579
580 /** Node state for ancr walks. */
581 walk_state_t ancr_state;
582
583 /** List of CSI members */
584 list_t members; /* of stree_csimbr_t */
585} stree_csi_t;
586
587typedef enum {
588 /* Class, struct or interface declaration */
589 mc_csi
590} modm_class_t;
591
592/** Module member */
593typedef struct {
594 modm_class_t mc;
595 union {
596 stree_csi_t *csi;
597 } u;
598} stree_modm_t;
599
600/** Module */
601typedef struct stree_module {
602 /** List of module members */
603 list_t members; /* of stree_modm_t */
604} stree_module_t;
605
606/** Symbol attribute class */
607typedef enum {
608 /** Builtin symbol (interpreter hook) */
609 sac_builtin
610} symbol_attr_class_t;
611
612/** Symbol atribute */
613typedef struct {
614 symbol_attr_class_t sac;
615} stree_symbol_attr_t;
616
617typedef enum {
618 /** CSI (class, struct or interface) */
619 sc_csi,
620 /** Member delegate */
621 sc_deleg,
622 /** Member function */
623 sc_fun,
624 /** Member variable */
625 sc_var,
626 /** Member property */
627 sc_prop
628} symbol_class_t;
629
630/** Symbol
631 *
632 * A symbol is a common superclass of different program elements that
633 * allow us to refer to them, print their fully qualified names, etc.
634 */
635typedef struct stree_symbol {
636 symbol_class_t sc;
637
638 union {
639 struct stree_csi *csi;
640 stree_deleg_t *deleg;
641 stree_fun_t *fun;
642 stree_var_t *var;
643 stree_prop_t *prop;
644 } u;
645
646 /** Containing CSI (for all symbols) */
647 stree_csi_t *outer_csi;
648
649 /** Containing block (for block-level symbols) */
650 stree_block_t *outer_block;
651
652 /** Symbol attributes. */
653 list_t attr; /* of stree_symbol_attr_t */
654} stree_symbol_t;
655
656/** Program */
657typedef struct stree_program {
658 /** The one and only module in the program */
659 stree_module_t *module;
660
661 /** Builtin symbols binding. */
662 struct builtin *builtin;
663} stree_program_t;
664
665#endif
Note: See TracBrowser for help on using the repository browser.