1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
3 |
Copyright (C) 2006 Carnegie Mellon University |
4 |
|
5 |
This program is free software; you can redistribute it and/or modify |
6 |
it under the terms of the GNU General Public License as published by |
7 |
the Free Software Foundation; either version 2, or (at your option) |
8 |
any later version. |
9 |
|
10 |
This program is distributed in the hope that it will be useful, |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
GNU General Public License for more details. |
14 |
|
15 |
You should have received a copy of the GNU General Public License |
16 |
along with this program; if not, write to the Free Software |
17 |
Foundation, Inc., 59 Temple Place - Suite 330, |
18 |
Boston, MA 02111-1307, USA. |
19 |
*//** |
20 |
@file |
21 |
Name external definitions. |
22 |
|
23 |
@todo WHAT'S IN A NAME??? That which we call a rose |
24 |
By any other name would smell as sweet. |
25 |
|
26 |
A name is a linked list of symchars, integers, and potentially |
27 |
unexpanded set definitions (array subscripts) |
28 |
that gives the route another instance starting at some root |
29 |
instance i. So if you have something's name and context instance, we |
30 |
know how to find the child (grandchild, etc) with the given name. |
31 |
A name without a context (either an instance or a type definition) |
32 |
means nothing. |
33 |
|
34 |
Requires: |
35 |
#include "utilities/ascConfig.h" |
36 |
#include "fractions.h" |
37 |
#include "compiler.h" |
38 |
#include "dimen.h" |
39 |
#include "expr_types.h" |
40 |
*//* |
41 |
by Tom Epperly |
42 |
July 31, 1989 |
43 |
Last in CVS: $Revision: 1.13 $ $Date: 1998/06/16 16:36:28 $ $Author: mthomas $ |
44 |
*/ |
45 |
|
46 |
#ifndef ASC_NAME_H |
47 |
#define ASC_NAME_H |
48 |
|
49 |
/** addtogroup compiler Compiler |
50 |
@{ |
51 |
*/ |
52 |
|
53 |
#include <utilities/ascConfig.h> |
54 |
|
55 |
#define CreateIdName(s) CreateIdNameF((s),NAMEBIT_IDTY) |
56 |
/**< |
57 |
Create name with Id flag. |
58 |
@see CreateIdNameF() |
59 |
*/ |
60 |
#define CreateSystemIdName(s) CreateIdNameF((s),NAMEBIT_IDTY|NAMEBIT_AUTO) |
61 |
/**< |
62 |
Create system name with Id+Auto flags. |
63 |
@see CreateIdNameF() |
64 |
*/ |
65 |
ASC_DLLSPEC struct Name*CreateIdNameF(symchar *s, int bits); |
66 |
/**< |
67 |
Create a name node with the identifier s |
68 |
and flag bits associated with it. Implementation |
69 |
function for CreateIdName() and CreateSystemIdName(). |
70 |
*/ |
71 |
|
72 |
extern struct Name *CreateSetName(struct Set *s); |
73 |
/**< |
74 |
Create a name node of type set with the set s associated with it. |
75 |
*/ |
76 |
|
77 |
extern struct Name *CreateEnumElementName(symchar *s); |
78 |
/**< |
79 |
Create a name node of type set with the subscript s associated with it. |
80 |
*/ |
81 |
|
82 |
extern struct Name *CreateIntegerElementName(long i); |
83 |
/**< |
84 |
Create a name node of type set with the subscript i associated with it. |
85 |
*/ |
86 |
|
87 |
extern struct Name *CreateReservedIndexName(symchar *reserved); |
88 |
/**< |
89 |
* Make subscript index from the reserved identifier given, |
90 |
* which in most uses will |
91 |
* contain an illegal character for an ascend ID reserving the |
92 |
* set index to internal compiler use only. |
93 |
*/ |
94 |
|
95 |
extern void LinkNames(struct Name *cur, struct Name *next); |
96 |
/**< |
97 |
Link "next" to cur so that NextName(cur) = next |
98 |
*/ |
99 |
|
100 |
#ifdef NDEBUG |
101 |
#define NextName(n) ((n)->next) |
102 |
#else |
103 |
#define NextName(n) NextNameF(n) |
104 |
#endif |
105 |
/**< |
106 |
Return the next attribute of n. |
107 |
@param n CONST struct Name*, Name to query. |
108 |
@return The next attribute as a struct Name*. |
109 |
@see NextNameF() |
110 |
*/ |
111 |
extern struct Name *NextNameF(CONST struct Name *n); |
112 |
/**< |
113 |
Return the next attribute of n. |
114 |
Implementation function for NextName(). Do not call this |
115 |
function directly - use NextName() instead. |
116 |
*/ |
117 |
|
118 |
#ifdef NDEBUG |
119 |
#define NameId(n) ((n)->bits & NAMEBIT_IDTY) |
120 |
#else |
121 |
#define NameId(n) NameIdF(n) |
122 |
#endif |
123 |
/**< |
124 |
Test whether a Name element is an identifier. |
125 |
We should have analogous functions for CHAT and ATTR, but since no |
126 |
clients yet use them, they aren't implemented. |
127 |
@param n CONST struct Name*, Name to query. |
128 |
@return An int: NAMEBIT_IDTY if n is an identifier type Name or 0 otherwise. |
129 |
@see NameIdF() |
130 |
|
131 |
@note This answers for just the *first* link in the name. |
132 |
|
133 |
*/ |
134 |
|
135 |
extern int NameIdF(CONST struct Name *n); |
136 |
/**< |
137 |
Return NAMEBIT_IDTY if n is an identifier type Name or 0 otherwise. |
138 |
We should have analogous functions for CHAT and ATTR, but since no |
139 |
clients yet use them, they aren't implemented. |
140 |
Implementation function for NameId(). Do not call this |
141 |
function directly - use NameId() instead. |
142 |
*/ |
143 |
|
144 |
#ifdef NDEBUG |
145 |
#define NameAuto(n) ((n)->bits & (NAMEBIT_AUTO|NAMEBIT_IDTY)) |
146 |
#else |
147 |
#define NameAuto(n) NameAutoF(n) |
148 |
#endif |
149 |
/**< |
150 |
Test whether a Name is a system generated identifier. |
151 |
@param n CONST struct Name*, Name to query. |
152 |
@return An int: NAMEBIT_AUTO if n is an system generated identifier |
153 |
type Name, or 0 otherwise. |
154 |
@see NameAutoF() |
155 |
*/ |
156 |
|
157 |
extern int NameAutoF(CONST struct Name *n); |
158 |
/**< |
159 |
Return NAMEBIT_AUTO if n is an system generated identifier |
160 |
type Name, or 0 otherwise. |
161 |
Implementation function for NameAuto(). Do not call this |
162 |
function directly - use NameAuto() instead. |
163 |
*/ |
164 |
|
165 |
#ifdef NDEBUG |
166 |
#define NameIdPtr(n) ((n)->val.id) |
167 |
#else |
168 |
#define NameIdPtr(n) NameIdPtrF(n) |
169 |
#endif |
170 |
/**< |
171 |
Returns the id pointer for identifier type name node n. |
172 |
@param n CONST struct Name*, Name to query. |
173 |
@return The id pointer as a symchar*. |
174 |
@see NameIdPtrF() |
175 |
*/ |
176 |
extern symchar *NameIdPtrF(CONST struct Name *n); |
177 |
/**< |
178 |
Assumes that n is a identifier type name node. |
179 |
@return the id pointer. |
180 |
Implementation function for NameIdPtr(). Do not call this |
181 |
function directly - use NameIdPtr() instead. |
182 |
*/ |
183 |
|
184 |
extern symchar *SimpleNameIdPtr(CONST struct Name *n); |
185 |
/**< |
186 |
Return NULL if n is not an NameId or if it has a next field. Otherwise, |
187 |
it returns the char pointer. |
188 |
*/ |
189 |
|
190 |
extern unsigned int NameLength(CONST struct Name *n); |
191 |
/**< |
192 |
Returns the number of links in a name. |
193 |
|
194 |
@note May be used in a similar manner to SimpleNameIdPtr, |
195 |
to determine if a name is a simple name |
196 |
|
197 |
@example |
198 |
<tt>my_var</tt> has length 1. |
199 |
<tt>my_var.your_var[1..3]</tt> has length 3. |
200 |
*/ |
201 |
|
202 |
#ifdef NDEBUG |
203 |
#define NameSetPtr(n) ((n)->val.s) |
204 |
#else |
205 |
#define NameSetPtr(n) NameSetPtrF(n) |
206 |
#endif |
207 |
/**< |
208 |
Returns the set pointer for set type name node n. |
209 |
@param n CONST struct Name*, Name to query. |
210 |
@return The set pointer as a CONST struct Set*. |
211 |
@see NameSetPtrF() |
212 |
*/ |
213 |
extern CONST struct Set *NameSetPtrF(CONST struct Name *n); |
214 |
/**< |
215 |
Assumes that n is a set type name node. |
216 |
Returns the set pointer. |
217 |
Implementation function for NameSetPtr(). Do not call this |
218 |
function directly - use NameSetPtr() instead. |
219 |
*/ |
220 |
|
221 |
extern struct Name *CopyName(CONST struct Name *n); |
222 |
/**< |
223 |
Make and return a copy of the whole name. |
224 |
*/ |
225 |
|
226 |
extern struct Name *CopyAppendNameNode(CONST struct Name *n, CONST struct Name *node); |
227 |
/**< |
228 |
Make a copy of n and append a copy of the node (which may be just the |
229 |
head of a longer name). The result is totally disjoint from the inputs. |
230 |
*/ |
231 |
|
232 |
ASC_DLLSPEC void DestroyName(struct Name *n); |
233 |
/**< |
234 |
Deallocate the whole name linked list |
235 |
Handles NULL input gracefully. |
236 |
*/ |
237 |
|
238 |
extern void DestroyNamePtr(struct Name *n); |
239 |
/**< |
240 |
Deallocate this name node, and don't change the next node. |
241 |
Handles NULL input gracefully. |
242 |
*/ |
243 |
|
244 |
extern struct Name *JoinNames(struct Name *n1, struct Name *n2); |
245 |
/**< |
246 |
Appends n2 to the end of n1. This will return n1, unless n1 is NULL in |
247 |
which case it will return n2. |
248 |
*/ |
249 |
|
250 |
extern struct Name *ReverseName(struct Name *n); |
251 |
/**< |
252 |
Returns the reverse of n. |
253 |
Normally only done to unreverse the order that yacc collects |
254 |
identifiers. |
255 |
*/ |
256 |
|
257 |
extern CONST struct Name *NextIdName(CONST struct Name *n); |
258 |
/**< |
259 |
Returns the first NameId element in the name after the current element |
260 |
which is expected to be a NameId. If there is none, returns NULL. |
261 |
*/ |
262 |
|
263 |
extern int NameCompound(CONST struct Name *n); |
264 |
/**< |
265 |
Test whether name is compound (i.e. crosses a MODEL/ATOM boundary). |
266 |
If so this returns 1, OTHERWISE this returns 0. So array names |
267 |
will return 0. |
268 |
|
269 |
The following return 0: |
270 |
- a |
271 |
- a[i] |
272 |
- [i][j] -- though this isn't a proper name, generally. |
273 |
|
274 |
The following return 1: |
275 |
- a.b |
276 |
- a[i].b |
277 |
- [i].b |
278 |
|
279 |
So basically, if the name is printed with a '.' this will return 1. |
280 |
*/ |
281 |
|
282 |
extern int NamesEqual(CONST struct Name *n1, CONST struct Name *n2); |
283 |
/**< |
284 |
Return TRUE if and only if n1 and n2 are structurally equivalent. |
285 |
*/ |
286 |
|
287 |
extern int CompareNames(CONST struct Name *n1, CONST struct Name *n2); |
288 |
/**< |
289 |
Returns -1 0 1 as n1 < = > n2. |
290 |
Will need fixing when we have supported attributes. |
291 |
*/ |
292 |
|
293 |
extern void name_init_pool(void); |
294 |
/**< |
295 |
Starts memory recycle. Do not call twice before stopping recycle. |
296 |
*/ |
297 |
|
298 |
extern void name_destroy_pool(void); |
299 |
/**< |
300 |
Stops memory recycle. Do not call while ANY names are outstanding. |
301 |
*/ |
302 |
|
303 |
extern void name_report_pool(void); |
304 |
/**< |
305 |
Write the pool report to ASCERR for the name pool. |
306 |
*/ |
307 |
|
308 |
/* @} */ |
309 |
|
310 |
#endif /* ASC_NAME_H */ |