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

Contents of /trunk/base/generic/compiler/instance_io.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: 12928 byte(s)
Adding doxygen 'addtogroup' for Solver, Compiler, Integrator.
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Weidner Epperly
3 Copyright 1996 Benjamin Andrew 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 Instance Output Routines.
23 *//*
24 by Tom Epperly
25 Created: 2/8/90
26 Version: $Revision: 1.21 $
27 Version control file: $RCSfile: instance_io.h,v $
28 Date last modified: $Date: 1998/01/11 17:03:34 $
29 Last modified by: $Author: ballan $
30 */
31 /* blimey tom epperly you keep gaining middle-names */
32
33
34 #ifndef ASC_INSTANCE_IO_H
35 #define ASC_INSTANCE_IO_H
36
37 /** addtogroup compiler Compiler
38 @{
39 */
40
41 #include <utilities/ascConfig.h>
42 #include <general/dstring.h>
43 #include <compiler/compiler.h>
44 #include <compiler/symtab.h>
45 #include <compiler/instance_enum.h>
46
47 /**
48 Return the instance's type name as given in instance_enum.h.
49 This is a constant char pointer that the called does NOT own.
50
51 Panics if the inst_t in the instance isn't found in our list of names.
52
53 @return the name
54 */
55 CONST char *instance_typename(CONST struct Instance *inst);
56
57 /**
58 * struct NameNode is used by the AllPaths() and WriteAliases() routines to
59 * keep track of an instance and which child name is used for a
60 * particular name chain.
61 */
62 struct NameNode {
63 CONST struct Instance *inst;
64 unsigned long index;
65 };
66
67 extern struct gl_list_t *ShortestPath(CONST struct Instance *inst,
68 CONST struct Instance *ref,
69 /* CONST */ unsigned int height,
70 /* CONST */ unsigned int best);
71 /**<
72 * Collect all instances in path connecting inst with ref and returns
73 * them in a list. If path doesn't exist, it returns NULL. Path will
74 * be such that the smallest number of intermediate instances are used.
75 * This is a recursive function so send in 0,UINT_MAX as the last two
76 * arguments to initiate the call.<br><br>
77 *
78 * This returns a list of pointers to instances, and it should be
79 * deallocated with gl_destroy(path).
80 */
81
82 extern struct gl_list_t *AllPaths(CONST struct Instance *inst);
83 /**<
84 * AllPaths makes and returns a list of lists of NameNode structures.
85 * Each member of list AllPaths returns is a path from the given instance
86 * to root.<br><br>
87 *
88 * How to deallocate the result of AllPaths:
89 * Here is an example of how to deallocate the results. Use it or
90 * something equivalent.
91 * <pre>
92 * struct gl_list_t *paths,*path;
93 * paths = AllPaths(i);
94 * ....whatever....
95 * for(c=1;c <= gl_length(paths);c++){
96 * gl_free_and_destroy(gl_fetch(paths,c));
97 * }
98 * gl_destroy(paths);
99 * </pre>
100 */
101
102 extern struct gl_list_t *ISAPaths(CONST struct gl_list_t *pathlist);
103 /**<
104 * Given pathlist, the output of AllPaths, returns the list of
105 * names which are real: that is names which have been constructed
106 * without ALIASES or WILL_BE's intermediate.
107 * The list returned contains pointers to elements of the pathlist given,
108 * so it should be destroyed with gl_destroy(isalist) before the
109 * AllPaths destruction is applied to pathlist.
110 * In well written MODELs, the isalist returned will be one long.
111 */
112
113 ASC_DLLSPEC int WriteInstanceName(FILE *f,
114 CONST struct Instance *i,
115 CONST struct Instance *ref);
116 /**<
117 Print the instance's name to the specified file. The name that is
118 printed is derived from the shortest path between i and ref. If
119 ref is NULL, the shortest path to root is used. The number of
120 characters written is returned, to assist in pretty printing or
121 line breaking.
122 */
123
124 extern void WriteInstanceNameDS(Asc_DString * dsPtr,
125 CONST struct Instance *i,
126 CONST struct Instance *ref);
127 /**<
128 Print the instance's name to the specified dstring. The name that is
129 printed is derived from the shortest path between i and ref. If
130 ref is NULL, the shortest path to root is used.
131 This does not put a . in at the beginning of a name, so you cannot
132 build up proper names in a DS with it. It writes proper
133 relative names instead, where the context is assumed to be ref.
134 */
135
136 ASC_DLLSPEC char*WriteInstanceNameString(CONST struct Instance *i,
137 CONST struct Instance *ref);
138 /**<
139 Return a string (that the caller then owns). The name that is
140 printed is derived from the shortest path between i and ref. If
141 ref is NULL, the shortest path to root is used.
142 The name will not begin with a '.', even if the path ref
143 is not a simulation or NULL.
144 */
145
146 ASC_DLLSPEC int WriteAnyInstanceName(FILE *f, struct Instance *i);
147 /**<
148 * Print the instance's name to the specified file.
149 * Very similar to WriteInstanceName(). The name that is
150 * printed is derived from *any* path from i to NULL.
151 * This function was designed for speed, rather than good
152 * looks, and may be used for bulk writing of instance names. Returns
153 * the count of characters written.
154 */
155
156 ASC_DLLSPEC unsigned long CountAliases(CONST struct Instance *i);
157 /**<
158 * Count all the known names of the instance given.
159 */
160
161 ASC_DLLSPEC unsigned long CountISAs(CONST struct Instance *i);
162 /**<
163 * Count the names with which the instance given was created.
164 */
165
166 extern void WriteAliases(FILE *f, CONST struct Instance *i);
167 /**<
168 * Print all the instance's names to the specified file.
169 */
170
171 extern void WriteISAs(FILE *f, CONST struct Instance *i);
172 /**<
173 * Print the instance's constructed names to the specified file.
174 * (there may not be any in bizarre circumstances).
175 */
176
177 ASC_DLLSPEC struct gl_list_t *WriteAliasStrings(CONST struct Instance *i);
178 /**<
179 * Return a list of strings of all the possible instance names for i.
180 * The list AND the strings on it are the user's responsibility to destroy.
181 * gl_free_and_destroy(aliases) would be convenient.
182 */
183
184 ASC_DLLSPEC struct gl_list_t *WriteISAStrings(CONST struct Instance *i);
185 /**<
186 * Return a list of strings of all the constructed instance names for i.
187 * Names created by WILL_BE/ALIASES are not returned.
188 * Under bizarre circumstances, the list may be empty.
189 * The list AND the strings on it are the user's responsibility to destroy.
190 * gl_free_and_destroy(aliases) would be convenient.
191 *
192 * @bug Returns IS_A'd parents as well. need to hunt down the path
193 * of instances being tracked and see if they were passed the original
194 * instance we queried about.
195 */
196
197 extern void WriteClique(FILE *f, CONST struct Instance *i);
198 /**<
199 * Print all the instance's clique members.
200 */
201
202 ASC_DLLSPEC void WriteInstance(FILE *f, CONST struct Instance *i);
203 /**<
204 * Print the information contained in i.
205 */
206
207 extern int WritePath(FILE *f, CONST struct gl_list_t *path);
208 /**<
209 * Returns the number of name pieces written.
210 */
211
212 extern char *WritePathString(CONST struct gl_list_t *path);
213 /**<
214 * <!-- str = WritePathString(path); -->
215 * <!-- CONST struct gl_list_t *path; -->
216 * <!-- char *str; -->
217 * Returns the path in a string. The caller should free the string when
218 * done with it.
219 */
220
221 ASC_DLLSPEC void SaveInstance(FILE *f, CONST struct Instance *inst, int dorelations);
222 /**<
223 * Save the information contained in inst in a format that will allow
224 * efficient reconstruction of the instance. This will be followed up
225 * with RestoreInstance.
226 */
227
228 extern void WriteInstanceList(struct gl_list_t *list);
229 /**<
230 * This is a debugging aid and not intended for general use.
231 * It assumes that this is a list of instances and will try to write
232 * out the instance name for each element on the list.
233 */
234
235 ASC_DLLSPEC void WriteAtomValue(FILE *fp, CONST struct Instance *i);
236 /**<
237 * Write an instance value to fp.
238 */
239
240 typedef VOIDPTR (*IPFunc)(struct Instance *,VOIDPTR);
241 /**<
242 * This is the type of function you should write for use with
243 * PushInterfacePtrs(). It will be applied to the instances in the
244 * tree. If your function returns anything other than NULL, then
245 * we will make the instance's interface pointer be the pointer you
246 * returned.<br><br>
247 * In constructing instance bridges it is good to be able to attach
248 * temporary data structures to instances during construction. These
249 * temporary structures should not be left laying about. Rather, you
250 * should call the following Push and Pop functions like so:
251 * <pre>
252 * int build_my_bridge(struct Instance *i, ...)
253 * {
254 * struct gl_list_t *oldips = NULL;
255 * oldips = PushInterfacePtrs(i,YourCreateFunc,0,1,vp);
256 * Do whatever you need to here, making the assumption
257 * that the instance's YourFunc was interested in have
258 * the data created by YourFunc in their interface_ptrs.
259 * PopInterfacePtrs(oldips,YourDestroyFunc,vp);
260 * }
261 * </pre>
262 * If everyone follows this rule, it is easy to see that we can
263 * support nested transient clients so long as they don't go
264 * sneaking around in each others guts. Abstraction is your friend.
265 * Clients, such as a horribly sloppy GUI, may work without using the
266 * push and pop functions, but sanity insurance is then THAT client's
267 * responsibility and none of ours.
268 */
269
270 extern struct gl_list_t *PushInterfacePtrs(struct Instance *i,
271 IPFunc ipcreatef,
272 unsigned long int iest,
273 int visitorder,
274 VOIDPTR vp);
275 /**<
276 * Creates a gl_list and returns it to you.
277 * It contains the information needed to restore the state of the
278 * instance interface pointers ipcreatef returns non-NULL values for.
279 * Remember that not all instance types have interface pointers.
280 * Push does not visit subatomic instances (ATOM/reln children).<br><br>
281 * The algorithm is as follows:
282 * - Create an initial gl_list of capacity = 2 * iest (we keep pairs).
283 * (Thus, iest allows you to give us a hint about how many insts
284 * you expect to be interested in. iest need not be a perfect hint.)
285 * - Visit the instance tree (visitorder is treated as order is in
286 * the VisitInstanceTree function). Each place that ipcreatef
287 * returns non-NULL, save ip state information in the gl_list and
288 * replace it in the instance with your ip data.
289 * - Return gllist.
290 * The gl_list returned here can only be safely destroyed by a call
291 * following to PopInterfacePtrs.
292 * The gl_list returned may be NULL if malloc fails or you forgot
293 * ipcreatef.<br><br>
294 *
295 * ASSUMPTION: For the duration of the Push/Pop sequence you will be
296 * taking NO compiler action that deletes, relocates, or merges any
297 * part of the subtree rooted at instance i.
298 * Violate this rule and we die most probably.
299 * This is not a hard assumption to meet in single thread code.
300 */
301
302 typedef VOIDPTR (*IPDeleteFunc)(struct Instance *, VOIDPTR, VOIDPTR);
303 /**<
304 * This is a function you supply. It will be called with the pointer
305 * you returned in IPFunc and the matching instance and the void
306 * you passed to PopInterfacePtrs.
307 * This is so you may do any destruction of the objects returned by IPFunc.
308 */
309
310 extern void PopInterfacePtrs(struct gl_list_t *oldips,
311 IPDeleteFunc ipdestroyf,
312 VOIDPTR vp);
313 /**<
314 * This function restores the previous state of interface pointers.
315 * oldips is from a call to PushInterfacePtrs.
316 * ipdestroyf is a function you provide. If you provide NULL
317 * (meaning that no deallocation of objects pointed at by interface_ptr)
318 * we simply restore the old state. If ipdestroyf is not NULL, we
319 * will call it on the instances in oldips.
320 * We deallocate oldips, this is not your job.
321 */
322
323 ASC_DLLSPEC int ArrayIsRelation(struct Instance *i);
324 /**<
325 * Returns 1 if the instance sent in is a good relation array or relation,
326 * 0 OTHERWISE.
327 */
328
329 ASC_DLLSPEC int ArrayIsLogRel(struct Instance *i);
330 /**<
331 * Returns 1 if the instance sent in is a good logical relation array
332 * or logical relation, 0 OTHERWISE.
333 */
334
335 ASC_DLLSPEC int ArrayIsWhen(struct Instance *i);
336 /**<
337 * Returns 1 if the instance sent in is a good when array
338 * or when, 0 OTHERWISE.
339 */
340
341 extern int ArrayIsModel(struct Instance *i);
342 /**<
343 * Returns 1 if the instance sent in is a good model array
344 * or when, 0 OTHERWISE.
345 */
346
347 /* @} */
348
349 #endif /* ASC_INSTANCE_IO_H */
350

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