properly mark symbols in the public API to be exported. This allows us to use -fvisib...
[libfirm] / include / libfirm / ident.h
1 /*
2  * Copyright (C) 1995-2008 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  * @brief
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_types.h"
34 #include "begin.h"
35
36 /* Identifiers */
37
38 /**
39  * The ident module interface.
40  */
41 struct ident_if_t {
42   /** The handle. */
43   void *handle;
44
45   /**
46    * Store a string and create an ident.
47    * This function may be NULL, new_id_from_chars()
48    * is then used to emulate its behavior.
49    *
50    * @param str   the string which shall be stored
51    */
52   ident *(*new_id_from_str)(void *handle, const char *str);
53
54   /**
55    * Store a string and create an ident.
56    *
57    * @param str   the string (or whatever) which shall be stored
58    * @param len   the length of the data in bytes
59    */
60   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
61
62   /**
63    * Returns a string represented by an ident.
64    */
65   const char *(*get_id_str)(void *handle, ident *id);
66
67   /**
68    * Returns the length of the string represented by an ident.
69    * This function may be NULL, get_id_str() is then used
70    * to emulate its behavior.
71    *
72    * @param id   the ident
73    */
74   int  (*get_id_strlen)(void *handle, ident *id);
75
76   /**
77    * Finish the ident module and frees all idents, may be NULL.
78    */
79   void (*finish_ident)(void *handle);
80 };
81
82 /**
83  *  Store a string and create an ident.
84  *
85  *  Stores a string in the ident module and returns a handle for the string.
86  *
87  *  Copies the string. @p str must be zero terminated
88  *
89  * @param str   the string which shall be stored
90  *
91  * @return id   a handle for the generated ident
92  *
93  * @see get_id_str(), get_id_strlen()
94  */
95 FIRM_DLL ident *new_id_from_str(const char *str);
96
97 /** Store a string and create an ident.
98  *
99  * Stores a string in the ident module and returns a handle for the string.
100  * Copies the string. This version takes non-zero-terminated strings.
101  *
102  * @param str   the string (or whatever) which shall be stored
103  * @param len   the length of the data in bytes
104  *
105  * @return id   a handle for the generated ident
106  *
107  * @see new_id_from_str(), get_id_strlen()
108  */
109 FIRM_DLL ident *new_id_from_chars(const char *str, int len);
110
111 /**
112  * Returns a string represented by an ident.
113  *
114  * Returns the string represented by id. This string is
115  * NULL terminated. The string may not be changed.
116  *
117  * @param id   the ident
118  *
119  * @return cp   a string
120  *
121  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
122  */
123 FIRM_DLL const char *get_id_str(ident *id);
124
125 /**
126  * Returns the length of the string represented by an ident.
127  *
128  * @param id   the ident
129  *
130  * @return len   the length of the string
131  *
132  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
133  */
134 FIRM_DLL int get_id_strlen(ident *id);
135
136 /**
137  * Returns true if prefix is a prefix of an ident.
138  *
139  * @param prefix   the prefix
140  * @param id       the ident
141  *
142  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
143  */
144 FIRM_DLL int id_is_prefix(ident *prefix, ident *id);
145
146 /**
147  * Returns true if suffix is a suffix of an ident.
148  *
149  * @param suffix   the suffix
150  * @param id       the ident
151  *
152  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
153  */
154 FIRM_DLL int id_is_suffix(ident *suffix, ident *id);
155
156 /**
157  * Return true if an ident contains a given character.
158  *
159  * @param id    the ident
160  * @param c     the character
161  *
162  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
163  */
164 FIRM_DLL int id_contains_char(ident *id, char c);
165
166 /**
167  * helper function for creating unique idents. It contains an internal counter
168  * and replaces a "%u" inside the tag with the counter.
169  */
170 FIRM_DLL ident *id_unique(const char *tag);
171
172 /** initializes the name mangling code */
173 FIRM_DLL void firm_init_mangle (void);
174
175 /** Computes a definite name for this entity by concatenating
176    the name of the owner type and the name of the entity with
177    a separating "_". */
178 FIRM_DLL ident *id_mangle_entity(ir_entity *ent);
179
180 /** mangle underscore: Returns a new ident that represents first_scnd. */
181 FIRM_DLL ident *id_mangle_u(ident *first, ident* scnd);
182
183 /** mangle dot: Returns a new ident that represents first.scnd. */
184 FIRM_DLL ident *id_mangle_dot(ident *first, ident* scnd);
185
186 /** mangle: Returns a new ident that represents firstscnd. */
187 FIRM_DLL ident *id_mangle(ident *first, ident* scnd);
188
189 /** Returns a new ident that represents 'prefixscndsuffix'. */
190 FIRM_DLL ident *id_mangle3(const char *prefix, ident *middle,
191                            const char *suffix);
192
193 /** returns a mangled name for a Win32 function using its calling convention */
194 FIRM_DLL ident *id_decorate_win32_c_fkt(ir_entity *ent, ident *id);
195
196 #include "end.h"
197
198 #endif