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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1066 - (show annotations) (download) (as text)
Sun Jan 7 10:02:41 2007 UTC (17 years, 8 months ago) by johnpye
File MIME type: text/x-chdr
File size: 11859 byte(s)
Adding doxygen 'addtogroup' for Solver, Compiler, Integrator.
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 1996 Benjamin Allan
4 Copyright (C) 2006 Carnegie Mellon University
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20 *//**
21 @file
22 This is a package of routines to process child lists.
23
24 Requires
25 #include "utilities/ascConfig.h"
26 #include "fractions.h"
27 #include "compiler.h"
28 #include "dimen.h"
29 #include "list.h"
30 *//*
31 by Tom Epperly
32 Version: $Revision: 1.21 $
33 Version control file: $RCSfile: child.h,v $
34 Date last modified: $Date: 1998/03/17 22:08:26 $
35 Last modified by: $Author: ballan $
36 */
37
38 #ifndef ASC_CHILD_H
39 #define ASC_CHILD_H
40
41 /** addtogroup compiler Compiler
42 @{
43 */
44
45 #include <utilities/ascConfig.h>
46
47 /**
48 * The ChildListStructure is a private implementation detail.
49 * All the public interface needs is a pointer thereto.
50 */
51 typedef CONST struct ChildListStructure *ChildListPtr;
52
53 /**
54 * The ChildListEntry is the interface container for creating
55 * childlists. Storage scheme and usage after that is all
56 * black magic which can only be done by following this header.<br><br>
57 *
58 * As of 9/96 we've added a number of important features to
59 * ChildList, and it's nobody's business how we implement it.
60 */
61 struct ChildListEntry {
62 symchar *strptr;
63 /**< the symbol table name of a child, eg "a" of a[i][j] */
64 CONST struct TypeDescription *typeptr;
65 /**< the most refined type for the child that can be determined
66 * at parse time. Corresponding instances at run time may be this or
67 * a more refined type. This allows several kinds of sanity checking.
68 * This pointer must not be NULL.
69 */
70 CONST struct Statement *statement;
71 /**< statement where child is initially defined. */
72 unsigned bflags;
73 /**< boolean flags, as defined below with CBF_* */
74 short isarray;
75 /**< isarray should be number of subscripts if you firmly
76 * believe the named child is an array. Nobody could possibly
77 * have more than a shorts worth of subscripts.
78 */
79 short origin;
80 /**< tells how child created (ALIASES, ARR, WILL_BE, IS_A,
81 * P-ALIASES, P-ARR, P-IS_A, P-WILL_BE)
82 * P-IS_A and P-WILL_BE indicate that it came through a parameter list.
83 * P-ALIASES indicates an alias of something that came through a
84 * parameter list WILL_BE directly or indirectly (as a part of a parameter).
85 *
86 * The set in the ALIASES-IS_A statement gets
87 * listed as an IS_A origin. The array gets listed as an ARR origin.
88 */
89
90 #define origin_ERR 0 /**< Origin code - invalid origin. */
91 /* set 1 */
92 #define origin_ALI 1 /**< Origin code - ALIASES. */
93 #define origin_ARR 2 /**< Origin code - ARR. */
94 #define origin_ISA 3 /**< Origin code - IS_A. */
95 #define origin_WB 4 /**< Origin code - WILL_BE. */
96 /* set 2 should match set 1, except having P and being > by offset */
97 #define origin_PALI 5 /**< Origin code - P-ALIASES. */
98 #define origin_PARR 6 /**< Origin code - P-ARR. */
99 #define origin_PISA 7 /**< Origin code - P-IS_A. */
100 #define origin_PWB 8 /**< Origin code - P-WILL_BE. */
101 #define origin_EXT 9 /**< Origin code - EXT statement */
102 #define origin_PARAMETER_OFFSET (origin_PALI - origin_ALI)
103 /**<
104 * Distance between corresponding origin and the parametric version.
105 * If you mess with these origin defines, fix the macro LegalOrigin
106 * in child.c
107 */
108
109 /* child boolean flag bit definitions */
110 #define CBF_VISIBLE 0x1 /**< child to be shown in UI among lists */
111 #define CBF_SUPPORTED 0x2 /**< child is a '$upported' attribute */
112 #define CBF_PASSED 0x4 /**< child is argument to another child.
113 Note that because of arrays, CBF_PASSED
114 is approximate. If a[1] is passed, a gets
115 marked passed, but if a.b is passed, a is not. */
116 /* other CBF as required */
117 }; /* struct ChildListEntry */
118
119 #define AliasingOrigin(ori) \
120 ((ori) == origin_PALI || (ori) == origin_ALI || \
121 (ori) == origin_PARR || (ori) == origin_ARR)
122 /**< Returns 1 if the value given is an alias sort. */
123
124 #define ParametricOrigin(ori) ((ori) >= origin_PALI && (ori) <= origin_PWB)
125 /**< Returns 1 if the value given is a parametric sort or 0 if not. */
126
127 extern int CmpChildListEntries(CONST struct ChildListEntry *e1,
128 CONST struct ChildListEntry *e2);
129 /**<
130 * Returns the result of an alphabetical order comparison
131 * on the names in the two pointers. Not necessarily implemented
132 * with strcmp, however, so you should use this function.
133 */
134
135 extern ChildListPtr CreateChildList(struct gl_list_t *l);
136 /**<
137 * This takes a list of struct ChildListEntry * from a gl_list_t to a
138 * ChildList type.
139 * l must be sorted and should not contain any duplicate entries,
140 * nor any entries with a NULL typeptr.
141 * There are no other preconditions on l. Children lists are always
142 * stored in alphabetic order (strcmp).
143 * If the list isn't sorted, we will sort it at rather an expense.
144 * You still own the list l AND its entries and should act accordingly.
145 * We will return a ChildListPtr. You don't know what is in that.
146 * We own the memory to it and only we know how to destroy it.
147 * Creating a ChildListPtr causes the type
148 * descriptions of the children to be copied.<br><br>
149 *
150 * This function should never return a NULL pointer except in the
151 * case where you have specified input with a NULL typeptr.
152 */
153
154 extern void DestroyChildList(ChildListPtr cl);
155 /**<
156 * Deallocate the memory associated with the list but not the symchars in
157 * the list. The fact that you're passing a CONST pointer object into
158 * this function is somewhat odd, but it suffices to know that after
159 * this call, any data that might have been in the pointer you gave us
160 * really has been disposed of.
161 */
162
163 extern ChildListPtr AppendChildList(ChildListPtr cl, struct gl_list_t *l);
164 /**<
165 * Create and return a new child list which contains all the information
166 * contained in cl or l. l must be sorted, and it is assumed that there
167 * are no duplicate entries. The new list returned is sorted.
168 * If l is not sorted, we will sort it at rather an expense.
169 * The same conditions for l in CreateChildList apply here.
170 */
171
172 ASC_DLLSPEC unsigned long ChildListLen(ChildListPtr cl);
173 /**<
174 * Return the length of the child list.
175 */
176
177 ASC_DLLSPEC symchar *ChildStrPtr(ChildListPtr cl, unsigned long n);
178 /**<
179 * Return child number n name element 1 string.
180 * Children are numbered 1..ChildListLen(cl).
181 */
182
183 extern unsigned int ChildIsArray(ChildListPtr cl, unsigned long n);
184 /**<
185 * Return >= 1 if child number n is determined array type at parse time.
186 * The return value the number of subscripts of child n
187 * needed to reach a single array element of ChildBaseTypePtr type.
188 * Returns 0 if type is not array.
189 */
190
191 extern unsigned int ChildOrigin(ChildListPtr cl, unsigned long n);
192 /**<
193 * Return the origin code of the child.
194 */
195
196 extern unsigned int ChildAliasing(ChildListPtr cl, unsigned long n);
197 /**<
198 * Return the Aliasness of a child, meaning if the child ALIASES one
199 * passed into the type definition or a part of the definition.
200 */
201
202 extern unsigned int ChildParametric(ChildListPtr cl, unsigned long n);
203 /**<
204 * Return the parametricness of a child. That is, if the child is one
205 * passed into the type definition or one aliasing something or a part of
206 * something passed into the definition.
207 */
208
209 extern CONST struct Statement *ChildStatement(ChildListPtr cl, unsigned long n);
210 /**<
211 * Return child number n initial declaration statement.
212 * Children are numbered 1..ChildListLen(cl).
213 */
214
215 ASC_DLLSPEC unsigned ChildGetBooleans(ChildListPtr cl, unsigned long n);
216 /**<
217 * Return child number n current boolean flags.
218 * Children are numbered 1..ChildListLen(cl).
219 * If an improperly large or small n is given, result is 0.
220 */
221
222 #define ChildVisible(cl,n) ((ChildGetBooleans((cl),(n)) & CBF_VISIBLE)!=0)
223 /**<
224 * Returns 1 if child has visibility bit turned on.
225 */
226
227 #define ChildSupported(cl,n) ((ChildGetBooleans((cl),(n)) & CBF_SUPPORTED)!=0)
228 /**<
229 * Returns 1 if child has supported bit turned on.
230 */
231
232 #define ChildPassed(cl,n) ((ChildGetBooleans((cl),(n)) & CBF_PASSED) !=0)
233 /**<
234 * Returns 1 if child has PASSED bit turned on.
235 */
236
237 ASC_DLLSPEC void ChildSetBoolean(ChildListPtr cl, unsigned long n,
238 unsigned cbfname, unsigned val);
239 /**<
240 * Set child number n current boolean flag bit cbfname to val.
241 * Children are numbered 1..ChildListLen(cl).
242 * cbfname is a child boolean flag CBF_ defined above.
243 * val is 0 or 1 only.
244 */
245
246 #define ChildHide(cl,n) ChildSetBoolean((cl),(n),CBF_VISIBLE,0)
247 /**<
248 * Hide (presumably for display purposes) the nth child in cl.
249 * @param cl CONST ChildListPtr*
250 * @param n unsigned long
251 */
252
253 #define ChildShow(cl,n) ChildSetBoolean((cl),(n),CBF_VISIBLE,1)
254 /**<
255 * Unhide (presumably for display purposes) the nth child in cl.
256 * @param cl CONST ChildListPtr
257 * @param n unsigned long
258 */
259
260 extern CONST struct TypeDescription *ChildBaseTypePtr(ChildListPtr cl,
261 unsigned long n);
262 /**<
263 * Return child number n type determinable at parse time.
264 * If type was not determinable, returns NULL, but this will never be
265 * the case as Something is always determinable.
266 * NOTE: an array child does not return an array type description but
267 * instead the base type for the array. Note that this requires we
268 * ignore refinement statements on specific array children when dealing
269 * with array base type info.
270 * If this pointer is not NULL, then any corresponding instance will
271 * be of at least the type returned.
272 * Children are numbered 1..ChildListLen(cl).<br><br>
273 *
274 * Note: The children of atoms always return NULL type since they do
275 * not have type descriptions in the system because they are not full
276 * instances.
277 */
278
279 ASC_DLLSPEC unsigned long ChildPos(ChildListPtr cl, symchar *s);
280 /**<
281 * Search for the string s in child list cl. If it is not found,
282 * it will return 0; otherwise, it returns the index of the child which
283 * matches s.
284 * s must be in the symbol table. If s is NOT in the symbol table,
285 * then it is impossible a priori for this function to return nonzero
286 * and so it will not return at all because you have asked a stupid
287 * question.
288 * If you need to check s yourself, AscFindSymbol(s) will return
289 * s if s is in the symbol table -- but there should never be a
290 * programming context where you need to check.
291 * If you need to guarantee s is in the table, call AddSymbol first.
292 */
293
294 extern int CompareChildLists(ChildListPtr cl, ChildListPtr c2, unsigned long *diff);
295 /**<
296 * Returns -1/0/1 as d1 <,==,> d2 (0). If cmp != 0, diff = position
297 * in child list d2 of first difference, i.e. if the lists are m and n
298 * long (m > n) and OTHERWISE equivalent, diff = n + 1.
299 */
300
301 extern void WriteChildList(FILE *fp, ChildListPtr cl);
302 /**<
303 * Write what is known at parse time about the children in the child list
304 * given. What is known may be surprising. It may be only mildly
305 * accurate.
306 */
307
308 /* @} */
309
310 #endif /* ASC_CHILD_H */

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