used entities are now marked
[libfirm] / ir / ident / ident.h
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief    Data type for unique names.
23  * @author   Goetz Lindenmaier
24  * @version  $Id$
25  * @summary
26  *  Declarations for identifiers in the firm library
27  *
28  *  Identifiers are used in the firm library. This is the interface to it.
29  */
30 #ifndef FIRM_IDENT_IDENT_H
31 #define FIRM_IDENT_IDENT_H
32
33 #include "firm_config.h"
34
35 #ifdef FIRM_ENABLE_WCHAR
36 #include <wchar.h>
37 #endif
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /* Identifiers */
44
45 /**
46  *  The abstract data type ident.
47  *
48  *  An ident represents an unique string. The == operator
49  *  is sufficient to compare two idents.
50  */
51 #ifndef _IDENT_TYPEDEF_
52 #define _IDENT_TYPEDEF_
53 typedef const struct _ident ident;
54 #endif
55
56 /**
57  * The ident module interface.
58  */
59 typedef struct _ident_if_t {
60   /** The handle. */
61   void *handle;
62
63   /**
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.
67    *
68    * @param str - the string which shall be stored
69    */
70   ident *(*new_id_from_str)(void *handle, const char *str);
71
72   /**
73    * Store a string and create an ident.
74    *
75    * @param str - the string (or whatever) which shall be stored
76    * @param len - the length of the data in bytes
77    */
78   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
79
80   /**
81    * Returns a string represented by an ident.
82    */
83   const char *(*get_id_str)(void *handle, ident *id);
84
85   /**
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.
89    *
90    * @param id - the ident
91    */
92   int  (*get_id_strlen)(void *handle, ident *id);
93
94   /**
95    * Finish the ident module and frees all idents, may be NULL.
96    */
97   void (*finish_ident)(void *handle);
98
99 #ifdef FIRM_ENABLE_WCHAR
100   /**
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.
104    *
105    * @param wstr - the string which shall be stored
106    */
107   ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
108
109   /**
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!
113    *
114    * @param wstr - the wide character string which shall be stored
115    * @param len  - the length of the string
116    */
117   ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
118
119   /**
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!
124    */
125   const wchar_t *(*get_id_wcs)(void *handle, ident *id);
126
127   /**
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.
131    *
132    * @param id - the ident
133    */
134   int  (*get_id_wcslen)(void *handle, ident *id);
135 #endif
136 } ident_if_t;
137
138 /**
139  *  Store a string and create an ident.
140  *
141  *  Stores a string in the ident module and returns a handle for the string.
142  *
143  *  Copies the string. @p str must be zero terminated
144  *
145  * @param str - the string which shall be stored
146  *
147  * @return id - a handle for the generated ident
148  *
149  * @see get_id_str(), get_id_strlen()
150  */
151 ident *new_id_from_str (const char *str);
152
153 /** Store a string and create an ident.
154  *
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.
157  *
158  * @param str - the string (or whatever) which shall be stored
159  * @param len - the length of the data in bytes
160  *
161  * @return id - a handle for the generated ident
162  *
163  * @see new_id_from_str(), get_id_strlen()
164  */
165 ident *new_id_from_chars (const char *str, int len);
166
167 /**
168  * Returns a string represented by an ident.
169  *
170  * Returns the string represented by id. This string is
171  * NULL terminated. The string may not be changed.
172  *
173  * @param id - the ident
174  *
175  * @return cp - a string
176  *
177  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
178  */
179 const char *get_id_str  (ident *id);
180
181 /**
182  * Returns the length of the string represented by an ident.
183  *
184  * @param id - the ident
185  *
186  * @return len - the length of the string
187  *
188  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
189  */
190 int  get_id_strlen(ident *id);
191
192 /**
193  * Returns true if prefix is a prefix of an ident.
194  *
195  * @param prefix - the prefix
196  * @param id     - the ident
197  *
198  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
199  */
200 int id_is_prefix (ident *prefix, ident *id);
201
202 /**
203  * Returns true if suffix is a suffix of an ident.
204  *
205  * @param suffix - the suffix
206  * @param id     - the ident
207  *
208  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
209  */
210 int id_is_suffix (ident *suffix, ident *id);
211
212 /**
213  * Returns true if infix is contained in id.  (Can be suffix or prefix)
214  *
215  * @param infix  - the infix
216  * @param id     - the ident to search in
217  *
218  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
219  */
220 /* int id_contains(ident *infix, ident *id); */
221
222 /**
223  * Return true if an ident contains a given character.
224  *
225  * @param id     - the ident
226  * @param c      - the character
227  *
228  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
229  */
230 int id_contains_char (ident *id, char c);
231
232 #ifdef FIRM_ENABLE_WCHAR
233 /**
234  *  Store a wide character string and create an ident.
235  *
236  *  Stores a string in the ident module and returns a handle for the string.
237  *
238  *  Copies the string. @p str must be zero terminated
239  *
240  * @param str - the wide character string which shall be stored
241  *
242  * @return id - a handle for the generated ident
243  *
244  * @see get_id_wcs(), get_id_wcs()
245  */
246 ident *new_id_from_wcs (const wchar_t *str);
247
248 /** Store a wide character string and create an ident.
249  *
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.
252  *
253  * @param wstr - the wide character string (or whatever) which shall be stored
254  * @param len  - the length of string
255  *
256  * @return id - a handle for the generated ident
257  *
258  * @see new_id_from_str(), get_id_strlen()
259  */
260 ident *new_id_from_wchars (const wchar_t *str, int len);
261
262 /**
263  * Returns a wide character string represented by an ident.
264  *
265  * Returns the string represented by id. This string is
266  * NULL terminated. The string may not be changed.
267  *
268  * @param id - the ident
269  *
270  * @return cp - a string
271  *
272  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
273  */
274 const wchar_t *get_id_wcs(ident *id);
275
276 /**
277  * Returns the length of the wide character string represented by an ident.
278  *
279  * @param id - the ident
280  *
281  * @return len - the length of the string
282  *
283  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
284  */
285 int  get_id_wcslen(ident *id);
286
287 /**
288  * Return true if an ident contains a given character.
289  *
290  * @param id     - the ident
291  * @param c      - the character
292  *
293  * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
294  */
295 int id_contains_wchar (ident *id, wchar_t c);
296
297 #endif /* FIRM_ENABLE_WCHAR */
298
299 #ifdef __cplusplus
300 }
301 #endif
302
303 #endif