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