| 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 |
|
|---|
| 34 | /** Class of primitive type. */
|
|---|
| 35 | typedef enum {
|
|---|
| 36 | /** Boolean type */
|
|---|
| 37 | tpc_bool,
|
|---|
| 38 | /** Character type */
|
|---|
| 39 | tpc_char,
|
|---|
| 40 | /** Integer type */
|
|---|
| 41 | tpc_int,
|
|---|
| 42 | /** Special type for nil reference */
|
|---|
| 43 | tpc_nil,
|
|---|
| 44 | /** String type */
|
|---|
| 45 | tpc_string,
|
|---|
| 46 | /** Resource type */
|
|---|
| 47 | tpc_resource
|
|---|
| 48 | } tprimitive_class_t;
|
|---|
| 49 |
|
|---|
| 50 | /** Primitive type. */
|
|---|
| 51 | typedef struct {
|
|---|
| 52 | /** Class of primitive type */
|
|---|
| 53 | tprimitive_class_t tpc;
|
|---|
| 54 | } tdata_primitive_t;
|
|---|
| 55 |
|
|---|
| 56 | /** Object type. */
|
|---|
| 57 | typedef struct {
|
|---|
| 58 | /** @c true if expression is a static CSI reference */
|
|---|
| 59 | bool_t static_ref;
|
|---|
| 60 |
|
|---|
| 61 | /** CSI definition */
|
|---|
| 62 | struct stree_csi *csi;
|
|---|
| 63 |
|
|---|
| 64 | /** (Real) type arguments */
|
|---|
| 65 | list_t targs; /* of tdata_item_t */
|
|---|
| 66 | } tdata_object_t;
|
|---|
| 67 |
|
|---|
| 68 | /** Array type. */
|
|---|
| 69 | typedef struct {
|
|---|
| 70 | /** Base type item */
|
|---|
| 71 | struct tdata_item *base_ti;
|
|---|
| 72 |
|
|---|
| 73 | /** Rank */
|
|---|
| 74 | int rank;
|
|---|
| 75 |
|
|---|
| 76 | /** Extents */
|
|---|
| 77 | list_t extents; /* of stree_expr_t */
|
|---|
| 78 | } tdata_array_t;
|
|---|
| 79 |
|
|---|
| 80 | /** Functional type. */
|
|---|
| 81 | typedef struct {
|
|---|
| 82 | /**
|
|---|
| 83 | * Function definition. We'll leave expansion to the call operation.
|
|---|
| 84 | */
|
|---|
| 85 | struct stree_fun *fun;
|
|---|
| 86 | } tdata_fun_t;
|
|---|
| 87 |
|
|---|
| 88 | typedef enum {
|
|---|
| 89 | /** Primitive type item */
|
|---|
| 90 | tic_tprimitive,
|
|---|
| 91 | /** Object type item */
|
|---|
| 92 | tic_tobject,
|
|---|
| 93 | /** Array type item */
|
|---|
| 94 | tic_tarray,
|
|---|
| 95 | /** Function type item */
|
|---|
| 96 | tic_tfun,
|
|---|
| 97 | /** Special error-recovery type item */
|
|---|
| 98 | tic_ignore
|
|---|
| 99 | } titem_class_t;
|
|---|
| 100 |
|
|---|
| 101 | /** Type item, the result of evaluating a type expression. */
|
|---|
| 102 | typedef struct tdata_item {
|
|---|
| 103 | titem_class_t tic;
|
|---|
| 104 |
|
|---|
| 105 | union {
|
|---|
| 106 | tdata_primitive_t *tprimitive;
|
|---|
| 107 | tdata_object_t *tobject;
|
|---|
| 108 | tdata_array_t *tarray;
|
|---|
| 109 | tdata_fun_t *tfun;
|
|---|
| 110 | } u;
|
|---|
| 111 | } tdata_item_t;
|
|---|
| 112 |
|
|---|
| 113 | #endif
|
|---|