1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 1996 Ben Allan |
3 |
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
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 |
*//** @file |
21 |
Ascend Instance Miscellaneous Queries. |
22 |
|
23 |
Requires: |
24 |
#include "instance_enum.h" |
25 |
#include "compiler.h" |
26 |
*//* |
27 |
by Tom Epperly & Ben Allan |
28 |
based on instance.c |
29 |
8/16/89 |
30 |
Last in CVS: $Revision: 1.13 $ $Date: 1998/02/05 16:36:48 $ $Author: ballan $ |
31 |
*/ |
32 |
|
33 |
#ifndef ASC_INSTQUERY_H |
34 |
#define ASC_INSTQUERY_H |
35 |
|
36 |
/** addtogroup compiler Compiler |
37 |
@{ |
38 |
*/ |
39 |
|
40 |
#include <utilities/ascConfig.h> |
41 |
|
42 |
/*------------------------------------------------------------------------------ |
43 |
INTERFACE POINTER FUNCTIONS |
44 |
|
45 |
The following InterfacePtr functions are to support a global, |
46 |
persistent client (most likely a GUI) that for some reason |
47 |
insists (brain dead idiot) that it must decorate the instance |
48 |
tree with persistent pointers to information packets of its own |
49 |
devising. |
50 |
|
51 |
These functions are used by the compiler to handle data an |
52 |
interface may have left hanging off the instance when an incremental |
53 |
compile (delete, move, merge) action is in progress. They should never |
54 |
OTHERWISE be active. |
55 |
|
56 |
For a more robust, transient protocol see instance_io.h. |
57 |
*/ |
58 |
|
59 |
extern void (*InterfacePtrDelete)(); |
60 |
/**< |
61 |
* This global variable should be provided by the interface. It is a |
62 |
* pointer to a void function(procedure). This procedure will be called |
63 |
* when an instance is deleted. Its purpose is to dispose of the |
64 |
* interface ptr, in other words to clean up/or save the object that the |
65 |
* interfaceptr is looking at. Below is a trivial example. The instance |
66 |
* pointer i may not be a complete instance. So you should not call |
67 |
* any instance routines on it. |
68 |
* <pre> |
69 |
* void InterfacePtrDeleteProc(i,ptr) |
70 |
* struct Instance *i; |
71 |
* struct InterfacePtr *ptr; |
72 |
* { |
73 |
* if (ptr!=NULL) free((VOIDPTR)ptr); |
74 |
* } |
75 |
* main(argc,argv) |
76 |
* { |
77 |
* ....other initialization junk....; |
78 |
* InterfacePtrDelete = InterfacePtrDeleteProc; |
79 |
* ...etc...; |
80 |
* } |
81 |
* </pre> |
82 |
*/ |
83 |
|
84 |
extern void (*InterfaceNotify)(); |
85 |
/**< |
86 |
* This global variable should be provided by the interface. It is a |
87 |
* pointer to a void function(procedure). This procedure will be called |
88 |
* when an instance is moved in memory. It is provided in case the |
89 |
* interface has a link to the instance. The old pointer should not be |
90 |
* dereferenced. Below is a trivial example: |
91 |
* <pre> |
92 |
* void InterfaceNotifyProc(ptr,old,new) |
93 |
* struct InterfacePtr *ptr; |
94 |
* struct Instance *old,*new; the old and new address of the instance |
95 |
* { |
96 |
* if(ptr!=NULL){ |
97 |
* ptr->inst = new; |
98 |
* } |
99 |
* } |
100 |
* |
101 |
* main(argc,argv) |
102 |
* { |
103 |
* ...other initialization junk...; |
104 |
* InterfaceNotify = InterfaceNotifyProc; |
105 |
* ...etc...; |
106 |
* } |
107 |
* </pre> |
108 |
*/ |
109 |
|
110 |
extern void (*InterfacePtrATS)(); |
111 |
/**< |
112 |
* This global variable should be provided by the interface. It is a |
113 |
* pointer to a void function(procedure). The function will be called |
114 |
* when two instances are going to be ARE_THE_SAME'd. The function's |
115 |
* job is to perform any actions that the interface might want done. |
116 |
* It should not destroy any memory. This will be done by destroy |
117 |
* Instance. |
118 |
* Below is a trivial example: |
119 |
* <pre> |
120 |
* void InterfacePtrATSFunc(i1,i2) |
121 |
* struct Instance *i1, *i2; |
122 |
* { |
123 |
* struct InterfacePtr *ptr1,*ptr2; |
124 |
* if (i1 && i2){ |
125 |
* ptr1 = GetInterfacePtr(i1); |
126 |
* ptr2 = GetInterfacePtr(i2); |
127 |
* if (ptr2!=NULL) { |
128 |
* if (ptr1!=NULL) { |
129 |
* } |
130 |
* } |
131 |
* } |
132 |
* main(argc,argv) |
133 |
* { |
134 |
* ....other initialization junk...; |
135 |
* InterfacePtrATS = InterfacePtrATSFunc; |
136 |
* ...etc...; |
137 |
* } |
138 |
* </pre> |
139 |
*/ |
140 |
|
141 |
/*------------------------------------------------------------------------------ |
142 |
GENERAL INSTANCE INTERROGATION ROUTINES |
143 |
*/ |
144 |
|
145 |
#ifndef NDEBUG |
146 |
ASC_DLLSPEC enum inst_t InstanceKindF(CONST struct Instance *i); |
147 |
/**< |
148 |
Implementation function for InstanceKind(). Do not use |
149 |
this function directly - use InstanceKind() instead. |
150 |
*/ |
151 |
# define InstanceKind(i) InstanceKindF(i) |
152 |
#else |
153 |
# define InstanceKind(i) ((i==NULL) ? ERROR_INST : ((struct Instance *)(i))->t) |
154 |
#endif |
155 |
/**< |
156 |
Return the enumerated inst_t that indicates the type of Instance* i. |
157 |
@see InstanceKindF() |
158 |
|
159 |
@see instance_enum.h for the various values you get back. |
160 |
*/ |
161 |
|
162 |
#define IsConstantInstance(i) ((i)->t & ICONS) |
163 |
/**< Returns TRUE (some value >0) if i is a constant instance. */ |
164 |
|
165 |
#define IsFundamentalInstance(i) ((i)->t & IFUND) |
166 |
/**< Returns TRUE (some value >0) if i is a fundamental instance. */ |
167 |
|
168 |
#define IsAtomicInstance(i) ((i)->t & IATOM) |
169 |
/**< Returns TRUE (some value >0) if i is an atomic instance. */ |
170 |
|
171 |
#define IsCompoundInstance(i) ((i)->t & ICOMP) |
172 |
/**< Returns TRUE (some value >0) if i is a compound instance. */ |
173 |
|
174 |
#define IsArrayInstance(i) ((i)->t & IARR) |
175 |
/**< Returns TRUE (some value >0) if i is an array instance. */ |
176 |
|
177 |
#define IsChildlessInstance(i) ((i)->t & ICHILDLESS) |
178 |
/**< Returns TRUE (some value >0) if i is a childless instance. */ |
179 |
|
180 |
extern unsigned long InstanceDepth(CONST struct Instance *i); |
181 |
/**< |
182 |
* Return the longest distance between i and root. The depth of NULL is 0. |
183 |
* The root instance is at depth 1. |
184 |
*/ |
185 |
|
186 |
ASC_DLLSPEC unsigned long InstanceShortDepth(CONST struct Instance *i); |
187 |
/**< |
188 |
* Return the shortest distance between i and root. The depth of NULL |
189 |
* is 0, and the depth of root is 1. |
190 |
*/ |
191 |
|
192 |
|
193 |
extern void SetNextCliqueMember(struct Instance *i, struct Instance *ptr); |
194 |
/**< |
195 |
* Sets i->alike_ptr to ptr for types that have alike_ptrs. |
196 |
* Exits on types that don't or bad input. |
197 |
* Instantiator use only! Clients should never ever touch this. |
198 |
* This is not an intelligent function. |
199 |
*/ |
200 |
|
201 |
ASC_DLLSPEC struct Instance*NextCliqueMember(CONST struct Instance *i); |
202 |
/**< |
203 |
* This is defined to give clients access to the cliques(ARE_ALIKE) links |
204 |
* between instances. Each instance has a clique pointer which points to |
205 |
* the next member of the clique list. These pointers form a circularly |
206 |
* linked list. The following loop can be used to access each member of |
207 |
* the clique. |
208 |
* <pre> |
209 |
* struct Instance *i,*start; |
210 |
* (* i points the instance whose clique is to be examined *) |
211 |
* start = i; |
212 |
* do { |
213 |
* (* insert your code here *) |
214 |
* i = NextCliqueMember(i); |
215 |
* } while(i!=start); |
216 |
* </pre> |
217 |
* This loop will execute the inserted code for each member of the clique. |
218 |
* This function can be call on *any* type of instance. |
219 |
*/ |
220 |
|
221 |
ASC_DLLSPEC VOIDPTR GetInterfacePtr(CONST struct Instance *i); |
222 |
/**< |
223 |
* Return the interface pointer. The compiler initializes this to NULL |
224 |
* when it creates an instance of the following kinds, and hence should |
225 |
* only be called on them. |
226 |
* |
227 |
* - SIM_INST |
228 |
* - MODEL_INST |
229 |
* - SET_ATOM_INST |
230 |
* - REL_INST |
231 |
* - LREL_INST |
232 |
* - WHEN_INST |
233 |
* - REAL_ATOM_INST |
234 |
* - INTEGER_ATOM_INST |
235 |
* - SYMBOL_ATOM_INST |
236 |
* - BOOLEAN_ATOM_INST |
237 |
* - ARRAY_ENUM_INST |
238 |
* - ARRAY_INT_INST |
239 |
* - REAL_CONSTANT_INST |
240 |
* - INTEGER_CONSTANT_INST |
241 |
* - SYMBOL_CONSTANT_INST |
242 |
* - BOOLEAN_CONSTANT_INST |
243 |
* |
244 |
* Those not supported are: |
245 |
* - (atom children) |
246 |
* - REAL_INST |
247 |
* - INTEGER_INST |
248 |
* - SYMBOL_INST |
249 |
* - BOOLEAN_INST |
250 |
* - SET_INST |
251 |
* |
252 |
* It is up to the interface to give this pointer meaning. |
253 |
* In a multiple interface environment this pointer needs to be |
254 |
* managed carefully. Any really sane environment will not use |
255 |
* this pointer except in a transient fashion with Push/Pop in |
256 |
* instance_io.h. |
257 |
*/ |
258 |
|
259 |
ASC_DLLSPEC void SetInterfacePtr(struct Instance *i, VOIDPTR c); |
260 |
/**< |
261 |
* Set the interface pointer. The interface must set and maintain this |
262 |
* pointer. See the note for GetInterfacePtr about applicability of this |
263 |
* function. |
264 |
*/ |
265 |
|
266 |
extern unsigned int GetAnonFlags(CONST struct Instance *i); |
267 |
/**< |
268 |
* Returns the flags associated with an instance. This is a utility |
269 |
* service provided for clients who need access to flags associated with |
270 |
* an instance. These flags may also be set with the below function. |
271 |
* Works for all instance kinds except subatomic ones. |
272 |
*/ |
273 |
|
274 |
extern void SetAnonFlags(struct Instance *i, unsigned int flags); |
275 |
/**< |
276 |
* Sets the flags associated with an instance. This is a utility |
277 |
* service provided for clients who need access to flags associated with |
278 |
* Works for all instance kinds except subatomic ones. |
279 |
*/ |
280 |
|
281 |
ASC_DLLSPEC struct BitList *InstanceBitList(CONST struct Instance *i); |
282 |
/**< |
283 |
* Return the bit list which indicates which statements have and have not |
284 |
* been executed. NULL indicates that there aren't any unexecuted statements. |
285 |
* Only MODEL_INST have bitlists. |
286 |
*/ |
287 |
|
288 |
/*------------------------------------------------------------------------------ |
289 |
INSTANCE QUERYING ROUTINES |
290 |
|
291 |
These are general instance querying routines. |
292 |
*/ |
293 |
|
294 |
ASC_DLLSPEC symchar *InstanceType(CONST struct Instance *i); |
295 |
/**< |
296 |
* Return a string indicating the type of instance i. This works for |
297 |
* all types of instances. It returns the blank string for arrays and |
298 |
* relations though. |
299 |
*/ |
300 |
|
301 |
ASC_DLLSPEC struct TypeDescription*InstanceTypeDesc(CONST struct Instance *i); |
302 |
/**< |
303 |
* Return the instance's type description. This returns NULL for fundamental |
304 |
* instances. |
305 |
*/ |
306 |
|
307 |
extern unsigned long InstanceIndirected(CONST struct Instance *i); |
308 |
/**< |
309 |
* Returns the indirected field of array instances and LONG_MAX |
310 |
* for other kinds of instances. |
311 |
* Does not tolerate NULL. |
312 |
*/ |
313 |
|
314 |
extern unsigned long InstanceSize(CONST struct Instance *i); |
315 |
/**< |
316 |
* Returns the number of bytes chargeable to the given instance i. |
317 |
* This is not recursive. |
318 |
* Fundamental types (which occur only as children of atoms/relations) |
319 |
* are charged to their parent atom/relation and hence have a 'cost' |
320 |
* of 0 according to this function. |
321 |
* Symbol table, set_t, and dimen items associated with instances |
322 |
* are not charged. |
323 |
*/ |
324 |
|
325 |
#define InstanceUniversal(i) \ |
326 |
(GetUniversalFlag(InstanceTypeDesc(i)) != 0) |
327 |
/**< |
328 |
* Returns TRUE if i is a UNIVERSAL instance. |
329 |
*/ |
330 |
|
331 |
ASC_DLLSPEC int IntegerSetInstance(CONST struct Instance *i); |
332 |
/**< |
333 |
* It will return true if the set is of integers and false otherwise. |
334 |
* This should only be called on set instances. |
335 |
*/ |
336 |
|
337 |
ASC_DLLSPEC symchar *GetSimulationName(struct Instance *i); |
338 |
/**< |
339 |
* Returns the name of the simulation instance. |
340 |
* i must be a SIM_INST kind. |
341 |
*/ |
342 |
|
343 |
extern struct gl_list_t *FindSimulationAncestors(struct Instance *i); |
344 |
/**< |
345 |
* Returns a list of all the simulation ancestors of i. |
346 |
* Caller should destroy the list (but obviously not its content). |
347 |
*/ |
348 |
|
349 |
ASC_DLLSPEC struct Instance*GetSimulationRoot(struct Instance *i); |
350 |
/**< |
351 |
* Returns the root instance of the simulation. This is where most if not |
352 |
* all useful queries of a simulation should be based. |
353 |
* i must be a sim instance. |
354 |
*/ |
355 |
|
356 |
/* @} */ |
357 |
|
358 |
#endif /* ASC_INSTQUERY_H */ |
359 |
|