[39e8406] | 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 | /** @file Static type system representation. */
|
---|
| 30 |
|
---|
| 31 | #ifndef TDATA_T_H_
|
---|
| 32 | #define TDATA_T_H_
|
---|
| 33 |
|
---|
[38aaacc2] | 34 | #include "intmap_t.h"
|
---|
| 35 |
|
---|
[39e8406] | 36 | /** Class of primitive type. */
|
---|
| 37 | typedef enum {
|
---|
[074444f] | 38 | /** Boolean type */
|
---|
| 39 | tpc_bool,
|
---|
| 40 | /** Character type */
|
---|
| 41 | tpc_char,
|
---|
[39e8406] | 42 | /** Integer type */
|
---|
| 43 | tpc_int,
|
---|
| 44 | /** Special type for nil reference */
|
---|
| 45 | tpc_nil,
|
---|
| 46 | /** String type */
|
---|
[37f527b] | 47 | tpc_string,
|
---|
| 48 | /** Resource type */
|
---|
| 49 | tpc_resource
|
---|
[39e8406] | 50 | } tprimitive_class_t;
|
---|
| 51 |
|
---|
| 52 | /** Primitive type. */
|
---|
| 53 | typedef struct {
|
---|
| 54 | /** Class of primitive type */
|
---|
| 55 | tprimitive_class_t tpc;
|
---|
| 56 | } tdata_primitive_t;
|
---|
| 57 |
|
---|
| 58 | /** Object type. */
|
---|
| 59 | typedef struct {
|
---|
[c5cb943d] | 60 | /** @c sn_static if expression is a static CSI reference */
|
---|
| 61 | statns_t static_ref;
|
---|
[39e8406] | 62 |
|
---|
| 63 | /** CSI definition */
|
---|
| 64 | struct stree_csi *csi;
|
---|
[074444f] | 65 |
|
---|
| 66 | /** (Real) type arguments */
|
---|
| 67 | list_t targs; /* of tdata_item_t */
|
---|
[39e8406] | 68 | } tdata_object_t;
|
---|
| 69 |
|
---|
| 70 | /** Array type. */
|
---|
| 71 | typedef struct {
|
---|
| 72 | /** Base type item */
|
---|
| 73 | struct tdata_item *base_ti;
|
---|
| 74 |
|
---|
| 75 | /** Rank */
|
---|
| 76 | int rank;
|
---|
| 77 |
|
---|
| 78 | /** Extents */
|
---|
| 79 | list_t extents; /* of stree_expr_t */
|
---|
| 80 | } tdata_array_t;
|
---|
| 81 |
|
---|
[38aaacc2] | 82 | /** Function signature type.
|
---|
| 83 | *
|
---|
| 84 | * This is a part of functional type or delegate type.
|
---|
| 85 | */
|
---|
| 86 | typedef struct {
|
---|
| 87 | /** Types of fixed arguments. */
|
---|
| 88 | list_t arg_ti; /* of tdata_item_t */
|
---|
| 89 |
|
---|
| 90 | /** Type of variadic argument */
|
---|
| 91 | struct tdata_item *varg_ti;
|
---|
| 92 |
|
---|
| 93 | /** Return type */
|
---|
| 94 | struct tdata_item *rtype;
|
---|
| 95 | } tdata_fun_sig_t;
|
---|
| 96 |
|
---|
| 97 | /** Delegate type. */
|
---|
| 98 | typedef struct {
|
---|
| 99 | /** Delegate definition or @c NULL if anonymous delegate */
|
---|
| 100 | struct stree_deleg *deleg;
|
---|
| 101 |
|
---|
| 102 | /** Delegate signature type */
|
---|
| 103 | tdata_fun_sig_t *tsig;
|
---|
| 104 | } tdata_deleg_t;
|
---|
| 105 |
|
---|
[051bc69a] | 106 | /** Enum-base type.
|
---|
| 107 | *
|
---|
| 108 | * Type for expression which reference an enum declaration. In run time
|
---|
| 109 | * enum type reference is represented by @c rdata_deleg_t. (Which is used
|
---|
| 110 | * for any symbol references).
|
---|
| 111 | */
|
---|
| 112 | typedef struct {
|
---|
| 113 | /** Enum definition */
|
---|
| 114 | struct stree_enum *enum_d;
|
---|
| 115 | } tdata_ebase_t;
|
---|
| 116 |
|
---|
| 117 | /** Enum type. */
|
---|
| 118 | typedef struct {
|
---|
| 119 | /** Enum definition */
|
---|
| 120 | struct stree_enum *enum_d;
|
---|
| 121 | } tdata_enum_t;
|
---|
| 122 |
|
---|
[39e8406] | 123 | /** Functional type. */
|
---|
| 124 | typedef struct {
|
---|
[38aaacc2] | 125 | /** Delegate definition or @c NULL if anonymous delegate */
|
---|
| 126 | struct stree_deleg *deleg;
|
---|
| 127 |
|
---|
| 128 | /** Function signature type */
|
---|
| 129 | tdata_fun_sig_t *tsig;
|
---|
[39e8406] | 130 | } tdata_fun_t;
|
---|
| 131 |
|
---|
[38aaacc2] | 132 | /** Type variable reference. */
|
---|
| 133 | typedef struct {
|
---|
| 134 | /** Definition of type argument this variable is referencing. */
|
---|
| 135 | struct stree_targ *targ;
|
---|
| 136 | } tdata_vref_t;
|
---|
| 137 |
|
---|
[39e8406] | 138 | typedef enum {
|
---|
[23de644] | 139 | /** Primitive type item */
|
---|
[39e8406] | 140 | tic_tprimitive,
|
---|
[23de644] | 141 | /** Object type item */
|
---|
[39e8406] | 142 | tic_tobject,
|
---|
[23de644] | 143 | /** Array type item */
|
---|
[39e8406] | 144 | tic_tarray,
|
---|
[38aaacc2] | 145 | /** Delegate type item */
|
---|
| 146 | tic_tdeleg,
|
---|
[051bc69a] | 147 | /** Enum-base type item */
|
---|
| 148 | tic_tebase,
|
---|
| 149 | /** Enum type item */
|
---|
| 150 | tic_tenum,
|
---|
[23de644] | 151 | /** Function type item */
|
---|
| 152 | tic_tfun,
|
---|
[38aaacc2] | 153 | /** Type variable item */
|
---|
| 154 | tic_tvref,
|
---|
[23de644] | 155 | /** Special error-recovery type item */
|
---|
| 156 | tic_ignore
|
---|
[39e8406] | 157 | } titem_class_t;
|
---|
| 158 |
|
---|
| 159 | /** Type item, the result of evaluating a type expression. */
|
---|
| 160 | typedef struct tdata_item {
|
---|
| 161 | titem_class_t tic;
|
---|
| 162 |
|
---|
| 163 | union {
|
---|
| 164 | tdata_primitive_t *tprimitive;
|
---|
| 165 | tdata_object_t *tobject;
|
---|
| 166 | tdata_array_t *tarray;
|
---|
[38aaacc2] | 167 | tdata_deleg_t *tdeleg;
|
---|
[051bc69a] | 168 | tdata_ebase_t *tebase;
|
---|
| 169 | tdata_enum_t *tenum;
|
---|
[39e8406] | 170 | tdata_fun_t *tfun;
|
---|
[38aaacc2] | 171 | tdata_vref_t *tvref;
|
---|
[39e8406] | 172 | } u;
|
---|
| 173 | } tdata_item_t;
|
---|
| 174 |
|
---|
[38aaacc2] | 175 | /** Type variable valuation (mapping of type argument names to values). */
|
---|
| 176 | typedef struct {
|
---|
| 177 | /** Maps name SID to type item */
|
---|
| 178 | intmap_t tvv; /* of tdata_item_t */
|
---|
| 179 | } tdata_tvv_t;
|
---|
| 180 |
|
---|
[39e8406] | 181 | #endif
|
---|