fix local labels
[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_tag_t;
48 typedef unsigned char namespace_t;
49
50 typedef enum storage_class_tag_t {
51         STORAGE_CLASS_NONE,
52         STORAGE_CLASS_EXTERN,
53         STORAGE_CLASS_STATIC,
54         STORAGE_CLASS_TYPEDEF,
55         STORAGE_CLASS_AUTO,
56         STORAGE_CLASS_REGISTER,
57         STORAGE_CLASS_THREAD,
58         STORAGE_CLASS_THREAD_EXTERN,
59         STORAGE_CLASS_THREAD_STATIC,
60 } storage_class_tag_t;
61 typedef unsigned char storage_class_t;
62
63 typedef enum decl_modifier_t {
64         DM_DLLIMPORT         = 1 <<  0,
65         DM_DLLEXPORT         = 1 <<  1,
66         DM_THREAD            = 1 <<  2,
67         DM_NAKED             = 1 <<  3,
68         DM_MICROSOFT_INLINE  = 1 <<  4,
69         DM_FORCEINLINE       = 1 <<  5,
70         DM_SELECTANY         = 1 <<  6,
71         DM_NOTHROW           = 1 <<  7,
72         DM_NOVTABLE          = 1 <<  8,
73         DM_NORETURN          = 1 <<  9,
74         DM_NOINLINE          = 1 << 10,
75         DM_RESTRICT          = 1 << 11,
76         DM_NOALIAS           = 1 << 12,
77         DM_PACKED            = 1 << 13,
78         DM_TRANSPARENT_UNION = 1 << 14,
79         DM_CONST             = 1 << 15,
80         DM_PURE              = 1 << 16,
81         DM_CONSTRUCTOR       = 1 << 17,
82         DM_DESTRUCTOR        = 1 << 18,
83         DM_UNUSED            = 1 << 19,
84         DM_USED              = 1 << 20,
85         DM_CDECL             = 1 << 21,
86         DM_FASTCALL          = 1 << 22,
87         DM_STDCALL           = 1 << 23,
88         DM_THISCALL          = 1 << 24,
89         DM_DEPRECATED        = 1 << 25
90 } decl_modifier_t;
91
92 typedef unsigned decl_modifiers_t;
93
94 /**
95  * a named entity is something which can be referenced by its name
96  * (a symbol)
97  */
98 struct entity_base_t {
99         entity_kind_t       kind;
100         namespace_t         namespc;
101         symbol_t           *symbol;
102         source_position_t   source_position;
103         scope_t            *parent_scope;       /**< The parent scope where this declaration lives. */
104
105         /** next declaration in a scope */
106         entity_t           *next;
107         /** next declaration with same symbol */
108         entity_t           *symbol_next;
109 };
110
111 struct compound_t {
112         entity_base_t     base;
113         scope_t           members;
114         decl_modifiers_t  modifiers;
115         bool              complete            : 1;
116         bool              has_flexible_member : 1;
117
118         /* ast2firm info */
119         ir_type          *irtype;
120         bool              irtype_complete : 1;
121 };
122
123 struct enum_t {
124         entity_base_t  base;
125         bool           complete : 1;
126
127         /* ast2firm info */
128         ir_type       *irtype;
129 };
130
131 struct enum_value_t {
132         entity_base_t  base;
133         expression_t  *value;
134         type_t        *enum_type;
135
136         /* ast2firm info */
137         tarval        *tv;
138 };
139
140 struct label_t {
141         entity_base_t  base;
142         bool           used : 1;
143         bool           address_taken : 1;
144         statement_t   *statement;
145
146         /* ast2firm info */
147         ir_node       *block;
148 };
149
150 struct typedef_t {
151         entity_base_t     base;
152         decl_modifiers_t  modifiers;
153         type_t           *type;
154         bool              builtin : 1;
155 };
156
157 struct declaration_t {
158         entity_base_t     base;
159         storage_class_t   declared_storage_class;
160         storage_class_t   storage_class;
161         decl_modifiers_t  modifiers;
162         const char       *deprecated_string;  /**< MS deprecated string if any. */
163         bool              used          : 1;  /**< Set if the declaration is used. */
164         bool              implicit      : 1;  /**< Set for implicit (not found in source code) declarations. */
165         type_t           *type;
166
167         /* ast2firm info */
168         unsigned char     kind;
169 };
170
171 struct compound_member_t {
172         declaration_t  base;
173         bool           read : 1;
174
175         /* ast2firm info */
176         ir_entity *entity;
177         il_size_t  offset;  /**< The offset of this member inside a compound. */
178 };
179
180 struct variable_t {
181         declaration_t  base;
182         bool           address_taken : 1;  /**< Set if the address of this declaration was taken. */
183         bool           read          : 1;
184         unsigned char  alignment;          /**< Alignment of the declaration, 0 for default. */
185         symbol_t      *get_property_sym;   /**< MS get property. */
186         symbol_t      *put_property_sym;   /**< MS put property. */
187
188         initializer_t *initializer;
189
190         /* ast2firm info */
191         union {
192                 unsigned int  value_number;
193                 ir_entity    *entity;
194                 ir_node      *vla_base;
195         } v;
196 };
197
198 struct function_t {
199         declaration_t  base;
200         bool           is_inline     : 1;
201         bool           need_closure  : 1;  /**< Inner function needs closure. */
202         bool           goto_to_outer : 1;  /**< Inner function has goto to outer function. */
203
204         scope_t        parameters;
205         statement_t   *statement;
206
207         /* ast2firm info */
208         ir_entity     *entity;
209 };
210
211 union entity_t {
212         entity_kind_t      kind;
213         entity_base_t      base;
214         compound_t         structe;
215         compound_t         unione;
216         compound_t         compound;
217         enum_t             enume;
218         enum_value_t       enum_value;
219         label_t            label;
220         typedef_t          typedefe;
221         declaration_t      declaration;
222         variable_t         variable;
223         function_t         function;
224         compound_member_t  compound_member;
225 };
226
227 static inline bool is_declaration(const entity_t *entity)
228 {
229         return entity->kind == ENTITY_FUNCTION || entity->kind == ENTITY_VARIABLE
230                 || entity->kind == ENTITY_COMPOUND_MEMBER;
231 }
232
233 #endif