/[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 54 - (show annotations) (download) (as text)
Tue Aug 2 11:20:09 2005 UTC (20 years, 5 months ago) by jds
File MIME type: text/x-chdr
File size: 13991 byte(s)
Manual rework of doxygen comments in all headers.
- Added @file comment to all headers.
- Added parameter names to all function declarations in headers.
- Corrected comment referencing where necessary.
- Split some comments which documented blocks of declarations.
- Converted notes about required work into @todo comments so doxygen can generate a todo list.
Minor bug fixes.
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 "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 __STATTYPES_H_SEEN__
47 #define __STATTYPES_H_SEEN__
48
49 /** FOR statement ordering types. */
50 enum ForOrder {
51 f_random, /**< FOR/CREATE only */
52 f_increasing, /**< FOR/DO INCREASING and FOR/DO default */
53 f_decreasing /**< FOR/DO DECREASING */
54 };
55
56 /** FOR statement kinds. */
57 enum ForKind {
58 fk_create, /**< for create */
59 fk_do, /**< for do */
60 fk_check, /**< for check */
61 fk_expect /**< for expect */
62 };
63
64 /** Codes for the varieties of flow control statement. */
65 enum FlowControl {
66 fc_break,
67 fc_continue,
68 fc_fallthru,
69 fc_return,
70 fc_stop /**< this one must be last or fix statio.c */
71 };
72
73 /** Statement types. */
74 enum stat_t {
75 ALIASES = 0, /**< ALIASES */
76 ISA, /**< IS_A */
77 ARR, /**< CREATE ARRAY i AND SIZE j FROM(list) */
78 IRT, /**< IS_REFINED_TO */
79 ATS, /**< ARE_THE_SAME */
80 AA, /**< ARE_ALIKE */
81 FLOW, /**< BREAK, CONTINUE, FALL_THROUGH, RETURN, STOP */
82 FOR, /**< FOR CREATE LOOP */
83 REL, /**< RELATION */
84 LOGREL, /**< LOGICAL RELATION */
85 ASGN, /**< ASSIGNMENT */
86 CASGN, /**< Structural ASSIGNMENT */
87 RUN, /**< RUN statement */
88 IF, /**< IF-ELSE statement */
89 WHEN, /**< WHEN statement */
90 FNAME, /**< Name of model or relation */
91 SELECT, /**< SELECT statement */
92 SWITCH, /**< SWITCH statement */
93 WHILE, /**< WHILE statement */
94 EXT, /**< EXTERNAL fcn/relation statement of abbott */
95 CALL, /**< user defined function statement */
96 REF, /**< REFERENCE statement */
97 COND, /**< CONDITIONAL statement */
98 WBTS, /**< WILL_BE_THE_SAME */
99 WNBTS, /**< WILL_NOT_BE_THE_SAME */
100 WILLBE /**< WILL_BE */
101 /* if you add anything after WILLBE, change statio.c/suppression
102 * accordingly.
103 */
104 /* Inserting before WILLBE is fine, though, don't forget to check
105 * that the io routines handle the new statements.
106 */
107 };
108
109 #define context_MODEL 0 /**< main declarative line */
110 #define context_FOR 0x1 /**< in a loop, declarative or method */
111 #define context_COND 0x2 /**< inside a CONDITIONAL statement*/
112 #define context_METH 0x4 /**< statement is in a method */
113 #define context_WRONG 0x8 /**< statement is uninstantiably bad */
114 #define context_MODPARAM 0x10 /**< statement is in model parameter list */
115 #define context_SELECT 0x20 /**< statement is in SELECT's statement list */
116 #define context_WHEN 0x40 /**< statement is in WHEN's statement list
117 The context in WHENs is useful only in
118 the case of a nested WHEN. It does not
119 hurt to have this information though. */
120 #define context_IF 0x80 /**< statement is in IF's statement list */
121 #define context_SWITCH 0x100 /**< statement is in SWITCH's statement list */
122 #define context_WHILE 0x200 /**< statement is in WHILE's statement list */
123 #define context_MODWHERE 0x400 /**< statement is in model where list */
124
125 /*
126 * Certain statement types are more easily interpreted if we cache
127 * some information about where they appear within the MODEL.
128 * These are the bit values we have detected a need for so far.
129 * Since statements are defined with a union, we aren't paying extra
130 * memory for the bits due to bizarre alignment restrictions.
131 *
132 * The StateIS keeps a string name of the type required for IS_A/
133 * IS_REFINED_TO statements. This name will be of the type expected
134 * in the type library by FindType when the statement is executed
135 * during instantiation. ChildList information derived from this
136 * name at parse time must be kept up to date with the type library.
137 * This is not the responsibility of the statement module, but is
138 * useful to know.
139 */
140
141 struct WhenList {
142 struct WhenList *next; /**< next in list */
143 struct Set *values; /**< matching values of the case */
144 struct StatementList *slist; /**< statements to be executed */
145 };
146
147 struct SelectList {
148 struct SelectList *next; /**< next in list */
149 struct Set *values; /**< matching values of the case */
150 struct StatementList *slist; /**< statements to be executed */
151 };
152
153 struct SwitchList {
154 struct SwitchList *next; /**< next in list */
155 struct Set *values; /**< matching values of the case */
156 struct StatementList *slist; /**< statements to be executed */
157 };
158
159 /** Lets see if we can get by with no more than 6 members in any of
160 * the individual statement types. 5-6 seems to be a functional
161 * minimum.
162 */
163 struct StateRUN {
164 struct Name *proc_name; /**< procedure name */
165 struct Name *type_name; /**< whether 'class access' eg a::b */
166 };
167
168 struct StateIF {
169 struct Expr *test; /**< expression to be tested */
170 struct StatementList *thenblock;
171 struct StatementList *elseblock;
172 };
173
174 struct StateCOND {
175 struct StatementList *stmts; /**< list of conditional log/relations */
176 unsigned int contains; /**< flags about what in COND stmts lists */
177 };
178
179 struct StateWHEN {
180 struct Name *nptr; /**< Name of the WHEN */
181 struct VariableList *vl; /**< list of variables */
182 struct WhenList *cases; /**< list of cases */
183 };
184
185 struct StateFNAME {
186 struct Name *wname; /**< Name of model or a relation (WHEN) */
187 };
188
189 struct StateSELECT {
190 struct VariableList *vl; /**< list of variables */
191 struct SelectList *cases; /**< list of cases */
192 int n_statements; /**< number of stmts in SELECT stmts lists */
193 unsigned int contains; /**< flags about what in SELECT stmts lists */
194 };
195
196
197 struct StateSWITCH {
198 struct VariableList *vl; /**< list of variables */
199 struct SwitchList *cases; /**< list of cases */
200 };
201
202 /** used for IS_A, IS_REFINED_TO, WILL_BE */
203 struct StateIS {
204 struct VariableList *vl; /**< all, but WILL_BE may want len=1. */
205 symchar *type; /**< all */
206 struct Set *typeargs; /**< all, parameter list. may be NULL */
207 symchar *settype; /**< IS_A only */
208 struct Expr *checkvalue; /**< WILL_BE only */
209 /* note that checkvalue!=NULL and typeargs!=NULL are mutually exclusive
210 * because checkvalues go with constants which are never parameterized.
211 */
212 };
213
214 /** used for ARR, the compound ALIASES/set IS_A. */
215 struct CompoundAlias {
216 struct VariableList *setname; /**< name of new set being defined, as varlist */
217 int intset; /**< 0 -> symbol set, 1-> integer set */
218 struct Set *setvals; /**< set expression for values, if given */
219 };
220
221 /**
222 * Used for ALIASES and IS (undefined). Eventually IS
223 * may be universe scope alii
224 * @todo fix this comment.
225 */
226 struct StateAlias {
227 struct VariableList *vl;
228 /**< ALIASES: LHS, new alii being defined a,b,c ALIASES y
229 * ARR: RHS list of instances to point at a[s] ALIASES y[s2]
230 * Ken has, quite reasonably, requested that vl be a set expression
231 * so that set arithmetic can control which subset y[i] | i IN foo
232 * is usable. This may play hell on type checking -- need to see
233 * what the rules are for determining the base type of instances
234 * named with a set expression.
235 */
236 union {
237 struct Name *nptr; /**< ALIASES: RHS, name of object being pointed at */
238 struct VariableList *avlname; /**< ARR: LHS, new alias being defined */
239 } u; /**< union of name and alias name */
240 struct CompoundAlias c; /**< ARR use only */
241 };
242
243 /** used for ARE_THE_SAM,E ARE_ALIKE and */
244 struct StateARE {
245 struct VariableList *vl; /**< WILL_BE_THE_SAME, WILL_NOT_BE_THE_SAME. */
246 };
247
248 /** used for assignment :==,:= statements */
249 struct StateAssign {
250 struct Name *nptr;
251 struct Expr *rhs;
252 };
253
254 /** used for general external methods */
255 struct StateCall {
256 symchar *id; /**< global function called */
257 struct Set *args; /**< list of arguments to function */
258 };
259
260 /** used for relations */
261 struct StateRelation {
262 struct Name *nptr;
263 struct Expr *relation;
264 };
265
266 /** used for logical relations */
267 struct StateLogicalRel {
268 struct Name *nptr;
269 struct Expr *logrel;
270 };
271
272 /** used for external statements */
273 struct StateExternal {
274 int mode; /**< 0=procedural, 1=glassbox, 2=blackbox */
275 struct Name *nptr; /**< name of the statement */
276 CONST char *extcall; /**< name of the function */
277 struct VariableList *vl; /**< list of arguments */
278 struct Name *data; /**< additional user data */
279 struct Name *scope; /**< scope to add the external relations for glassboxes */
280 };
281
282 struct StateReference {
283 int mode; /**< clone or reference */
284 symchar *ref_name; /**< thing being referenced */
285 symchar *settype;
286 struct VariableList *vl;
287 };
288
289 struct StateFlow {
290 enum FlowControl fc; /**< what control flow change */
291 struct bracechar *message; /**< message on change, if any */
292 };
293
294 /**< used for FOR loops */
295 struct StateFOR {
296 symchar *index;
297 struct Expr *e;
298 struct StatementList *stmts;
299 enum ForOrder order;
300 enum ForKind kind;
301 /* NOTE: the following bits are recursive. If stmts contains a for
302 * loop which contains relations, then thereby this for loop does too.
303 */
304 unsigned int contains; /**< bit flags about what in for statement list */
305 };
306
307 /**< used for While loops */
308 struct StateWhile {
309 struct Expr *test;
310 struct StatementList *block;
311 };
312
313 /**
314 * The following bits are used for BOTH FOR statements and SELECT
315 * statements. VRR
316 */
317 #define contains_REL 0x1 /**< TRUE if relations in stmts list */
318 #define contains_DEF 0x2 /**< true if default statements in stmts list */
319 #define contains_CAS 0x4 /**< true if structural var assignments in stmts list*/
320 #define contains_ALI 0x8 /**< true if aliases in stmts list */
321 #define contains_ISA 0x10 /**< true if IS_A in stmts list */
322 #define contains_WILLBE 0x20 /**< true if IS_A in stmts list */
323 #define contains_ATS 0x40 /**< true if ARE_THE_SAME in stmts list */
324 #define contains_IRT 0x80 /**< true if IS_REFINED_TO in stmts list */
325 #define contains_LREL 0x100 /**< TRUE if logical relations in stmts list */
326 #define contains_WHEN 0x200 /**< TRUE if WHENs in stmts list */
327 #define contains_AA 0x400 /**< true if aliases in stmts list */
328 #define contains_WBTS 0x800 /**< true if WILL_BE_THE_SAME in stmts list */
329 #define contains_ARR 0x1000 /**< true if CREATE ARRAY in stmts list */
330 #define contains_WNBTS 0x2000 /**< true if WILL_NOT_BE_THE_SAME in stmts list */
331 #define contains_SELECT 0x4000 /**< true if SELECT in stmts list */
332 #define contains_COND 0x8000 /**< true if CONDITIONAL in stmts list
333 I am doing this seeking for a *
334 generalization. IMHO, a CONDITIONAL
335 should always be only in the context of a
336 MODEL, and any loop should be inside the
337 CONDITIONAL statement. VRR */
338 #define contains_ILL 0x10000 /**< true if illegal statement in loop */
339 /* unsupported values, meaning we should be using them but don't yet */
340
341 union StateUnion {
342 struct StateAlias ali;
343 struct StateIS i;
344 struct StateARE a;
345 struct StateAssign asgn;
346 struct StateRelation rel;
347 struct StateLogicalRel lrel;
348 struct StateFOR f;
349 struct StateRUN r;
350 struct StateCall call;
351 struct StateIF ifs;
352 struct StateWHEN w;
353 struct StateFNAME n;
354 struct StateSELECT se;
355 struct StateSWITCH sw;
356 struct StateExternal ext;
357 struct StateReference ref;
358 struct StateCOND cond;
359 struct StateWhile loop;
360 struct StateFlow flow;
361 };
362
363 struct Statement {
364 enum stat_t t;
365 unsigned int context; /**< tells about context and correctness */
366 union StateUnion v;
367 struct module_t *mod; /**< module where statement occurs */
368 unsigned long linenum; /**< line number where statement occurs */
369 char *stringform; /**< character string in {} list format */
370 REFCOUNT_T ref_count; /**< number of references to this structure */
371 };
372
373 struct StatementList {
374 REFCOUNT_T ref_count;
375 struct gl_list_t *l;
376 };
377
378 #endif /* __STATTYPES_H_SEEN__ */
379

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