56c5b4e194242e54ae99a576290fb616260dfe81
[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 set_entry ident;
37
38 /**
39  *  Store a string and create an ident.
40  *
41  *  Stores a string in the ident module and returns a handle for the string.
42  *
43  *  Copies the string. @p str must be zero terminated
44  *
45  * @param str - the string which shall be stored
46  *
47  * @return id - a handle for the generated ident
48  *
49  * @see get_id_str(), get_id_strlen()
50  */
51 ident *new_id_from_str (const char *str);
52
53 /**
54  *  Store a string and create an ident.
55  *
56  *  Stores a string in the ident module and returns a handle for the string.
57  *
58  *  Copies the string. This version can take non-zero-terminated strings
59  *
60  * @param str - the string (or whatever) which shall be stored
61  * @param len - the length of the data in bytes
62  *
63  * @return id - a handle for the generated ident
64  *
65  * @see new_get_id_str(), get_id_strlen()
66  */
67 INLINE ident *id_from_str (const char *str, int len);
68
69 /**
70  * Returns a string represented by an ident.
71  *
72  * Returns the string represented by id. This string is
73  * NULL terminated. The string may not be changed.
74  *
75  * @param id - the ident
76  *
77  * @return cp - a string
78  *
79  * @see new_get_id_str(), id_from_str(), get_id_strlen()
80  */
81 INLINE const char *get_id_str  (ident *id);
82 #define id_to_str  get_id_str
83
84 /**
85  * Returns the length of the string represented by an ident.
86  *
87  * @param id - the ident
88  *
89  * @return len - the length of the string
90  *
91  * @see new_get_id_str(), id_from_str(), get_id_str()
92  */
93 INLINE int  get_id_strlen(ident *id);
94 #define id_to_strlen get_id_strlen
95 /**
96  * Returns true if prefix is a prefix of an ident.
97  *
98  * @param prefix - the prefix
99  * @param id     - the ident
100  *
101  * @see new_get_id_str(), id_from_str(), get_id_str(), id_is_prefix()
102  */
103 int id_is_prefix (ident *prefix, ident *id);
104
105 /**
106  * Returns true if suffix is a suffix of an ident.
107  *
108  * @param suffix - the suffix
109  * @param id     - the ident
110  *
111  * @see new_get_id_str(), id_from_str(), get_id_str(), id_is_prefix()
112  */
113 int id_is_suffix (ident *suffix, ident *id);
114
115 /**
116  * Returns true if infix is a contained in id.  (Can be suffix or prefix)
117  *
118  * @param infix  - the infix
119  * @param id     - the ident to search in
120  *
121  * @see new_get_id_str(), id_from_str(), get_id_str(), id_is_prefix()
122  */
123 //int id_contains(ident *infix, ident *id);
124
125 /**
126  * Return true if an ident contains a given character.
127  *
128  * @param id     - the ident
129  * @param c      - the character
130  *
131  * @see new_get_id_str(), id_from_str(), get_id_str()
132  */
133 int id_contains_char (ident *id, char c);
134
135 /**
136  * Prints the ident to stdout.
137  *
138  * @param id - The ident to be printed.
139  *
140  * @return
141  *    number of btes written
142  *
143  * @see new_get_id_str(), id_from_str(), get_id_str(), id_is_prefix(), fprint_id()
144  */
145 int print_id (ident *id);
146
147 /**
148  * Prints the ident to the file passed.
149  *
150  * @param F  - file pointer to print the ident to.
151  * @param id - The ident to print and the file.
152  *
153  * @return
154  *    number of btes written
155  *
156  * @see new_get_id_str(), id_from_str(), get_id_str(), id_is_prefix(), print_id()
157  */
158 int fprint_id (FILE *F, ident *id);
159
160 # endif /* _IDENT_H_ */