source: mainline/uspace/app/sbi/src/stree_t.h@ 074444f

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

Update SBI to rev. 184.

  • Property mode set to 100644
File size: 11.7 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/** Arithmetic expression class */
189typedef enum {
190 ec_nameref,
191 ec_literal,
192 ec_self_ref,
193 ec_binop,
194 ec_unop,
195 ec_new,
196 ec_access,
197 ec_call,
198 ec_assign,
199 ec_index,
200 ec_as
201} expr_class_t;
202
203/** Arithmetic expression */
204typedef struct stree_expr {
205 expr_class_t ec;
206
207 struct tdata_item *titem;
208
209 union {
210 stree_nameref_t *nameref;
211 stree_literal_t *literal;
212 stree_self_ref_t *self_ref;
213 stree_binop_t *binop;
214 stree_unop_t *unop;
215 stree_new_t *new_op;
216 stree_access_t *access;
217 stree_call_t *call;
218 stree_index_t *index;
219 stree_assign_t *assign;
220 stree_as_t *as_op;
221 } u;
222} stree_expr_t;
223
224/*
225 * Type expressions
226 */
227
228struct stree_texpr;
229
230/** Type literal class */
231typedef enum {
232 tlc_bool,
233 tlc_char,
234 tlc_int,
235 tlc_resource,
236 tlc_string
237} tliteral_class_t;
238
239/** Type literal */
240typedef struct {
241 tliteral_class_t tlc;
242} stree_tliteral_t;
243
244/** Type name reference */
245typedef struct {
246 stree_ident_t *name;
247} stree_tnameref_t;
248
249/** Type member access operation */
250typedef struct {
251 /** Argument */
252 struct stree_texpr *arg;
253 /** Name of member being accessed. */
254 stree_ident_t *member_name;
255} stree_taccess_t;
256
257/** Type application operation */
258typedef struct {
259 /* Base type */
260 struct stree_texpr *gtype;
261
262 /** (Formal) type arguments */
263 list_t targs; /* of stree_texpr_t */
264} stree_tapply_t;
265
266/** Type index operation */
267typedef struct {
268 /** Base type */
269 struct stree_texpr *base_type;
270
271 /**
272 * Number of arguments (rank). Needed when only rank is specified
273 * and @c args are not used.
274 */
275 int n_args;
276
277 /** Arguments (extents) */
278 list_t args; /* of stree_expr_t */
279} stree_tindex_t;
280
281/** Type expression class */
282typedef enum {
283 tc_tliteral,
284 tc_tnameref,
285 tc_taccess,
286 tc_tapply,
287 tc_tindex
288} texpr_class_t;
289
290/** Arithmetic expression */
291typedef struct stree_texpr {
292 texpr_class_t tc;
293
294 union {
295 stree_tliteral_t *tliteral;
296 stree_tnameref_t *tnameref;
297 stree_taccess_t *taccess;
298 stree_tapply_t *tapply;
299 stree_tindex_t *tindex;
300 } u;
301} stree_texpr_t;
302
303/*
304 * Statements, class members and module members.
305 */
306
307/** Statement block */
308typedef struct stree_block {
309 /** List of statements in the block */
310 list_t stats; /* of stree_stat_t */
311} stree_block_t;
312
313/** Variable declaration */
314typedef struct {
315 stree_ident_t *name;
316 stree_texpr_t *type;
317} stree_vdecl_t;
318
319/** @c except clause */
320typedef struct {
321 stree_ident_t *evar;
322 stree_texpr_t *etype;
323 stree_block_t *block;
324} stree_except_t;
325
326/** If statement */
327typedef struct {
328 stree_expr_t *cond;
329 stree_block_t *if_block;
330 stree_block_t *else_block;
331} stree_if_t;
332
333/** While statement */
334typedef struct {
335 stree_expr_t *cond;
336 stree_block_t *body;
337} stree_while_t;
338
339/** For statement */
340typedef struct {
341 stree_block_t *body;
342} stree_for_t;
343
344/** Raise statement */
345typedef struct {
346 stree_expr_t *expr;
347} stree_raise_t;
348
349/** Return statement */
350typedef struct {
351 stree_expr_t *expr;
352} stree_return_t;
353
354/** Expression statement */
355typedef struct {
356 stree_expr_t *expr;
357} stree_exps_t;
358
359/** With-try-except-finally statement (WEF) */
360typedef struct {
361 stree_block_t *with_block;
362 list_t except_clauses; /* of stree_except_t */
363 stree_block_t *finally_block;
364} stree_wef_t;
365
366/** Statement class */
367typedef enum {
368 st_vdecl,
369 st_if,
370 st_while,
371 st_for,
372 st_raise,
373 st_return,
374 st_exps,
375 st_wef
376} stat_class_t;
377
378/** Statement */
379typedef struct {
380 stat_class_t sc;
381
382 union {
383 stree_vdecl_t *vdecl_s;
384 stree_if_t *if_s;
385 stree_while_t *while_s;
386 stree_for_t *for_s;
387 stree_raise_t *raise_s;
388 stree_return_t *return_s;
389 stree_exps_t *exp_s;
390 stree_wef_t *wef_s;
391 } u;
392} stree_stat_t;
393
394/** Argument attribute class */
395typedef enum {
396 /** Packed argument (for variadic functions) */
397 aac_packed
398} arg_attr_class_t;
399
400/** Argument atribute */
401typedef struct {
402 arg_attr_class_t aac;
403} stree_arg_attr_t;
404
405/** Formal function parameter */
406typedef struct {
407 /* Argument name */
408 stree_ident_t *name;
409
410 /* Argument type */
411 stree_texpr_t *type;
412
413 /* Attributes */
414 list_t attr; /* of stree_arg_attr_t */
415} stree_proc_arg_t;
416
417/** Procedure
418 *
419 * Procedure is the common term for a getter, setter or function body.
420 * A procedure can be invoked. However, the arguments are specified by
421 * the containing symbol.
422 */
423typedef struct stree_proc {
424 /** Symbol (function or property) containing the procedure */
425 struct stree_symbol *outer_symbol;
426
427 /** Main block for regular procedures */
428 stree_block_t *body;
429
430 /** Builtin handler for builtin procedures */
431 builtin_proc_t bi_handler;
432} stree_proc_t;
433
434/** Member function declaration */
435typedef struct stree_fun {
436 /** Function name */
437 stree_ident_t *name;
438
439 /** Symbol */
440 struct stree_symbol *symbol;
441
442 /** Formal parameters */
443 list_t args; /* of stree_proc_arg_t */
444
445 /** Variadic argument or @c NULL if none. */
446 stree_proc_arg_t *varg;
447
448 /** Return type */
449 stree_texpr_t *rtype;
450
451 /** Function implementation */
452 stree_proc_t *proc;
453} stree_fun_t;
454
455/** Member variable declaration */
456typedef struct stree_var {
457 stree_ident_t *name;
458 struct stree_symbol *symbol;
459 stree_texpr_t *type;
460} stree_var_t;
461
462/** Member property declaration */
463typedef struct stree_prop {
464 stree_ident_t *name;
465 struct stree_symbol *symbol;
466 stree_texpr_t *type;
467
468 stree_proc_t *getter;
469
470 stree_proc_t *setter;
471 stree_proc_arg_t *setter_arg;
472
473 /** Formal parameters (for indexed properties) */
474 list_t args; /* of stree_proc_arg_t */
475
476 /** Variadic argument or @c NULL if none. */
477 stree_proc_arg_t *varg;
478} stree_prop_t;
479
480/**
481 * Fake identifiers used with symbols that do not really have one.
482 * (Mostly for error messages.)
483 */
484#define INDEXER_IDENT "$indexer"
485
486typedef enum {
487 csimbr_csi,
488 csimbr_fun,
489 csimbr_var,
490 csimbr_prop
491} csimbr_class_t;
492
493/** Class, struct or interface member */
494typedef struct {
495 csimbr_class_t cc;
496
497 union {
498 struct stree_csi *csi;
499 stree_fun_t *fun;
500 stree_var_t *var;
501 stree_prop_t *prop;
502 } u;
503} stree_csimbr_t;
504
505typedef enum {
506 csi_class,
507 csi_struct,
508 csi_interface
509} csi_class_t;
510
511/** Class, struct or interface declaration */
512typedef struct stree_csi {
513 /** Which of class, struct or interface */
514 csi_class_t cc;
515
516 /** Name of this CSI */
517 stree_ident_t *name;
518
519 /** List of type argument names */
520 list_t targ_names; /* of stree_ident_t */
521
522 /** Symbol for this CSI */
523 struct stree_symbol *symbol;
524
525 /** Type expression referencing base CSI. */
526 stree_texpr_t *base_csi_ref;
527
528 /** Base CSI. Only available when ancr_state == ws_visited. */
529 struct stree_csi *base_csi;
530
531 /** Node state for ancr walks. */
532 walk_state_t ancr_state;
533
534 /** List of CSI members */
535 list_t members; /* of stree_csimbr_t */
536} stree_csi_t;
537
538typedef enum {
539 /* Class, struct or interface declaration */
540 mc_csi
541} modm_class_t;
542
543/** Module member */
544typedef struct {
545 modm_class_t mc;
546 union {
547 stree_csi_t *csi;
548 } u;
549} stree_modm_t;
550
551/** Module */
552typedef struct stree_module {
553 /** List of module members */
554 list_t members; /* of stree_modm_t */
555} stree_module_t;
556
557/** Symbol attribute class */
558typedef enum {
559 /** Builtin symbol (interpreter hook) */
560 sac_builtin
561} symbol_attr_class_t;
562
563/** Symbol atribute */
564typedef struct {
565 symbol_attr_class_t sac;
566} stree_symbol_attr_t;
567
568
569typedef enum {
570 sc_csi,
571 sc_fun,
572 sc_var,
573 sc_prop
574} symbol_class_t;
575
576/** Symbol
577 *
578 * A symbol is a common superclass of different program elements that
579 * allow us to refer to them, print their fully qualified names, etc.
580 */
581typedef struct stree_symbol {
582 symbol_class_t sc;
583
584 union {
585 struct stree_csi *csi;
586 stree_fun_t *fun;
587 stree_var_t *var;
588 stree_prop_t *prop;
589 } u;
590
591 /** Containing CSI (for all symbols) */
592 stree_csi_t *outer_csi;
593
594 /** Containing block (for block-level symbols) */
595 stree_block_t *outer_block;
596
597 /** Symbol attributes. */
598 list_t attr; /* of stree_symbol_attr_t */
599} stree_symbol_t;
600
601/** Program */
602typedef struct stree_program {
603 /** The one and only module in the program */
604 stree_module_t *module;
605
606 /** Builtin symbols binding. */
607 struct builtin *builtin;
608} stree_program_t;
609
610#endif
Note: See TracBrowser for help on using the repository browser.