/[ascend]/trunk/base/generic/compiler/name.h
ViewVC logotype

Contents of /trunk/base/generic/compiler/name.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1291 - (show annotations) (download) (as text)
Mon Feb 26 06:20:43 2007 UTC (17 years, 5 months ago) by johnpye
File MIME type: text/x-chdr
File size: 8509 byte(s)
Added EXTERNAL asc_default_all plus test cases.
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 by Tom Epperly
35 July 31, 1989
36 Last in CVS: $Revision: 1.13 $ $Date: 1998/06/16 16:36:28 $ $Author: mthomas $
37 */
38
39 #ifndef ASC_NAME_H
40 #define ASC_NAME_H
41
42 #include <utilities/ascConfig.h>
43 #include "compiler.h"
44 #include "expr_types.h"
45
46 /** @addtogroup compiler Compiler
47 @{
48 */
49
50 #include <utilities/ascConfig.h>
51
52 #define CreateIdName(s) CreateIdNameF((s),NAMEBIT_IDTY)
53 /**<
54 Create name with Id flag.
55 @see CreateIdNameF()
56 */
57 #define CreateSystemIdName(s) CreateIdNameF((s),NAMEBIT_IDTY|NAMEBIT_AUTO)
58 /**<
59 Create system name with Id+Auto flags.
60 @see CreateIdNameF()
61 */
62 ASC_DLLSPEC struct Name*CreateIdNameF(symchar *s, int bits);
63 /**<
64 Create a name node with the identifier s
65 and flag bits associated with it. Implementation
66 function for CreateIdName() and CreateSystemIdName().
67 */
68
69 extern struct Name *CreateSetName(struct Set *s);
70 /**<
71 Create a name node of type set with the set s associated with it.
72 */
73
74 extern struct Name *CreateEnumElementName(symchar *s);
75 /**<
76 Create a name node of type set with the subscript s associated with it.
77 */
78
79 extern struct Name *CreateIntegerElementName(long i);
80 /**<
81 Create a name node of type set with the subscript i associated with it.
82 */
83
84 extern struct Name *CreateReservedIndexName(symchar *reserved);
85 /**<
86 * Make subscript index from the reserved identifier given,
87 * which in most uses will
88 * contain an illegal character for an ascend ID reserving the
89 * set index to internal compiler use only.
90 */
91
92 extern void LinkNames(struct Name *cur, struct Name *next);
93 /**<
94 Link "next" to cur so that NextName(cur) = next
95 */
96
97 #ifdef NDEBUG
98 #define NextName(n) ((n)->next)
99 #else
100 #define NextName(n) NextNameF(n)
101 #endif
102 /**<
103 Return the next attribute of n.
104 @param n CONST struct Name*, Name to query.
105 @return The next attribute as a struct Name*.
106 @see NextNameF()
107 */
108 extern struct Name *NextNameF(CONST struct Name *n);
109 /**<
110 Return the next attribute of n.
111 Implementation function for NextName(). Do not call this
112 function directly - use NextName() instead.
113 */
114
115 #ifdef NDEBUG
116 #define NameId(n) ((n)->bits & NAMEBIT_IDTY)
117 #else
118 #define NameId(n) NameIdF(n)
119 #endif
120 /**<
121 Test whether a Name element is an identifier.
122 We should have analogous functions for CHAT and ATTR, but since no
123 clients yet use them, they aren't implemented.
124 @param n CONST struct Name*, Name to query.
125 @return An int: NAMEBIT_IDTY if n is an identifier type Name or 0 otherwise.
126 @see NameIdF()
127
128 @note This answers for just the *first* link in the name.
129
130 */
131
132 extern int NameIdF(CONST struct Name *n);
133 /**<
134 Return NAMEBIT_IDTY if n is an identifier type Name or 0 otherwise.
135 We should have analogous functions for CHAT and ATTR, but since no
136 clients yet use them, they aren't implemented.
137 Implementation function for NameId(). Do not call this
138 function directly - use NameId() instead.
139 */
140
141 #ifdef NDEBUG
142 #define NameAuto(n) ((n)->bits & (NAMEBIT_AUTO|NAMEBIT_IDTY))
143 #else
144 #define NameAuto(n) NameAutoF(n)
145 #endif
146 /**<
147 Test whether a Name is a system generated identifier.
148 @param n CONST struct Name*, Name to query.
149 @return An int: NAMEBIT_AUTO if n is an system generated identifier
150 type Name, or 0 otherwise.
151 @see NameAutoF()
152 */
153
154 extern int NameAutoF(CONST struct Name *n);
155 /**<
156 Return NAMEBIT_AUTO if n is an system generated identifier
157 type Name, or 0 otherwise.
158 Implementation function for NameAuto(). Do not call this
159 function directly - use NameAuto() instead.
160 */
161
162 #ifdef NDEBUG
163 #define NameIdPtr(n) ((n)->val.id)
164 #else
165 #define NameIdPtr(n) NameIdPtrF(n)
166 #endif
167 /**<
168 Returns the id pointer for identifier type name node n.
169 @param n CONST struct Name*, Name to query.
170 @return The id pointer as a symchar*.
171 @see NameIdPtrF()
172 */
173 extern symchar *NameIdPtrF(CONST struct Name *n);
174 /**<
175 Assumes that n is a identifier type name node.
176 @return the id pointer.
177 Implementation function for NameIdPtr(). Do not call this
178 function directly - use NameIdPtr() instead.
179 */
180
181 extern symchar *SimpleNameIdPtr(CONST struct Name *n);
182 /**<
183 Return NULL if n is not an NameId or if it has a next field. Otherwise,
184 it returns the char pointer.
185 */
186
187 extern unsigned int NameLength(CONST struct Name *n);
188 /**<
189 Returns the number of links in a name.
190
191 @note May be used in a similar manner to SimpleNameIdPtr,
192 to determine if a name is a simple name
193
194 @example
195 <tt>my_var</tt> has length 1.
196 <tt>my_var.your_var[1..3]</tt> has length 3.
197 */
198
199 #ifdef NDEBUG
200 #define NameSetPtr(n) ((n)->val.s)
201 #else
202 #define NameSetPtr(n) NameSetPtrF(n)
203 #endif
204 /**<
205 Returns the set pointer for set type name node n.
206 @param n CONST struct Name*, Name to query.
207 @return The set pointer as a CONST struct Set*.
208 @see NameSetPtrF()
209 */
210 extern CONST struct Set *NameSetPtrF(CONST struct Name *n);
211 /**<
212 Assumes that n is a set type name node.
213 Returns the set pointer.
214 Implementation function for NameSetPtr(). Do not call this
215 function directly - use NameSetPtr() instead.
216 */
217
218 extern struct Name *CopyName(CONST struct Name *n);
219 /**<
220 Make and return a copy of the whole name.
221 */
222
223 extern struct Name *CopyAppendNameNode(CONST struct Name *n, CONST struct Name *node);
224 /**<
225 Make a copy of n and append a copy of the node (which may be just the
226 head of a longer name). The result is totally disjoint from the inputs.
227 */
228
229 ASC_DLLSPEC void DestroyName(struct Name *n);
230 /**<
231 Deallocate the whole name linked list
232 Handles NULL input gracefully.
233 */
234
235 extern void DestroyNamePtr(struct Name *n);
236 /**<
237 Deallocate this name node, and don't change the next node.
238 Handles NULL input gracefully.
239 */
240
241 extern struct Name *JoinNames(struct Name *n1, struct Name *n2);
242 /**<
243 Appends n2 to the end of n1. This will return n1, unless n1 is NULL in
244 which case it will return n2.
245 */
246
247 extern struct Name *ReverseName(struct Name *n);
248 /**<
249 Returns the reverse of n.
250 Normally only done to unreverse the order that yacc collects
251 identifiers.
252 */
253
254 extern CONST struct Name *NextIdName(CONST struct Name *n);
255 /**<
256 Returns the first NameId element in the name after the current element
257 which is expected to be a NameId. If there is none, returns NULL.
258 */
259
260 extern int NameCompound(CONST struct Name *n);
261 /**<
262 Test whether name is compound (i.e. crosses a MODEL/ATOM boundary).
263 If so this returns 1, OTHERWISE this returns 0. So array names
264 will return 0.
265
266 The following return 0:
267 - a
268 - a[i]
269 - [i][j] -- though this isn't a proper name, generally.
270
271 The following return 1:
272 - a.b
273 - a[i].b
274 - [i].b
275
276 So basically, if the name is printed with a '.' this will return 1.
277 */
278
279 extern int NamesEqual(CONST struct Name *n1, CONST struct Name *n2);
280 /**<
281 Return TRUE if and only if n1 and n2 are structurally equivalent.
282 */
283
284 extern int CompareNames(CONST struct Name *n1, CONST struct Name *n2);
285 /**<
286 Returns -1 0 1 as n1 < = > n2.
287 Will need fixing when we have supported attributes.
288 */
289
290 extern void name_init_pool(void);
291 /**<
292 Starts memory recycle. Do not call twice before stopping recycle.
293 */
294
295 extern void name_destroy_pool(void);
296 /**<
297 Stops memory recycle. Do not call while ANY names are outstanding.
298 */
299
300 extern void name_report_pool(void);
301 /**<
302 Write the pool report to ASCERR for the name pool.
303 */
304
305 /* @} */
306
307 #endif /* ASC_NAME_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22