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 |
Ascend Pending Instance Routines. |
22 |
|
23 |
The pending list is implemented as a doubly linked list. |
24 |
Clients of this module should NOT access the internals of this list. |
25 |
They should not access next and prev in particular. |
26 |
Note that only complex types (models, arrays) and not atomic ones |
27 |
(atoms, relations, constants) should ever be put on the list. |
28 |
No client should ever free a struct pending_t *. That is our job. |
29 |
|
30 |
Requires: |
31 |
#include <stdio.h> |
32 |
#include "utilities/ascConfig.h" |
33 |
#include "instance_enum.h" |
34 |
#include "compiler.h" |
35 |
*//* |
36 |
by Tom Epperly |
37 |
Created: 1/24/90 |
38 |
Version: $Revision: 1.6 $ |
39 |
Version control file: $RCSfile: pending.h,v $ |
40 |
Date last modified: $Date: 1997/07/18 12:32:40 $ |
41 |
Last modified by: $Author: mthomas $ |
42 |
*/ |
43 |
|
44 |
#ifndef ASC_PENDING_H |
45 |
#define ASC_PENDING_H |
46 |
|
47 |
/** addtogroup compiler Compiler |
48 |
@{ |
49 |
*/ |
50 |
|
51 |
#include <utilities/ascConfig.h> |
52 |
|
53 |
struct pending_t { |
54 |
struct pending_t *next, *prev; |
55 |
struct Instance *inst; |
56 |
}; |
57 |
|
58 |
extern void InitPendingPool(void); |
59 |
/**< |
60 |
* <!-- InitPendingPool(); --> |
61 |
* Sets up pending structure data management |
62 |
* before anything can be built, ideally at startup time. |
63 |
* Do not call it again unless DestroyPendingPool is called first. |
64 |
* If insufficient memory to compile anything at all, does exit(2). |
65 |
*/ |
66 |
|
67 |
extern void DestroyPendingPool(void); |
68 |
/**< |
69 |
* <!-- DestroyPendingPool(); --> |
70 |
* Destroy pending structure data management. This must be called to |
71 |
* clean up before shutting down ASCEND. |
72 |
* Do not call this function while there are any instances actively |
73 |
* pending unless you are shutting down. |
74 |
* Do not attempt to instantiate anything after you call this unless you |
75 |
* have recalled InitPendingPool. |
76 |
*/ |
77 |
|
78 |
extern void ReportPendingPool(FILE *f); |
79 |
/**< |
80 |
* <!-- ReportPendingPool(f); --> |
81 |
* <!-- FILE *f; --> |
82 |
* Reports on the pending pool to f. |
83 |
*/ |
84 |
|
85 |
#ifdef NDEBUG |
86 |
#define PendingInstance(pt) ((pt)->inst) |
87 |
#else |
88 |
#define PendingInstance(pt) PendingInstanceF(pt) |
89 |
#endif |
90 |
/**< |
91 |
* Returns the instance part of a pending_t structure. |
92 |
* @param pt CONST struct pending_t*, pending instance to query. |
93 |
* @return Returns the instance as a <code>struct Instance*</code>. |
94 |
* @see PendingInstanceF() |
95 |
*/ |
96 |
extern struct Instance *PendingInstanceF(CONST struct pending_t *pt); |
97 |
/**< |
98 |
* <!-- macro PendingInstance(pt) --> |
99 |
* <!-- struct Instance PendingInstanceF(pt) --> |
100 |
* <!-- const struct pending_t *pt; --> |
101 |
* |
102 |
* <!-- This returns the instance part of a pending_t structure. --> |
103 |
* Implementation function for PendingInstance(). Do not call this |
104 |
* function directly - use PendingInstance() instead. |
105 |
*/ |
106 |
|
107 |
extern void ClearList(void); |
108 |
/**< |
109 |
* <!-- void ClearList() --> |
110 |
* Prepare an empty list. This gets rid of any remaining list and makes |
111 |
* a new empty list ready for use. |
112 |
* Causes any instance remaining in the list to forget that they are |
113 |
* pending. |
114 |
*/ |
115 |
|
116 |
extern unsigned long NumberPending(void); |
117 |
/**< |
118 |
* <!-- unsigned long NumberPending() --> |
119 |
* Return the number of instances in the pending instance list. |
120 |
*/ |
121 |
|
122 |
extern void AddBelow(struct pending_t *pt, struct Instance *i); |
123 |
/**< |
124 |
* <!-- void AddBelow(pt,i) --> |
125 |
* <!-- struct pending_t *pt; --> |
126 |
* <!-- struct Instance *i; --> |
127 |
* This adds i into the pending list just below the entry pt. If pt |
128 |
* is NULL, this adds i to the top. |
129 |
* i should be a MODEL_INST or ARRAY_*_INST |
130 |
*/ |
131 |
|
132 |
extern void AddToEnd(struct Instance *i); |
133 |
/**< |
134 |
* <!-- void AddToEnd(i) --> |
135 |
* <!-- struct Instance *i; --> |
136 |
* Insert instance i at the end of the pending instance list. |
137 |
* i should be a MODEL_INST or ARRAY_*_INST |
138 |
*/ |
139 |
|
140 |
extern void RemoveInstance(struct Instance *i); |
141 |
/**< |
142 |
* <!-- void RemoveInstance(i) --> |
143 |
* <!-- struct Instance *i; --> |
144 |
* Remove instance i from the pending instance list if it is in it. |
145 |
* i should be a MODEL_INST or ARRAY_*_INST |
146 |
*/ |
147 |
|
148 |
extern void PendingInstanceRealloced(struct Instance *old_inst, struct Instance *new_inst); |
149 |
/**< |
150 |
* <!-- void PendingInstanceRealloced(old,new) --> |
151 |
* <!-- struct Instance *old,*new; --> |
152 |
* Change references to old to new. |
153 |
* Assumes the old instance will never be used by anyone at all ever again. |
154 |
* new should be a MODEL_INST or ARRAY_*_INST recently realloced. |
155 |
*/ |
156 |
|
157 |
extern int InstanceInList(struct Instance *i); |
158 |
/**< |
159 |
* <!-- int InstanceInList(i) --> |
160 |
* <!-- struct Instance *i; --> |
161 |
* Return true iff i is in the list. |
162 |
* i should be a MODEL_INST or ARRAY_*_INST as any other kind cannot be |
163 |
* pending. |
164 |
*/ |
165 |
|
166 |
extern struct pending_t *TopEntry(void); |
167 |
/**< |
168 |
* <!-- struct pending_t *TopEntry() --> |
169 |
* Return the top item in the pending list. |
170 |
*/ |
171 |
|
172 |
extern struct pending_t *ListEntry(unsigned long n); |
173 |
/**< |
174 |
* <!-- struct pending_t *ListEntry(n) --> |
175 |
* <!-- unsigned long n; --> |
176 |
* Return the n'th entry in the list. This returns NULL if n is less |
177 |
* than one or greater than the length of the list. |
178 |
*/ |
179 |
|
180 |
extern struct pending_t *BottomEntry(void); |
181 |
/**< |
182 |
* <!-- struct pending_t *BottomEntry() --> |
183 |
* Return the bottom item in the pending list. |
184 |
*/ |
185 |
|
186 |
extern void MoveToBottom(struct pending_t *pt); |
187 |
/**< |
188 |
* <!-- void MoveToBottom(struct pending_t *pt) --> |
189 |
* Move the item pt to the bottom of the list. |
190 |
*/ |
191 |
|
192 |
ASC_DLLSPEC unsigned long NumberPendingInstances(struct Instance *i); |
193 |
/**< |
194 |
* <!-- unsigned long NumberPendingInstances; --> |
195 |
* <!-- struct Instance *i; --> |
196 |
* Visits the Instance Tree seatch for instances with pending statements. |
197 |
* Increments g_unresolved_count for each pending instance found. |
198 |
* Returns the total count of pendings. |
199 |
*/ |
200 |
|
201 |
/* @} */ |
202 |
|
203 |
#endif /* ASC_PENDING_H */ |
204 |
|