stree_t.h

00001 /*
00002  * Copyright (c) 2011 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #ifndef STREE_T_H_
00030 #define STREE_T_H_
00031 
00032 #include "bigint_t.h"
00033 #include "list_t.h"
00034 #include "builtin_t.h"
00035 
00036 /*
00037  * Arithmetic expressions
00038  */
00039 
00040 struct stree_expr;
00041 
00043 typedef struct {
00044         int sid;
00045         struct cspan *cspan;
00046 } stree_ident_t;
00047 
00049 typedef struct {
00051         struct stree_expr *expr;
00052 
00053         stree_ident_t *name;
00054 } stree_nameref_t;
00055 
00057 typedef struct {
00058         bool_t value;
00059 } stree_lit_bool_t;
00060 
00062 typedef struct {
00063         bigint_t value;
00064 } stree_lit_char_t;
00065 
00067 typedef struct {
00068         bigint_t value;
00069 } stree_lit_int_t;
00070 
00072 typedef struct {
00073 } stree_lit_ref_t;
00074 
00076 typedef struct {
00077         char *value;
00078 } stree_lit_string_t;
00079 
00080 typedef enum {
00081         ltc_bool,
00082         ltc_char,
00083         ltc_int,
00084         ltc_ref,
00085         ltc_string
00086 } literal_class_t;
00087 
00089 typedef struct {
00091         struct stree_expr *expr;
00092 
00093         literal_class_t ltc;
00094         union {
00095                 stree_lit_bool_t lit_bool;
00096                 stree_lit_char_t lit_char;
00097                 stree_lit_int_t lit_int;
00098                 stree_lit_ref_t lit_ref;
00099                 stree_lit_string_t lit_string;
00100         } u;
00101 } stree_literal_t;
00102 
00104 typedef struct {
00106         struct stree_expr *expr;
00107 } stree_self_ref_t;
00108 
00110 typedef enum {
00111         bo_equal,
00112         bo_notequal,
00113         bo_lt,
00114         bo_gt,
00115         bo_lt_equal,
00116         bo_gt_equal,
00117         bo_plus,
00118         bo_minus,
00119         bo_mult,
00120         bo_and,
00121         bo_or
00122 } binop_class_t;
00123 
00125 typedef enum {
00126         uo_plus,
00127         uo_minus,
00128         uo_not
00129 } unop_class_t;
00130 
00132 typedef struct {
00134         struct stree_expr *expr;
00135 
00137         binop_class_t bc;
00138 
00140         struct stree_expr *arg1, *arg2;
00141 } stree_binop_t;
00142 
00144 typedef struct {
00146         struct stree_expr *expr;
00147 
00149         unop_class_t uc;
00150 
00152         struct stree_expr *arg;
00153 } stree_unop_t;
00154 
00156 typedef struct {
00158         struct stree_expr *expr;
00159 
00161         struct stree_texpr *texpr;
00162 
00164         list_t ctor_args; /* of stree_expr_t */
00165 } stree_new_t;
00166 
00168 typedef struct {
00170         struct stree_expr *expr;
00171 
00173         struct stree_expr *arg;
00175         stree_ident_t *member_name;
00176 } stree_access_t;
00177 
00179 typedef struct {
00181         struct stree_expr *expr;
00182 
00184         struct stree_expr *fun;
00185 
00187         list_t args; /* of stree_expr_t */
00188 } stree_call_t;
00189 
00190 typedef enum {
00191         ac_set,
00192         ac_increase
00193 } assign_class_t;
00194 
00196 typedef struct {
00198         struct stree_expr *expr;
00199 
00200         assign_class_t ac;
00201         struct stree_expr *dest, *src;
00202 } stree_assign_t;
00203 
00205 typedef struct {
00207         struct stree_expr *expr;
00208 
00210         struct stree_expr *base;
00211 
00213         list_t args; /* of stree_expr_t */
00214 } stree_index_t;
00215 
00217 typedef struct {
00219         struct stree_expr *expr;
00220 
00222         struct stree_expr *arg;
00223 
00225         struct stree_texpr *dtype;
00226 } stree_as_t;
00227 
00234 typedef struct {
00236         struct stree_expr *expr;
00237 
00238         /* Primitive type expression */
00239         struct stree_expr *arg;
00240 } stree_box_t;
00241 
00243 typedef enum {
00244         ec_nameref,
00245         ec_literal,
00246         ec_self_ref,
00247         ec_binop,
00248         ec_unop,
00249         ec_new,
00250         ec_access,
00251         ec_call,
00252         ec_assign,
00253         ec_index,
00254         ec_as,
00255         ec_box
00256 } expr_class_t;
00257 
00259 typedef struct stree_expr {
00260         expr_class_t ec;
00261 
00263         struct tdata_item *titem;
00264 
00266         struct cspan *cspan;
00267 
00268         union {
00269                 stree_nameref_t *nameref;
00270                 stree_literal_t *literal;
00271                 stree_self_ref_t *self_ref;
00272                 stree_binop_t *binop;
00273                 stree_unop_t *unop;
00274                 stree_new_t *new_op;
00275                 stree_access_t *access;
00276                 stree_call_t *call;
00277                 stree_index_t *index;
00278                 stree_assign_t *assign;
00279                 stree_as_t *as_op;
00280                 stree_box_t *box;
00281         } u;
00282 } stree_expr_t;
00283 
00284 /*
00285  * Type expressions
00286  */
00287 
00288 struct stree_texpr;
00289 
00291 typedef enum {
00292         tlc_bool,
00293         tlc_char,
00294         tlc_int,
00295         tlc_resource,
00296         tlc_string
00297 } tliteral_class_t;
00298 
00300 typedef struct {
00302         struct stree_texpr *texpr;
00303 
00304         tliteral_class_t tlc;
00305 } stree_tliteral_t;
00306 
00308 typedef struct {
00310         struct stree_texpr *texpr;
00311 
00312         stree_ident_t *name;
00313 } stree_tnameref_t;
00314 
00316 typedef struct {
00318         struct stree_texpr *texpr;
00319 
00321         struct stree_texpr *arg;
00322 
00324         stree_ident_t *member_name;
00325 } stree_taccess_t;
00326 
00328 typedef struct {
00330         struct stree_texpr *texpr;
00331 
00332         /* Base type */
00333         struct stree_texpr *gtype;
00334 
00336         list_t targs; /* of stree_texpr_t */
00337 } stree_tapply_t;
00338 
00340 typedef struct {
00342         struct stree_texpr *texpr;
00343 
00345         struct stree_texpr *base_type;
00346 
00351         int n_args;
00352 
00354         list_t args; /* of stree_expr_t */
00355 } stree_tindex_t;
00356 
00358 typedef enum {
00359         tc_tliteral,
00360         tc_tnameref,
00361         tc_taccess,
00362         tc_tapply,
00363         tc_tindex
00364 } texpr_class_t;
00365 
00367 typedef struct stree_texpr {
00368         texpr_class_t tc;
00369 
00371         struct cspan *cspan;
00372 
00373         union {
00374                 stree_tliteral_t *tliteral;
00375                 stree_tnameref_t *tnameref;
00376                 stree_taccess_t *taccess;
00377                 stree_tapply_t *tapply;
00378                 stree_tindex_t *tindex;
00379         } u;
00380 } stree_texpr_t;
00381 
00382 /*
00383  * Statements, class members and module members.
00384  */
00385 
00387 typedef struct stree_block {
00389         list_t stats; /* of stree_stat_t */
00390 } stree_block_t;
00391 
00393 typedef struct {
00394         stree_ident_t *name;
00395         stree_texpr_t *type;
00396 
00398         struct tdata_item *titem;
00399 } stree_vdecl_t;
00400 
00402 typedef struct {
00403         stree_ident_t *evar;
00404         stree_texpr_t *etype;
00405         stree_block_t *block;
00406 
00408         struct tdata_item *titem;
00409 } stree_except_t;
00410 
00412 typedef struct {
00413         stree_expr_t *cond;
00414         stree_block_t *block;
00415 } stree_if_clause_t;
00416 
00418 typedef struct {
00420         list_t if_clauses; /* of stree_if_clause_t */
00421 
00423         stree_block_t *else_block;
00424 } stree_if_t;
00425 
00427 typedef struct {
00429         list_t exprs; /* of stree_expr_t */
00430         stree_block_t *block;
00431 } stree_when_t;
00432 
00434 typedef struct {
00436         stree_expr_t *expr;
00437 
00439         list_t when_clauses; /* of stree_when_t */
00440 
00442         stree_block_t *else_block;
00443 } stree_switch_t;
00444 
00446 typedef struct {
00447         stree_expr_t *cond;
00448         stree_block_t *body;
00449 } stree_while_t;
00450 
00452 typedef struct {
00453         stree_block_t *body;
00454 } stree_for_t;
00455 
00457 typedef struct {
00458         stree_expr_t *expr;
00459 } stree_raise_t;
00460 
00462 typedef struct {
00463 } stree_break_t;
00464 
00466 typedef struct {
00467         stree_expr_t *expr;
00468 } stree_return_t;
00469 
00471 typedef struct {
00472         stree_expr_t *expr;
00473 } stree_exps_t;
00474 
00476 typedef struct {
00477         stree_block_t *with_block;
00478         list_t except_clauses; /* of stree_except_t */
00479         stree_block_t *finally_block;
00480 } stree_wef_t;
00481 
00483 typedef enum {
00484         st_vdecl,
00485         st_if,
00486         st_switch,
00487         st_while,
00488         st_for,
00489         st_raise,
00490         st_break,
00491         st_return,
00492         st_exps,
00493         st_wef
00494 } stat_class_t;
00495 
00497 typedef struct {
00498         stat_class_t sc;
00499 
00500         union {
00501                 stree_vdecl_t *vdecl_s;
00502                 stree_if_t *if_s;
00503                 stree_switch_t *switch_s;
00504                 stree_while_t *while_s;
00505                 stree_for_t *for_s;
00506                 stree_raise_t *raise_s;
00507                 stree_break_t *break_s;
00508                 stree_return_t *return_s;
00509                 stree_exps_t *exp_s;
00510                 stree_wef_t *wef_s;
00511         } u;
00512 } stree_stat_t;
00513 
00515 typedef enum {
00517         aac_packed
00518 } arg_attr_class_t;
00519 
00521 typedef struct {
00522         arg_attr_class_t aac;
00523 } stree_arg_attr_t;
00524 
00526 typedef struct {
00527         /* Argument name */
00528         stree_ident_t *name;
00529 
00530         /* Argument type */
00531         stree_texpr_t *type;
00532 
00533         /* Attributes */
00534         list_t attr; /* of stree_arg_attr_t */
00535 } stree_proc_arg_t;
00536 
00542 typedef struct {
00544         list_t args; /* of stree_proc_arg_t */
00545 
00547         stree_proc_arg_t *varg;
00548 
00550         stree_texpr_t *rtype;
00551 } stree_fun_sig_t;
00552 
00559 typedef struct stree_proc {
00561         struct stree_symbol *outer_symbol;
00562 
00564         stree_block_t *body;
00565 
00567         builtin_proc_t bi_handler;
00568 } stree_proc_t;
00569 
00571 typedef struct stree_ctor {
00573         stree_ident_t *name;
00574 
00576         struct stree_symbol *symbol;
00577 
00579         stree_fun_sig_t *sig;
00580 
00582         stree_proc_t *proc;
00583 
00585         struct tdata_item *titem;
00586 } stree_ctor_t;
00587 
00589 typedef struct stree_deleg {
00591         stree_ident_t *name;
00592 
00594         struct stree_symbol *symbol;
00595 
00597         stree_fun_sig_t *sig;
00598 
00600         struct tdata_item *titem;
00601 } stree_deleg_t;
00602 
00604 typedef struct stree_embr {
00606         struct stree_enum *outer_enum;
00607 
00609         stree_ident_t *name;
00610 } stree_embr_t;
00611 
00613 typedef struct stree_enum {
00615         stree_ident_t *name;
00616 
00618         struct stree_symbol *symbol;
00619 
00621         list_t members; /* of stree_embr_t */
00622 
00624         struct tdata_item *titem;
00625 } stree_enum_t;
00626 
00628 typedef struct stree_fun {
00630         stree_ident_t *name;
00631 
00633         struct stree_symbol *symbol;
00634 
00636         stree_fun_sig_t *sig;
00637 
00639         stree_proc_t *proc;
00640 
00642         struct tdata_item *titem;
00643 } stree_fun_t;
00644 
00646 typedef struct stree_var {
00647         stree_ident_t *name;
00648         struct stree_symbol *symbol;
00649         stree_texpr_t *type;
00650 } stree_var_t;
00651 
00653 typedef struct stree_prop {
00654         stree_ident_t *name;
00655         struct stree_symbol *symbol;
00656         stree_texpr_t *type;
00657 
00658         stree_proc_t *getter;
00659 
00660         stree_proc_t *setter;
00661         stree_proc_arg_t *setter_arg;
00662 
00664         list_t args; /* of stree_proc_arg_t */
00665 
00667         stree_proc_arg_t *varg;
00668 
00670         struct tdata_item *titem;
00671 } stree_prop_t;
00672 
00676 #define CTOR_IDENT "$ctor"
00677 #define INDEXER_IDENT "$indexer"
00678 
00679 typedef enum {
00680         csimbr_csi,
00681         csimbr_ctor,
00682         csimbr_deleg,
00683         csimbr_enum,
00684         csimbr_fun,
00685         csimbr_var,
00686         csimbr_prop
00687 } csimbr_class_t;
00688 
00690 typedef struct {
00691         csimbr_class_t cc;
00692 
00693         union {
00694                 struct stree_csi *csi;
00695                 stree_ctor_t *ctor;
00696                 stree_deleg_t *deleg;
00697                 stree_enum_t *enum_d;
00698                 stree_fun_t *fun;
00699                 stree_var_t *var;
00700                 stree_prop_t *prop;
00701         } u;
00702 } stree_csimbr_t;
00703 
00704 typedef enum {
00705         csi_class,
00706         csi_struct,
00707         csi_interface
00708 } csi_class_t;
00709 
00711 typedef struct stree_targ {
00712         stree_ident_t *name;
00713         struct stree_symbol *symbol;
00714 } stree_targ_t;
00715 
00717 typedef struct stree_csi {
00719         csi_class_t cc;
00720 
00722         stree_ident_t *name;
00723 
00725         list_t targ; /* of stree_targ_t */
00726 
00728         struct stree_symbol *symbol;
00729 
00731         list_t inherit; /* of stree_texpr_t */
00732 
00734         struct stree_csi *base_csi;
00735 
00737         list_t impl_if_ti; /* of tdata_item_t */
00738 
00740         walk_state_t ancr_state;
00741 
00743         list_t members; /* of stree_csimbr_t */
00744 } stree_csi_t;
00745 
00746 typedef enum {
00747         /* Class, struct or interface declaration */
00748         mc_csi,
00749         /* Enum declaration */
00750         mc_enum
00751 } modm_class_t;
00752 
00754 typedef struct {
00755         modm_class_t mc;
00756         union {
00757                 stree_csi_t *csi;
00758                 stree_enum_t *enum_d;
00759         } u;
00760 } stree_modm_t;
00761 
00763 typedef struct stree_module {
00765         list_t members; /* of stree_modm_t */
00766 } stree_module_t;
00767 
00769 typedef enum {
00771         sac_builtin,
00772 
00774         sac_static
00775 } symbol_attr_class_t;
00776 
00778 typedef struct {
00779         symbol_attr_class_t sac;
00780 } stree_symbol_attr_t;
00781 
00782 typedef enum {
00784         sc_csi,
00786         sc_ctor,
00788         sc_deleg,
00790         sc_enum,
00792         sc_fun,
00794         sc_var,
00796         sc_prop
00797 } symbol_class_t;
00798 
00804 typedef struct stree_symbol {
00805         symbol_class_t sc;
00806 
00807         union {
00808                 struct stree_csi *csi;
00809                 stree_ctor_t *ctor;
00810                 stree_deleg_t *deleg;
00811                 stree_enum_t *enum_d;
00812                 stree_fun_t *fun;
00813                 stree_var_t *var;
00814                 stree_prop_t *prop;
00815         } u;
00816 
00818         stree_csi_t *outer_csi;
00819 
00821         list_t attr; /* of stree_symbol_attr_t */
00822 } stree_symbol_t;
00823 
00825 typedef struct stree_program {
00827         stree_module_t *module;
00828 
00830         struct builtin *builtin;
00831 } stree_program_t;
00832 
00833 #endif

Generated on Thu Jun 2 07:45:42 2011 for HelenOS/USB by  doxygen 1.4.7