fixed a bunch of warnings (in OPTIMIZE mode)
[libfirm] / include / libfirm / ident.h
1 /*
2  * Copyright (C) 1995-2007 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 #ifdef FIRM_ENABLE_WCHAR
219 /**
220  *  Store a wide character string and create an ident.
221  *
222  *  Stores a string in the ident module and returns a handle for the string.
223  *
224  *  Copies the string. @p str must be zero terminated
225  *
226  * @param str - the wide character string which shall be stored
227  *
228  * @return id - a handle for the generated ident
229  *
230  * @see get_id_wcs(), get_id_wcs()
231  */
232 ident *new_id_from_wcs (const wchar_t *str);
233
234 /** Store a wide character string and create an ident.
235  *
236  * Stores a string in the ident module and returns a handle for the string.
237  * Copies the string. This version takes non-zero-terminated strings.
238  *
239  * @param wstr - the wide character string (or whatever) which shall be stored
240  * @param len  - the length of string
241  *
242  * @return id - a handle for the generated ident
243  *
244  * @see new_id_from_str(), get_id_strlen()
245  */
246 ident *new_id_from_wchars (const wchar_t *str, int len);
247
248 /**
249  * Returns a wide character string represented by an ident.
250  *
251  * Returns the string represented by id. This string is
252  * NULL terminated. The string may not be changed.
253  *
254  * @param id - the ident
255  *
256  * @return cp - a string
257  *
258  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
259  */
260 const wchar_t *get_id_wcs(ident *id);
261
262 /**
263  * Returns the length of the wide character string represented by an ident.
264  *
265  * @param id - the ident
266  *
267  * @return len - the length of the string
268  *
269  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
270  */
271 int  get_id_wcslen(ident *id);
272
273 /**
274  * Return true if an ident contains a given character.
275  *
276  * @param id     - the ident
277  * @param c      - the character
278  *
279  * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
280  */
281 int id_contains_wchar (ident *id, wchar_t c);
282
283 #endif /* FIRM_ENABLE_WCHAR */
284
285 /** initializes the name mangling code */
286 void   firm_init_mangle (void);
287
288 /** Computes a definite name for this entity by concatenating
289    the name of the owner type and the name of the entity with
290    a separating "_". */
291 ident *mangle_entity (ir_entity *ent);
292
293 /** mangle underscore: Returns a new ident that represents first_scnd. */
294 ident *mangle_u (ident *first, ident* scnd);
295
296 /** mangle dot: Returns a new ident that represents first.scnd. */
297 ident *mangle_dot (ident *first, ident* scnd);
298
299 /** mangle: Returns a new ident that represents firstscnd. */
300 ident *mangle   (ident *first, ident* scnd);
301
302 /** returns a mangled name for a Win32 function using it's calling convention */
303 ident *decorate_win32_c_fkt(ir_entity *ent, ident *id);
304
305 #endif