source: mainline/uspace/app/sbi/src/stree_t.h@ 3aae4e8

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

Update SBI to rev. 144.

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