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

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