change for cpp
[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
20
21 # ifndef _IDENT_H_
22 # define _IDENT_H_
23
24 # include <stdio.h>
25 # include <assert.h>
26 # include "firm_common.h"
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 s_ident ident;
39 #endif
40
41 /**
42  * The ident module interface.
43  */
44 typedef struct _ident_if_t {
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 it's 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 it's 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   /** The handle. */
82   void *handle;
83
84 } ident_if_t;
85
86 /**
87  *  Store a string and create an ident.
88  *
89  *  Stores a string in the ident module and returns a handle for the string.
90  *
91  *  Copies the string. @p str must be zero terminated
92  *
93  * @param str - the string which shall be stored
94  *
95  * @return id - a handle for the generated ident
96  *
97  * @see get_id_str(), get_id_strlen()
98  */
99 ident *new_id_from_str (const char *str);
100
101 /** Store a string and create an ident.
102  *
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.
105  *
106  * @param str - the string (or whatever) which shall be stored
107  * @param len - the length of the data in bytes
108  *
109  * @return id - a handle for the generated ident
110  *
111  * @see new_id_from_str(), get_id_strlen()
112  */
113 ident *new_id_from_chars (const char *str, int len);
114
115 /**
116  * Returns a string represented by an ident.
117  *
118  * Returns the string represented by id. This string is
119  * NULL terminated. The string may not be changed.
120  *
121  * @param id - the ident
122  *
123  * @return cp - a string
124  *
125  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
126  */
127 const char *get_id_str  (ident *id);
128
129 /**
130  * Returns the length of the string represented by an ident.
131  *
132  * @param id - the ident
133  *
134  * @return len - the length of the string
135  *
136  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
137  */
138 int  get_id_strlen(ident *id);
139 /**
140  * Returns true if prefix is a prefix of an ident.
141  *
142  * @param prefix - the prefix
143  * @param id     - the ident
144  *
145  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
146  */
147 int id_is_prefix (ident *prefix, ident *id);
148
149 /**
150  * Returns true if suffix is a suffix of an ident.
151  *
152  * @param suffix - the suffix
153  * @param id     - the ident
154  *
155  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
156  */
157 int id_is_suffix (ident *suffix, ident *id);
158
159 /**
160  * Returns true if infix is contained in id.  (Can be suffix or prefix)
161  *
162  * @param infix  - the infix
163  * @param id     - the ident to search in
164  *
165  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
166  */
167 /* int id_contains(ident *infix, ident *id); */
168
169 /**
170  * Return true if an ident contains a given character.
171  *
172  * @param id     - the ident
173  * @param c      - the character
174  *
175  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
176  */
177 int id_contains_char (ident *id, char c);
178
179 /**
180  * Prints the ident to stdout.
181  *
182  * @param id - The ident to be printed.
183  *
184  * @return
185  *    number of bytes written
186  *
187  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), fprint_id()
188  */
189 int print_id (ident *id);
190
191 /**
192  * Prints the ident to the file passed.
193  *
194  * @param F  - file pointer to print the ident to.
195  * @param id - The ident to print and the file.
196  *
197  * @return
198  *    number of btes written
199  *
200  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), print_id()
201  */
202 int fprint_id (FILE *F, ident *id);
203
204 # endif /* _IDENT_H_ */