1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 2006 Carnegie Mellon University |
3 |
Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
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 |
*//** @file |
20 |
Ascend Instance Tree Search Routines. |
21 |
|
22 |
Requires: |
23 |
#include "utilities/ascConfig.h" |
24 |
#include "fractions.h" |
25 |
#include "compiler.h" |
26 |
#include "instance_enum.h" |
27 |
#include "dimen.h" |
28 |
#include "expr_types.h" |
29 |
*//* |
30 |
by Tom Epperly |
31 |
Created: 1/24/90 |
32 |
Last in CVS: $Revision: 1.12 $ $Date: 1998/03/26 20:39:45 $ $Author: ballan $ |
33 |
*/ |
34 |
|
35 |
#ifndef ASC_FIND_H |
36 |
#define ASC_FIND_H |
37 |
|
38 |
/** addtogroup compiler Compiler |
39 |
@{ |
40 |
*/ |
41 |
|
42 |
/** |
43 |
* Search error codes. |
44 |
* At present, there is a GREAT DEAL of insanity between find_errors and |
45 |
* evaluation_error (value_type.h). In particular there is a lot of idiocy |
46 |
* mapping undefined_instance <--> undefined_value which is just plain wrong |
47 |
* in most cases. |
48 |
*/ |
49 |
enum find_errors { |
50 |
unmade_instance, /**< Found an unmade instance (NULL child). */ |
51 |
undefined_instance, /**< Instance in an expression is unknown child. */ |
52 |
impossible_instance, /**< Name cannot possibily exist(real error),often sets. */ |
53 |
correct_instance /**< Return value when everything went okay. */ |
54 |
}; |
55 |
|
56 |
extern int ListMode; |
57 |
/**< |
58 |
* Tells whether to evaluate a set strictly as a set i.e no order, |
59 |
* or as a list, i.e., with order important. |
60 |
*/ |
61 |
|
62 |
extern int EvaluatingSets; |
63 |
/**< |
64 |
* Tells whether the evaluation of a set is in place. Used for marking |
65 |
* atoms as mutable or not. |
66 |
*/ |
67 |
|
68 |
extern int g_DeclarativeContext; |
69 |
/**< |
70 |
* Tells whether declarative processing, the default = 0 , is in effect, |
71 |
* or procedural processing as when doing initializations. |
72 |
* Access this varible only by GetDeclarativeContext() and |
73 |
* SetDeclarativeContext() below. |
74 |
*/ |
75 |
|
76 |
#define FINDEBUG 0 |
77 |
#if (FINDEBUG==0) |
78 |
# define GetDeclarativeContext() g_DeclarativeContext |
79 |
/**< retrieve the declarative context */ |
80 |
# define SetDeclarativeContext(n) g_DeclarativeContext = (n) |
81 |
/**< set the declarative context */ |
82 |
#else |
83 |
# define GetDeclarativeContext() GetDeclarativeContextF() |
84 |
/** retrieve the declarative context */ |
85 |
extern int GetDeclarativeContextF(void); |
86 |
/**< retrieve the declarative context (for debugging) */ |
87 |
# define SetDeclarativeContext(n) SetDeclarativeContextF((n),__FILE__,__LINE__) |
88 |
/**< set the declarative context */ |
89 |
extern void SetDeclarativeContextF(int value, char *file, int line); |
90 |
/**< set the declarative context (for debugging) */ |
91 |
#endif |
92 |
|
93 |
extern CONST struct Instance *g_EvaluationContext; |
94 |
/**< |
95 |
* Global variable used throughout semantic analysis to |
96 |
* indicate context of evaluation. Do Not reference this |
97 |
* directly, but use GetEvaluationContext() and |
98 |
* SetEvaluationContext() instead. |
99 |
*/ |
100 |
|
101 |
extern struct for_table_t *g_EvaluationForTable; |
102 |
/**< |
103 |
* Global variable used throughout semantic analysis to |
104 |
* indicate context of evaluation. Do Not reference this |
105 |
* directly, but use GetEvaluationForTable() and |
106 |
* SetEvaluationForTable() instead. |
107 |
*/ |
108 |
|
109 |
#ifndef NDEBUG |
110 |
# define EVALDEBUG 0 /**< 1 = contextnoisy, 2 = fornoisy, 3 = both */ |
111 |
# define GetEvaluationContext() GetEvaluationContextF() |
112 |
# define GetEvaluationForTable() GetEvaluationForTableF() |
113 |
# if EVALDEBUG |
114 |
# if (EVALDEBUG == 1 || EVALDEBUG == 3) |
115 |
# define SetEvaluationContext(i) SetEvaluationContextF((i),__FILE__,__LINE__) |
116 |
# else |
117 |
# define SetEvaluationContext(i) SetEvaluationContextF(i) |
118 |
# endif |
119 |
# if (EVALDEBUG == 2 || EVALDEBUG == 3) |
120 |
# define SetEvaluationForTable(ft) SetEvaluationForTableF((ft),__FILE__,__LINE__) |
121 |
# else |
122 |
# define SetEvaluationForTable(ft) SetEvaluationForTableF(ft) |
123 |
# endif |
124 |
# else |
125 |
# define SetEvaluationContext(i) SetEvaluationContextF(i) |
126 |
# define SetEvaluationForTable(ft) SetEvaluationForTableF(ft) |
127 |
# endif |
128 |
#else |
129 |
# define GetEvaluationContext() g_EvaluationContext |
130 |
# define SetEvaluationContext(i) g_EvaluationContext = (i) |
131 |
# define GetEvaluationForTable() g_EvaluationForTable |
132 |
# define SetEvaluationForTable(ft) g_EvaluationForTable = (ft) |
133 |
#endif |
134 |
|
135 |
/* |
136 |
* Wrappers mainly for break point purposes of g_EvaluationContext |
137 |
* and g_EvaluationForTable. |
138 |
*/ |
139 |
extern struct Instance *GetEvaluationContextF(void); |
140 |
/**< retrieve the evaluation context (mainly for debugging) */ |
141 |
|
142 |
extern struct for_table_t *GetEvaluationForTableF(void); |
143 |
/**< retrieve the evaluation for table (mainly for debugging) */ |
144 |
|
145 |
#if EVALDEBUG /* version printing file/line when setting globals */ |
146 |
extern void SetEvaluationContextF(CONST struct Instance *i |
147 |
#if (EVALDEBUG == 1 || EVALDEBUG == 3) |
148 |
,char *file, int line |
149 |
#endif /* evaldebug 13 */ |
150 |
); |
151 |
/**< set the evaluation context (mainly for debugging) */ |
152 |
|
153 |
extern void SetEvaluationForTableF(struct for_table_t *ft |
154 |
#if (EVALDEBUG == 2 || EVALDEBUG == 3) |
155 |
,char *file, int line |
156 |
#endif /* evaldebug 23 */ |
157 |
); |
158 |
/**< set the evaluation for table (mainly for debugging) */ |
159 |
|
160 |
#else /* evaldebug */ |
161 |
extern void SetEvaluationContextF(CONST struct Instance *i); |
162 |
/**< set the evaluation context (mainly for debugging) */ |
163 |
extern void SetEvaluationForTableF(struct for_table_t *ft); |
164 |
/**< set the evaluation for table (mainly for debugging) */ |
165 |
#endif /* evaldebug*/ |
166 |
|
167 |
extern struct value_t InstanceEvaluateName(CONST struct Name *nptr); |
168 |
/**< |
169 |
* This evaluates the name in the context given by EvaluationContext. |
170 |
* This must be set before the InstanceEvaluateName call. Note since |
171 |
* this is a global variable you cannot evaluate names in more than |
172 |
* one context simultaneously. |
173 |
* |
174 |
* If EvaluationForTable is non-NULL, the for table will be checked before |
175 |
* the instance tree. |
176 |
*/ |
177 |
|
178 |
extern struct value_t InstanceEvaluateSatisfiedName(CONST struct Name *nptr, |
179 |
double tol); |
180 |
/**< |
181 |
* This function is specially to evaluate name of relations or logical |
182 |
* relations included in SATISFIED expressions. |
183 |
* This evaluates the name in the context given by EvaluationContext. |
184 |
* This must be set before the InstanceEvaluateName call. Note since |
185 |
* this is a global variable you cannot evaluate names in more than |
186 |
* one context simultaneously. |
187 |
* If EvaluationForTable is non-NULL, the for table will be checked before |
188 |
* the instance tree. |
189 |
*/ |
190 |
|
191 |
extern struct gl_list_t *FindInstances(CONST struct Instance *i, |
192 |
CONST struct Name *n, |
193 |
enum find_errors *err); |
194 |
/**< |
195 |
* Return the list of instances specified by n. If this returns NULL, |
196 |
* it indicates that it couldn't find the name. Check err to discover why. |
197 |
*/ |
198 |
|
199 |
|
200 |
extern struct gl_list_t *FindInstancesFromNames(CONST struct Instance *i, |
201 |
CONST struct gl_list_t *names, |
202 |
enum find_errors *err, |
203 |
unsigned long *errpos); |
204 |
/**< |
205 |
* <!-- struct gl_list_t *FindInstancesFromNames(i,names,err,errpos) --> |
206 |
* <!-- struct Instance *i; --> |
207 |
* <!-- CONST struct gl_list_t *names; --> |
208 |
* <!-- enum find_errors *err; --> |
209 |
* <!-- unsigned long *errpos; --> |
210 |
* Return the list of instances specified by names. If this returns NULL, |
211 |
* it indicates that it couldn't find a name. Check err to discover why |
212 |
* and errpos to discover which list element had the problem. |
213 |
* Each listed name on input must resolve to a single instance, or |
214 |
* the err will be impossible_instance. |
215 |
*/ |
216 |
/* @} */ |
217 |
|
218 |
#endif /* ASC_FIND_H */ |
219 |
|