[09ababb7] | 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 |
|
---|
[23de644] | 32 | #include "bigint_t.h"
|
---|
[09ababb7] | 33 | #include "list_t.h"
|
---|
[37f527b] | 34 | #include "builtin_t.h"
|
---|
[09ababb7] | 35 |
|
---|
| 36 | /*
|
---|
| 37 | * Arithmetic expressions
|
---|
| 38 | */
|
---|
| 39 |
|
---|
| 40 | struct stree_expr;
|
---|
| 41 |
|
---|
| 42 | /** Identifier */
|
---|
| 43 | typedef struct {
|
---|
| 44 | int sid;
|
---|
[051bc69a] | 45 | struct cspan *cspan;
|
---|
[09ababb7] | 46 | } stree_ident_t;
|
---|
| 47 |
|
---|
| 48 | /** Name reference */
|
---|
| 49 | typedef struct {
|
---|
[051bc69a] | 50 | /** Expression backlink */
|
---|
| 51 | struct stree_expr *expr;
|
---|
| 52 |
|
---|
[09ababb7] | 53 | stree_ident_t *name;
|
---|
| 54 | } stree_nameref_t;
|
---|
| 55 |
|
---|
[074444f] | 56 | /** Boolean literal */
|
---|
| 57 | typedef struct {
|
---|
| 58 | bool_t value;
|
---|
| 59 | } stree_lit_bool_t;
|
---|
| 60 |
|
---|
| 61 | /** Character literal */
|
---|
| 62 | typedef struct {
|
---|
| 63 | bigint_t value;
|
---|
| 64 | } stree_lit_char_t;
|
---|
| 65 |
|
---|
| 66 | /** Integer literal */
|
---|
[09ababb7] | 67 | typedef struct {
|
---|
[23de644] | 68 | bigint_t value;
|
---|
[09ababb7] | 69 | } stree_lit_int_t;
|
---|
| 70 |
|
---|
[fa36f29] | 71 | /** Reference literal (there is only one: @c nil). */
|
---|
| 72 | typedef struct {
|
---|
| 73 | } stree_lit_ref_t;
|
---|
| 74 |
|
---|
[074444f] | 75 | /** String literal */
|
---|
[09ababb7] | 76 | typedef struct {
|
---|
| 77 | char *value;
|
---|
| 78 | } stree_lit_string_t;
|
---|
| 79 |
|
---|
| 80 | typedef enum {
|
---|
[074444f] | 81 | ltc_bool,
|
---|
| 82 | ltc_char,
|
---|
[09ababb7] | 83 | ltc_int,
|
---|
[fa36f29] | 84 | ltc_ref,
|
---|
[09ababb7] | 85 | ltc_string
|
---|
| 86 | } literal_class_t;
|
---|
| 87 |
|
---|
| 88 | /** Literal */
|
---|
| 89 | typedef struct {
|
---|
[051bc69a] | 90 | /** Expression backlink */
|
---|
| 91 | struct stree_expr *expr;
|
---|
| 92 |
|
---|
[09ababb7] | 93 | literal_class_t ltc;
|
---|
| 94 | union {
|
---|
[074444f] | 95 | stree_lit_bool_t lit_bool;
|
---|
| 96 | stree_lit_char_t lit_char;
|
---|
[09ababb7] | 97 | stree_lit_int_t lit_int;
|
---|
[fa36f29] | 98 | stree_lit_ref_t lit_ref;
|
---|
[09ababb7] | 99 | stree_lit_string_t lit_string;
|
---|
| 100 | } u;
|
---|
| 101 | } stree_literal_t;
|
---|
| 102 |
|
---|
[051bc69a] | 103 | /** Reference to currently active object. */
|
---|
| 104 | typedef struct {
|
---|
| 105 | /** Expression backlink */
|
---|
| 106 | struct stree_expr *expr;
|
---|
| 107 | } stree_self_ref_t;
|
---|
| 108 |
|
---|
[09ababb7] | 109 | /** Binary operation class */
|
---|
| 110 | typedef enum {
|
---|
| 111 | bo_equal,
|
---|
| 112 | bo_notequal,
|
---|
| 113 | bo_lt,
|
---|
| 114 | bo_gt,
|
---|
| 115 | bo_lt_equal,
|
---|
| 116 | bo_gt_equal,
|
---|
[23de644] | 117 | bo_plus,
|
---|
| 118 | bo_minus,
|
---|
[051bc69a] | 119 | bo_mult,
|
---|
| 120 | bo_and,
|
---|
| 121 | bo_or
|
---|
[09ababb7] | 122 | } binop_class_t;
|
---|
| 123 |
|
---|
| 124 | /** Unary operation class */
|
---|
| 125 | typedef enum {
|
---|
[23de644] | 126 | uo_plus,
|
---|
| 127 | uo_minus,
|
---|
[051bc69a] | 128 | uo_not
|
---|
[09ababb7] | 129 | } unop_class_t;
|
---|
| 130 |
|
---|
| 131 | /** Binary operation */
|
---|
| 132 | typedef struct {
|
---|
[051bc69a] | 133 | /** Expression backlink */
|
---|
| 134 | struct stree_expr *expr;
|
---|
| 135 |
|
---|
[09ababb7] | 136 | /** Binary operation class */
|
---|
| 137 | binop_class_t bc;
|
---|
| 138 |
|
---|
| 139 | /** Arguments */
|
---|
| 140 | struct stree_expr *arg1, *arg2;
|
---|
| 141 | } stree_binop_t;
|
---|
| 142 |
|
---|
| 143 | /** Unary operation */
|
---|
| 144 | typedef struct {
|
---|
[051bc69a] | 145 | /** Expression backlink */
|
---|
| 146 | struct stree_expr *expr;
|
---|
| 147 |
|
---|
[09ababb7] | 148 | /** Operation class */
|
---|
[23de644] | 149 | unop_class_t uc;
|
---|
[09ababb7] | 150 |
|
---|
| 151 | /** Argument */
|
---|
| 152 | struct stree_expr *arg;
|
---|
| 153 | } stree_unop_t;
|
---|
| 154 |
|
---|
[fa36f29] | 155 | /** New operation */
|
---|
| 156 | typedef struct {
|
---|
[051bc69a] | 157 | /** Expression backlink */
|
---|
| 158 | struct stree_expr *expr;
|
---|
| 159 |
|
---|
[fa36f29] | 160 | /** Type of object to construct. */
|
---|
| 161 | struct stree_texpr *texpr;
|
---|
[051bc69a] | 162 |
|
---|
| 163 | /** Constructor arguments */
|
---|
| 164 | list_t ctor_args; /* of stree_expr_t */
|
---|
[fa36f29] | 165 | } stree_new_t;
|
---|
| 166 |
|
---|
[09ababb7] | 167 | /** Member access operation */
|
---|
| 168 | typedef struct {
|
---|
[051bc69a] | 169 | /** Expression backlink */
|
---|
| 170 | struct stree_expr *expr;
|
---|
| 171 |
|
---|
[09ababb7] | 172 | /** Argument */
|
---|
| 173 | struct stree_expr *arg;
|
---|
| 174 | /** Name of member being accessed. */
|
---|
| 175 | stree_ident_t *member_name;
|
---|
| 176 | } stree_access_t;
|
---|
| 177 |
|
---|
| 178 | /** Function call operation */
|
---|
| 179 | typedef struct {
|
---|
[051bc69a] | 180 | /** Expression backlink */
|
---|
| 181 | struct stree_expr *expr;
|
---|
| 182 |
|
---|
[09ababb7] | 183 | /** Function */
|
---|
| 184 | struct stree_expr *fun;
|
---|
| 185 |
|
---|
| 186 | /** Arguments */
|
---|
| 187 | list_t args; /* of stree_expr_t */
|
---|
| 188 | } stree_call_t;
|
---|
| 189 |
|
---|
| 190 | typedef enum {
|
---|
| 191 | ac_set,
|
---|
| 192 | ac_increase
|
---|
| 193 | } assign_class_t;
|
---|
| 194 |
|
---|
| 195 | /** Assignment */
|
---|
| 196 | typedef struct {
|
---|
[051bc69a] | 197 | /** Expression backlink */
|
---|
| 198 | struct stree_expr *expr;
|
---|
| 199 |
|
---|
[09ababb7] | 200 | assign_class_t ac;
|
---|
| 201 | struct stree_expr *dest, *src;
|
---|
| 202 | } stree_assign_t;
|
---|
| 203 |
|
---|
[94d484a] | 204 | /** Indexing operation */
|
---|
| 205 | typedef struct {
|
---|
[051bc69a] | 206 | /** Expression backlink */
|
---|
| 207 | struct stree_expr *expr;
|
---|
| 208 |
|
---|
[94d484a] | 209 | /** Base */
|
---|
| 210 | struct stree_expr *base;
|
---|
| 211 |
|
---|
| 212 | /** Arguments (indices) */
|
---|
| 213 | list_t args; /* of stree_expr_t */
|
---|
| 214 | } stree_index_t;
|
---|
| 215 |
|
---|
[37f527b] | 216 | /** @c as conversion operation */
|
---|
| 217 | typedef struct {
|
---|
[051bc69a] | 218 | /** Expression backlink */
|
---|
| 219 | struct stree_expr *expr;
|
---|
| 220 |
|
---|
[37f527b] | 221 | /** Expression to convert */
|
---|
| 222 | struct stree_expr *arg;
|
---|
[051bc69a] | 223 |
|
---|
[37f527b] | 224 | /** Destination type of conversion. */
|
---|
| 225 | struct stree_texpr *dtype;
|
---|
| 226 | } stree_as_t;
|
---|
| 227 |
|
---|
[38aaacc2] | 228 | /** Boxing of primitive type (pseudo)
|
---|
| 229 | *
|
---|
| 230 | * This pseudo-node is used internally to box a value of primitive type.
|
---|
| 231 | * It is implicitly inserted by stype_convert(). It does not correspond
|
---|
| 232 | * to a an explicit program construct.
|
---|
| 233 | */
|
---|
| 234 | typedef struct {
|
---|
[051bc69a] | 235 | /** Expression backlink */
|
---|
| 236 | struct stree_expr *expr;
|
---|
| 237 |
|
---|
[38aaacc2] | 238 | /* Primitive type expression */
|
---|
| 239 | struct stree_expr *arg;
|
---|
| 240 | } stree_box_t;
|
---|
| 241 |
|
---|
[09ababb7] | 242 | /** Arithmetic expression class */
|
---|
| 243 | typedef enum {
|
---|
| 244 | ec_nameref,
|
---|
| 245 | ec_literal,
|
---|
[fa36f29] | 246 | ec_self_ref,
|
---|
[09ababb7] | 247 | ec_binop,
|
---|
| 248 | ec_unop,
|
---|
[fa36f29] | 249 | ec_new,
|
---|
[09ababb7] | 250 | ec_access,
|
---|
| 251 | ec_call,
|
---|
[94d484a] | 252 | ec_assign,
|
---|
[37f527b] | 253 | ec_index,
|
---|
[38aaacc2] | 254 | ec_as,
|
---|
| 255 | ec_box
|
---|
[09ababb7] | 256 | } expr_class_t;
|
---|
| 257 |
|
---|
| 258 | /** Arithmetic expression */
|
---|
| 259 | typedef struct stree_expr {
|
---|
| 260 | expr_class_t ec;
|
---|
| 261 |
|
---|
[051bc69a] | 262 | /** Type of this expression or @c NULL if not typed yet */
|
---|
[39e8406] | 263 | struct tdata_item *titem;
|
---|
| 264 |
|
---|
[051bc69a] | 265 | /** Coordinate span */
|
---|
| 266 | struct cspan *cspan;
|
---|
| 267 |
|
---|
[09ababb7] | 268 | union {
|
---|
| 269 | stree_nameref_t *nameref;
|
---|
| 270 | stree_literal_t *literal;
|
---|
[fa36f29] | 271 | stree_self_ref_t *self_ref;
|
---|
[09ababb7] | 272 | stree_binop_t *binop;
|
---|
| 273 | stree_unop_t *unop;
|
---|
[fa36f29] | 274 | stree_new_t *new_op;
|
---|
[09ababb7] | 275 | stree_access_t *access;
|
---|
| 276 | stree_call_t *call;
|
---|
[94d484a] | 277 | stree_index_t *index;
|
---|
[09ababb7] | 278 | stree_assign_t *assign;
|
---|
[37f527b] | 279 | stree_as_t *as_op;
|
---|
[38aaacc2] | 280 | stree_box_t *box;
|
---|
[09ababb7] | 281 | } u;
|
---|
| 282 | } stree_expr_t;
|
---|
| 283 |
|
---|
| 284 | /*
|
---|
| 285 | * Type expressions
|
---|
| 286 | */
|
---|
| 287 |
|
---|
| 288 | struct stree_texpr;
|
---|
| 289 |
|
---|
[fa36f29] | 290 | /** Type literal class */
|
---|
| 291 | typedef enum {
|
---|
[074444f] | 292 | tlc_bool,
|
---|
| 293 | tlc_char,
|
---|
[fa36f29] | 294 | tlc_int,
|
---|
[37f527b] | 295 | tlc_resource,
|
---|
[fa36f29] | 296 | tlc_string
|
---|
| 297 | } tliteral_class_t;
|
---|
| 298 |
|
---|
| 299 | /** Type literal */
|
---|
| 300 | typedef struct {
|
---|
[051bc69a] | 301 | /** Type expression backlink */
|
---|
| 302 | struct stree_texpr *texpr;
|
---|
| 303 |
|
---|
[fa36f29] | 304 | tliteral_class_t tlc;
|
---|
| 305 | } stree_tliteral_t;
|
---|
| 306 |
|
---|
[09ababb7] | 307 | /** Type name reference */
|
---|
| 308 | typedef struct {
|
---|
[051bc69a] | 309 | /** Type expression backlink */
|
---|
| 310 | struct stree_texpr *texpr;
|
---|
| 311 |
|
---|
[09ababb7] | 312 | stree_ident_t *name;
|
---|
| 313 | } stree_tnameref_t;
|
---|
| 314 |
|
---|
| 315 | /** Type member access operation */
|
---|
| 316 | typedef struct {
|
---|
[051bc69a] | 317 | /** Type expression backlink */
|
---|
| 318 | struct stree_texpr *texpr;
|
---|
| 319 |
|
---|
[09ababb7] | 320 | /** Argument */
|
---|
| 321 | struct stree_texpr *arg;
|
---|
[051bc69a] | 322 |
|
---|
[09ababb7] | 323 | /** Name of member being accessed. */
|
---|
| 324 | stree_ident_t *member_name;
|
---|
| 325 | } stree_taccess_t;
|
---|
| 326 |
|
---|
| 327 | /** Type application operation */
|
---|
| 328 | typedef struct {
|
---|
[051bc69a] | 329 | /** Type expression backlink */
|
---|
| 330 | struct stree_texpr *texpr;
|
---|
| 331 |
|
---|
[074444f] | 332 | /* Base type */
|
---|
| 333 | struct stree_texpr *gtype;
|
---|
| 334 |
|
---|
| 335 | /** (Formal) type arguments */
|
---|
| 336 | list_t targs; /* of stree_texpr_t */
|
---|
[09ababb7] | 337 | } stree_tapply_t;
|
---|
| 338 |
|
---|
[94d484a] | 339 | /** Type index operation */
|
---|
| 340 | typedef struct {
|
---|
[051bc69a] | 341 | /** Type expression backlink */
|
---|
| 342 | struct stree_texpr *texpr;
|
---|
| 343 |
|
---|
[94d484a] | 344 | /** Base type */
|
---|
| 345 | struct stree_texpr *base_type;
|
---|
| 346 |
|
---|
| 347 | /**
|
---|
| 348 | * Number of arguments (rank). Needed when only rank is specified
|
---|
| 349 | * and @c args are not used.
|
---|
| 350 | */
|
---|
| 351 | int n_args;
|
---|
| 352 |
|
---|
| 353 | /** Arguments (extents) */
|
---|
| 354 | list_t args; /* of stree_expr_t */
|
---|
| 355 | } stree_tindex_t;
|
---|
| 356 |
|
---|
[09ababb7] | 357 | /** Type expression class */
|
---|
| 358 | typedef enum {
|
---|
[fa36f29] | 359 | tc_tliteral,
|
---|
[09ababb7] | 360 | tc_tnameref,
|
---|
| 361 | tc_taccess,
|
---|
[94d484a] | 362 | tc_tapply,
|
---|
| 363 | tc_tindex
|
---|
[09ababb7] | 364 | } texpr_class_t;
|
---|
| 365 |
|
---|
| 366 | /** Arithmetic expression */
|
---|
| 367 | typedef struct stree_texpr {
|
---|
| 368 | texpr_class_t tc;
|
---|
| 369 |
|
---|
[051bc69a] | 370 | /** Coordinate span */
|
---|
| 371 | struct cspan *cspan;
|
---|
| 372 |
|
---|
[09ababb7] | 373 | union {
|
---|
[fa36f29] | 374 | stree_tliteral_t *tliteral;
|
---|
[09ababb7] | 375 | stree_tnameref_t *tnameref;
|
---|
| 376 | stree_taccess_t *taccess;
|
---|
| 377 | stree_tapply_t *tapply;
|
---|
[94d484a] | 378 | stree_tindex_t *tindex;
|
---|
[09ababb7] | 379 | } u;
|
---|
| 380 | } stree_texpr_t;
|
---|
| 381 |
|
---|
| 382 | /*
|
---|
| 383 | * Statements, class members and module members.
|
---|
| 384 | */
|
---|
| 385 |
|
---|
| 386 | /** Statement block */
|
---|
[d0febca] | 387 | typedef struct stree_block {
|
---|
[09ababb7] | 388 | /** List of statements in the block */
|
---|
| 389 | list_t stats; /* of stree_stat_t */
|
---|
| 390 | } stree_block_t;
|
---|
| 391 |
|
---|
| 392 | /** Variable declaration */
|
---|
| 393 | typedef struct {
|
---|
| 394 | stree_ident_t *name;
|
---|
| 395 | stree_texpr_t *type;
|
---|
| 396 | } stree_vdecl_t;
|
---|
| 397 |
|
---|
[94d484a] | 398 | /** @c except clause */
|
---|
| 399 | typedef struct {
|
---|
| 400 | stree_ident_t *evar;
|
---|
| 401 | stree_texpr_t *etype;
|
---|
| 402 | stree_block_t *block;
|
---|
| 403 | } stree_except_t;
|
---|
| 404 |
|
---|
[051bc69a] | 405 | /** @c if or @c elif clause */
|
---|
[09ababb7] | 406 | typedef struct {
|
---|
| 407 | stree_expr_t *cond;
|
---|
[051bc69a] | 408 | stree_block_t *block;
|
---|
| 409 | } stree_if_clause_t;
|
---|
| 410 |
|
---|
| 411 | /** If statement */
|
---|
| 412 | typedef struct {
|
---|
| 413 | /** If and elif clauses */
|
---|
| 414 | list_t if_clauses; /* of stree_if_clause_t */
|
---|
| 415 |
|
---|
| 416 | /** Else block */
|
---|
[09ababb7] | 417 | stree_block_t *else_block;
|
---|
| 418 | } stree_if_t;
|
---|
| 419 |
|
---|
| 420 | /** While statement */
|
---|
| 421 | typedef struct {
|
---|
| 422 | stree_expr_t *cond;
|
---|
| 423 | stree_block_t *body;
|
---|
| 424 | } stree_while_t;
|
---|
| 425 |
|
---|
| 426 | /** For statement */
|
---|
| 427 | typedef struct {
|
---|
| 428 | stree_block_t *body;
|
---|
| 429 | } stree_for_t;
|
---|
| 430 |
|
---|
| 431 | /** Raise statement */
|
---|
| 432 | typedef struct {
|
---|
[94d484a] | 433 | stree_expr_t *expr;
|
---|
[09ababb7] | 434 | } stree_raise_t;
|
---|
| 435 |
|
---|
[051bc69a] | 436 | /** Break statement */
|
---|
| 437 | typedef struct {
|
---|
| 438 | } stree_break_t;
|
---|
| 439 |
|
---|
[fa36f29] | 440 | /** Return statement */
|
---|
| 441 | typedef struct {
|
---|
| 442 | stree_expr_t *expr;
|
---|
| 443 | } stree_return_t;
|
---|
| 444 |
|
---|
[09ababb7] | 445 | /** Expression statement */
|
---|
| 446 | typedef struct {
|
---|
| 447 | stree_expr_t *expr;
|
---|
| 448 | } stree_exps_t;
|
---|
| 449 |
|
---|
| 450 | /** With-try-except-finally statement (WEF) */
|
---|
| 451 | typedef struct {
|
---|
| 452 | stree_block_t *with_block;
|
---|
[94d484a] | 453 | list_t except_clauses; /* of stree_except_t */
|
---|
[09ababb7] | 454 | stree_block_t *finally_block;
|
---|
| 455 | } stree_wef_t;
|
---|
| 456 |
|
---|
| 457 | /** Statement class */
|
---|
| 458 | typedef enum {
|
---|
| 459 | st_vdecl,
|
---|
| 460 | st_if,
|
---|
| 461 | st_while,
|
---|
| 462 | st_for,
|
---|
| 463 | st_raise,
|
---|
[051bc69a] | 464 | st_break,
|
---|
[fa36f29] | 465 | st_return,
|
---|
[09ababb7] | 466 | st_exps,
|
---|
| 467 | st_wef
|
---|
| 468 | } stat_class_t;
|
---|
| 469 |
|
---|
| 470 | /** Statement */
|
---|
| 471 | typedef struct {
|
---|
| 472 | stat_class_t sc;
|
---|
| 473 |
|
---|
| 474 | union {
|
---|
| 475 | stree_vdecl_t *vdecl_s;
|
---|
| 476 | stree_if_t *if_s;
|
---|
| 477 | stree_while_t *while_s;
|
---|
| 478 | stree_for_t *for_s;
|
---|
| 479 | stree_raise_t *raise_s;
|
---|
[051bc69a] | 480 | stree_break_t *break_s;
|
---|
[fa36f29] | 481 | stree_return_t *return_s;
|
---|
[09ababb7] | 482 | stree_exps_t *exp_s;
|
---|
| 483 | stree_wef_t *wef_s;
|
---|
| 484 | } u;
|
---|
| 485 | } stree_stat_t;
|
---|
| 486 |
|
---|
[94d484a] | 487 | /** Argument attribute class */
|
---|
| 488 | typedef enum {
|
---|
| 489 | /** Packed argument (for variadic functions) */
|
---|
| 490 | aac_packed
|
---|
| 491 | } arg_attr_class_t;
|
---|
| 492 |
|
---|
| 493 | /** Argument atribute */
|
---|
| 494 | typedef struct {
|
---|
| 495 | arg_attr_class_t aac;
|
---|
| 496 | } stree_arg_attr_t;
|
---|
| 497 |
|
---|
[09ababb7] | 498 | /** Formal function parameter */
|
---|
| 499 | typedef struct {
|
---|
| 500 | /* Argument name */
|
---|
| 501 | stree_ident_t *name;
|
---|
| 502 |
|
---|
| 503 | /* Argument type */
|
---|
| 504 | stree_texpr_t *type;
|
---|
[94d484a] | 505 |
|
---|
| 506 | /* Attributes */
|
---|
| 507 | list_t attr; /* of stree_arg_attr_t */
|
---|
[d0febca] | 508 | } stree_proc_arg_t;
|
---|
[09ababb7] | 509 |
|
---|
[38aaacc2] | 510 | /** Function signature.
|
---|
| 511 | *
|
---|
| 512 | * Foormal parameters and return type. This is common to function and delegate
|
---|
| 513 | * delcarations.
|
---|
| 514 | */
|
---|
| 515 | typedef struct {
|
---|
| 516 | /** Formal parameters */
|
---|
| 517 | list_t args; /* of stree_proc_arg_t */
|
---|
| 518 |
|
---|
| 519 | /** Variadic argument or @c NULL if none. */
|
---|
| 520 | stree_proc_arg_t *varg;
|
---|
| 521 |
|
---|
| 522 | /** Return type */
|
---|
| 523 | stree_texpr_t *rtype;
|
---|
| 524 | } stree_fun_sig_t;
|
---|
| 525 |
|
---|
[39e8406] | 526 | /** Procedure
|
---|
| 527 | *
|
---|
| 528 | * Procedure is the common term for a getter, setter or function body.
|
---|
| 529 | * A procedure can be invoked. However, the arguments are specified by
|
---|
| 530 | * the containing symbol.
|
---|
| 531 | */
|
---|
| 532 | typedef struct stree_proc {
|
---|
| 533 | /** Symbol (function or property) containing the procedure */
|
---|
| 534 | struct stree_symbol *outer_symbol;
|
---|
| 535 |
|
---|
[37f527b] | 536 | /** Main block for regular procedures */
|
---|
[39e8406] | 537 | stree_block_t *body;
|
---|
[37f527b] | 538 |
|
---|
| 539 | /** Builtin handler for builtin procedures */
|
---|
| 540 | builtin_proc_t bi_handler;
|
---|
[39e8406] | 541 | } stree_proc_t;
|
---|
| 542 |
|
---|
[051bc69a] | 543 | /** Constructor declaration */
|
---|
| 544 | typedef struct stree_ctor {
|
---|
| 545 | /** Constructor 'name'. Points to the @c new keyword. */
|
---|
| 546 | stree_ident_t *name;
|
---|
| 547 |
|
---|
| 548 | /** Symbol */
|
---|
| 549 | struct stree_symbol *symbol;
|
---|
| 550 |
|
---|
| 551 | /** Signature (arguments, return type is always none) */
|
---|
| 552 | stree_fun_sig_t *sig;
|
---|
| 553 |
|
---|
| 554 | /** Constructor implementation */
|
---|
| 555 | stree_proc_t *proc;
|
---|
| 556 |
|
---|
| 557 | /** Type item describing the constructor */
|
---|
| 558 | struct tdata_item *titem;
|
---|
| 559 | } stree_ctor_t;
|
---|
| 560 |
|
---|
[38aaacc2] | 561 | /** Delegate declaration */
|
---|
| 562 | typedef struct stree_deleg {
|
---|
| 563 | /** Delegate name */
|
---|
| 564 | stree_ident_t *name;
|
---|
| 565 |
|
---|
| 566 | /** Symbol */
|
---|
| 567 | struct stree_symbol *symbol;
|
---|
| 568 |
|
---|
| 569 | /** Signature (arguments and return type) */
|
---|
| 570 | stree_fun_sig_t *sig;
|
---|
| 571 |
|
---|
| 572 | /** Type item describing the delegate */
|
---|
| 573 | struct tdata_item *titem;
|
---|
| 574 | } stree_deleg_t;
|
---|
| 575 |
|
---|
[051bc69a] | 576 | /** Enum member */
|
---|
| 577 | typedef struct stree_embr {
|
---|
| 578 | /** Enum containing this declaration */
|
---|
| 579 | struct stree_enum *outer_enum;
|
---|
| 580 |
|
---|
| 581 | /** Enum member name */
|
---|
| 582 | stree_ident_t *name;
|
---|
| 583 | } stree_embr_t;
|
---|
| 584 |
|
---|
| 585 | /** Enum declaration */
|
---|
| 586 | typedef struct stree_enum {
|
---|
| 587 | /** Enum name */
|
---|
| 588 | stree_ident_t *name;
|
---|
| 589 |
|
---|
| 590 | /** Symbol */
|
---|
| 591 | struct stree_symbol *symbol;
|
---|
| 592 |
|
---|
| 593 | /** List of enum members */
|
---|
| 594 | list_t members; /* of stree_embr_t */
|
---|
| 595 |
|
---|
| 596 | /** Type item describing the enum */
|
---|
| 597 | struct tdata_item *titem;
|
---|
| 598 | } stree_enum_t;
|
---|
| 599 |
|
---|
[09ababb7] | 600 | /** Member function declaration */
|
---|
[39e8406] | 601 | typedef struct stree_fun {
|
---|
[09ababb7] | 602 | /** Function name */
|
---|
| 603 | stree_ident_t *name;
|
---|
| 604 |
|
---|
| 605 | /** Symbol */
|
---|
| 606 | struct stree_symbol *symbol;
|
---|
| 607 |
|
---|
[38aaacc2] | 608 | /** Signature (arguments and return type) */
|
---|
| 609 | stree_fun_sig_t *sig;
|
---|
[09ababb7] | 610 |
|
---|
[39e8406] | 611 | /** Function implementation */
|
---|
| 612 | stree_proc_t *proc;
|
---|
[38aaacc2] | 613 |
|
---|
| 614 | /** Type item describing the function */
|
---|
| 615 | struct tdata_item *titem;
|
---|
[09ababb7] | 616 | } stree_fun_t;
|
---|
| 617 |
|
---|
| 618 | /** Member variable declaration */
|
---|
[39e8406] | 619 | typedef struct stree_var {
|
---|
[09ababb7] | 620 | stree_ident_t *name;
|
---|
| 621 | struct stree_symbol *symbol;
|
---|
| 622 | stree_texpr_t *type;
|
---|
| 623 | } stree_var_t;
|
---|
| 624 |
|
---|
| 625 | /** Member property declaration */
|
---|
[39e8406] | 626 | typedef struct stree_prop {
|
---|
[09ababb7] | 627 | stree_ident_t *name;
|
---|
| 628 | struct stree_symbol *symbol;
|
---|
| 629 | stree_texpr_t *type;
|
---|
[d0febca] | 630 |
|
---|
[39e8406] | 631 | stree_proc_t *getter;
|
---|
| 632 |
|
---|
| 633 | stree_proc_t *setter;
|
---|
| 634 | stree_proc_arg_t *setter_arg;
|
---|
[d0febca] | 635 |
|
---|
| 636 | /** Formal parameters (for indexed properties) */
|
---|
| 637 | list_t args; /* of stree_proc_arg_t */
|
---|
| 638 |
|
---|
| 639 | /** Variadic argument or @c NULL if none. */
|
---|
| 640 | stree_proc_arg_t *varg;
|
---|
[c5cb943d] | 641 |
|
---|
| 642 | /** Type of the property */
|
---|
| 643 | struct tdata_item *titem;
|
---|
[09ababb7] | 644 | } stree_prop_t;
|
---|
| 645 |
|
---|
[d0febca] | 646 | /**
|
---|
[39e8406] | 647 | * Fake identifiers used with symbols that do not really have one.
|
---|
[d0febca] | 648 | */
|
---|
[051bc69a] | 649 | #define CTOR_IDENT "$ctor"
|
---|
[d0febca] | 650 | #define INDEXER_IDENT "$indexer"
|
---|
| 651 |
|
---|
[09ababb7] | 652 | typedef enum {
|
---|
| 653 | csimbr_csi,
|
---|
[051bc69a] | 654 | csimbr_ctor,
|
---|
[38aaacc2] | 655 | csimbr_deleg,
|
---|
[051bc69a] | 656 | csimbr_enum,
|
---|
[09ababb7] | 657 | csimbr_fun,
|
---|
| 658 | csimbr_var,
|
---|
| 659 | csimbr_prop
|
---|
| 660 | } csimbr_class_t;
|
---|
| 661 |
|
---|
| 662 | /** Class, struct or interface member */
|
---|
| 663 | typedef struct {
|
---|
| 664 | csimbr_class_t cc;
|
---|
| 665 |
|
---|
| 666 | union {
|
---|
| 667 | struct stree_csi *csi;
|
---|
[051bc69a] | 668 | stree_ctor_t *ctor;
|
---|
[38aaacc2] | 669 | stree_deleg_t *deleg;
|
---|
[051bc69a] | 670 | stree_enum_t *enum_d;
|
---|
[09ababb7] | 671 | stree_fun_t *fun;
|
---|
| 672 | stree_var_t *var;
|
---|
| 673 | stree_prop_t *prop;
|
---|
| 674 | } u;
|
---|
| 675 | } stree_csimbr_t;
|
---|
| 676 |
|
---|
| 677 | typedef enum {
|
---|
| 678 | csi_class,
|
---|
| 679 | csi_struct,
|
---|
| 680 | csi_interface
|
---|
| 681 | } csi_class_t;
|
---|
| 682 |
|
---|
[38aaacc2] | 683 | /** CSI formal type argument */
|
---|
| 684 | typedef struct stree_targ {
|
---|
| 685 | stree_ident_t *name;
|
---|
| 686 | struct stree_symbol *symbol;
|
---|
| 687 | } stree_targ_t;
|
---|
| 688 |
|
---|
[09ababb7] | 689 | /** Class, struct or interface declaration */
|
---|
| 690 | typedef struct stree_csi {
|
---|
| 691 | /** Which of class, struct or interface */
|
---|
| 692 | csi_class_t cc;
|
---|
| 693 |
|
---|
| 694 | /** Name of this CSI */
|
---|
| 695 | stree_ident_t *name;
|
---|
| 696 |
|
---|
[38aaacc2] | 697 | /** List of type arguments */
|
---|
| 698 | list_t targ; /* of stree_targ_t */
|
---|
[074444f] | 699 |
|
---|
[09ababb7] | 700 | /** Symbol for this CSI */
|
---|
| 701 | struct stree_symbol *symbol;
|
---|
| 702 |
|
---|
[c5cb943d] | 703 | /** Type expressions referencing inherited CSIs. */
|
---|
| 704 | list_t inherit; /* of stree_texpr_t */
|
---|
[09ababb7] | 705 |
|
---|
[94d484a] | 706 | /** Base CSI. Only available when ancr_state == ws_visited. */
|
---|
| 707 | struct stree_csi *base_csi;
|
---|
| 708 |
|
---|
[c5cb943d] | 709 | /** Types of implemented or accumulated interfaces. */
|
---|
| 710 | list_t impl_if_ti; /* of tdata_item_t */
|
---|
| 711 |
|
---|
[09ababb7] | 712 | /** Node state for ancr walks. */
|
---|
| 713 | walk_state_t ancr_state;
|
---|
| 714 |
|
---|
| 715 | /** List of CSI members */
|
---|
| 716 | list_t members; /* of stree_csimbr_t */
|
---|
| 717 | } stree_csi_t;
|
---|
| 718 |
|
---|
| 719 | typedef enum {
|
---|
| 720 | /* Class, struct or interface declaration */
|
---|
[051bc69a] | 721 | mc_csi,
|
---|
| 722 | /* Enum declaration */
|
---|
| 723 | mc_enum
|
---|
[09ababb7] | 724 | } modm_class_t;
|
---|
| 725 |
|
---|
| 726 | /** Module member */
|
---|
| 727 | typedef struct {
|
---|
| 728 | modm_class_t mc;
|
---|
| 729 | union {
|
---|
| 730 | stree_csi_t *csi;
|
---|
[051bc69a] | 731 | stree_enum_t *enum_d;
|
---|
[09ababb7] | 732 | } u;
|
---|
| 733 | } stree_modm_t;
|
---|
| 734 |
|
---|
| 735 | /** Module */
|
---|
| 736 | typedef struct stree_module {
|
---|
| 737 | /** List of module members */
|
---|
| 738 | list_t members; /* of stree_modm_t */
|
---|
| 739 | } stree_module_t;
|
---|
| 740 |
|
---|
[37f527b] | 741 | /** Symbol attribute class */
|
---|
| 742 | typedef enum {
|
---|
| 743 | /** Builtin symbol (interpreter hook) */
|
---|
[c5cb943d] | 744 | sac_builtin,
|
---|
| 745 |
|
---|
| 746 | /** Static symbol */
|
---|
| 747 | sac_static
|
---|
[37f527b] | 748 | } symbol_attr_class_t;
|
---|
| 749 |
|
---|
| 750 | /** Symbol atribute */
|
---|
| 751 | typedef struct {
|
---|
| 752 | symbol_attr_class_t sac;
|
---|
| 753 | } stree_symbol_attr_t;
|
---|
| 754 |
|
---|
[09ababb7] | 755 | typedef enum {
|
---|
[38aaacc2] | 756 | /** CSI (class, struct or interface) */
|
---|
[09ababb7] | 757 | sc_csi,
|
---|
[051bc69a] | 758 | /** Constructor */
|
---|
| 759 | sc_ctor,
|
---|
[38aaacc2] | 760 | /** Member delegate */
|
---|
| 761 | sc_deleg,
|
---|
[051bc69a] | 762 | /** Enum */
|
---|
| 763 | sc_enum,
|
---|
[38aaacc2] | 764 | /** Member function */
|
---|
[09ababb7] | 765 | sc_fun,
|
---|
[38aaacc2] | 766 | /** Member variable */
|
---|
[09ababb7] | 767 | sc_var,
|
---|
[38aaacc2] | 768 | /** Member property */
|
---|
[09ababb7] | 769 | sc_prop
|
---|
| 770 | } symbol_class_t;
|
---|
| 771 |
|
---|
[39e8406] | 772 | /** Symbol
|
---|
| 773 | *
|
---|
| 774 | * A symbol is a common superclass of different program elements that
|
---|
| 775 | * allow us to refer to them, print their fully qualified names, etc.
|
---|
| 776 | */
|
---|
[09ababb7] | 777 | typedef struct stree_symbol {
|
---|
| 778 | symbol_class_t sc;
|
---|
| 779 |
|
---|
| 780 | union {
|
---|
| 781 | struct stree_csi *csi;
|
---|
[051bc69a] | 782 | stree_ctor_t *ctor;
|
---|
[38aaacc2] | 783 | stree_deleg_t *deleg;
|
---|
[051bc69a] | 784 | stree_enum_t *enum_d;
|
---|
[09ababb7] | 785 | stree_fun_t *fun;
|
---|
| 786 | stree_var_t *var;
|
---|
| 787 | stree_prop_t *prop;
|
---|
| 788 | } u;
|
---|
| 789 |
|
---|
| 790 | /** Containing CSI (for all symbols) */
|
---|
| 791 | stree_csi_t *outer_csi;
|
---|
| 792 |
|
---|
| 793 | /** Containing block (for block-level symbols) */
|
---|
| 794 | stree_block_t *outer_block;
|
---|
[37f527b] | 795 |
|
---|
| 796 | /** Symbol attributes. */
|
---|
| 797 | list_t attr; /* of stree_symbol_attr_t */
|
---|
[09ababb7] | 798 | } stree_symbol_t;
|
---|
| 799 |
|
---|
| 800 | /** Program */
|
---|
| 801 | typedef struct stree_program {
|
---|
| 802 | /** The one and only module in the program */
|
---|
| 803 | stree_module_t *module;
|
---|
[37f527b] | 804 |
|
---|
| 805 | /** Builtin symbols binding. */
|
---|
| 806 | struct builtin *builtin;
|
---|
[09ababb7] | 807 | } stree_program_t;
|
---|
| 808 |
|
---|
| 809 | #endif
|
---|