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"
35 #ifdef FIRM_ENABLE_WCHAR
46 * The abstract data type ident.
48 * An ident represents an unique string. The == operator
49 * is sufficient to compare two idents.
51 #ifndef _IDENT_TYPEDEF_
52 #define _IDENT_TYPEDEF_
53 typedef const struct _ident ident;
57 * The ident module interface.
59 typedef struct _ident_if_t {
64 * Store a string and create an ident.
65 * This function may be NULL, new_id_from_chars()
66 * is then used to emulate it's behavior.
68 * @param str - the string which shall be stored
70 ident *(*new_id_from_str)(void *handle, const char *str);
73 * Store a string and create an ident.
75 * @param str - the string (or whatever) which shall be stored
76 * @param len - the length of the data in bytes
78 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
81 * Returns a string represented by an ident.
83 const char *(*get_id_str)(void *handle, ident *id);
86 * Returns the length of the string represented by an ident.
87 * This function may be NULL, get_id_str() is then used
88 * to emulate it's behavior.
90 * @param id - the ident
92 int (*get_id_strlen)(void *handle, ident *id);
95 * Finish the ident module and frees all idents, may be NULL.
97 void (*finish_ident)(void *handle);
99 #ifdef FIRM_ENABLE_WCHAR
101 * Store a wide character string and create an ident.
102 * This function may be NULL, new_id_from_wchars()
103 * is then used to emulate it's behavior.
105 * @param wstr - the string which shall be stored
107 ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
110 * Store a wide character string and create an ident.
111 * This function may be NULL, new_id_from_chars() is then used appropriate.
112 * Beware: the string might not be stored at a right alignment!
114 * @param wstr - the wide character string which shall be stored
115 * @param len - the length of the string
117 ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
120 * Returns a wide character string represented by an ident.
121 * This function may be NULL, get_id_str() is then used.
122 * This assume that the strings are stored at an address aligned
123 * for wchar_t, so beware!
125 const wchar_t *(*get_id_wcs)(void *handle, ident *id);
128 * Returns the length of the string represented by an ident.
129 * This function may be NULL, get_id_wcs() is then used
130 * to emulate it's behavior.
132 * @param id - the ident
134 int (*get_id_wcslen)(void *handle, ident *id);
139 * Store a string and create an ident.
141 * Stores a string in the ident module and returns a handle for the string.
143 * Copies the string. @p str must be zero terminated
145 * @param str - the string which shall be stored
147 * @return id - a handle for the generated ident
149 * @see get_id_str(), get_id_strlen()
151 ident *new_id_from_str (const char *str);
153 /** Store a string and create an ident.
155 * Stores a string in the ident module and returns a handle for the string.
156 * Copies the string. This version takes non-zero-terminated strings.
158 * @param str - the string (or whatever) which shall be stored
159 * @param len - the length of the data in bytes
161 * @return id - a handle for the generated ident
163 * @see new_id_from_str(), get_id_strlen()
165 ident *new_id_from_chars (const char *str, int len);
168 * Returns a string represented by an ident.
170 * Returns the string represented by id. This string is
171 * NULL terminated. The string may not be changed.
173 * @param id - the ident
175 * @return cp - a string
177 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
179 const char *get_id_str (ident *id);
182 * Returns the length of the string represented by an ident.
184 * @param id - the ident
186 * @return len - the length of the string
188 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
190 int get_id_strlen(ident *id);
193 * Returns true if prefix is a prefix of an ident.
195 * @param prefix - the prefix
196 * @param id - the ident
198 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
200 int id_is_prefix (ident *prefix, ident *id);
203 * Returns true if suffix is a suffix of an ident.
205 * @param suffix - the suffix
206 * @param id - the ident
208 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
210 int id_is_suffix (ident *suffix, ident *id);
213 * Returns true if infix is contained in id. (Can be suffix or prefix)
215 * @param infix - the infix
216 * @param id - the ident to search in
218 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
220 /* int id_contains(ident *infix, ident *id); */
223 * Return true if an ident contains a given character.
225 * @param id - the ident
226 * @param c - the character
228 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
230 int id_contains_char (ident *id, char c);
232 #ifdef FIRM_ENABLE_WCHAR
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.
238 * Copies the string. @p str must be zero terminated
240 * @param str - the wide character string which shall be stored
242 * @return id - a handle for the generated ident
244 * @see get_id_wcs(), get_id_wcs()
246 ident *new_id_from_wcs (const wchar_t *str);
248 /** Store a wide character string and create an ident.
250 * Stores a string in the ident module and returns a handle for the string.
251 * Copies the string. This version takes non-zero-terminated strings.
253 * @param wstr - the wide character string (or whatever) which shall be stored
254 * @param len - the length of string
256 * @return id - a handle for the generated ident
258 * @see new_id_from_str(), get_id_strlen()
260 ident *new_id_from_wchars (const wchar_t *str, int len);
263 * Returns a wide character string represented by an ident.
265 * Returns the string represented by id. This string is
266 * NULL terminated. The string may not be changed.
268 * @param id - the ident
270 * @return cp - a string
272 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
274 const wchar_t *get_id_wcs(ident *id);
277 * Returns the length of the wide character string represented by an ident.
279 * @param id - the ident
281 * @return len - the length of the string
283 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
285 int get_id_wcslen(ident *id);
288 * Return true if an ident contains a given character.
290 * @param id - the ident
291 * @param c - the character
293 * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
295 int id_contains_wchar (ident *id, wchar_t c);
297 #endif /* FIRM_ENABLE_WCHAR */