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