- add tarval_top and tarval_bottom as alias for tarval_undefined and tarval_bad
[libfirm] / include / libfirm / ident.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Data type for unique names.
23  * @author   Goetz Lindenmaier
24  * @version  $Id$
25  * @summary
26  *  Declarations for identifiers in the firm library
27  *
28  *  Identifiers are used in the firm library. This is the interface to it.
29  */
30 #ifndef FIRM_IDENT_IDENT_H
31 #define FIRM_IDENT_IDENT_H
32
33 #include "firm_config.h"
34 #include "firm_types.h"
35
36 #ifdef FIRM_ENABLE_WCHAR
37 #include <wchar.h>
38 #endif
39
40 /* Identifiers */
41
42 /**
43  * The ident module interface.
44  */
45 typedef struct _ident_if_t {
46   /** The handle. */
47   void *handle;
48
49   /**
50    * Store a string and create an ident.
51    * This function may be NULL, new_id_from_chars()
52    * is then used to emulate it's behavior.
53    *
54    * @param str - the string which shall be stored
55    */
56   ident *(*new_id_from_str)(void *handle, const char *str);
57
58   /**
59    * Store a string and create an ident.
60    *
61    * @param str - the string (or whatever) which shall be stored
62    * @param len - the length of the data in bytes
63    */
64   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
65
66   /**
67    * Returns a string represented by an ident.
68    */
69   const char *(*get_id_str)(void *handle, ident *id);
70
71   /**
72    * Returns the length of the string represented by an ident.
73    * This function may be NULL, get_id_str() is then used
74    * to emulate it's behavior.
75    *
76    * @param id - the ident
77    */
78   int  (*get_id_strlen)(void *handle, ident *id);
79
80   /**
81    * Finish the ident module and frees all idents, may be NULL.
82    */
83   void (*finish_ident)(void *handle);
84
85 #ifdef FIRM_ENABLE_WCHAR
86   /**
87    * Store a wide character string and create an ident.
88    * This function may be NULL, new_id_from_wchars()
89    * is then used to emulate it's behavior.
90    *
91    * @param wstr - the string which shall be stored
92    */
93   ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
94
95   /**
96    * Store a wide character string and create an ident.
97    * This function may be NULL, new_id_from_chars() is then used appropriate.
98    * Beware: the string might not be stored at a right alignment!
99    *
100    * @param wstr - the wide character string which shall be stored
101    * @param len  - the length of the string
102    */
103   ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
104
105   /**
106    * Returns a wide character string represented by an ident.
107    * This function may be NULL, get_id_str() is then used.
108    * This assume that the strings are stored at an address aligned
109    * for wchar_t, so beware!
110    */
111   const wchar_t *(*get_id_wcs)(void *handle, ident *id);
112
113   /**
114    * Returns the length of the string represented by an ident.
115    * This function may be NULL, get_id_wcs() is then used
116    * to emulate it's behavior.
117    *
118    * @param id - the ident
119    */
120   int  (*get_id_wcslen)(void *handle, ident *id);
121 #endif
122 } ident_if_t;
123
124 /**
125  *  Store a string and create an ident.
126  *
127  *  Stores a string in the ident module and returns a handle for the string.
128  *
129  *  Copies the string. @p str must be zero terminated
130  *
131  * @param str - the string which shall be stored
132  *
133  * @return id - a handle for the generated ident
134  *
135  * @see get_id_str(), get_id_strlen()
136  */
137 ident *new_id_from_str (const char *str);
138
139 /** Store a string and create an ident.
140  *
141  * Stores a string in the ident module and returns a handle for the string.
142  * Copies the string. This version takes non-zero-terminated strings.
143  *
144  * @param str - the string (or whatever) which shall be stored
145  * @param len - the length of the data in bytes
146  *
147  * @return id - a handle for the generated ident
148  *
149  * @see new_id_from_str(), get_id_strlen()
150  */
151 ident *new_id_from_chars (const char *str, int len);
152
153 /**
154  * Returns a string represented by an ident.
155  *
156  * Returns the string represented by id. This string is
157  * NULL terminated. The string may not be changed.
158  *
159  * @param id - the ident
160  *
161  * @return cp - a string
162  *
163  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
164  */
165 const char *get_id_str  (ident *id);
166
167 /**
168  * Returns the length of the string represented by an ident.
169  *
170  * @param id - the ident
171  *
172  * @return len - the length of the string
173  *
174  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
175  */
176 int  get_id_strlen(ident *id);
177
178 /**
179  * Returns true if prefix is a prefix of an ident.
180  *
181  * @param prefix - the prefix
182  * @param id     - the ident
183  *
184  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
185  */
186 int id_is_prefix (ident *prefix, ident *id);
187
188 /**
189  * Returns true if suffix is a suffix of an ident.
190  *
191  * @param suffix - the suffix
192  * @param id     - the ident
193  *
194  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
195  */
196 int id_is_suffix (ident *suffix, ident *id);
197
198 /**
199  * Returns true if infix is contained in id.  (Can be suffix or prefix)
200  *
201  * @param infix  - the infix
202  * @param id     - the ident to search in
203  *
204  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
205  */
206 /* int id_contains(ident *infix, ident *id); */
207
208 /**
209  * Return true if an ident contains a given character.
210  *
211  * @param id     - the ident
212  * @param c      - the character
213  *
214  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
215  */
216 int id_contains_char (ident *id, char c);
217
218 /**
219  * helper function for creating unique idents. It contains an internal counter
220  * and replaces a "%u" inside the tag with the counter.
221  */
222 ident *id_unique(const char *tag);
223
224 #ifdef FIRM_ENABLE_WCHAR
225 /**
226  *  Store a wide character string and create an ident.
227  *
228  *  Stores a string in the ident module and returns a handle for the string.
229  *
230  *  Copies the string. @p str must be zero terminated
231  *
232  * @param str - the wide character string which shall be stored
233  *
234  * @return id - a handle for the generated ident
235  *
236  * @see get_id_wcs(), get_id_wcs()
237  */
238 ident *new_id_from_wcs (const wchar_t *str);
239
240 /** Store a wide character string and create an ident.
241  *
242  * Stores a string in the ident module and returns a handle for the string.
243  * Copies the string. This version takes non-zero-terminated strings.
244  *
245  * @param wstr - the wide character string (or whatever) which shall be stored
246  * @param len  - the length of string
247  *
248  * @return id - a handle for the generated ident
249  *
250  * @see new_id_from_str(), get_id_strlen()
251  */
252 ident *new_id_from_wchars (const wchar_t *str, int len);
253
254 /**
255  * Returns a wide character string represented by an ident.
256  *
257  * Returns the string represented by id. This string is
258  * NULL terminated. The string may not be changed.
259  *
260  * @param id - the ident
261  *
262  * @return cp - a string
263  *
264  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
265  */
266 const wchar_t *get_id_wcs(ident *id);
267
268 /**
269  * Returns the length of the wide character string represented by an ident.
270  *
271  * @param id - the ident
272  *
273  * @return len - the length of the string
274  *
275  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
276  */
277 int  get_id_wcslen(ident *id);
278
279 /**
280  * Return true if an ident contains a given character.
281  *
282  * @param id     - the ident
283  * @param c      - the character
284  *
285  * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
286  */
287 int id_contains_wchar (ident *id, wchar_t c);
288
289 #endif /* FIRM_ENABLE_WCHAR */
290
291 /** initializes the name mangling code */
292 void   firm_init_mangle (void);
293
294 /** Computes a definite name for this entity by concatenating
295    the name of the owner type and the name of the entity with
296    a separating "_". */
297 ident *mangle_entity (ir_entity *ent);
298
299 /** mangle underscore: Returns a new ident that represents first_scnd. */
300 ident *mangle_u (ident *first, ident* scnd);
301
302 /** mangle dot: Returns a new ident that represents first.scnd. */
303 ident *mangle_dot (ident *first, ident* scnd);
304
305 /** mangle: Returns a new ident that represents firstscnd. */
306 ident *mangle   (ident *first, ident* scnd);
307
308 /** Returns a new ident that represents 'prefixscndsuffix'. */
309 ident *mangle3 (const char *prefix, ident *middle, const char *suffix);
310
311 /** returns a mangled name for a Win32 function using it's calling convention */
312 ident *decorate_win32_c_fkt(ir_entity *ent, ident *id);
313
314 #endif