3 * File name: ir/common/ident_t.h
4 * Purpose: Data type for unique names.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * Declarations for identifiers in the firm library
17 * Identifiers are used in the firm library. This is the interface to it.
22 #include "firm_config.h"
24 #ifdef FIRM_ENABLE_WCHAR
35 * The abstract data type ident.
37 * An ident represents an unique string. The == operator
38 * is sufficient to compare two idents.
40 #ifndef _IDENT_TYPEDEF_
41 #define _IDENT_TYPEDEF_
42 typedef const struct _ident ident;
46 * The ident module interface.
48 typedef struct _ident_if_t {
53 * Store a string and create an ident.
54 * This function may be NULL, new_id_from_chars()
55 * is then used to emulate it's behavior.
57 * @param str - the string which shall be stored
59 ident *(*new_id_from_str)(void *handle, const char *str);
62 * Store a string and create an ident.
64 * @param str - the string (or whatever) which shall be stored
65 * @param len - the length of the data in bytes
67 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
70 * Returns a string represented by an ident.
72 const char *(*get_id_str)(void *handle, ident *id);
75 * Returns the length of the string represented by an ident.
76 * This function may be NULL, get_id_str() is then used
77 * to emulate it's behavior.
79 * @param id - the ident
81 int (*get_id_strlen)(void *handle, ident *id);
84 * Finish the ident module and frees all idents, may be NULL.
86 void (*finish_ident)(void *handle);
88 #ifdef FIRM_ENABLE_WCHAR
90 * Store a wide character string and create an ident.
91 * This function may be NULL, new_id_from_wchars()
92 * is then used to emulate it's behavior.
94 * @param wstr - the string which shall be stored
96 ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
99 * Store a wide character string and create an ident.
100 * This function may be NULL, new_id_from_chars() is then used appropriate.
101 * Beware: the string might not be stored at a right alignment!
103 * @param wstr - the wide character string which shall be stored
104 * @param len - the length of the string
106 ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
109 * Returns a wide character string represented by an ident.
110 * This function may be NULL, get_id_str() is then used.
111 * This assume that the strings are stored at an address aligned
112 * for wchar_t, so beware!
114 const wchar_t *(*get_id_wcs)(void *handle, ident *id);
117 * Returns the length of the string represented by an ident.
118 * This function may be NULL, get_id_wcs() is then used
119 * to emulate it's behavior.
121 * @param id - the ident
123 int (*get_id_wcslen)(void *handle, ident *id);
128 * Store a string and create an ident.
130 * Stores a string in the ident module and returns a handle for the string.
132 * Copies the string. @p str must be zero terminated
134 * @param str - the string which shall be stored
136 * @return id - a handle for the generated ident
138 * @see get_id_str(), get_id_strlen()
140 ident *new_id_from_str (const char *str);
142 /** Store a string and create an ident.
144 * Stores a string in the ident module and returns a handle for the string.
145 * Copies the string. This version takes non-zero-terminated strings.
147 * @param str - the string (or whatever) which shall be stored
148 * @param len - the length of the data in bytes
150 * @return id - a handle for the generated ident
152 * @see new_id_from_str(), get_id_strlen()
154 ident *new_id_from_chars (const char *str, int len);
157 * Returns a string represented by an ident.
159 * Returns the string represented by id. This string is
160 * NULL terminated. The string may not be changed.
162 * @param id - the ident
164 * @return cp - a string
166 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
168 const char *get_id_str (ident *id);
171 * Returns the length of the string represented by an ident.
173 * @param id - the ident
175 * @return len - the length of the string
177 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
179 int get_id_strlen(ident *id);
182 * Returns true if prefix is a prefix of an ident.
184 * @param prefix - the prefix
185 * @param id - the ident
187 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
189 int id_is_prefix (ident *prefix, ident *id);
192 * Returns true if suffix is a suffix of an ident.
194 * @param suffix - the suffix
195 * @param id - the ident
197 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
199 int id_is_suffix (ident *suffix, ident *id);
202 * Returns true if infix is contained in id. (Can be suffix or prefix)
204 * @param infix - the infix
205 * @param id - the ident to search in
207 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
209 /* int id_contains(ident *infix, ident *id); */
212 * Return true if an ident contains a given character.
214 * @param id - the ident
215 * @param c - the character
217 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
219 int id_contains_char (ident *id, char c);
221 #ifdef FIRM_ENABLE_WCHAR
223 * Store a wide character string and create an ident.
225 * Stores a string in the ident module and returns a handle for the string.
227 * Copies the string. @p str must be zero terminated
229 * @param str - the wide character string which shall be stored
231 * @return id - a handle for the generated ident
233 * @see get_id_wcs(), get_id_wcs()
235 ident *new_id_from_wcs (const wchar_t *str);
237 /** Store a wide character string and create an ident.
239 * Stores a string in the ident module and returns a handle for the string.
240 * Copies the string. This version takes non-zero-terminated strings.
242 * @param wstr - the wide character string (or whatever) which shall be stored
243 * @param len - the length of string
245 * @return id - a handle for the generated ident
247 * @see new_id_from_str(), get_id_strlen()
249 ident *new_id_from_wchars (const wchar_t *str, int len);
252 * Returns a wide character string represented by an ident.
254 * Returns the string represented by id. This string is
255 * NULL terminated. The string may not be changed.
257 * @param id - the ident
259 * @return cp - a string
261 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
263 const wchar_t *get_id_wcs(ident *id);
266 * Returns the length of the wide character string represented by an ident.
268 * @param id - the ident
270 * @return len - the length of the string
272 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
274 int get_id_wcslen(ident *id);
277 * Return true if an ident contains a given character.
279 * @param id - the ident
280 * @param c - the character
282 * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
284 int id_contains_wchar (ident *id, wchar_t c);
286 #endif /* FIRM_ENABLE_WCHAR */
292 # endif /* _IDENT_H_ */