2 * Copyright (c) 2011 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
34 #include "builtin_t.h"
37 * Arithmetic expressions
50 /** Expression backlink */
51 struct stree_expr
*expr
;
56 /** Boolean literal */
61 /** Character literal */
66 /** Integer literal */
71 /** Reference literal (there is only one: @c nil). */
90 /** Expression backlink */
91 struct stree_expr
*expr
;
95 stree_lit_bool_t lit_bool
;
96 stree_lit_char_t lit_char
;
97 stree_lit_int_t lit_int
;
98 stree_lit_ref_t lit_ref
;
99 stree_lit_string_t lit_string
;
103 /** Reference to currently active object. */
105 /** Expression backlink */
106 struct stree_expr
*expr
;
109 /** Binary operation class */
124 /** Unary operation class */
131 /** Binary operation */
133 /** Expression backlink */
134 struct stree_expr
*expr
;
136 /** Binary operation class */
140 struct stree_expr
*arg1
, *arg2
;
143 /** Unary operation */
145 /** Expression backlink */
146 struct stree_expr
*expr
;
148 /** Operation class */
152 struct stree_expr
*arg
;
157 /** Expression backlink */
158 struct stree_expr
*expr
;
160 /** Type of object to construct. */
161 struct stree_texpr
*texpr
;
163 /** Constructor arguments */
164 list_t ctor_args
; /* of stree_expr_t */
167 /** Member access operation */
169 /** Expression backlink */
170 struct stree_expr
*expr
;
173 struct stree_expr
*arg
;
174 /** Name of member being accessed. */
175 stree_ident_t
*member_name
;
178 /** Function call operation */
180 /** Expression backlink */
181 struct stree_expr
*expr
;
184 struct stree_expr
*fun
;
187 list_t args
; /* of stree_expr_t */
197 /** Expression backlink */
198 struct stree_expr
*expr
;
201 struct stree_expr
*dest
, *src
;
204 /** Indexing operation */
206 /** Expression backlink */
207 struct stree_expr
*expr
;
210 struct stree_expr
*base
;
212 /** Arguments (indices) */
213 list_t args
; /* of stree_expr_t */
216 /** @c as conversion operation */
218 /** Expression backlink */
219 struct stree_expr
*expr
;
221 /** Expression to convert */
222 struct stree_expr
*arg
;
224 /** Destination type of conversion. */
225 struct stree_texpr
*dtype
;
228 /** Boxing of primitive type (pseudo)
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.
235 /** Expression backlink */
236 struct stree_expr
*expr
;
238 /* Primitive type expression */
239 struct stree_expr
*arg
;
242 /** Arithmetic expression class */
258 /** Arithmetic expression */
259 typedef struct stree_expr
{
262 /** Type of this expression or @c NULL if not typed yet */
263 struct tdata_item
*titem
;
265 /** Coordinate span */
269 stree_nameref_t
*nameref
;
270 stree_literal_t
*literal
;
271 stree_self_ref_t
*self_ref
;
272 stree_binop_t
*binop
;
275 stree_access_t
*access
;
277 stree_index_t
*index
;
278 stree_assign_t
*assign
;
290 /** Type literal class */
301 /** Type expression backlink */
302 struct stree_texpr
*texpr
;
304 tliteral_class_t tlc
;
307 /** Type name reference */
309 /** Type expression backlink */
310 struct stree_texpr
*texpr
;
315 /** Type member access operation */
317 /** Type expression backlink */
318 struct stree_texpr
*texpr
;
321 struct stree_texpr
*arg
;
323 /** Name of member being accessed. */
324 stree_ident_t
*member_name
;
327 /** Type application operation */
329 /** Type expression backlink */
330 struct stree_texpr
*texpr
;
333 struct stree_texpr
*gtype
;
335 /** (Formal) type arguments */
336 list_t targs
; /* of stree_texpr_t */
339 /** Type index operation */
341 /** Type expression backlink */
342 struct stree_texpr
*texpr
;
345 struct stree_texpr
*base_type
;
348 * Number of arguments (rank). Needed when only rank is specified
349 * and @c args are not used.
353 /** Arguments (extents) */
354 list_t args
; /* of stree_expr_t */
357 /** Type expression class */
366 /** Type expression */
367 typedef struct stree_texpr
{
370 /** Coordinate span */
374 stree_tliteral_t
*tliteral
;
375 stree_tnameref_t
*tnameref
;
376 stree_taccess_t
*taccess
;
377 stree_tapply_t
*tapply
;
378 stree_tindex_t
*tindex
;
383 * Statements, class members and module members.
386 /** Statement block */
387 typedef struct stree_block
{
388 /** List of statements in the block */
389 list_t stats
; /* of stree_stat_t */
392 /** Variable declaration */
397 /** Type of this variable or @c NULL if not typed yet */
398 struct tdata_item
*titem
;
401 /** @c except clause */
404 stree_texpr_t
*etype
;
405 stree_block_t
*block
;
407 /** Evaluated etype or @c NULL if not typed yet */
408 struct tdata_item
*titem
;
411 /** @c if or @c elif clause */
414 stree_block_t
*block
;
419 /** If and elif clauses */
420 list_t if_clauses
; /* of stree_if_clause_t */
423 stree_block_t
*else_block
;
426 /** @c when clause */
428 /** List of expressions -- cases -- for this clause */
429 list_t exprs
; /* of stree_expr_t */
430 stree_block_t
*block
;
433 /** Switch statement */
435 /** Switch expression */
439 list_t when_clauses
; /* of stree_when_t */
442 stree_block_t
*else_block
;
445 /** While statement */
456 /** Raise statement */
461 /** Break statement */
465 /** Return statement */
470 /** Expression statement */
475 /** With-try-except-finally (WEF) statement */
477 stree_block_t
*with_block
;
478 list_t except_clauses
; /* of stree_except_t */
479 stree_block_t
*finally_block
;
482 /** Statement class */
501 stree_vdecl_t
*vdecl_s
;
503 stree_switch_t
*switch_s
;
504 stree_while_t
*while_s
;
506 stree_raise_t
*raise_s
;
507 stree_break_t
*break_s
;
508 stree_return_t
*return_s
;
514 /** Argument attribute class */
516 /** Packed argument (for variadic functions) */
520 /** Argument atribute */
522 arg_attr_class_t aac
;
525 /** Formal function parameter */
534 list_t attr
; /* of stree_arg_attr_t */
537 /** Function signature.
539 * Formal parameters and return type. This is common to function and delegate
543 /** Formal parameters */
544 list_t args
; /* of stree_proc_arg_t */
546 /** Variadic argument or @c NULL if none. */
547 stree_proc_arg_t
*varg
;
550 stree_texpr_t
*rtype
;
555 * Procedure is the common term for a getter, setter or function body.
556 * A procedure can be invoked. However, the arguments are specified by
557 * the containing symbol.
559 typedef struct stree_proc
{
560 /** Symbol (function or property) containing the procedure */
561 struct stree_symbol
*outer_symbol
;
563 /** Main block for regular procedures */
566 /** Builtin handler for builtin procedures */
567 builtin_proc_t bi_handler
;
570 /** Constructor declaration */
571 typedef struct stree_ctor
{
572 /** Constructor 'name'. Points to the @c new keyword. */
576 struct stree_symbol
*symbol
;
578 /** Signature (arguments, return type is always none) */
579 stree_fun_sig_t
*sig
;
581 /** Constructor implementation */
584 /** Type item describing the constructor */
585 struct tdata_item
*titem
;
588 /** Delegate declaration */
589 typedef struct stree_deleg
{
594 struct stree_symbol
*symbol
;
596 /** Signature (arguments and return type) */
597 stree_fun_sig_t
*sig
;
599 /** Type item describing the delegate */
600 struct tdata_item
*titem
;
604 typedef struct stree_embr
{
605 /** Enum containing this declaration */
606 struct stree_enum
*outer_enum
;
608 /** Enum member name */
612 /** Enum declaration */
613 typedef struct stree_enum
{
618 struct stree_symbol
*symbol
;
620 /** List of enum members */
621 list_t members
; /* of stree_embr_t */
623 /** Type item describing the enum */
624 struct tdata_item
*titem
;
627 /** Member function declaration */
628 typedef struct stree_fun
{
633 struct stree_symbol
*symbol
;
635 /** Signature (arguments and return type) */
636 stree_fun_sig_t
*sig
;
638 /** Function implementation */
641 /** Type item describing the function */
642 struct tdata_item
*titem
;
645 /** Member variable declaration */
646 typedef struct stree_var
{
648 struct stree_symbol
*symbol
;
652 /** Member property declaration */
653 typedef struct stree_prop
{
655 struct stree_symbol
*symbol
;
658 stree_proc_t
*getter
;
660 stree_proc_t
*setter
;
661 stree_proc_arg_t
*setter_arg
;
663 /** Formal parameters (for indexed properties) */
664 list_t args
; /* of stree_proc_arg_t */
666 /** Variadic argument or @c NULL if none. */
667 stree_proc_arg_t
*varg
;
669 /** Type of the property */
670 struct tdata_item
*titem
;
674 * Fake identifiers used with symbols that do not really have one.
676 #define CTOR_IDENT "$ctor"
677 #define INDEXER_IDENT "$indexer"
689 /** Class, struct or interface member */
694 struct stree_csi
*csi
;
696 stree_deleg_t
*deleg
;
697 stree_enum_t
*enum_d
;
710 /** CSI formal type argument */
711 typedef struct stree_targ
{
713 struct stree_symbol
*symbol
;
716 /** Class, struct or interface declaration */
717 typedef struct stree_csi
{
718 /** Which of class, struct or interface */
721 /** Name of this CSI */
724 /** List of type arguments */
725 list_t targ
; /* of stree_targ_t */
727 /** Symbol for this CSI */
728 struct stree_symbol
*symbol
;
730 /** Type expressions referencing inherited CSIs. */
731 list_t inherit
; /* of stree_texpr_t */
733 /** Base CSI. Only available when ancr_state == ws_visited. */
734 struct stree_csi
*base_csi
;
736 /** Types of implemented or accumulated interfaces. */
737 list_t impl_if_ti
; /* of tdata_item_t */
739 /** Node state for ancr walks. */
740 walk_state_t ancr_state
;
742 /** List of CSI members */
743 list_t members
; /* of stree_csimbr_t */
747 /* Class, struct or interface declaration */
749 /* Enum declaration */
758 stree_enum_t
*enum_d
;
763 typedef struct stree_module
{
764 /** List of module members */
765 list_t members
; /* of stree_modm_t */
768 /** Symbol attribute class */
770 /** Builtin symbol (interpreter hook) */
775 } symbol_attr_class_t
;
777 /** Symbol atribute */
779 symbol_attr_class_t sac
;
780 } stree_symbol_attr_t
;
783 /** CSI (class, struct or interface) */
787 /** Member delegate */
791 /** Member function */
793 /** Member variable */
795 /** Member property */
801 * A symbol is a common superclass of different program elements that
802 * allow us to refer to them, print their fully qualified names, etc.
804 typedef struct stree_symbol
{
808 struct stree_csi
*csi
;
810 stree_deleg_t
*deleg
;
811 stree_enum_t
*enum_d
;
817 /** Containing CSI */
818 stree_csi_t
*outer_csi
;
820 /** Symbol attributes */
821 list_t attr
; /* of stree_symbol_attr_t */
825 typedef struct stree_program
{
826 /** The one and only module in the program */
827 stree_module_t
*module
;
829 /** Builtin symbols binding. */
830 struct builtin
*builtin
;