get rid of scope->parent
[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_tag_t;
61 typedef unsigned char storage_class_t;
62
63 typedef enum decl_modifier_t {
64         DM_NONE              = 0,
65         DM_DLLIMPORT         = 1 <<  0,
66         DM_DLLEXPORT         = 1 <<  1,
67         DM_THREAD            = 1 <<  2,
68         DM_NAKED             = 1 <<  3,
69         DM_MICROSOFT_INLINE  = 1 <<  4,
70         DM_FORCEINLINE       = 1 <<  5,
71         DM_SELECTANY         = 1 <<  6,
72         DM_NOTHROW           = 1 <<  7,
73         DM_NOVTABLE          = 1 <<  8,
74         DM_NORETURN          = 1 <<  9,
75         DM_NOINLINE          = 1 << 10,
76         DM_RESTRICT          = 1 << 11,
77         DM_NOALIAS           = 1 << 12,
78         DM_PACKED            = 1 << 13,
79         DM_TRANSPARENT_UNION = 1 << 14,
80         DM_CONST             = 1 << 15,
81         DM_PURE              = 1 << 16,
82         DM_CONSTRUCTOR       = 1 << 17,
83         DM_DESTRUCTOR        = 1 << 18,
84         DM_UNUSED            = 1 << 19,
85         DM_USED              = 1 << 20,
86         DM_CDECL             = 1 << 21,
87         DM_FASTCALL          = 1 << 22,
88         DM_STDCALL           = 1 << 23,
89         DM_THISCALL          = 1 << 24,
90         DM_DEPRECATED        = 1 << 25
91 } decl_modifier_t;
92
93 typedef unsigned decl_modifiers_t;
94
95 /**
96  * A scope containing entities.
97  */
98 struct scope_t {
99         entity_t *entities;
100         entity_t *last_entity;
101         unsigned  depth;        /**< while parsing, the depth of this scope in the
102                                      scope stack. */
103 };
104
105 /**
106  * a named entity is something which can be referenced by its name
107  * (a symbol)
108  */
109 struct entity_base_t {
110         entity_kind_t       kind;
111         entity_namespace_t  namespc;
112         symbol_t           *symbol;
113         source_position_t   source_position;
114         scope_t            *parent_scope;    /**< The scope where this entity
115                                                                                       is contained in */
116
117         /** next declaration in a scope */
118         entity_t           *next;
119         /** next declaration with same symbol */
120         entity_t           *symbol_next;
121 };
122
123 struct compound_t {
124         entity_base_t     base;
125         entity_t         *alias; /* used for name mangling of anonymous types */
126         scope_t           members;
127         decl_modifiers_t  modifiers;
128         bool              complete            : 1;
129         bool              has_flexible_member : 1;
130
131         /* ast2firm info */
132         ir_type          *irtype;
133         bool              irtype_complete : 1;
134 };
135
136 struct enum_t {
137         entity_base_t  base;
138         entity_t      *alias; /* used for name mangling of anonymous types */
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           thread_local  : 1;  /**< GCC __thread */
202         bool           address_taken : 1;  /**< Set if the address of this declaration was taken. */
203         bool           read          : 1;
204         unsigned char  alignment;          /**< Alignment of the declaration, 0 for default. */
205         symbol_t      *get_property_sym;   /**< MS get property. */
206         symbol_t      *put_property_sym;   /**< MS put property. */
207
208         initializer_t *initializer;
209
210         /* ast2firm info */
211         union {
212                 unsigned int  value_number;
213                 ir_entity    *entity;
214                 ir_node      *vla_base;
215         } v;
216 };
217
218 struct function_t {
219         declaration_t  base;
220         bool           is_inline     : 1;
221         bool           need_closure  : 1;  /**< Inner function needs closure. */
222         bool           goto_to_outer : 1;  /**< Inner function has goto to outer function. */
223
224         scope_t        parameters;
225         statement_t   *statement;
226
227         /* ast2firm info */
228         ir_entity     *entity;
229 };
230
231 union entity_t {
232         entity_kind_t      kind;
233         entity_base_t      base;
234         compound_t         structe;
235         compound_t         unione;
236         compound_t         compound;
237         enum_t             enume;
238         enum_value_t       enum_value;
239         label_t            label;
240         namespace_t        namespacee;
241         typedef_t          typedefe;
242         declaration_t      declaration;
243         variable_t         variable;
244         function_t         function;
245         compound_member_t  compound_member;
246 };
247
248 static inline bool is_declaration(const entity_t *entity)
249 {
250         return entity->kind == ENTITY_FUNCTION || entity->kind == ENTITY_VARIABLE
251                 || entity->kind == ENTITY_COMPOUND_MEMBER;
252 }
253
254 #endif