preprocessor flag for node_nr
[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 typedef const struct ident ident;
37
38 /**
39  * The ident module interface.
40  */
41 typedef struct _ident_if_t {
42   /**
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.
46    *
47    * @param str - the string which shall be stored
48    */
49   ident *(*new_id_from_str)(void *handle, const char *str);
50
51   /**
52    * Store a string and create an ident.
53    *
54    * @param str - the string (or whatever) which shall be stored
55    * @param len - the length of the data in bytes
56    */
57   ident *(*new_id_from_chars)(void *handle, const char *str, int len);
58
59   /**
60    * Returns a string represented by an ident.
61    */
62   const char *(*get_id_str)(void *handle, ident *id);
63
64   /**
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.
68    *
69    * @param id - the ident
70    */
71   int  (*get_id_strlen)(void *handle, ident *id);
72
73   /**
74    * Finish the ident module and frees all idents, may be NULL.
75    */
76   void (*finish_ident)(void *handle);
77
78   /** The handle. */
79   void *handle;
80
81 } ident_if_t;
82
83 /**
84  *  Store a string and create an ident.
85  *
86  *  Stores a string in the ident module and returns a handle for the string.
87  *
88  *  Copies the string. @p str must be zero terminated
89  *
90  * @param str - the string which shall be stored
91  *
92  * @return id - a handle for the generated ident
93  *
94  * @see get_id_str(), get_id_strlen()
95  */
96 ident *new_id_from_str (const char *str);
97
98 /** Store a string and create an ident.
99  *
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.
102  *
103  * @param str - the string (or whatever) which shall be stored
104  * @param len - the length of the data in bytes
105  *
106  * @return id - a handle for the generated ident
107  *
108  * @see new_id_from_str(), get_id_strlen()
109  */
110 ident *new_id_from_chars (const char *str, int len);
111
112 /**
113  * Returns a string represented by an ident.
114  *
115  * Returns the string represented by id. This string is
116  * NULL terminated. The string may not be changed.
117  *
118  * @param id - the ident
119  *
120  * @return cp - a string
121  *
122  * @see new_id_from_str(), new_id_from_chars(), get_id_strlen()
123  */
124 const char *get_id_str  (ident *id);
125
126 /**
127  * Returns the length of the string represented by an ident.
128  *
129  * @param id - the ident
130  *
131  * @return len - the length of the string
132  *
133  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
134  */
135 int  get_id_strlen(ident *id);
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 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 int id_is_suffix (ident *suffix, ident *id);
155
156 /**
157  * Returns true if infix is contained in id.  (Can be suffix or prefix)
158  *
159  * @param infix  - the infix
160  * @param id     - the ident to search in
161  *
162  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix()
163  */
164 /* int id_contains(ident *infix, ident *id); */
165
166 /**
167  * Return true if an ident contains a given character.
168  *
169  * @param id     - the ident
170  * @param c      - the character
171  *
172  * @see new_id_from_str(), new_id_from_chars(), get_id_str()
173  */
174 int id_contains_char (ident *id, char c);
175
176 /**
177  * Prints the ident to stdout.
178  *
179  * @param id - The ident to be printed.
180  *
181  * @return
182  *    number of bytes written
183  *
184  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), fprint_id()
185  */
186 int print_id (ident *id);
187
188 /**
189  * Prints the ident to the file passed.
190  *
191  * @param F  - file pointer to print the ident to.
192  * @param id - The ident to print and the file.
193  *
194  * @return
195  *    number of btes written
196  *
197  * @see new_id_from_str(), new_id_from_chars(), get_id_str(), id_is_prefix(), print_id()
198  */
199 int fprint_id (FILE *F, ident *id);
200
201 # endif /* _IDENT_H_ */