More work for C++ mode:
[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
27 typedef enum {
28         ENTITY_INVALID,
29         ENTITY_VARIABLE,
30         ENTITY_COMPOUND_MEMBER,
31         ENTITY_FUNCTION,
32         ENTITY_TYPEDEF,
33         ENTITY_STRUCT,
34         ENTITY_UNION,
35         ENTITY_ENUM,
36         ENTITY_ENUM_VALUE,
37         ENTITY_LABEL,
38         ENTITY_LOCAL_LABEL,
39         ENTITY_NAMESPACE
40 } entity_kind_tag_t;
41 typedef unsigned char entity_kind_t;
42
43 typedef enum namespace_tag_t {
44         NAMESPACE_INVALID,
45         NAMESPACE_NORMAL,
46         NAMESPACE_STRUCT,
47         NAMESPACE_UNION,
48         NAMESPACE_ENUM,
49         NAMESPACE_LABEL
50 } namespace_tag_t;
51 typedef unsigned char entity_namespace_t;
52
53 typedef enum storage_class_tag_t {
54         STORAGE_CLASS_NONE,
55         STORAGE_CLASS_EXTERN,
56         STORAGE_CLASS_STATIC,
57         STORAGE_CLASS_TYPEDEF,
58         STORAGE_CLASS_AUTO,
59         STORAGE_CLASS_REGISTER,
60         STORAGE_CLASS_THREAD,
61         STORAGE_CLASS_THREAD_EXTERN,
62         STORAGE_CLASS_THREAD_STATIC,
63 } storage_class_tag_t;
64 typedef unsigned char storage_class_t;
65
66 typedef enum decl_modifier_t {
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         scope_t  *parent;       /**< points to the parent scope. */
104         unsigned  depth;        /**< while parsing, the depth of this scope in the
105                                      scope stack. */
106 };
107
108 /**
109  * a named entity is something which can be referenced by its name
110  * (a symbol)
111  */
112 struct entity_base_t {
113         entity_kind_t       kind;
114         entity_namespace_t  namespc;
115         symbol_t           *symbol;
116         source_position_t   source_position;
117         scope_t            *parent_scope;       /**< The parent scope where this declaration lives. */
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         scope_t           members;
128         decl_modifiers_t  modifiers;
129         bool              complete            : 1;
130         bool              has_flexible_member : 1;
131
132         /* ast2firm info */
133         ir_type          *irtype;
134         bool              irtype_complete : 1;
135 };
136
137 struct enum_t {
138         entity_base_t  base;
139         bool           complete : 1;
140
141         /* ast2firm info */
142         ir_type       *irtype;
143 };
144
145 struct enum_value_t {
146         entity_base_t  base;
147         expression_t  *value;
148         type_t        *enum_type;
149
150         /* ast2firm info */
151         tarval        *tv;
152 };
153
154 struct label_t {
155         entity_base_t  base;
156         bool           used : 1;
157         bool           address_taken : 1;
158         statement_t   *statement;
159
160         /* ast2firm info */
161         ir_node       *block;
162 };
163
164 struct namespace_t {
165         entity_base_t  base;
166         scope_t        members;
167 };
168
169 struct typedef_t {
170         entity_base_t     base;
171         decl_modifiers_t  modifiers;
172         type_t           *type;
173         bool              builtin : 1;
174 };
175
176 struct declaration_t {
177         entity_base_t     base;
178         storage_class_t   declared_storage_class;
179         storage_class_t   storage_class;
180         decl_modifiers_t  modifiers;
181         const char       *deprecated_string;  /**< MS deprecated string if any. */
182         bool              used          : 1;  /**< Set if the declaration is used. */
183         bool              implicit      : 1;  /**< Set for implicit (not found in source code) declarations. */
184         type_t           *type;
185
186         /* ast2firm info */
187         unsigned char     kind;
188 };
189
190 struct compound_member_t {
191         declaration_t  base;
192         bool           read : 1;
193
194         /* ast2firm info */
195         ir_entity *entity;
196         il_size_t  offset;  /**< The offset of this member inside a compound. */
197 };
198
199 struct variable_t {
200         declaration_t  base;
201         bool           address_taken : 1;  /**< Set if the address of this declaration was taken. */
202         bool           read          : 1;
203         unsigned char  alignment;          /**< Alignment of the declaration, 0 for default. */
204         symbol_t      *get_property_sym;   /**< MS get property. */
205         symbol_t      *put_property_sym;   /**< MS put property. */
206
207         initializer_t *initializer;
208
209         /* ast2firm info */
210         union {
211                 unsigned int  value_number;
212                 ir_entity    *entity;
213                 ir_node      *vla_base;
214         } v;
215 };
216
217 struct function_t {
218         declaration_t  base;
219         bool           is_inline     : 1;
220         bool           need_closure  : 1;  /**< Inner function needs closure. */
221         bool           goto_to_outer : 1;  /**< Inner function has goto to outer function. */
222
223         scope_t        parameters;
224         statement_t   *statement;
225
226         /* ast2firm info */
227         ir_entity     *entity;
228 };
229
230 union entity_t {
231         entity_kind_t      kind;
232         entity_base_t      base;
233         compound_t         structe;
234         compound_t         unione;
235         compound_t         compound;
236         enum_t             enume;
237         enum_value_t       enum_value;
238         label_t            label;
239         namespace_t        namespacee;
240         typedef_t          typedefe;
241         declaration_t      declaration;
242         variable_t         variable;
243         function_t         function;
244         compound_member_t  compound_member;
245 };
246
247 static inline bool is_declaration(const entity_t *entity)
248 {
249         return entity->kind == ENTITY_FUNCTION || entity->kind == ENTITY_VARIABLE
250                 || entity->kind == ENTITY_COMPOUND_MEMBER;
251 }
252
253 #endif