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

Contents of /trunk/base/generic/compiler/stattypes.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: 15698 byte(s)
Adding doxygen 'addtogroup' for Solver, Compiler, Integrator.
1 /*
2 * Type definitions for statements and statement lists.
3 * Tom Epperly
4 * August 10, 1989
5 * Version: $Revision: 1.28 $
6 * Version control file: $RCSfile: stattypes.h,v $
7 * Date last modified: $Date: 1998/04/21 23:49:57 $
8 * Last modified by: $Author: ballan $
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
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 along
25 * with the program; if not, write to the Free Software Foundation, Inc., 675
26 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27 */
28
29 /** @file
30 * Type definitions for statements and statement lists.
31 * <pre>
32 * When #including stattypes.h, make sure these files are #included first:
33 * #include <limits.h>
34 * #include "fractions.h"
35 * #include "compiler.h"
36 * #include "dimen.h"
37 * #include "expr_types.h"
38 * #include "list.h"
39 * #include "bit.h"
40 * #include "module.h"
41 * #include "vlist.h"
42 * </pre>
43 * @todo Complete documentation of stattypes.h.
44 */
45
46 #ifndef ASC_STATTYPES_H
47 #define ASC_STATTYPES_H
48
49 /** addtogroup compiler Compiler
50 @{
51 */
52
53 /** FOR statement ordering types. */
54 enum ForOrder {
55 f_random, /**< FOR/CREATE only */
56 f_increasing, /**< FOR/DO INCREASING and FOR/DO default */
57 f_decreasing /**< FOR/DO DECREASING */
58 };
59
60 /** FOR statement kinds. */
61 enum ForKind {
62 fk_create, /**< for create */
63 fk_do, /**< for do */
64 fk_check, /**< for check */
65 fk_expect /**< for expect */
66 };
67
68 /** Codes for the varieties of flow control statement. */
69 enum FlowControl {
70 fc_break,
71 fc_continue,
72 fc_fallthru,
73 fc_return,
74 fc_stop /**< this one must be last or fix statio.c */
75 };
76
77 enum ExternalKind {
78 ek_method = 0, /**< method call */
79 ek_glass = 1, /**< glass box relations */
80 ek_black = 2 /**< black box relations */
81 };
82
83 /** Statement types. */
84 enum stat_t {
85 ALIASES = 0, /**< ALIASES */
86 ISA, /**< IS_A */
87 ARR, /**< CREATE ARRAY i AND SIZE j FROM(list) */
88 IRT, /**< IS_REFINED_TO */
89 ATS, /**< ARE_THE_SAME */
90 AA, /**< ARE_ALIKE */
91 FLOW, /**< BREAK, CONTINUE, FALL_THROUGH, RETURN, STOP */
92 FOR, /**< FOR CREATE LOOP */
93 REL, /**< RELATION */
94 LOGREL, /**< LOGICAL RELATION */
95 ASGN, /**< ASSIGNMENT */
96 CASGN, /**< Structural ASSIGNMENT */
97 RUN, /**< RUN statement */
98 FIX, /**< FIX statement */
99 FREE, /**< FREE statement */
100 ASSERT, /**< TEST statement */
101 IF, /**< IF-ELSE statement */
102 WHEN, /**< WHEN statement */
103 FNAME, /**< Name of model or relation */
104 SELECT, /**< SELECT statement */
105 SWITCH, /**< SWITCH statement */
106 WHILE, /**< WHILE statement */
107 EXT, /**< EXTERNAL fcn/relation statement of abbott */
108 CALL, /**< user defined function statement */
109 REF, /**< REFERENCE statement */
110 COND, /**< CONDITIONAL statement */
111 WBTS, /**< WILL_BE_THE_SAME */
112 WNBTS, /**< WILL_NOT_BE_THE_SAME */
113 WILLBE /**< WILL_BE */
114 /* if you add anything after WILLBE, change statio.c/suppression
115 * accordingly.
116 */
117 /* Inserting before WILLBE is fine, though, don't forget to check
118 * that the io routines handle the new statements.
119 */
120 };
121
122 #define context_MODEL 0 /**< main declarative line */
123 #define context_FOR 0x1 /**< in a loop, declarative or method */
124 #define context_COND 0x2 /**< inside a CONDITIONAL statement*/
125 #define context_METH 0x4 /**< statement is in a method */
126 #define context_WRONG 0x8 /**< statement is uninstantiably bad */
127 #define context_MODPARAM 0x10 /**< statement is in model parameter list */
128 #define context_SELECT 0x20 /**< statement is in SELECT's statement list */
129 #define context_WHEN 0x40 /**< statement is in WHEN's statement list
130 The context in WHENs is useful only in
131 the case of a nested WHEN. It does not
132 hurt to have this information though. */
133 #define context_IF 0x80 /**< statement is in IF's statement list */
134 #define context_SWITCH 0x100 /**< statement is in SWITCH's statement list */
135 #define context_WHILE 0x200 /**< statement is in WHILE's statement list */
136 #define context_MODWHERE 0x400 /**< statement is in model where list */
137
138 /*
139 * Certain statement types are more easily interpreted if we cache
140 * some information about where they appear within the MODEL.
141 * These are the bit values we have detected a need for so far.
142 * Since statements are defined with a union, we aren't paying extra
143 * memory for the bits due to bizarre alignment restrictions.
144 *
145 * The StateIS keeps a string name of the type required for IS_A/
146 * IS_REFINED_TO statements. This name will be of the type expected
147 * in the type library by FindType when the statement is executed
148 * during instantiation. ChildList information derived from this
149 * name at parse time must be kept up to date with the type library.
150 * This is not the responsibility of the statement module, but is
151 * useful to know.
152 */
153
154 struct WhenList {
155 struct WhenList *next; /**< next in list */
156 struct Set *values; /**< matching values of the case */
157 struct StatementList *slist; /**< statements to be executed */
158 };
159
160 struct SelectList {
161 struct SelectList *next; /**< next in list */
162 struct Set *values; /**< matching values of the case */
163 struct StatementList *slist; /**< statements to be executed */
164 };
165
166 struct SwitchList {
167 struct SwitchList *next; /**< next in list */
168 struct Set *values; /**< matching values of the case */
169 struct StatementList *slist; /**< statements to be executed */
170 };
171
172 /** Lets see if we can get by with no more than 6 members in any of
173 * the individual statement types. 5-6 seems to be a functional
174 * minimum.
175 */
176 struct StateRUN {
177 struct Name *proc_name; /**< procedure name */
178 struct Name *type_name; /**< whether 'class access' eg a::b */
179 };
180
181 struct StateFIX {
182 struct VariableList *vars; /**< Variable(s) to be fixed */
183 };
184
185 struct StateASSERT {
186 struct Expr *test;
187 };
188
189 struct StateIF {
190 struct Expr *test; /**< expression to be tested */
191 struct StatementList *thenblock;
192 struct StatementList *elseblock;
193 };
194
195 struct StateCOND {
196 struct StatementList *stmts; /**< list of conditional log/relations */
197 unsigned int contains; /**< flags about what in COND stmts lists */
198 };
199
200 struct StateWHEN {
201 struct Name *nptr; /**< Name of the WHEN */
202 struct VariableList *vl; /**< list of variables */
203 struct WhenList *cases; /**< list of cases */
204 };
205
206 struct StateFNAME {
207 struct Name *wname; /**< Name of model or a relation (WHEN) */
208 };
209
210 struct StateSELECT {
211 struct VariableList *vl; /**< list of variables */
212 struct SelectList *cases; /**< list of cases */
213 int n_statements; /**< number of stmts in SELECT stmts lists */
214 unsigned int contains; /**< flags about what in SELECT stmts lists */
215 };
216
217
218 struct StateSWITCH {
219 struct VariableList *vl; /**< list of variables */
220 struct SwitchList *cases; /**< list of cases */
221 };
222
223 /** used for IS_A, IS_REFINED_TO, WILL_BE */
224 struct StateIS {
225 struct VariableList *vl; /**< all, but WILL_BE may want len=1. */
226 symchar *type; /**< all */
227 struct Set *typeargs; /**< all, parameter list. may be NULL */
228 symchar *settype; /**< IS_A only */
229 struct Expr *checkvalue; /**< WILL_BE only */
230 /* note that checkvalue!=NULL and typeargs!=NULL are mutually exclusive
231 * because checkvalues go with constants which are never parameterized.
232 */
233 };
234
235 /** used for ARR, the compound ALIASES/set IS_A. */
236 struct CompoundAlias {
237 struct VariableList *setname; /**< name of new set being defined, as varlist */
238 int intset; /**< 0 -> symbol set, 1-> integer set */
239 struct Set *setvals; /**< set expression for values, if given */
240 };
241
242 /**
243 * Used for ALIASES and IS (undefined). Eventually IS
244 * may be universe scope alii
245 * @todo fix this comment.
246 */
247 struct StateAlias {
248 struct VariableList *vl;
249 /**< ALIASES: LHS, new alii being defined a,b,c ALIASES y
250 * ARR: RHS list of instances to point at a[s] ALIASES y[s2]
251 * Ken has, quite reasonably, requested that vl be a set expression
252 * so that set arithmetic can control which subset y[i] | i IN foo
253 * is usable. This may play hell on type checking -- need to see
254 * what the rules are for determining the base type of instances
255 * named with a set expression.
256 */
257 union {
258 struct Name *nptr; /**< ALIASES: RHS, name of object being pointed at */
259 struct VariableList *avlname; /**< ARR: LHS, new alias being defined */
260 } u; /**< union of name and alias name */
261 struct CompoundAlias c; /**< ARR use only */
262 };
263
264 /** used for ARE_THE_SAM,E ARE_ALIKE and */
265 struct StateARE {
266 struct VariableList *vl; /**< WILL_BE_THE_SAME, WILL_NOT_BE_THE_SAME. */
267 };
268
269 /** used for assignment :==,:= statements */
270 struct StateAssign {
271 struct Name *nptr;
272 struct Expr *rhs;
273 };
274
275 /** used for general external methods */
276 struct StateCall {
277 symchar *id; /**< global function called */
278 struct Set *args; /**< list of arguments to function */
279 };
280
281 /** used for relations */
282 struct StateRelation {
283 struct Name *nptr;
284 struct Expr *relation;
285 };
286
287 /** used for logical relations */
288 struct StateLogicalRel {
289 struct Name *nptr;
290 struct Expr *logrel;
291 };
292
293 /** legacy external methods in METHODS section */
294 struct StateExternalMethod {
295 struct VariableList *vl; /**< list of arguments */
296 };
297
298 /** Black or glass box equation model. */
299 struct StateExternalRelation {
300 struct Name *nptr; /**< name of the statement */
301 struct VariableList *vl; /**< list of arguments */
302 };
303
304 /** Black box equation model. Top must match StateExternalRelation. */
305 struct StateExternalBlackBox {
306 struct Name *nptr; /**< name of the statement */
307 struct VariableList *vl; /**< list of arguments */
308 struct Name *data; /**< additional user data */
309 };
310
311 /* blackboxes contain an implicit for loop. For
312 internal compiler processing, we make this explicit
313 with a loop index name BBOX_RESERVED_INDEX
314 */
315 #define BBOX_RESERVED_INDEX "?BBOX_OUTPUT"
316 #define BBOX_RESERVED_INDEX_LEN 12
317
318 /** Glassbox equation model. Top must match StateExternalRelation. */
319 struct StateExternalGlassBox {
320 struct Name *nptr; /**< name of the statement */
321 struct VariableList *vl; /**< list of arguments */
322 struct Name *data; /**< additional user data */
323 struct Name *scope; /**< scope to add the external relations for glassboxes */
324 };
325
326
327 /** used for external statements */
328 struct StateExternal {
329 enum ExternalKind mode; /**< 0=procedural, 1=glassbox, 2=blackbox */
330 CONST char *extcall; /**< name of the function */
331 union {
332 struct StateExternalRelation relation; /* which is either glass or black */
333 struct StateExternalGlassBox glass;
334 struct StateExternalBlackBox black;
335 struct StateExternalMethod method;
336 } u;
337 };
338
339 struct StateReference {
340 int mode; /**< clone or reference */
341 symchar *ref_name; /**< thing being referenced */
342 symchar *settype;
343 struct VariableList *vl;
344 };
345
346 struct StateFlow {
347 enum FlowControl fc; /**< what control flow change */
348 struct bracechar *message; /**< message on change, if any */
349 };
350
351 /**< used for FOR loops */
352 struct StateFOR {
353 symchar *index;
354 struct Expr *e;
355 struct StatementList *stmts;
356 enum ForOrder order;
357 enum ForKind kind;
358 /* NOTE: the following bits are recursive. If stmts contains a for
359 * loop which contains relations, then thereby this for loop does too.
360 */
361 unsigned int contains; /**< bit flags about what in for statement list */
362 };
363
364 /**< used for While loops */
365 struct StateWhile {
366 struct Expr *test;
367 struct StatementList *block;
368 };
369
370 /**
371 * The following bits are used for BOTH FOR statements and SELECT
372 * statements. VRR
373 */
374 #define contains_REL 0x1 /**< TRUE if relations in stmts list */
375 #define contains_DEF 0x2 /**< true if default statements in stmts list */
376 #define contains_CAS 0x4 /**< true if structural var assignments in stmts list*/
377 #define contains_ALI 0x8 /**< true if aliases in stmts list */
378 #define contains_ISA 0x10 /**< true if IS_A in stmts list */
379 #define contains_WILLBE 0x20 /**< true if IS_A in stmts list */
380 #define contains_ATS 0x40 /**< true if ARE_THE_SAME in stmts list */
381 #define contains_IRT 0x80 /**< true if IS_REFINED_TO in stmts list */
382 #define contains_LREL 0x100 /**< TRUE if logical relations in stmts list */
383 #define contains_WHEN 0x200 /**< TRUE if WHENs in stmts list */
384 #define contains_AA 0x400 /**< true if aliases in stmts list */
385 #define contains_WBTS 0x800 /**< true if WILL_BE_THE_SAME in stmts list */
386 #define contains_ARR 0x1000 /**< true if CREATE ARRAY in stmts list */
387 #define contains_WNBTS 0x2000 /**< true if WILL_NOT_BE_THE_SAME in stmts list */
388 #define contains_SELECT 0x4000 /**< true if SELECT in stmts list */
389 #define contains_COND 0x8000 /**< true if CONDITIONAL in stmts list
390 I am doing this seeking for a *
391 generalization. IMHO, a CONDITIONAL
392 should always be only in the context of a
393 MODEL, and any loop should be inside the
394 CONDITIONAL statement. VRR */
395 #define contains_EXT 0x10000 /*< contains a External statement. */
396 #define contains_ILL 0x80000 /**< true if illegal statement in loop */
397 /* unsupported values, meaning we should be using them but don't yet */
398
399 union StateUnion {
400 struct StateAlias ali;
401 struct StateIS i;
402 struct StateARE a;
403 struct StateAssign asgn;
404 struct StateRelation rel;
405 struct StateLogicalRel lrel;
406 struct StateFOR f;
407 struct StateRUN r;
408 struct StateFIX fx;
409 struct StateCall call;
410 struct StateIF ifs;
411 struct StateASSERT asserts;
412 struct StateWHEN w;
413 struct StateFNAME n;
414 struct StateSELECT se;
415 struct StateSWITCH sw;
416 struct StateExternal ext;
417 struct StateReference ref;
418 struct StateCOND cond;
419 struct StateWhile loop;
420 struct StateFlow flow;
421 };
422
423 struct Statement {
424 enum stat_t t;
425 unsigned int context; /**< tells about context and correctness */
426 union StateUnion v;
427 struct module_t *mod; /**< module where statement occurs */
428 unsigned long linenum; /**< line number where statement occurs */
429 char *stringform; /**< character string in {} list format */
430 REFCOUNT_T ref_count; /**< number of references to this structure */
431 };
432
433 struct StatementList {
434 REFCOUNT_T ref_count;
435 struct gl_list_t *l;
436 };
437
438 /* @} */
439
440 #endif /* ASC_STATTYPES_H */
441

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