9843e3532fb301b2b2843a70bc965797467049e7
[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 /* Identifiers */
29
30 /**
31  *  The abstract data type ident.
32  *
33  *  An ident represents an unique string. The == operator
34  *  is sufficient to compare two idents.
35  */
36 #ifndef _IDENT_TYPEDEF_
37 #define _IDENT_TYPEDEF_
38 typedef const struct ident ident;
39 #endif
40
41 /**
42  * The ident module interface.
43  */
44 typedef struct _ident_if_t {
45   /** The handle. */
46   void *handle;
47
48   /**
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.
52    *
53    * @param str - the string which shall be stored
54    */
55   ident *(*new_id_from_str)(void *handle, const char *str);
56
57   /**
58    * Store a string and create an ident.
59    *
60    * @param str - the string (or whatever) which shall be stored
61    * @param len - the length of the data in bytes
62    */
63   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
64
65   /**
66    * Returns a string represented by an ident.
67    */
68   const char *(*get_id_str)(void *handle, ident *id);
69
70   /**
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.
74    *
75    * @param id - the ident
76    */
77   int  (*get_id_strlen)(void *handle, ident *id);
78
79   /**
80    * Finish the ident module and frees all idents, may be NULL.
81    */
82   void (*finish_ident)(void *handle);
83
84 #ifdef FIRM_ENABLE_WCHAR
85   /**
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.
89    *
90    * @param wstr - the string which shall be stored
91    */
92   ident *(*new_id_from_wcs)(void *handle, const wchar_t *wstr);
93
94   /**
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!
98    *
99    * @param wstr - the wide character string which shall be stored
100    * @param len  - the length of the string
101    */
102   ident *(*new_id_from_wchars)(void *handle, const wchar_t *wstr, int len);
103
104   /**
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!
109    */
110   const wchar_t *(*get_id_wcs)(void *handle, ident *id);
111
112   /**
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.
116    *
117    * @param id - the ident
118    */
119   int  (*get_id_wcslen)(void *handle, ident *id);
120 #endif
121 } ident_if_t;
122
123 /**
124  *  Store a string and create an ident.
125  *
126  *  Stores a string in the ident module and returns a handle for the string.
127  *
128  *  Copies the string. @p str must be zero terminated
129  *
130  * @param str - the string which shall be stored
131  *
132  * @return id - a handle for the generated ident
133  *
134  * @see get_id_str(), get_id_strlen()
135  */
136 ident *new_id_from_str (const char *str);
137
138 /** Store a string and create an ident.
139  *
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.
142  *
143  * @param str - the string (or whatever) which shall be stored
144  * @param len - the length of the data in bytes
145  *
146  * @return id - a handle for the generated ident
147  *
148  * @see new_id_from_str(), get_id_strlen()
149  */
150 ident *new_id_from_chars (const char *str, int len);
151
152 /**
153  * Returns a string represented by an ident.
154  *
155  * Returns the string represented by id. This string is
156  * NULL terminated. The string may not be changed.
157  *
158  * @param id - the ident
159  *
160  * @return cp - a string
161  *
162  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
163  */
164 const char *get_id_str  (ident *id);
165
166 /**
167  * Returns the length of the string represented by an ident.
168  *
169  * @param id - the ident
170  *
171  * @return len - the length of the string
172  *
173  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
174  */
175 int  get_id_strlen(ident *id);
176
177 /**
178  * Returns true if prefix is a prefix of an ident.
179  *
180  * @param prefix - the prefix
181  * @param id     - the ident
182  *
183  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
184  */
185 int id_is_prefix (ident *prefix, ident *id);
186
187 /**
188  * Returns true if suffix is a suffix of an ident.
189  *
190  * @param suffix - the suffix
191  * @param id     - the ident
192  *
193  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
194  */
195 int id_is_suffix (ident *suffix, ident *id);
196
197 /**
198  * Returns true if infix is contained in id.  (Can be suffix or prefix)
199  *
200  * @param infix  - the infix
201  * @param id     - the ident to search in
202  *
203  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
204  */
205 /* int id_contains(ident *infix, ident *id); */
206
207 /**
208  * Return true if an ident contains a given character.
209  *
210  * @param id     - the ident
211  * @param c      - the character
212  *
213  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
214  */
215 int id_contains_char (ident *id, char c);
216
217 #ifdef FIRM_ENABLE_WCHAR
218 /**
219  *  Store a wide character string and create an ident.
220  *
221  *  Stores a string in the ident module and returns a handle for the string.
222  *
223  *  Copies the string. @p str must be zero terminated
224  *
225  * @param str - the wide character string which shall be stored
226  *
227  * @return id - a handle for the generated ident
228  *
229  * @see get_id_wcs(), get_id_wcs()
230  */
231 ident *new_id_from_wcs (const wchar_t *str);
232
233 /** Store a wide character string and create an ident.
234  *
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.
237  *
238  * @param wstr - the wide character string (or whatever) which shall be stored
239  * @param len  - the length of string
240  *
241  * @return id - a handle for the generated ident
242  *
243  * @see new_id_from_str(), get_id_strlen()
244  */
245 ident *new_id_from_wchars (const wchar_t *str, int len);
246
247 /**
248  * Returns a wide character string represented by an ident.
249  *
250  * Returns the string represented by id. This string is
251  * NULL terminated. The string may not be changed.
252  *
253  * @param id - the ident
254  *
255  * @return cp - a string
256  *
257  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcslen()
258  */
259 const wchar_t *get_id_wcs(ident *id);
260
261 /**
262  * Returns the length of the wide character string represented by an ident.
263  *
264  * @param id - the ident
265  *
266  * @return len - the length of the string
267  *
268  * @see new_id_from_wcs(), new_id_from_wchars(), get_id_wcs()
269  */
270 int  get_id_wcslen(ident *id);
271
272 /**
273  * Return true if an ident contains a given character.
274  *
275  * @param id     - the ident
276  * @param c      - the character
277  *
278  * @see new_id_from_wcs(), new_id_from_chars(), get_id_str()
279  */
280 int id_contains_wchar (ident *id, wchar_t c);
281
282 #endif /* FIRM_ENABLE_WCHAR */
283
284 # endif /* _IDENT_H_ */