3 * File name: ir/common/ident_t.h
4 * Purpose: Data type for unique names.
5 * Author: Goetz Lindenmaier
9 * Copyright: (c) 1999-2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 * Declarations for identifiers in the firm library
17 * Identifiers are used in the firm library. This is the interface to it.
26 # include "firm_common.h"
31 * The abstract data type ident.
33 * An ident represents an unique string. The == operator
34 * is sufficient to compare two idents.
36 typedef const struct ident ident;
39 * The ident module interface.
41 typedef struct _ident_if_t {
43 * Store a string and create an ident.
44 * This function may be NULL, new_id_from_chars()
45 * is then used to emulate it's behavior.
47 * @param str - the string which shall be stored
49 ident *(*new_id_from_str)(void *handle, const char *str);
52 * Store a string and create an ident.
54 * @param str - the string (or whatever) which shall be stored
55 * @param len - the length of the data in bytes
57 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
60 * Returns a string represented by an ident.
62 const char *(*get_id_str)(void *handle, ident *id);
65 * Returns the length of the string represented by an ident.
66 * This function may be NULL, get_id_str() is then used
67 * to emulate it's behavior.
69 * @param id - the ident
71 int (*get_id_strlen)(void *handle, ident *id);
74 * Finish the ident module and frees all idents, may be NULL.
76 void (*finish_ident)(void *handle);
84 * Store a string and create an ident.
86 * Stores a string in the ident module and returns a handle for the string.
88 * Copies the string. @p str must be zero terminated
90 * @param str - the string which shall be stored
92 * @return id - a handle for the generated ident
94 * @see get_id_str(), get_id_strlen()
96 ident *new_id_from_str (const char *str);
98 /** Store a string and create an ident.
100 * Stores a string in the ident module and returns a handle for the string.
101 * Copies the string. This version takes non-zero-terminated strings.
103 * @param str - the string (or whatever) which shall be stored
104 * @param len - the length of the data in bytes
106 * @return id - a handle for the generated ident
108 * @see new_id_from_str(), get_id_strlen()
110 ident *new_id_from_chars (const char *str, int len);
113 * Returns a string represented by an ident.
115 * Returns the string represented by id. This string is
116 * NULL terminated. The string may not be changed.
118 * @param id - the ident
120 * @return cp - a string
122 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
124 const char *get_id_str (ident *id);
127 * Returns the length of the string represented by an ident.
129 * @param id - the ident
131 * @return len - the length of the string
133 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
135 int get_id_strlen(ident *id);
137 * Returns true if prefix is a prefix of an ident.
139 * @param prefix - the prefix
140 * @param id - the ident
142 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
144 int id_is_prefix (ident *prefix, ident *id);
147 * Returns true if suffix is a suffix of an ident.
149 * @param suffix - the suffix
150 * @param id - the ident
152 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
154 int id_is_suffix (ident *suffix, ident *id);
157 * Returns true if infix is contained in id. (Can be suffix or prefix)
159 * @param infix - the infix
160 * @param id - the ident to search in
162 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
164 /* int id_contains(ident *infix, ident *id); */
167 * Return true if an ident contains a given character.
169 * @param id - the ident
170 * @param c - the character
172 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
174 int id_contains_char (ident *id, char c);
177 * Prints the ident to stdout.
179 * @param id - The ident to be printed.
182 * number of bytes written
184 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), fprint_id()
186 int print_id (ident *id);
189 * Prints the ident to the file passed.
191 * @param F - file pointer to print the ident to.
192 * @param id - The ident to print and the file.
195 * number of btes written
197 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), print_id()
199 int fprint_id (FILE *F, ident *id);
201 # endif /* _IDENT_H_ */