db2968e11a728b8defeac6042a2e309e4d61fb8a
[libfirm] / ir / tr / type_t.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/tr/type_t.h
4  * Purpose:     Representation of types -- private header.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 # ifndef _TYPE_T_H_
14 # define _TYPE_T_H_
15 # ifdef HAVE_CONFIG_H
16 # include "config.h"
17 # endif
18 # include "type.h"
19 /**
20  * @file type_t.h
21  * This file contains the datatypes hidden in type.h.
22  *
23  * @author Goetz Lindenmaier
24  * @see  type.h tpop_t.h tpop.h
25  */
26
27 /** class attributes */
28 typedef struct {
29   entity **members;    /**< fields and methods of this class */
30   type   **subtypes;   /**< direct subtypes */
31   type   **supertypes; /**< direct supertypes */
32   peculiarity peculiarity;
33   int dfn;             /**< number used for 'instanceof' operator */
34 } cls_attr;
35
36 /** struct attributs */
37 typedef struct {
38   entity **members;    /**< fields of this struct. No method entities
39                           allowed. */
40 } stc_attr;
41
42 /** method attributes */
43 typedef struct {
44   int n_params;        /**< number of parameters */
45   type **param_type;   /**< code generation needs this information. */
46   type *value_params;  /**< A type whose entities represent copied value arguments. */
47   int n_res;           /**< number of results */
48   type **res_type;     /**< array with result types */
49   type *value_ress;    /**< A type whose entities represent copied value results. */
50   variadicity variadicity; /**< variadicity of the method */
51 } mtd_attr;
52
53 /** union attributs */
54 typedef struct {
55   int     n_types;
56   /* type  **unioned_type; * a list of unioned types. */
57   /* ident **delim_names;  * names of the union delimiters. */
58   entity **members;    /**< fields of this union. No method entities
59                           allowed.  */
60
61 } uni_attr;
62
63 /** array attributs */
64 typedef struct {
65   int   n_dimensions;  /**< Number of array dimensions.  */
66   ir_node **lower_bound;   /**< Lower bounds of dimensions.  Usually all 0. */
67   ir_node **upper_bound;   /**< Upper bounds or dimensions. */
68   int *order;              /**< Ordering of dimensions. */
69   type *element_type;  /**< The type of the array elements. */
70   entity *element_ent; /**< Entity for the array elements, to be used for
71                           element selection with Sel. */
72 } arr_attr;
73
74 /** enum attributs */
75 typedef struct {
76   int      n_enums;    /**< Number of enumerators. */
77   tarval **enumer;     /**< Contains all constants that represent a member
78                           of the enum -- enumerators. */
79   ident  **enum_nameid;/**< Contains the names of the enum fields as specified by
80                           the source program */
81 } enm_attr;
82
83 /** pointer attributs */
84 typedef struct {
85   type *points_to;     /**< The type of the enitity the pointer points to. */
86 } ptr_attr;
87
88 /*
89 typedef struct {   * No private attr yet! *
90 } pri_attr; */
91
92
93 /*
94 typedef struct {        * No private attr, must be smaller than others! *
95 } id_attr;
96 */
97
98 /** general type attributs */
99 typedef union {
100   cls_attr ca;
101   stc_attr sa;
102   mtd_attr ma;
103   uni_attr ua;
104   arr_attr aa;
105   enm_attr ea;
106   ptr_attr pa;
107 } tp_attr;
108
109 /** the structure of a type */
110 struct type {
111   firm_kind kind;
112   tp_op *type_op;
113   ident *name;
114   type_state state;        /**< Represents the types state: layout undefined or
115                               fixed. */
116   int size;                /**< Size of an entity of this type.  This is determined
117                               when fixing the layout of this class.  Size must be
118                               given in bytes. */
119   ir_mode *mode;           /**< The mode for atomic types */
120   unsigned long visit;     /**< visited counter for walks of the type information */
121   void *link;              /**< holds temporary data - like in irnode_t.h */
122   struct dbg_info* dbi;    /**< A pointer to information for debug support. */
123
124 #ifdef DEBUG_libfirm
125   int nr;             /**< a unique node number for each node to make output
126                               readable. */
127 #endif
128   tp_attr attr;            /* type kind specific fields. This must be the last
129                               entry in this struct!  Varying size! */
130 };
131
132 /**
133  *   Creates a new type representation:
134  *
135  *   @param type_op - the kind of this type.  May not be type_id.
136  *   @param mode    - the mode to be used for this type, may be NULL
137  *   @param name    - an ident for the name of this type.
138  *   @return a new type of the given type.  The remaining private attributes are not
139  *   @return initalized.  The type is in state layout_undefined.
140  *
141  */
142 INLINE type *
143 new_type(tp_op *type_op,
144          ir_mode *mode,
145          ident* name);
146 void free_type_attrs       (type *tp);
147
148 INLINE void free_class_attrs      (type *clss);
149 INLINE void free_struct_attrs     (type *strct);
150 INLINE void free_method_attrs     (type *method);
151 INLINE void free_union_attrs      (type *uni);
152 INLINE void free_array_attrs      (type *array);
153 INLINE void free_enumeration_attrs(type *enumeration);
154 INLINE void free_pointer_attrs    (type *pointer);
155 INLINE void free_primitive_attrs  (type *primitive);
156
157
158 /** initialize the type module */
159 void init_type (void);
160
161 # endif /* _TYPE_T_H_ */