- Introduce ENTITY_PARAMETER
[cparser] / entity_t.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #ifndef ENTITY_T_H
21 #define ENTITY_T_H
22
23 #include "lexer.h"
24 #include "symbol.h"
25 #include "entity.h"
26 #include <libfirm/firm_types.h>
27
28 typedef enum {
29         ENTITY_INVALID,
30         ENTITY_VARIABLE,
31         ENTITY_COMPOUND_MEMBER,
32         ENTITY_PARAMETER,
33         ENTITY_FUNCTION,
34         ENTITY_TYPEDEF,
35         ENTITY_STRUCT,
36         ENTITY_UNION,
37         ENTITY_ENUM,
38         ENTITY_ENUM_VALUE,
39         ENTITY_LABEL,
40         ENTITY_LOCAL_LABEL,
41         ENTITY_NAMESPACE
42 } entity_kind_tag_t;
43 typedef unsigned char entity_kind_t;
44
45 typedef enum namespace_tag_t {
46         NAMESPACE_INVALID,
47         NAMESPACE_NORMAL,
48         NAMESPACE_STRUCT,
49         NAMESPACE_UNION,
50         NAMESPACE_ENUM,
51         NAMESPACE_LABEL
52 } namespace_tag_t;
53 typedef unsigned char entity_namespace_t;
54
55 typedef enum storage_class_tag_t {
56         STORAGE_CLASS_NONE,
57         STORAGE_CLASS_EXTERN,
58         STORAGE_CLASS_STATIC,
59         STORAGE_CLASS_TYPEDEF,
60         STORAGE_CLASS_AUTO,
61         STORAGE_CLASS_REGISTER,
62 } storage_class_tag_t;
63 typedef unsigned char storage_class_t;
64
65 typedef enum decl_modifier_t {
66         DM_NONE              = 0,
67         DM_DLLIMPORT         = 1 <<  0,
68         DM_DLLEXPORT         = 1 <<  1,
69         DM_THREAD            = 1 <<  2,
70         DM_NAKED             = 1 <<  3,
71         DM_MICROSOFT_INLINE  = 1 <<  4,
72         DM_FORCEINLINE       = 1 <<  5,
73         DM_SELECTANY         = 1 <<  6,
74         DM_NOTHROW           = 1 <<  7,
75         DM_NOVTABLE          = 1 <<  8,
76         DM_NORETURN          = 1 <<  9,
77         DM_NOINLINE          = 1 << 10,
78         DM_RESTRICT          = 1 << 11,
79         DM_NOALIAS           = 1 << 12,
80         DM_PACKED            = 1 << 13,
81         DM_TRANSPARENT_UNION = 1 << 14,
82         DM_CONST             = 1 << 15,
83         DM_PURE              = 1 << 16,
84         DM_CONSTRUCTOR       = 1 << 17,
85         DM_DESTRUCTOR        = 1 << 18,
86         DM_UNUSED            = 1 << 19,
87         DM_USED              = 1 << 20,
88         DM_CDECL             = 1 << 21,
89         DM_FASTCALL          = 1 << 22,
90         DM_STDCALL           = 1 << 23,
91         DM_THISCALL          = 1 << 24,
92         DM_DEPRECATED        = 1 << 25
93 } decl_modifier_t;
94
95 typedef unsigned decl_modifiers_t;
96
97 /**
98  * A scope containing entities.
99  */
100 struct scope_t {
101         entity_t *entities;
102         entity_t *last_entity;
103         unsigned  depth;        /**< while parsing, the depth of this scope in the
104                                      scope stack. */
105 };
106
107 /**
108  * a named entity is something which can be referenced by its name
109  * (a symbol)
110  */
111 struct entity_base_t {
112         entity_kind_t       kind;
113         entity_namespace_t  namespc;
114         symbol_t           *symbol;
115         source_position_t   source_position;
116         scope_t            *parent_scope;    /**< The scope where this entity
117                                                                                       is contained in */
118
119         /** next declaration in a scope */
120         entity_t           *next;
121         /** next declaration with same symbol */
122         entity_t           *symbol_next;
123 };
124
125 struct compound_t {
126         entity_base_t     base;
127         entity_t         *alias; /* used for name mangling of anonymous types */
128         scope_t           members;
129         decl_modifiers_t  modifiers;
130         bool              complete            : 1;
131         bool              has_flexible_member : 1;
132
133         /* ast2firm info */
134         ir_type          *irtype;
135         bool              irtype_complete : 1;
136 };
137
138 struct enum_t {
139         entity_base_t  base;
140         entity_t      *alias; /* used for name mangling of anonymous types */
141         bool           complete : 1;
142
143         /* ast2firm info */
144         ir_type       *irtype;
145 };
146
147 struct enum_value_t {
148         entity_base_t  base;
149         expression_t  *value;
150         type_t        *enum_type;
151
152         /* ast2firm info */
153         tarval        *tv;
154 };
155
156 struct label_t {
157         entity_base_t  base;
158         bool           used : 1;
159         bool           address_taken : 1;
160         statement_t   *statement;
161
162         /* ast2firm info */
163         ir_node       *block;
164 };
165
166 struct namespace_t {
167         entity_base_t  base;
168         scope_t        members;
169 };
170
171 struct typedef_t {
172         entity_base_t     base;
173         decl_modifiers_t  modifiers;
174         type_t           *type;
175         bool              builtin : 1;
176 };
177
178 struct declaration_t {
179         entity_base_t     base;
180         storage_class_t   declared_storage_class;
181         storage_class_t   storage_class;
182         decl_modifiers_t  modifiers;
183         const char       *deprecated_string;  /**< MS deprecated string if any. */
184         bool              used          : 1;  /**< Set if the declaration is used. */
185         bool              implicit      : 1;  /**< Set for implicit (not found in source code) declarations. */
186         type_t           *type;
187
188         /* ast2firm info */
189         unsigned char     kind;
190 };
191
192 struct compound_member_t {
193         declaration_t  base;
194         bool           read          : 1;
195         bool           address_taken : 1;  /**< Set if the address of this declaration was taken. */
196
197         /* ast2firm info */
198         ir_entity *entity;
199         il_size_t  offset;  /**< The offset of this member inside a compound. */
200 };
201
202 struct variable_t {
203         declaration_t  base;
204         bool           thread_local  : 1;  /**< GCC __thread */
205         bool           address_taken : 1;  /**< Set if the address of this declaration was taken. */
206         bool           read          : 1;
207         unsigned char  alignment;          /**< Alignment of the declaration, 0 for default. */
208         symbol_t      *get_property_sym;   /**< MS get property. */
209         symbol_t      *put_property_sym;   /**< MS put property. */
210
211         initializer_t *initializer;
212
213         /* ast2firm info */
214         union {
215                 unsigned int  value_number;
216                 ir_entity    *entity;
217                 ir_node      *vla_base;
218         } v;
219 };
220
221 struct parameter_t {
222         declaration_t  base;
223         bool           address_taken : 1;
224         bool           read          : 1;
225
226         /* ast2firm info */
227         union {
228                 unsigned int  value_number;
229                 ir_entity    *entity;
230         } v;
231 };
232
233 struct function_t {
234         declaration_t  base;
235         bool           is_inline     : 1;
236         bool           need_closure  : 1;  /**< Inner function needs closure. */
237         bool           goto_to_outer : 1;  /**< Inner function has goto to outer function. */
238
239         scope_t        parameters;
240         statement_t   *statement;
241
242         /* ast2firm info */
243         ir_entity     *entity;
244 };
245
246 union entity_t {
247         entity_kind_t      kind;
248         entity_base_t      base;
249         compound_t         structe;
250         compound_t         unione;
251         compound_t         compound;
252         enum_t             enume;
253         enum_value_t       enum_value;
254         label_t            label;
255         namespace_t        namespacee;
256         typedef_t          typedefe;
257         declaration_t      declaration;
258         variable_t         variable;
259         parameter_t        parameter;
260         function_t         function;
261         compound_member_t  compound_member;
262 };
263
264 static inline bool is_declaration(const entity_t *entity)
265 {
266         return entity->kind == ENTITY_FUNCTION || entity->kind == ENTITY_VARIABLE
267                 || entity->kind == ENTITY_PARAMETER
268                 || entity->kind == ENTITY_COMPOUND_MEMBER;
269 }
270
271
272 const char *get_entity_kind_name(entity_kind_t kind);
273
274 #endif