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 #ifndef _IDENT_TYPEDEF_
37 #define _IDENT_TYPEDEF_
38 typedef const struct ident ident;
42 * The ident module interface.
44 typedef struct _ident_if_t {
46 * Store a string and create an ident.
47 * This function may be NULL, new_id_from_chars()
48 * is then used to emulate it's behavior.
50 * @param str - the string which shall be stored
52 ident *(*new_id_from_str)(void *handle, const char *str);
55 * Store a string and create an ident.
57 * @param str - the string (or whatever) which shall be stored
58 * @param len - the length of the data in bytes
60 ident *(*new_id_from_chars)(void *handle, const char *str, int len);
63 * Returns a string represented by an ident.
65 const char *(*get_id_str)(void *handle, ident *id);
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 it's behavior.
72 * @param id - the ident
74 int (*get_id_strlen)(void *handle, ident *id);
77 * Finish the ident module and frees all idents, may be NULL.
79 void (*finish_ident)(void *handle);
87 * Store a string and create an ident.
89 * Stores a string in the ident module and returns a handle for the string.
91 * Copies the string. @p str must be zero terminated
93 * @param str - the string which shall be stored
95 * @return id - a handle for the generated ident
97 * @see get_id_str(), get_id_strlen()
99 ident *new_id_from_str (const char *str);
101 /** Store a string and create an ident.
103 * Stores a string in the ident module and returns a handle for the string.
104 * Copies the string. This version takes non-zero-terminated strings.
106 * @param str - the string (or whatever) which shall be stored
107 * @param len - the length of the data in bytes
109 * @return id - a handle for the generated ident
111 * @see new_id_from_str(), get_id_strlen()
113 ident *new_id_from_chars (const char *str, int len);
116 * Returns a string represented by an ident.
118 * Returns the string represented by id. This string is
119 * NULL terminated. The string may not be changed.
121 * @param id - the ident
123 * @return cp - a string
125 * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
127 const char *get_id_str (ident *id);
130 * Returns the length of the string represented by an ident.
132 * @param id - the ident
134 * @return len - the length of the string
136 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
138 int get_id_strlen(ident *id);
140 * Returns true if prefix is a prefix of an ident.
142 * @param prefix - the prefix
143 * @param id - the ident
145 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
147 int id_is_prefix (ident *prefix, ident *id);
150 * Returns true if suffix is a suffix of an ident.
152 * @param suffix - the suffix
153 * @param id - the ident
155 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
157 int id_is_suffix (ident *suffix, ident *id);
160 * Returns true if infix is contained in id. (Can be suffix or prefix)
162 * @param infix - the infix
163 * @param id - the ident to search in
165 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
167 /* int id_contains(ident *infix, ident *id); */
170 * Return true if an ident contains a given character.
172 * @param id - the ident
173 * @param c - the character
175 * @see new_id_from_str(), new_id_from_chars(), get_id_str()
177 int id_contains_char (ident *id, char c);
180 * Prints the ident to stdout.
182 * @param id - The ident to be printed.
185 * number of bytes written
187 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), fprint_id()
189 int print_id (ident *id);
192 * Prints the ident to the file passed.
194 * @param F - file pointer to print the ident to.
195 * @param id - The ident to print and the file.
198 * number of btes written
200 * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), print_id()
202 int fprint_id (FILE *F, ident *id);
204 # endif /* _IDENT_H_ */