2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
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.
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.
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
26 #include "attribute.h"
27 #include <libfirm/firm_types.h>
32 ENTITY_COMPOUND_MEMBER,
44 typedef unsigned char entity_kind_t;
46 typedef enum namespace_tag_t {
52 typedef unsigned char entity_namespace_t;
54 typedef enum storage_class_tag_t {
58 STORAGE_CLASS_TYPEDEF,
60 STORAGE_CLASS_REGISTER,
61 } storage_class_tag_t;
62 typedef unsigned char storage_class_t;
64 typedef enum decl_modifier_t {
66 DM_DLLIMPORT = 1 << 0,
67 DM_DLLEXPORT = 1 << 1,
70 DM_MICROSOFT_INLINE = 1 << 4,
71 DM_FORCEINLINE = 1 << 5,
72 DM_SELECTANY = 1 << 6,
76 DM_NOINLINE = 1 << 10,
77 DM_RESTRICT = 1 << 11,
79 DM_TRANSPARENT_UNION = 1 << 13,
82 DM_CONSTRUCTOR = 1 << 16,
83 DM_DESTRUCTOR = 1 << 17,
87 DM_FASTCALL = 1 << 21,
89 DM_THISCALL = 1 << 23,
90 DM_DEPRECATED = 1 << 24,
91 DM_RETURNS_TWICE = 1 << 25,
96 * A scope containing entities.
100 entity_t *last_entity;
101 unsigned depth; /**< while parsing, the depth of this scope in the
106 * a named entity is something which can be referenced by its name
109 struct entity_base_t {
111 entity_namespace_t namespc;
113 source_position_t source_position;
114 scope_t *parent_scope; /**< The scope where this entity
117 /** next declaration in a scope */
119 /** next declaration with same symbol */
120 entity_t *symbol_next;
125 entity_t *alias; /* used for name mangling of anonymous types */
127 decl_modifiers_t modifiers;
130 bool transparent_union : 1;
133 il_alignment_t alignment;
138 bool irtype_complete : 1;
143 entity_t *alias; /* used for name mangling of anonymous types */
150 struct enum_value_t {
162 bool address_taken : 1;
163 statement_t *statement;
176 decl_modifiers_t modifiers;
178 il_alignment_t alignment;
182 struct declaration_t {
185 storage_class_t declared_storage_class;
186 storage_class_t storage_class;
187 decl_modifiers_t modifiers;
188 il_alignment_t alignment;
189 attribute_t *attributes;
190 bool used : 1; /**< Set if the declaration is used. */
191 bool implicit : 1; /**< Set for implicit (not found in source code) declarations. */
197 struct compound_member_t {
200 bool address_taken : 1; /**< Set if the address of this declaration was taken. */
201 unsigned short offset; /**< the offset of this member in the compound */
202 unsigned char bit_offset; /**< extra bit offset for bitfield members */
210 bool thread_local : 1; /**< GCC __thread */
215 bool address_taken : 1; /**< Set if the address of this declaration was taken. */
218 initializer_t *initializer;
222 unsigned int value_number;
230 bool address_taken : 1;
235 unsigned int value_number;
241 * GNU builtin or MS intrinsic functions.
243 typedef enum builtin_kind_t {
244 bk_none = 0, /**< no builtin */
245 bk_gnu_builtin_alloca, /**< GNU __builtin_alloca */
246 bk_gnu_builtin_huge_val, /**< GNU __builtin_huge_val */
247 bk_gnu_builtin_inf, /**< GNU __builtin_inf */
248 bk_gnu_builtin_inff, /**< GNU __builtin_inff */
249 bk_gnu_builtin_infl, /**< GNU __builtin_infl */
250 bk_gnu_builtin_nan, /**< GNU __builtin_nan */
251 bk_gnu_builtin_nanf, /**< GNU __builtin_nanf */
252 bk_gnu_builtin_nanl, /**< GNU __builtin_nanl */
253 bk_gnu_builtin_va_end, /**< GNU __builtin_va_end */
254 bk_gnu_builtin_expect, /**< GNU __builtin_expect */
255 bk_gnu_builtin_return_address, /**< GNU __builtin_return_address */
256 bk_gnu_builtin_frame_address, /**< GNU __builtin_frame_address */
257 bk_gnu_builtin_ffs, /**< GNU __builtin_ffs */
258 bk_gnu_builtin_clz, /**< GNU __builtin_clz */
259 bk_gnu_builtin_ctz, /**< GNU __builtin_ctz */
260 bk_gnu_builtin_popcount, /**< GNU __builtin_popcount */
261 bk_gnu_builtin_parity, /**< GNU __builtin_parity */
262 bk_gnu_builtin_prefetch, /**< GNU __builtin_prefetch */
263 bk_gnu_builtin_trap, /**< GNU __builtin_trap */
265 bk_ms_rotl, /**< MS _rotl */
266 bk_ms_rotr, /**< MS _rotr */
267 bk_ms_rotl64, /**< MS _rotl64 */
268 bk_ms_rotr64, /**< MS _rotr64 */
269 bk_ms_byteswap_ushort, /**< MS _byteswap_ushort */
270 bk_ms_byteswap_ulong, /**< MS _byteswap_ulong */
271 bk_ms_byteswap_uint64, /**< MS _byteswap_uint64 */
273 bk_ms__debugbreak, /**< MS __debugbreak */
274 bk_ms_ReturnAddress, /**< MS _ReturnAddress */
275 bk_ms_AddressOfReturnAddress, /**< MS _AddressOfReturnAddress */
276 bk_ms__popcount, /**< MS __popcount */
277 bk_ms_enable, /**< MS _enable */
278 bk_ms_disable, /**< MS _disable */
279 bk_ms__inbyte, /**< MS __inbyte */
280 bk_ms__inword, /**< MS __inword */
281 bk_ms__indword, /**< MS __indword */
282 bk_ms__outbyte, /**< MS __outbyte */
283 bk_ms__outword, /**< MS __outword */
284 bk_ms__outdword, /**< MS __outdword */
285 bk_ms__ud2, /**< MS __ud2 */
286 bk_ms_BitScanForward, /**< MS _BitScanForward */
287 bk_ms_BitScanReverse, /**< MS _BitScanReverse */
288 bk_ms_InterlockedExchange, /**< MS _InterlockedExchange */
289 bk_ms_InterlockedExchange64, /**< MS _InterlockedExchange64 */
290 bk_ms__readeflags, /**< MS __readflags */
291 bk_ms__writeeflags, /**< MS __writeflags */
298 bool need_closure : 1; /**< Inner function needs closure. */
299 bool goto_to_outer : 1; /**< Inner function has goto to outer function. */
303 statement_t *statement;
307 ir_node *static_link; /**< if need_closure is set, the node representing
318 enum_value_t enum_value;
320 namespace_t namespacee;
322 declaration_t declaration;
324 parameter_t parameter;
326 compound_member_t compound_member;
329 #define DECLARATION_KIND_CASES \
330 case ENTITY_FUNCTION: \
331 case ENTITY_VARIABLE: \
332 case ENTITY_PARAMETER: \
333 case ENTITY_COMPOUND_MEMBER:
335 static inline bool is_declaration(const entity_t *entity)
337 switch(entity->kind) {
338 DECLARATION_KIND_CASES
345 const char *get_entity_kind_name(entity_kind_t kind);