2 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Data type for unique names.
23 * @author Goetz Lindenmaier
26 * Declarations for identifiers in the firm library
28 * Identifiers are used in the firm library. This is the interface to it.
30 #ifndef FIRM_IDENT_IDENT_H
31 #define FIRM_IDENT_IDENT_H
33 #include "firm_config.h"
34 #include "firm_types.h"
36 #ifdef FIRM_ENABLE_WCHAR
43 * The ident module interface.
45 typedef struct _ident_if_t {
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.
54 * @param str - the string which shall be stored
56 ident *(*new_id_from_str)(void *handle, const char *str);
59 * Store a string and create an ident.
61 * @param str - the string (or whatever) which shall be stored
62 * @param len - the length of the data in bytes
64 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
67 * Returns a string represented by an ident.
69 const char *(*get_id_str)(void *handle, ident *id);
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.
76 * @param id - the ident
78 int (*get_id_strlen)(void *handle, ident *id);
81 * Finish the ident module and frees all idents, may be NULL.
83 void (*finish_ident)(void *handle);
85 #ifdef FIRM_ENABLE_WCHAR
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.
91 * @param wstr - the string which shall be stored
93 ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
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!
100 * @param wstr - the wide character string which shall be stored
101 * @param len - the length of the string
103 ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
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!
111 const wchar_t *(*get_id_wcs)(void *handle, ident *id);
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.
118 * @param id - the ident
120 int (*get_id_wcslen)(void *handle, ident *id);
125 * Store a string and create an ident.
127 * Stores a string in the ident module and returns a handle for the string.
129 * Copies the string. @p str must be zero terminated
131 * @param str - the string which shall be stored
133 * @return id - a handle for the generated ident
135 * @see get_id_str(), get_id_strlen()
137 ident *new_id_from_str (const char *str);
139 /** Store a string and create an ident.
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.
144 * @param str - the string (or whatever) which shall be stored
145 * @param len - the length of the data in bytes
147 * @return id - a handle for the generated ident
149 * @see new_id_from_str(), get_id_strlen()
151 ident *new_id_from_chars (const char *str, int len);
154 * Returns a string represented by an ident.
156 * Returns the string represented by id. This string is
157 * NULL terminated. The string may not be changed.
159 * @param id - the ident
161 * @return cp - a string
163 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
165 const char *get_id_str (ident *id);
168 * Returns the length of the string represented by an ident.
170 * @param id - the ident
172 * @return len - the length of the string
174 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
176 int get_id_strlen(ident *id);
179 * Returns true if prefix is a prefix of an ident.
181 * @param prefix - the prefix
182 * @param id - the ident
184 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
186 int id_is_prefix (ident *prefix, ident *id);
189 * Returns true if suffix is a suffix of an ident.
191 * @param suffix - the suffix
192 * @param id - the ident
194 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
196 int id_is_suffix (ident *suffix, ident *id);
199 * Returns true if infix is contained in id. (Can be suffix or prefix)
201 * @param infix - the infix
202 * @param id - the ident to search in
204 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
206 /* int id_contains(ident *infix, ident *id); */
209 * Return true if an ident contains a given character.
211 * @param id - the ident
212 * @param c - the character
214 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
216 int id_contains_char (ident *id, char c);
218 #ifdef FIRM_ENABLE_WCHAR
220 * Store a wide character string and create an ident.
222 * Stores a string in the ident module and returns a handle for the string.
224 * Copies the string. @p str must be zero terminated
226 * @param str - the wide character string which shall be stored
228 * @return id - a handle for the generated ident
230 * @see get_id_wcs(), get_id_wcs()
232 ident *new_id_from_wcs (const wchar_t *str);
234 /** Store a wide character string and create an ident.
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.
239 * @param wstr - the wide character string (or whatever) which shall be stored
240 * @param len - the length of string
242 * @return id - a handle for the generated ident
244 * @see new_id_from_str(), get_id_strlen()
246 ident *new_id_from_wchars (const wchar_t *str, int len);
249 * Returns a wide character string represented by an ident.
251 * Returns the string represented by id. This string is
252 * NULL terminated. The string may not be changed.
254 * @param id - the ident
256 * @return cp - a string
258 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
260 const wchar_t *get_id_wcs(ident *id);
263 * Returns the length of the wide character string represented by an ident.
265 * @param id - the ident
267 * @return len - the length of the string
269 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
271 int get_id_wcslen(ident *id);
274 * Return true if an ident contains a given character.
276 * @param id - the ident
277 * @param c - the character
279 * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
281 int id_contains_wchar (ident *id, wchar_t c);
283 #endif /* FIRM_ENABLE_WCHAR */
285 /** initializes the name mangling code */
286 void firm_init_mangle (void);
288 /** Computes a definite name for this entity by concatenating
289 the name of the owner type and the name of the entity with
291 ident *mangle_entity (ir_entity *ent);
293 /** mangle underscore: Returns a new ident that represents first_scnd. */
294 ident *mangle_u (ident *first, ident* scnd);
296 /** mangle dot: Returns a new ident that represents first.scnd. */
297 ident *mangle_dot (ident *first, ident* scnd);
299 /** mangle: Returns a new ident that represents firstscnd. */
300 ident *mangle (ident *first, ident* scnd);
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);