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
31 * The abstract data type ident.
33 * An ident represents an unique string. The == operator
34 * is sufficient to compare two idents.
36 #ifndef _IDENT_TYPEDEF_
37 #define _IDENT_TYPEDEF_
38 typedef const struct ident ident;
42 * The ident module interface.
44 typedef struct _ident_if_t {
49 * Store a string and create an ident.
50 * This function may be NULL, new_id_from_chars()
51 * is then used to emulate it's behavior.
53 * @param str - the string which shall be stored
55 ident *(*new_id_from_str)(void *handle, const char *str);
58 * Store a string and create an ident.
60 * @param str - the string (or whatever) which shall be stored
61 * @param len - the length of the data in bytes
63 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
66 * Returns a string represented by an ident.
68 const char *(*get_id_str)(void *handle, ident *id);
71 * Returns the length of the string represented by an ident.
72 * This function may be NULL, get_id_str() is then used
73 * to emulate it's behavior.
75 * @param id - the ident
77 int (*get_id_strlen)(void *handle, ident *id);
80 * Finish the ident module and frees all idents, may be NULL.
82 void (*finish_ident)(void *handle);
84 #ifdef FIRM_ENABLE_WCHAR
86 * Store a wide character string and create an ident.
87 * This function may be NULL, new_id_from_wchars()
88 * is then used to emulate it's behavior.
90 * @param wstr - the string which shall be stored
92 ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
95 * Store a wide character string and create an ident.
96 * This function may be NULL, new_id_from_chars() is then used appropriate.
97 * Beware: the string might not be stored at a right alignment!
99 * @param wstr - the wide character string which shall be stored
100 * @param len - the length of the string
102 ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
105 * Returns a wide character string represented by an ident.
106 * This function may be NULL, get_id_str() is then used.
107 * This assume that the strings are stored at an address aligned
108 * for wchar_t, so beware!
110 const wchar_t *(*get_id_wcs)(void *handle, ident *id);
113 * Returns the length of the string represented by an ident.
114 * This function may be NULL, get_id_wcs() is then used
115 * to emulate it's behavior.
117 * @param id - the ident
119 int (*get_id_wcslen)(void *handle, ident *id);
124 * Store a string and create an ident.
126 * Stores a string in the ident module and returns a handle for the string.
128 * Copies the string. @p str must be zero terminated
130 * @param str - the string which shall be stored
132 * @return id - a handle for the generated ident
134 * @see get_id_str(), get_id_strlen()
136 ident *new_id_from_str (const char *str);
138 /** Store a string and create an ident.
140 * Stores a string in the ident module and returns a handle for the string.
141 * Copies the string. This version takes non-zero-terminated strings.
143 * @param str - the string (or whatever) which shall be stored
144 * @param len - the length of the data in bytes
146 * @return id - a handle for the generated ident
148 * @see new_id_from_str(), get_id_strlen()
150 ident *new_id_from_chars (const char *str, int len);
153 * Returns a string represented by an ident.
155 * Returns the string represented by id. This string is
156 * NULL terminated. The string may not be changed.
158 * @param id - the ident
160 * @return cp - a string
162 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
164 const char *get_id_str (ident *id);
167 * Returns the length of the string represented by an ident.
169 * @param id - the ident
171 * @return len - the length of the string
173 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
175 int get_id_strlen(ident *id);
178 * Returns true if prefix is a prefix of an ident.
180 * @param prefix - the prefix
181 * @param id - the ident
183 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
185 int id_is_prefix (ident *prefix, ident *id);
188 * Returns true if suffix is a suffix of an ident.
190 * @param suffix - the suffix
191 * @param id - the ident
193 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
195 int id_is_suffix (ident *suffix, ident *id);
198 * Returns true if infix is contained in id. (Can be suffix or prefix)
200 * @param infix - the infix
201 * @param id - the ident to search in
203 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
205 /* int id_contains(ident *infix, ident *id); */
208 * Return true if an ident contains a given character.
210 * @param id - the ident
211 * @param c - the character
213 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
215 int id_contains_char (ident *id, char c);
217 #ifdef FIRM_ENABLE_WCHAR
219 * Store a wide character string and create an ident.
221 * Stores a string in the ident module and returns a handle for the string.
223 * Copies the string. @p str must be zero terminated
225 * @param str - the wide character string which shall be stored
227 * @return id - a handle for the generated ident
229 * @see get_id_wcs(), get_id_wcs()
231 ident *new_id_from_wcs (const wchar_t *str);
233 /** Store a wide character string and create an ident.
235 * Stores a string in the ident module and returns a handle for the string.
236 * Copies the string. This version takes non-zero-terminated strings.
238 * @param wstr - the wide character string (or whatever) which shall be stored
239 * @param len - the length of string
241 * @return id - a handle for the generated ident
243 * @see new_id_from_str(), get_id_strlen()
245 ident *new_id_from_wchars (const wchar_t *str, int len);
248 * Returns a wide character string represented by an ident.
250 * Returns the string represented by id. This string is
251 * NULL terminated. The string may not be changed.
253 * @param id - the ident
255 * @return cp - a string
257 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
259 const wchar_t *get_id_wcs(ident *id);
262 * Returns the length of the wide character string represented by an ident.
264 * @param id - the ident
266 * @return len - the length of the string
268 * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
270 int get_id_wcslen(ident *id);
273 * Return true if an ident contains a given character.
275 * @param id - the ident
276 * @param c - the character
278 * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
280 int id_contains_wchar (ident *id, wchar_t c);
282 #endif /* FIRM_ENABLE_WCHAR */
284 # endif /* _IDENT_H_ */