some workaround to avoid condeval creating Phibs which not all backends like
[libfirm] / ir / ident / ident.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/ident_t.h
4  * Purpose:     Data type for unique names.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1999-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12 /**
13  * @file ident.h
14  *
15  * Declarations for identifiers in the firm library
16  *
17  * Identifiers are used in the firm library. This is the interface to it.
18  */
19 #ifndef _IDENT_H_
20 #define _IDENT_H_
21
22 #include "firm_config.h"
23
24 #ifdef FIRM_ENABLE_WCHAR
25 #include <wchar.h>
26 #endif
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /* Identifiers */
33
34 /**
35  *  The abstract data type ident.
36  *
37  *  An ident represents an unique string. The == operator
38  *  is sufficient to compare two idents.
39  */
40 #ifndef _IDENT_TYPEDEF_
41 #define _IDENT_TYPEDEF_
42 typedef const struct _ident ident;
43 #endif
44
45 /**
46  * The ident module interface.
47  */
48 typedef struct _ident_if_t {
49   /** The handle. */
50   void *handle;
51
52   /**
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.
56    *
57    * @param str - the string which shall be stored
58    */
59   ident *(*new_id_from_str)(void *handle, const char *str);
60
61   /**
62    * Store a string and create an ident.
63    *
64    * @param str - the string (or whatever) which shall be stored
65    * @param len - the length of the data in bytes
66    */
67   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
68
69   /**
70    * Returns a string represented by an ident.
71    */
72   const char *(*get_id_str)(void *handle, ident *id);
73
74   /**
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.
78    *
79    * @param id - the ident
80    */
81   int  (*get_id_strlen)(void *handle, ident *id);
82
83   /**
84    * Finish the ident module and frees all idents, may be NULL.
85    */
86   void (*finish_ident)(void *handle);
87
88 #ifdef FIRM_ENABLE_WCHAR
89   /**
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.
93    *
94    * @param wstr - the string which shall be stored
95    */
96   ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
97
98   /**
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!
102    *
103    * @param wstr - the wide character string which shall be stored
104    * @param len  - the length of the string
105    */
106   ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
107
108   /**
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!
113    */
114   const wchar_t *(*get_id_wcs)(void *handle, ident *id);
115
116   /**
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.
120    *
121    * @param id - the ident
122    */
123   int  (*get_id_wcslen)(void *handle, ident *id);
124 #endif
125 } ident_if_t;
126
127 /**
128  *  Store a string and create an ident.
129  *
130  *  Stores a string in the ident module and returns a handle for the string.
131  *
132  *  Copies the string. @p str must be zero terminated
133  *
134  * @param str - the string which shall be stored
135  *
136  * @return id - a handle for the generated ident
137  *
138  * @see get_id_str(), get_id_strlen()
139  */
140 ident *new_id_from_str (const char *str);
141
142 /** Store a string and create an ident.
143  *
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.
146  *
147  * @param str - the string (or whatever) which shall be stored
148  * @param len - the length of the data in bytes
149  *
150  * @return id - a handle for the generated ident
151  *
152  * @see new_id_from_str(), get_id_strlen()
153  */
154 ident *new_id_from_chars (const char *str, int len);
155
156 /**
157  * Returns a string represented by an ident.
158  *
159  * Returns the string represented by id. This string is
160  * NULL terminated. The string may not be changed.
161  *
162  * @param id - the ident
163  *
164  * @return cp - a string
165  *
166  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
167  */
168 const char *get_id_str  (ident *id);
169
170 /**
171  * Returns the length of the string represented by an ident.
172  *
173  * @param id - the ident
174  *
175  * @return len - the length of the string
176  *
177  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
178  */
179 int  get_id_strlen(ident *id);
180
181 /**
182  * Returns true if prefix is a prefix of an ident.
183  *
184  * @param prefix - the prefix
185  * @param id     - the ident
186  *
187  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
188  */
189 int id_is_prefix (ident *prefix, ident *id);
190
191 /**
192  * Returns true if suffix is a suffix of an ident.
193  *
194  * @param suffix - the suffix
195  * @param id     - the ident
196  *
197  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
198  */
199 int id_is_suffix (ident *suffix, ident *id);
200
201 /**
202  * Returns true if infix is contained in id.  (Can be suffix or prefix)
203  *
204  * @param infix  - the infix
205  * @param id     - the ident to search in
206  *
207  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
208  */
209 /* int id_contains(ident *infix, ident *id); */
210
211 /**
212  * Return true if an ident contains a given character.
213  *
214  * @param id     - the ident
215  * @param c      - the character
216  *
217  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
218  */
219 int id_contains_char (ident *id, char c);
220
221 #ifdef FIRM_ENABLE_WCHAR
222 /**
223  *  Store a wide character string and create an ident.
224  *
225  *  Stores a string in the ident module and returns a handle for the string.
226  *
227  *  Copies the string. @p str must be zero terminated
228  *
229  * @param str - the wide character string which shall be stored
230  *
231  * @return id - a handle for the generated ident
232  *
233  * @see get_id_wcs(), get_id_wcs()
234  */
235 ident *new_id_from_wcs (const wchar_t *str);
236
237 /** Store a wide character string and create an ident.
238  *
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.
241  *
242  * @param wstr - the wide character string (or whatever) which shall be stored
243  * @param len  - the length of string
244  *
245  * @return id - a handle for the generated ident
246  *
247  * @see new_id_from_str(), get_id_strlen()
248  */
249 ident *new_id_from_wchars (const wchar_t *str, int len);
250
251 /**
252  * Returns a wide character string represented by an ident.
253  *
254  * Returns the string represented by id. This string is
255  * NULL terminated. The string may not be changed.
256  *
257  * @param id - the ident
258  *
259  * @return cp - a string
260  *
261  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
262  */
263 const wchar_t *get_id_wcs(ident *id);
264
265 /**
266  * Returns the length of the wide character string represented by an ident.
267  *
268  * @param id - the ident
269  *
270  * @return len - the length of the string
271  *
272  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
273  */
274 int  get_id_wcslen(ident *id);
275
276 /**
277  * Return true if an ident contains a given character.
278  *
279  * @param id     - the ident
280  * @param c      - the character
281  *
282  * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
283  */
284 int id_contains_wchar (ident *id, wchar_t c);
285
286 #endif /* FIRM_ENABLE_WCHAR */
287
288 #ifdef __cplusplus
289 }
290 #endif
291
292 # endif /* _IDENT_H_ */