source: mainline/uspace/app/sbi/src/stree_t.h@ 23de644

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

Update SBI to rev. 174.

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