/[ascend]/trunk/ascend/compiler/statement.c
ViewVC logotype

Contents of /trunk/ascend/compiler/statement.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2397 - (show annotations) (download) (as text)
Mon Feb 28 12:18:48 2011 UTC (13 years, 3 months ago) by jpye
File MIME type: text/x-csrc
File size: 65109 byte(s)
Add test of failing FIX statements for bug #488.
Commented out unmigrated makemps code (need to migrate to new slv_param_* functions).
1 /*
2 * Implementation of the statement routines
3 * by Tom Epperly
4 * August 10, 1989
5 * Version: $Revision: 1.32 $
6 * Version control file: $RCSfile: statement.c,v $
7 * Date last modified: $Date: 1998/04/21 23:49:48 $
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
25 * along with the program; if not, write to the Free Software Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27 * COPYING.
28 *
29 */
30
31 #include <stdarg.h>
32 #include <ascend/general/platform.h>
33 #include <ascend/general/ascMalloc.h>
34
35 #include "symtab.h"
36 #include "braced.h"
37 #include <ascend/general/panic.h>
38 #include <ascend/general/list.h>
39
40
41 #include "functype.h"
42 #include "expr_types.h"
43 #include "stattypes.h"
44 #include "statement.h"
45 #include "slist.h"
46 #include "statio.h"
47 #include "exprs.h"
48 #include "name.h"
49 #include "vlist.h"
50 #include "sets.h"
51 #include "select.h"
52 #include "switch.h"
53 #include "when.h"
54 #include "module.h"
55 #include "scanner.h"
56 /* additional for statement comparisons */
57 #include "instance_enum.h"
58 #include "cmpfunc.h"
59 #include "child.h"
60 #include "type_desc.h"
61 #include "type_descio.h"
62 #include "library.h"
63
64 #define STMALLOC stmallocF()
65 #define STFREE(p) ascfree((char *)(p))
66
67 #ifndef TRUE
68 #define TRUE 1
69 #endif
70
71 #ifndef lint
72 static CONST char StatementID[] = "$Id: statement.c,v 1.32 1998/04/21 23:49:48 ballan Exp $";
73 #endif
74
75 static
76 struct Statement *stmallocF()
77 {
78 struct Statement *result;
79 result = ASC_NEW(struct Statement);
80 result->stringform = NULL;
81 return result;
82 }
83
84 /**
85 Create a statement of the specified type and assign the local context to it
86 */
87 static struct Statement *
88 create_statement_here(enum stat_t t){
89 struct Statement *result;
90 result=STMALLOC;
91 assert(result!=NULL);
92 result->t=t;
93 result->linenum = LineNum();
94 result->mod = Asc_CurrentModule();
95 result->context = context_MODEL;
96 result->ref_count=1;
97 return result;
98 }
99
100 void AddContext(struct StatementList *slist, unsigned int con)
101 {
102 unsigned long c,length;
103 struct Statement *s;
104 struct gl_list_t *flist;
105 struct StatementList *sublist;
106 struct WhenList *w;
107 struct SelectList *sel;
108 struct SwitchList *sw;
109
110 if (StatementListLength(slist)==0) {
111 return;
112 }
113 flist = GetList(slist);
114 length=gl_length(flist);
115 for(c=1;c<=length;c++){
116 s = (struct Statement *)gl_fetch(flist,c);
117 assert(s!=NULL);
118 s->context |= con;
119 switch (s->t){
120 case ALIASES:
121 case ISA:
122 case ARR:
123 case WILLBE:
124 case IRT:
125 case AA:
126 case ATS:
127 case WBTS:
128 case WNBTS:
129 case REL:
130 case LOGREL:
131 case ASGN:
132 case CASGN:
133 case CALL:
134 case EXT:
135 case REF:
136 case FIX:
137 case FREE:
138 case SOLVER:
139 case OPTION:
140 case SOLVE:
141 case RUN:
142 case FNAME:
143 case FLOW:
144 break;
145 case FOR:
146 sublist = ForStatStmts(s);
147 if (sublist!=NULL) {
148 AddContext(sublist,con);
149 }
150 break;
151 case WHILE:
152 sublist = WhileStatBlock(s);
153 if (sublist!=NULL) {
154 AddContext(sublist,con);
155 }
156 break;
157 case ASSERT:
158 /* no sublists under a TEST statement */
159 break;
160 case IF:
161 sublist = IfStatThen(s);
162 AddContext(sublist,con);
163 sublist = IfStatElse(s);
164 if (sublist!=NULL) {
165 AddContext(sublist,con);
166 }
167 break;
168 case SWITCH:
169 sw = SwitchStatCases(s);
170 while (sw!=NULL) {
171 sublist = SwitchStatementList(sw);
172 if (sublist!=NULL) {
173 AddContext(sublist,con);
174 }
175 sw = NextSwitchCase(sw);
176 }
177 break;
178 case WHEN:
179 w = WhenStatCases(s);
180 while (w!=NULL) {
181 sublist = WhenStatementList(w);
182 if (sublist!=NULL) {
183 AddContext(sublist,con);
184 }
185 w = NextWhenCase(w);
186 }
187 break;
188 case SELECT:
189 sel = SelectStatCases(s);
190 while (sel!=NULL) {
191 sublist = SelectStatementList(sel);
192 if (sublist!=NULL) {
193 AddContext(sublist,con);
194 }
195 sel = NextSelectCase(sel);
196 }
197 break;
198 case COND:
199 sublist = CondStatList(s);
200 if (sublist!=NULL) {
201 AddContext(sublist,con);
202 }
203 break;
204 default:
205 ASC_PANIC("AddContext called with bad statement list.");
206 break;
207 }
208 }
209 }
210
211 struct Statement *CreateALIASES(struct VariableList *vl, struct Name *n)
212 {
213 struct Statement *result;
214 result=create_statement_here(ALIASES);
215 result->v.ali.vl = vl;
216 result->v.ali.u.nptr = n;
217 result->v.ali.c.setname = NULL;
218 result->v.ali.c.intset = -1;
219 result->v.ali.c.setvals = NULL;
220 /* should check nptr and all vl names here for !contains_at */
221 return result;
222 }
223
224 struct Statement *CreateARR(struct VariableList *avlname,
225 struct VariableList *vl,
226 struct VariableList *sn,
227 int intset,
228 struct Set *sv) {
229 struct Statement *result;
230 result=create_statement_here(ARR);
231 result->v.ali.u.avlname = avlname;
232 result->v.ali.vl = vl;
233 result->v.ali.c.setname = sn;
234 result->v.ali.c.intset = intset;
235 result->v.ali.c.setvals = sv;
236 return result;
237 }
238
239 struct Statement *CreateISA(struct VariableList *vl,
240 symchar *t,
241 struct Set *ta,
242 symchar *st)
243 {
244 struct Statement *result;
245 result=create_statement_here(ISA);
246 result->v.i.vl = vl;
247 result->v.i.type = t;
248 result->v.i.typeargs = ta;
249 result->v.i.settype = st;
250 result->v.i.checkvalue = NULL;
251 return result;
252 }
253
254 struct Statement *CreateWILLBE(struct VariableList *vl, symchar *t,
255 struct Set *ta,
256 symchar *st, struct Expr *cv)
257 {
258 struct Statement *result;
259 result=create_statement_here(WILLBE);
260 result->v.i.vl = vl;
261 result->v.i.type = t;
262 result->v.i.typeargs = ta;
263 result->v.i.settype = st;
264 result->v.i.checkvalue = cv;
265 return result;
266 }
267
268 struct Statement *CreateIRT(struct VariableList *vl, symchar *t,
269 struct Set *ta)
270 {
271 register struct Statement *result;
272 result=create_statement_here(IRT);
273 result->v.i.type = t;
274 result->v.i.typeargs = ta;
275 result->v.i.settype = NULL;
276 result->v.i.checkvalue = NULL;
277 result->v.i.vl = vl;
278 return result;
279 }
280
281 struct Statement *CreateAA(struct VariableList *vl)
282 {
283 register struct Statement *result;
284 result=create_statement_here(AA);
285 result->v.a.vl = vl;
286 return result;
287 }
288
289 struct Statement *CreateATS(struct VariableList *vl)
290 {
291 register struct Statement *result;
292 result=create_statement_here(ATS);
293 result->v.a.vl = vl;
294 return result;
295 }
296
297 struct Statement *CreateFIX(struct VariableList *vars){
298 register struct Statement *result;
299 /*CONSOLE_DEBUG("CREATING FIX STMT");*/
300 result=create_statement_here(FIX);
301 result->v.fx.vars = vars;
302 /*WriteVariableList(ASCERR,result->v.fx.vars);*/
303 return result;
304 }
305
306 struct Statement *CreateFREE(struct VariableList *vars){
307 register struct Statement *result;
308 /* CONSOLE_DEBUG("CREATING FREE STMT"); */
309 result=create_statement_here(FREE);
310 result->v.fx.vars = vars;
311 return result;
312 }
313
314 struct Statement *CreateSOLVER(CONST char *solvername){
315 register struct Statement *result;
316 result=create_statement_here(SOLVER);
317 result->v.solver.name = solvername;
318 /*CONSOLE_DEBUG("CREATED SOLVER STATEMENT");*/
319 return result;
320 }
321
322 struct Statement *CreateOPTION(CONST char *optname, struct Expr *rhs){
323 register struct Statement *result;
324 result=create_statement_here(OPTION);
325 result->v.option.name = optname;
326 result->v.option.rhs = rhs;
327 return result;
328 }
329
330 struct Statement *CreateSOLVE(){
331 register struct Statement *result;
332 result=create_statement_here(SOLVE);
333 return result;
334 }
335
336 struct Statement *CreateWBTS(struct VariableList *vl)
337 {
338 register struct Statement *result;
339 result=create_statement_here(WBTS);
340 result->v.a.vl = vl;
341 return result;
342 }
343
344 struct Statement *CreateWNBTS(struct VariableList *vl)
345 {
346 register struct Statement *result;
347 result=create_statement_here(WNBTS);
348 result->v.a.vl = vl;
349 return result;
350 }
351
352
353 /********************************************************************\
354 Returns an unsigned with the low bits set according to whether or
355 not there is a statement of the indicated class in the slist given.
356 The value is determined by examining the list, not by looking up
357 some attribute.
358 The return type is valid as a contains field.
359 \********************************************************************/
360 unsigned int SlistHasWhat(struct StatementList *slist)
361 {
362 unsigned long c,length;
363 struct Statement *stat;
364 struct gl_list_t *flist;
365 unsigned int what=0;
366
367 flist = GetList(slist);
368 for(c=1,length=gl_length(flist);c<=length;c++){
369 stat = (struct Statement *)gl_fetch(flist,c);
370 switch (StatementType(stat)){
371 case ALIASES:
372 what |= contains_ALI;
373 break;
374 case ARR:
375 what |= contains_ARR;
376 break;
377 case ISA:
378 what |= contains_ISA;
379 break;
380 case WILLBE:
381 what |= contains_WILLBE;
382 break;
383 case IRT:
384 what |= contains_IRT;
385 break;
386 case ATS:
387 what |= contains_ATS;
388 break;
389 case WBTS:
390 what |= contains_WBTS;
391 break;
392 case WNBTS:
393 what |= contains_WNBTS;
394 break;
395 case AA:
396 what |= contains_AA;
397 break;
398 case CASGN:
399 what |= contains_CAS;
400 break;
401 case ASGN:
402 what |= contains_DEF;
403 break;
404 case REL:
405 what |= contains_REL;
406 break;
407 case EXT:
408 what |= contains_EXT;
409 break;
410 case LOGREL:
411 what |= contains_LREL;
412 break;
413 case WHEN:
414 what |= contains_WHEN;
415 break;
416 case SELECT:
417 what |= contains_SELECT;
418 what |= SelectContains(stat);
419 break;
420 case COND:
421 what |= contains_COND;
422 what |= CondContains(stat);
423 break;
424 case FOR:
425 what |= ForContains(stat);
426 break;
427 default:
428 break;
429 }
430 }
431 return what;
432 }
433
434 struct Statement *CreateFOR(symchar *sindex,
435 struct Expr *expr,
436 struct StatementList *stmts,
437 enum ForOrder order, enum ForKind kind)
438 {
439 register struct Statement *result;
440 result=create_statement_here(FOR);
441 result->v.f.index = sindex;
442 result->v.f.e = expr;
443 result->v.f.stmts = stmts;
444 result->v.f.order = order;
445 result->v.f.kind = kind;
446 result->v.f.contains = SlistHasWhat(stmts);
447 AddContext(stmts,context_FOR);
448 return result;
449 }
450
451 struct Statement *CreateFlow(enum FlowControl fc, CONST char *mt)
452 {
453 register struct Statement *result;
454
455 switch (fc) {
456 case fc_break:
457 case fc_continue:
458 case fc_fallthru:
459 case fc_return:
460 case fc_stop:
461 break;
462 default:
463 Asc_Panic(2, "CreateFlow",
464 "CreateFlow called with unknown flow of control enum");
465 break; /*NOTREACHED*/
466 }
467 result=create_statement_here(FLOW);
468 result->v.flow.fc = fc;
469 if (mt != NULL) {
470 result->v.flow.message = AddBraceChar(mt,AddSymbol("stop"));
471 } else {
472 result->v.flow.message = NULL;
473 }
474 return result;
475 }
476
477 void SetRelationName(struct Statement *stat, struct Name *n)
478 {
479 assert(stat && (stat->t==REL) && (stat->v.rel.nptr==NULL));
480 /* make assignment */
481 stat->v.rel.nptr = n;
482 }
483
484 struct Statement *CreateREL(struct Name *n, struct Expr *relation)
485 {
486 register struct Statement *result;
487 result=create_statement_here(REL);
488 result->v.rel.nptr = n;
489 result->v.rel.relation = relation;
490 return result;
491 }
492
493
494 void SetLogicalRelName(struct Statement *stat, struct Name *n)
495 {
496 assert(stat && (stat->t==LOGREL) && (stat->v.lrel.nptr==NULL));
497 /* make assignment */
498 stat->v.lrel.nptr = n;
499 }
500
501 struct Statement *CreateLOGREL(struct Name *n, struct Expr *logrel)
502 {
503 register struct Statement *result;
504 result=create_statement_here(LOGREL);
505 result->v.lrel.nptr = n;
506 result->v.lrel.logrel = logrel;
507 return result;
508 }
509
510 struct Statement *CreateEXTERNGlassBox(
511 struct Name *n, CONST char *funcname,
512 struct VariableList *vl,
513 struct Name *data,
514 struct Name *scope)
515 {
516 register struct Statement *result;
517 ERROR_REPORTER_DEBUG("Found glassbox equation statement '%s'\n",funcname);
518
519 result=create_statement_here(EXT);
520 result->v.ext.mode = ek_glass;
521 result->v.ext.extcall = funcname;
522 result->v.ext.u.glass.nptr = n;
523 result->v.ext.u.glass.vl = vl;
524 result->v.ext.u.glass.data = data; /* NULL is valid */
525 result->v.ext.u.glass.scope = scope; /* NULL is valid */
526 return result;
527 }
528
529 struct Statement *CreateEXTERNBlackBox(
530 struct Name *n, CONST char *funcname,
531 struct VariableList *vl,
532 struct Name *data,
533 unsigned long n_inputs,
534 unsigned long n_outputs)
535 {
536 register struct Statement *result;
537 struct Name *bbsuffix;
538 symchar *bsuf;
539 /* ERROR_REPORTER_DEBUG("Found blackbox equation statement '%s'\n",funcname); */
540
541 result=create_statement_here(EXT);
542 result->v.ext.mode = ek_black;
543 result->v.ext.extcall = funcname;
544 /* bbox names are indexed bbox{[optionalUserFORIndices]}[?BBOX_OUTPUT].
545 The last index is always ?BBOX_OUTPUT and there is never a case
546 where there can be two such indices, by bbox definition.
547 We could call the symbol ?* instead, but in case another similar
548 internal compiler usage pops up (likely) we like the informative name.
549 */
550 /* name of the bbox implicit int set */
551 bsuf = AddSymbol(BBOX_RESERVED_INDEX);
552 bbsuffix = CreateReservedIndexName(bsuf); /* add a [?BBOX_OUTPUT] index */
553 n = JoinNames(n, bbsuffix);
554 result->v.ext.u.black.nptr = n;
555 result->v.ext.u.black.vl = vl;
556 result->v.ext.u.black.data = data; /* NULL is valid */
557 result->v.ext.u.black.n_inputs = n_inputs; //number of inputs from parsed statement
558 result->v.ext.u.black.n_outputs = n_outputs; //number of outputs from parsed statement
559 return result;
560 }
561
562 struct Statement *CreateEXTERNMethod(
563 CONST char *funcname,
564 struct VariableList *vl)
565 {
566 register struct Statement *result;
567 /* ERROR_REPORTER_DEBUG("Found external method statement '%s'\n",funcname); */
568 result=create_statement_here(EXT);
569 result->v.ext.mode = ek_method;
570 result->v.ext.extcall = funcname;
571 result->v.ext.u.method.vl = vl;
572 return result;
573 }
574
575 struct Statement *CreateREF(struct VariableList *vl,
576 symchar *ref_name,
577 symchar *st,
578 int mode)
579 {
580 register struct Statement *result;
581 result=create_statement_here(REF);
582 result->v.ref.mode = mode;
583 result->v.ref.ref_name = ref_name;
584 result->v.ref.settype = st;
585 result->v.ref.vl = vl;
586 return result;
587 }
588
589 struct Statement *CreateRUN(struct Name *n,struct Name *type_access)
590 {
591 register struct Statement *result;
592 result=create_statement_here(RUN);
593 result->v.r.proc_name = n;
594 result->v.r.type_name = type_access; /* NULL is valid */
595 return result;
596 }
597
598 struct Statement *CreateCALL(symchar *sym,struct Set *args)
599 {
600 register struct Statement *result;
601 result=create_statement_here(CALL);
602 result->v.call.id = sym;
603 result->v.call.args = args; /* NULL is valid */
604 return result;
605 }
606
607 struct Statement *CreateASSERT(struct Expr *ex){
608 register struct Statement *result;
609 result=create_statement_here(ASSERT);
610 result->v.asserts.test = ex;
611 return result;
612 }
613
614 struct Statement *CreateIF(struct Expr *ex,
615 struct StatementList *thenblock,
616 struct StatementList *elseblock)
617 {
618 register struct Statement *result;
619 result=create_statement_here(IF);
620 result->v.ifs.test = ex;
621 result->v.ifs.thenblock = thenblock;
622 result->v.ifs.elseblock = elseblock; /* this may be NULL */
623 if (thenblock != NULL) {
624 AddContext(thenblock,context_IF);
625 }
626 if (elseblock != NULL) {
627 AddContext(elseblock,context_IF);
628 }
629 return result;
630 }
631
632 struct Statement *CreateWhile(struct Expr *ex,
633 struct StatementList *thenblock)
634 {
635 register struct Statement *result;
636 result=create_statement_here(WHILE);
637 result->v.loop.test = ex;
638 result->v.loop.block = thenblock;
639 if (thenblock != NULL) {
640 AddContext(thenblock,context_WHILE);
641 }
642 return result;
643 }
644
645 struct Statement *CreateWHEN(struct Name *wname, struct VariableList *vlist,
646 struct WhenList *wl)
647 {
648 struct StatementList *sl;
649 register struct Statement *result;
650 result=create_statement_here(WHEN);
651 result->v.w.nptr = wname;
652 result->v.w.vl = vlist;
653 result->v.w.cases = wl;
654 while (wl!= NULL) {
655 sl = WhenStatementList(wl);
656 AddContext(sl,context_WHEN);
657 wl = NextWhenCase(wl);
658 }
659 return result;
660 }
661
662 struct Statement *CreateFNAME(struct Name *name)
663 {
664 register struct Statement *result;
665 result=create_statement_here(FNAME);
666 result->v.n.wname = name;
667 return result;
668 }
669
670
671 struct Statement *CreateSWITCH(struct VariableList *v, struct SwitchList *sw)
672 {
673 struct StatementList *sl;
674 register struct Statement *result;
675 result=create_statement_here(SWITCH);
676 result->v.sw.vl = v;
677 result->v.sw.cases = sw;
678 while (sw!= NULL) {
679 sl = SwitchStatementList(sw);
680 AddContext(sl,context_SWITCH);
681 sw = NextSwitchCase(sw);
682 }
683 return result;
684 }
685
686
687 /*
688 * This function gives us the number of statements inside a
689 * SELECT statement. If there is a SELECT inside a SELECT,
690 * the function works recursively
691 */
692 static
693 int CountStatementsInSelect(struct SelectList *sel)
694 {
695 struct StatementList *sl;
696 unsigned long c,length;
697 int tmp, count;
698 struct Statement *s;
699
700 count = 0;
701 while ( sel!=NULL) {
702 sl = SelectStatementList(sel);
703 length = StatementListLength(sl);
704 count = count + length;
705 for(c=1;c<=length;c++){
706 tmp = 0;
707 s = GetStatement(sl,c);
708 assert(s!=NULL);
709 switch(StatementType(s)) {
710 case SELECT:
711 tmp = CountStatementsInSelect(SelectStatCases(s));
712 break;
713 default:
714 break;
715 }
716 count = count + tmp;
717 }
718 sel = NextSelectCase(sel);
719 }
720 return count;
721 }
722
723 struct Statement *CreateSELECT(struct VariableList *v, struct SelectList *sel)
724 {
725 unsigned int tmp=0;
726 struct StatementList *sl;
727 register struct Statement *result;
728 result=create_statement_here(SELECT);
729 result->v.se.vl = v;
730 result->v.se.cases = sel;
731 result->v.se.n_statements = CountStatementsInSelect(sel);
732 while (sel!= NULL) {
733 sl = SelectStatementList(sel);
734 tmp |= SlistHasWhat(sl);
735 AddContext(sl,context_SELECT);
736 sel = NextSelectCase(sel);
737 }
738 result->v.se.contains = tmp;
739 return result;
740 }
741
742
743 struct Statement *CreateCOND(struct StatementList *stmts)
744 {
745 register struct Statement *result;
746 result=create_statement_here(COND);
747 result->v.cond.stmts = stmts;
748 AddContext(stmts,context_COND);
749 result->v.cond.contains = SlistHasWhat(stmts);
750 return result;
751 }
752
753
754 struct Statement *CreateASSIGN(struct Name *n, struct Expr *rhs)
755 {
756 register struct Statement *result;
757 result=create_statement_here(ASGN);
758 result->v.asgn.nptr = n;
759 result->v.asgn.rhs = rhs;
760 return result;
761 }
762
763 struct Statement *CreateCASSIGN(struct Name *n, struct Expr *rhs)
764 {
765 register struct Statement *result;
766 result=create_statement_here(CASGN);
767 result->v.asgn.nptr = n;
768 result->v.asgn.rhs = rhs;
769 return result;
770 }
771
772 enum stat_t StatementTypeF(CONST struct Statement *s)
773 {
774 assert(s!=NULL);
775 assert(s->ref_count);
776 return s->t;
777 }
778
779 struct module_t *StatementModuleF(CONST struct Statement *s)
780 {
781 assert(s!=NULL);
782 assert(s->ref_count);
783 return s->mod;
784 }
785
786 unsigned long StatementLineNumF(CONST struct Statement *s)
787 {
788 assert(s!=NULL);
789 assert(s->ref_count);
790 return s->linenum;
791 }
792
793 struct Statement *CopyStatementF(struct Statement *s)
794 {
795 assert(s!=NULL);
796 assert(s->ref_count);
797 if (s->ref_count<MAXREFCOUNT) s->ref_count++;
798 return s;
799 }
800
801 void DestroyStatement(struct Statement *s)
802 {
803 assert(s!=NULL);
804 assert(s->ref_count);
805 if (s->ref_count<MAXREFCOUNT) {
806 --(s->ref_count);
807 if (s->ref_count ==0) {
808 switch(s->t) {
809 case ALIASES:
810 DestroyVariableList(s->v.ali.vl);
811 DestroyName(s->v.ali.u.nptr);
812 s->v.ali.vl = NULL;
813 s->v.ali.u.nptr = NULL;
814 break;
815 case ARR:
816 DestroyVariableList(s->v.ali.vl);
817 DestroyVariableList(s->v.ali.u.avlname);
818 DestroyVariableList(s->v.ali.c.setname);
819 s->v.ali.vl = NULL;
820 s->v.ali.u.avlname = NULL;
821 s->v.ali.c.setname = NULL;
822 s->v.ali.c.intset = -2;
823 if (s->v.ali.c.setvals != NULL) {
824 DestroySetList(s->v.ali.c.setvals);
825 s->v.ali.c.setvals = NULL;
826 }
827 break;
828 case ISA:
829 case IRT:
830 case WILLBE:
831 DestroyVariableList(s->v.i.vl);
832 s->v.i.vl = NULL;
833 if (s->v.i.checkvalue != NULL) {
834 DestroyExprList(s->v.i.checkvalue);
835 s->v.i.checkvalue = NULL;
836 }
837 if (s->v.i.typeargs != NULL) {
838 DestroySetList(s->v.i.typeargs);
839 s->v.i.typeargs = NULL;
840 }
841 break;
842 case ATS:
843 case AA:
844 case WBTS:
845 case WNBTS:
846 DestroyVariableList(s->v.a.vl);
847 s->v.a.vl = NULL;
848 break;
849 case FOR:
850 DestroyExprList(s->v.f.e);
851 s->v.f.e = NULL;
852 DestroyStatementList(s->v.f.stmts);
853 s->v.f.stmts = NULL;
854 break;
855 case REL:
856 DestroyName(s->v.rel.nptr);
857 s->v.rel.nptr = NULL;
858 DestroyExprList(s->v.rel.relation);
859 s->v.rel.relation = NULL;
860 break;
861 case LOGREL:
862 DestroyName(s->v.lrel.nptr);
863 s->v.lrel.nptr = NULL;
864 DestroyExprList(s->v.lrel.logrel);
865 s->v.lrel.logrel = NULL;
866 break;
867 case CALL:
868 s->v.call.id = NULL;
869 DestroySetList(s->v.call.args);
870 s->v.call.args = NULL;
871 break;
872 case EXT:
873 s->v.ext.extcall = NULL;
874 switch (s->v.ext.mode) {
875 case ek_method:
876 DestroyVariableList(s->v.ext.u.method.vl);
877 s->v.ext.u.method.vl = NULL;
878 break;
879 case ek_glass:
880 DestroyName(s->v.ext.u.glass.nptr);
881 s->v.ext.u.glass.nptr = NULL;
882 DestroyVariableList(s->v.ext.u.glass.vl);
883 s->v.ext.u.glass.vl = NULL;
884 if (s->v.ext.u.glass.data) DestroyName(s->v.ext.u.glass.data);
885 s->v.ext.u.glass.data = NULL;
886 if (s->v.ext.u.glass.scope) DestroyName(s->v.ext.u.glass.scope);
887 s->v.ext.u.glass.scope = NULL;
888 break;
889 case ek_black:
890 DestroyName(s->v.ext.u.black.nptr);
891 s->v.ext.u.black.nptr = NULL;
892 DestroyVariableList(s->v.ext.u.black.vl);
893 s->v.ext.u.black.vl = NULL;
894 if (s->v.ext.u.black.data) DestroyName(s->v.ext.u.black.data);
895 s->v.ext.u.black.data = NULL;
896 break;
897 }
898 break;
899 case REF:
900 DestroyVariableList(s->v.ref.vl);
901 s->v.ref.vl = NULL;
902 break;
903 case ASGN:
904 case CASGN:
905 DestroyName(s->v.asgn.nptr);
906 s->v.asgn.nptr = NULL;
907 DestroyExprList(s->v.asgn.rhs);
908 s->v.asgn.rhs = NULL;
909 break;
910 case RUN:
911 DestroyName(s->v.r.proc_name);
912 s->v.r.proc_name = NULL;
913 DestroyName(s->v.r.type_name);
914 s->v.r.type_name = NULL;
915 break;
916
917 case FIX:
918 case FREE:
919 DestroyVariableList(s->v.fx.vars);
920 break;
921
922 case ASSERT:
923 DestroyExprList(s->v.asserts.test);
924 s->v.asserts.test = NULL;
925 break;
926
927 case SOLVER:
928 s->v.solver.name = NULL;
929 break;
930
931 case OPTION:
932 s->v.option.name = NULL;
933 DestroyExprList(s->v.option.rhs);
934 break;
935
936 case SOLVE:
937 /* currently there's no data stored in this command */
938 break;
939
940 case IF:
941 DestroyStatementList(s->v.ifs.thenblock);
942 s->v.ifs.thenblock = NULL;
943 if (s->v.ifs.elseblock!=NULL){
944 DestroyStatementList(s->v.ifs.elseblock);
945 s->v.ifs.elseblock = NULL;
946 }
947 DestroyExprList(s->v.ifs.test);
948 s->v.ifs.test = NULL;
949 break;
950 case WHEN:
951 DestroyName(s->v.w.nptr);
952 s->v.w.nptr = NULL;
953 DestroyWhenList(s->v.w.cases);
954 s->v.w.cases = NULL;
955 DestroyVariableList(s->v.w.vl);
956 s->v.w.vl = NULL;
957 break;
958 case FNAME:
959 DestroyName(s->v.n.wname);
960 s->v.n.wname = NULL;
961 break;
962 case SELECT:
963 DestroySelectList(s->v.se.cases);
964 s->v.se.cases = NULL;
965 DestroyVariableList(s->v.se.vl);
966 s->v.se.vl = NULL;
967 break;
968 case SWITCH:
969 DestroySwitchList(s->v.sw.cases);
970 s->v.sw.cases = NULL;
971 DestroyVariableList(s->v.sw.vl);
972 s->v.sw.vl = NULL;
973 break;
974 case COND:
975 DestroyStatementList(s->v.cond.stmts);
976 s->v.cond.stmts = NULL;
977 break;
978 case FLOW:
979 DestroyBraceChar(s->v.flow.message); /* tolerates NULL */
980 break;
981 case WHILE:
982 if (s->v.loop.block!=NULL){
983 DestroyStatementList(s->v.loop.block);
984 s->v.loop.block = NULL;
985 }
986 DestroyExprList(s->v.loop.test);
987 s->v.loop.test = NULL;
988 break;
989 }
990 s->mod = NULL;
991 s->linenum = 0;
992 s->context |= context_WRONG;
993 if (s->stringform != NULL) {
994 ascfree(s->stringform);
995 s->stringform = NULL;
996 }
997 STFREE(s);
998 }
999 }
1000 }
1001
1002 struct Statement *CopyToModify(struct Statement *s)
1003 {
1004 register struct Statement *result;
1005 size_t size;
1006 assert(s!=NULL);
1007 assert(s->ref_count);
1008 result = STMALLOC;
1009 if (s->stringform != NULL) {
1010 size = strlen(s->stringform);
1011 result->stringform = ASC_NEW_ARRAY(char,size+1);
1012 memcpy(result->stringform,s->stringform,size+1);
1013 }
1014 result->ref_count = 1;
1015 result->t = s->t;
1016 result->mod = s->mod;
1017 result->linenum = s->linenum;
1018 result->context = s->context;
1019 switch(result->t) {
1020 case ARR:
1021 result->v.ali.c.intset = s->v.ali.c.intset;
1022 result->v.ali.c.setname = CopyVariableList(s->v.ali.c.setname);
1023 result->v.ali.c.setvals = CopySetList(s->v.ali.c.setvals);
1024 result->v.ali.vl = CopyVariableList(s->v.ali.vl);
1025 result->v.ali.u.avlname = CopyVariableList(s->v.ali.u.avlname);
1026 break;
1027 case ALIASES:
1028 result->v.ali.vl = CopyVariableList(s->v.ali.vl);
1029 result->v.ali.u.nptr = CopyName(s->v.ali.u.nptr);
1030 result->v.ali.c.setname = NULL;
1031 result->v.ali.c.intset = -1;
1032 result->v.ali.c.setvals = NULL;
1033 break;
1034 case ISA:
1035 case IRT:
1036 case WILLBE:
1037 result->v.i.type = s->v.i.type;
1038 result->v.i.settype = s->v.i.settype;
1039 result->v.i.vl = CopyVariableList(s->v.i.vl);
1040 result->v.i.checkvalue = CopyExprList(s->v.i.checkvalue);
1041 /* is this complete for IS_A with args to type? */
1042 break;
1043 case AA:
1044 case ATS:
1045 case WBTS:
1046 case WNBTS:
1047 result->v.a.vl = CopyVariableList(s->v.a.vl);
1048 break;
1049 case FOR:
1050 result->v.f.index = s->v.f.index;
1051 result->v.f.e = CopyExprList(s->v.f.e);
1052 result->v.f.stmts = CopyListToModify(s->v.f.stmts);
1053 result->v.f.order = s->v.f.order;
1054 break;
1055 case REL:
1056 result->v.rel.nptr = CopyName(s->v.rel.nptr);
1057 result->v.rel.relation = CopyExprList(s->v.rel.relation);
1058 break;
1059 case LOGREL:
1060 result->v.lrel.nptr = CopyName(s->v.lrel.nptr);
1061 result->v.lrel.logrel = CopyExprList(s->v.lrel.logrel);
1062 break;
1063 case CALL:
1064 result->v.call.args = CopySetList(s->v.call.args);
1065 result->v.call.id = s->v.call.id;
1066 break;
1067 case EXT:
1068 result->v.ext.mode = s->v.ext.mode;
1069 result->v.ext.extcall = s->v.ext.extcall;
1070 switch (s->v.ext.mode) {
1071 case ek_glass:
1072 result->v.ext.u.glass.nptr = CopyName(s->v.ext.u.glass.nptr);
1073 result->v.ext.u.glass.vl = CopyVariableList(s->v.ext.u.glass.vl);
1074 result->v.ext.u.glass.data = CopyName(s->v.ext.u.glass.data);
1075 result->v.ext.u.glass.scope = CopyName(s->v.ext.u.glass.scope);
1076 break;
1077 case ek_black:
1078 result->v.ext.u.black.nptr = CopyName(s->v.ext.u.black.nptr);
1079 result->v.ext.u.black.vl = CopyVariableList(s->v.ext.u.black.vl);
1080 result->v.ext.u.black.data = CopyName(s->v.ext.u.black.data);
1081 break;
1082 case ek_method:
1083 result->v.ext.u.method.vl = CopyVariableList(s->v.ext.u.method.vl);
1084 break;
1085 }
1086 break;
1087 case REF:
1088 result->v.ref.mode = s->v.ref.mode;
1089 result->v.ref.ref_name = s->v.ref.ref_name;
1090 result->v.ref.vl = CopyVariableList(s->v.ref.vl);
1091 break;
1092 case ASGN:
1093 case CASGN:
1094 result->v.asgn.nptr = CopyName(s->v.asgn.nptr);
1095 result->v.asgn.rhs = CopyExprList(s->v.asgn.rhs);
1096 break;
1097 case RUN:
1098 result->v.r.proc_name = CopyName(s->v.r.proc_name);
1099 result->v.r.type_name = CopyName(s->v.r.type_name);
1100 break;
1101
1102 case ASSERT:
1103 result->v.asserts.test = CopyExprList(s->v.asserts.test);
1104 break;
1105
1106 case FIX:
1107 case FREE:
1108 result->v.fx.vars = CopyVariableList(s->v.fx.vars);
1109 break;
1110
1111 case SOLVER:
1112 result->v.solver.name = s->v.solver.name;
1113 break;
1114
1115 case OPTION:
1116 result->v.option.name = s->v.option.name;
1117 result->v.option.rhs = CopyExprList(s->v.option.rhs);
1118 break;
1119
1120 case SOLVE:
1121 /* no data to be copied for this command */
1122 break;
1123
1124 case IF:
1125 result->v.ifs.test = CopyExprList(s->v.ifs.test);
1126 result->v.ifs.thenblock = CopyListToModify(s->v.ifs.thenblock);
1127 if (s->v.ifs.elseblock!=NULL) {
1128 result->v.ifs.elseblock = CopyListToModify(s->v.ifs.elseblock);
1129 } else {
1130 result->v.ifs.elseblock = NULL;
1131 }
1132 break;
1133 case WHEN:
1134 result->v.w.nptr = CopyName(s->v.w.nptr);
1135 result->v.w.vl = CopyVariableList(s->v.w.vl);
1136 result->v.w.cases = CopyWhenList(s->v.w.cases);
1137 break;
1138 case FNAME:
1139 result->v.n.wname = CopyName(s->v.n.wname);
1140 break;
1141 case SELECT:
1142 result->v.se.vl = CopyVariableList(s->v.se.vl);
1143 result->v.se.cases = CopySelectList(s->v.se.cases);
1144 result->v.se.n_statements = s->v.se.n_statements;
1145 result->v.se.contains = s->v.se.contains;
1146 break;
1147 case SWITCH:
1148 result->v.sw.vl = CopyVariableList(s->v.sw.vl);
1149 result->v.sw.cases = CopySwitchList(s->v.sw.cases);
1150 break;
1151 case COND:
1152 result->v.cond.stmts = CopyListToModify(s->v.cond.stmts);
1153 break;
1154 case FLOW:
1155 result->v.flow.fc = s->v.flow.fc;
1156 break;
1157 case WHILE:
1158 result->v.loop.test = CopyExprList(s->v.loop.test);
1159 if (s->v.loop.block!=NULL) {
1160 result->v.loop.block = CopyListToModify(s->v.loop.block);
1161 } else {
1162 result->v.loop.block = NULL;
1163 }
1164 break;
1165 }
1166 return result;
1167 }
1168
1169 unsigned int GetStatContextF(CONST struct Statement *s)
1170 {
1171 assert(s!=NULL);
1172 switch (s->t) {
1173 case ALIASES:
1174 case ARR:
1175 case ISA:
1176 case WILLBE:
1177 case IRT:
1178 case AA:
1179 case ATS:
1180 case WBTS:
1181 case WNBTS:
1182 case REL:
1183 case LOGREL:
1184 case ASGN:
1185 case CASGN:
1186 case FOR:
1187 case CALL:
1188 case EXT:
1189 case REF:
1190 case RUN:
1191 case FIX:
1192 case FREE:
1193 case SOLVER:
1194 case OPTION:
1195 case SOLVE:
1196 case ASSERT:
1197 case IF:
1198 case WHEN:
1199 case FNAME:
1200 case SELECT:
1201 case SWITCH:
1202 case COND:
1203 case WHILE:
1204 case FLOW:
1205 return s->context;
1206 default:
1207 ERROR_REPORTER_STAT(ASC_PROG_ERR,s,"GetStatContext called on incorrect statement type.");
1208 return context_MODEL;
1209 }
1210 }
1211
1212 void SetStatContext(struct Statement *s, unsigned int c)
1213 {
1214 assert(s!=NULL);
1215 switch (s->t) {
1216 case ALIASES:
1217 case ARR:
1218 case ISA:
1219 case WILLBE:
1220 case IRT:
1221 case AA:
1222 case ATS:
1223 case WBTS:
1224 case WNBTS:
1225 case REL:
1226 case LOGREL:
1227 case ASGN:
1228 case CASGN:
1229 case FOR:
1230 case CALL:
1231 case EXT:
1232 case REF:
1233 case RUN:
1234 case FIX:
1235 case FREE:
1236 case SOLVER:
1237 case OPTION:
1238 case SOLVE:
1239 case ASSERT:
1240 case IF:
1241 case WHEN:
1242 case FNAME:
1243 case SELECT:
1244 case SWITCH:
1245 case COND:
1246 case WHILE:
1247 case FLOW:
1248 s->context = c;
1249 break;
1250 default:
1251 Asc_Panic(2, "SetStatContext",
1252 "SetStatContext called on incorrect statement type.\n");
1253 break;
1254 }
1255 }
1256
1257 void MarkStatContext(struct Statement *s, unsigned int c)
1258 {
1259 assert(s!=NULL);
1260 switch (s->t) {
1261 case ALIASES:
1262 case ARR:
1263 case ISA:
1264 case WILLBE:
1265 case IRT:
1266 case AA:
1267 case ATS:
1268 case WBTS:
1269 case WNBTS:
1270 case REL:
1271 case LOGREL:
1272 case ASGN:
1273 case CASGN:
1274 case FOR:
1275 case CALL:
1276 case EXT:
1277 case REF:
1278 case RUN:
1279 case FIX:
1280 case FREE:
1281 case SOLVER:
1282 case OPTION:
1283 case SOLVE:
1284 case ASSERT:
1285 case IF:
1286 case WHEN:
1287 case FNAME:
1288 case SELECT:
1289 case SWITCH:
1290 case COND:
1291 case WHILE:
1292 case FLOW:
1293 s->context |= c;
1294 break;
1295 default:
1296 Asc_Panic(2, "MarkStatContext",
1297 "MarkStatContext called on incorrect statement type.\n");
1298 break;
1299 }
1300 }
1301
1302 struct VariableList *GetStatVarList(CONST struct Statement *s)
1303 {
1304 assert(s!=NULL);
1305 assert(s->ref_count);
1306 assert( (s->t==ISA) ||
1307 (s->t==WILLBE) ||
1308 (s->t==IRT) ||
1309 (s->t==AA) ||
1310 (s->t==ATS) ||
1311 (s->t==WBTS) ||
1312 (s->t==WNBTS) ||
1313 (s->t==ARR) ||
1314 (s->t==ALIASES)
1315 );
1316 switch (s->t) {
1317 case ISA:
1318 case WILLBE:
1319 case IRT:
1320 return (s)->v.i.vl;
1321 case AA:
1322 case ATS:
1323 case WBTS:
1324 case WNBTS:
1325 return (s)->v.a.vl;
1326 case ALIASES:
1327 case ARR:
1328 return (s)->v.ali.vl;
1329 default:
1330 return NULL;
1331 }
1332 }
1333
1334 symchar *GetStatTypeF(CONST struct Statement *s)
1335 {
1336 assert(s!=NULL);
1337 assert(s->ref_count);
1338 assert((s->t==ISA) || (s->t==IRT) || (s->t==WILLBE));
1339 return s->v.i.type;
1340 }
1341
1342 CONST struct Set *GetStatTypeArgsF(CONST struct Statement *s)
1343 {
1344 assert(s!=NULL);
1345 assert(s->ref_count);
1346 assert((s->t==ISA) || (s->t==IRT) || (s->t==WILLBE));
1347 return s->v.i.typeargs;
1348 }
1349
1350 unsigned int GetStatNeedsArgs(CONST struct Statement *s)
1351 {
1352 CONST struct TypeDescription *d;
1353 assert(s!=NULL);
1354 assert(s->ref_count);
1355 assert((s->t==ISA) || (s->t==IRT));
1356 d = FindType(s->v.i.type);
1357 if (d==NULL || GetBaseType(d) != model_type) {
1358 return 0;
1359 }
1360 return GetModelParameterCount(d);
1361 }
1362
1363 symchar *GetStatSetTypeF(CONST struct Statement *s)
1364 {
1365 assert(s!=NULL);
1366 assert(s->ref_count);
1367 assert(s->t==ISA || s->t==WILLBE);
1368 return s->v.i.settype;
1369 }
1370
1371 CONST struct Expr *GetStatCheckValueF(CONST struct Statement *s)
1372 {
1373 assert(s!=NULL);
1374 assert(s->ref_count);
1375 assert(s->t==WILLBE);
1376 return s->v.i.checkvalue;
1377 }
1378
1379 CONST struct Name *AliasStatNameF(CONST struct Statement *s)
1380 {
1381 assert(s!=NULL);
1382 assert(s->ref_count);
1383 assert(s->t==ALIASES);
1384 return s->v.ali.u.nptr;
1385 }
1386
1387 CONST struct VariableList *ArrayStatAvlNamesF(CONST struct Statement *s)
1388 {
1389 assert(s!=NULL);
1390 assert(s->ref_count);
1391 assert(s->t==ARR);
1392 return s->v.ali.u.avlname;
1393 }
1394
1395 CONST struct VariableList *ArrayStatSetNameF(CONST struct Statement *s)
1396 {
1397 assert(s!=NULL);
1398 assert(s->ref_count);
1399 assert(s->t==ARR);
1400 return s->v.ali.c.setname;
1401 }
1402
1403 int ArrayStatIntSetF(CONST struct Statement *s)
1404 {
1405 assert(s!=NULL);
1406 assert(s->ref_count);
1407 assert(s->t==ARR);
1408 return s->v.ali.c.intset;
1409 }
1410
1411 CONST struct Set *ArrayStatSetValuesF(CONST struct Statement *s)
1412 {
1413 assert(s!=NULL);
1414 assert(s->ref_count);
1415 assert(s->t==ARR);
1416 return s->v.ali.c.setvals;
1417 }
1418
1419 symchar *ForStatIndexF(CONST struct Statement *s)
1420 {
1421 assert(s!=NULL);
1422 assert(s->ref_count);
1423 assert(s->t==FOR);
1424 return s->v.f.index;
1425 }
1426
1427 struct Expr *ForStatExprF(CONST struct Statement *s)
1428 {
1429 assert(s!=NULL);
1430 assert(s->ref_count);
1431 assert(s->t==FOR);
1432 return s->v.f.e;
1433 }
1434
1435 struct StatementList *ForStatStmtsF(CONST struct Statement *s)
1436 {
1437 assert(s!=NULL);
1438 assert(s->ref_count);
1439 assert(s->t == FOR);
1440 return s->v.f.stmts;
1441 }
1442
1443 enum ForOrder ForLoopOrderF(CONST struct Statement *s)
1444 {
1445 assert(s!=NULL);
1446 assert(s->t==FOR);
1447 return s->v.f.order;
1448 }
1449
1450 enum ForKind ForLoopKindF(CONST struct Statement *s)
1451 {
1452 assert(s!=NULL);
1453 assert(s->t==FOR);
1454 return s->v.f.kind;
1455 }
1456
1457
1458 unsigned ForContainsF(CONST struct Statement *s)
1459 {
1460 assert(s!=NULL);
1461 assert(s->t==FOR);
1462 return (s->v.f.contains);
1463 }
1464
1465 unsigned ForContainsRelationsF(CONST struct Statement *s)
1466 {
1467 assert(s!=NULL);
1468 assert(s->t==FOR);
1469 return (s->v.f.contains & contains_REL);
1470 }
1471
1472 unsigned ForContainsExternalF(CONST struct Statement *s)
1473 {
1474 assert(s!=NULL);
1475 assert(s->t==FOR);
1476 return (s->v.f.contains & contains_EXT);
1477 }
1478
1479
1480 unsigned ForContainsLogRelationsF(CONST struct Statement *s)
1481 {
1482 assert(s!=NULL);
1483 assert(s->t==FOR);
1484 return (s->v.f.contains & contains_LREL);
1485 }
1486
1487 unsigned ForContainsDefaultsF(CONST struct Statement *s)
1488 {
1489 assert(s!=NULL);
1490 assert(s->t==FOR);
1491 return (s->v.f.contains & contains_DEF);
1492 }
1493
1494 unsigned ForContainsCAssignsF(CONST struct Statement *s)
1495 {
1496 assert(s!=NULL);
1497 assert(s->t==FOR);
1498 return (s->v.f.contains & contains_CAS);
1499 }
1500
1501
1502 unsigned ForContainsWhenF(CONST struct Statement *s)
1503 {
1504 assert(s!=NULL);
1505 assert(s->t==FOR);
1506 return (s->v.f.contains & contains_WHEN);
1507 }
1508
1509 unsigned ForContainsIsaF(CONST struct Statement *s)
1510 {
1511 assert(s!=NULL);
1512 assert(s->t==FOR);
1513 return (s->v.f.contains & contains_ISA);
1514 }
1515
1516 unsigned ForContainsIrtF(CONST struct Statement *s)
1517 {
1518 assert(s!=NULL);
1519 assert(s->t==FOR);
1520 return (s->v.f.contains & contains_IRT);
1521 }
1522
1523 unsigned ForContainsAlikeF(CONST struct Statement *s)
1524 {
1525 assert(s!=NULL);
1526 assert(s->t==FOR);
1527 return (s->v.f.contains & contains_AA);
1528 }
1529
1530 unsigned ForContainsAliasF(CONST struct Statement *s)
1531 {
1532 assert(s!=NULL);
1533 assert(s->t==FOR);
1534 return (s->v.f.contains & contains_ALI);
1535 }
1536
1537 unsigned ForContainsArrayF(CONST struct Statement *s)
1538 {
1539 assert(s!=NULL);
1540 assert(s->t==FOR);
1541 return (s->v.f.contains & contains_ARR);
1542 }
1543
1544 unsigned ForContainsAtsF(CONST struct Statement *s)
1545 {
1546 assert(s!=NULL);
1547 assert(s->t==FOR);
1548 return (s->v.f.contains & contains_ATS);
1549 }
1550
1551 unsigned ForContainsWbtsF(CONST struct Statement *s)
1552 {
1553 assert(s!=NULL);
1554 assert(s->t==FOR);
1555 return (s->v.f.contains & contains_WBTS);
1556 }
1557
1558 unsigned ForContainsWnbtsF(CONST struct Statement *s)
1559 {
1560 assert(s!=NULL);
1561 assert(s->t==FOR);
1562 return (s->v.f.contains & contains_WNBTS);
1563 }
1564
1565 unsigned ForContainsWillbeF(CONST struct Statement *s)
1566 {
1567 assert(s!=NULL);
1568 assert(s->t==FOR);
1569 return (s->v.f.contains & contains_WILLBE);
1570 }
1571
1572 unsigned ForContainsSelectF(CONST struct Statement *s)
1573 {
1574 assert(s!=NULL);
1575 assert(s->t==FOR);
1576 return (s->v.f.contains & contains_SELECT);
1577 }
1578
1579 unsigned ForContainsConditionalF(CONST struct Statement *s)
1580 {
1581 assert(s!=NULL);
1582 assert(s->t==FOR);
1583 return (s->v.f.contains & contains_COND);
1584 }
1585
1586 unsigned ForContainsIllegalF(CONST struct Statement *s)
1587 {
1588 assert(s!=NULL);
1589 assert(s->t==FOR);
1590 return (s->v.f.contains & contains_ILL);
1591 }
1592
1593 struct Name *DefaultStatVarF(CONST struct Statement *s)
1594 {
1595 assert(s!=NULL);
1596 assert(s->ref_count);
1597 assert(s->t==ASGN);
1598 return s->v.asgn.nptr;
1599 }
1600
1601 struct Name *AssignStatVarF(CONST struct Statement *s)
1602 {
1603 assert(s!=NULL);
1604 assert(s->ref_count);
1605 assert(s->t==CASGN);
1606 return s->v.asgn.nptr;
1607 }
1608
1609 struct Expr *DefaultStatRHSF(CONST struct Statement *s)
1610 {
1611 assert(s!=NULL);
1612 assert(s->ref_count);
1613 assert(s->t==ASGN);
1614 return s->v.asgn.rhs;
1615 }
1616
1617
1618 struct Expr *AssignStatRHSF(CONST struct Statement *s)
1619 {
1620 assert(s!=NULL);
1621 assert(s->ref_count);
1622 assert(s->t==CASGN);
1623 return s->v.asgn.rhs;
1624 }
1625
1626 struct Name *RelationStatNameF(CONST struct Statement *s)
1627 {
1628 assert(s!=NULL);
1629 assert(s->ref_count);
1630 assert(s->t==REL);
1631 return s->v.rel.nptr;
1632 }
1633
1634 struct Expr *RelationStatExprF(CONST struct Statement *s)
1635 {
1636 assert(s!=NULL);
1637 assert(s->ref_count);
1638 assert(s->t==REL);
1639 return s->v.rel.relation;
1640 }
1641
1642 struct Name *LogicalRelStatNameF(CONST struct Statement *s)
1643 {
1644 assert(s!=NULL);
1645 assert(s->ref_count);
1646 assert(s->t==LOGREL);
1647 return s->v.lrel.nptr;
1648 }
1649
1650 struct Expr *LogicalRelStatExprF(CONST struct Statement *s)
1651 {
1652 assert(s!=NULL);
1653 assert(s->ref_count);
1654 assert(s->t==LOGREL);
1655 return s->v.lrel.logrel;
1656 }
1657
1658 enum ExternalKind ExternalStatModeF(CONST struct Statement *s)
1659 {
1660 assert(s!=NULL);
1661 assert(s->t==EXT);
1662 return(s->v.ext.mode);
1663 }
1664
1665 struct Name *ExternalStatNameRelationF(CONST struct Statement *s)
1666 {
1667 assert(s!=NULL);
1668 assert(s->t==EXT);
1669 assert(s->v.ext.mode == ek_glass || s->v.ext.mode == ek_black);
1670 return(s->v.ext.u.relation.nptr);
1671 }
1672
1673 struct Name *ExternalStatDataBlackBoxF(CONST struct Statement *s)
1674 {
1675 assert(s!=NULL);
1676 assert(s->t==EXT);
1677 assert(s->v.ext.mode == ek_black);
1678 return(s->v.ext.u.black.data);
1679 }
1680
1681 struct Name *ExternalStatDataGlassBoxF(CONST struct Statement *s)
1682 {
1683 assert(s!=NULL);
1684 assert(s->t==EXT);
1685 assert(s->v.ext.mode == ek_glass);
1686 return(s->v.ext.u.glass.data);
1687 }
1688
1689 struct Name *ExternalStatScopeGlassBoxF(CONST struct Statement *s)
1690 {
1691 assert(s!=NULL);
1692 assert(s->t==EXT);
1693 assert(s->v.ext.mode == ek_glass);
1694 return(s->v.ext.u.glass.scope);
1695 }
1696
1697 CONST struct VariableList *ExternalStatVlistRelationF(CONST struct Statement *s)
1698 {
1699 assert(s!=NULL);
1700 assert(s->t==EXT);
1701 assert(s->v.ext.mode == ek_black || s->v.ext.mode == ek_glass);
1702 return(s->v.ext.u.relation.vl);
1703 }
1704
1705 CONST struct VariableList *ExternalStatVlistMethodF(CONST struct Statement *s)
1706 {
1707 assert(s!=NULL);
1708 assert(s->t==EXT);
1709 assert(s->v.ext.mode == ek_method);
1710 return(s->v.ext.u.method.vl);
1711 }
1712
1713 CONST char *ExternalStatFuncNameF(CONST struct Statement *s)
1714 {
1715 assert(s!=NULL);
1716 assert(s->t==EXT);
1717 return(s->v.ext.extcall);
1718 }
1719
1720 int ReferenceStatModeF(CONST struct Statement *s)
1721 {
1722 assert(s!=NULL);
1723 assert(s->t==REF);
1724 return(s->v.ref.mode);
1725 }
1726
1727 symchar *ReferenceStatNameF(CONST struct Statement *s)
1728 {
1729 assert(s!=NULL);
1730 assert(s->t==REF);
1731 return(s->v.ref.ref_name);
1732 }
1733
1734 symchar *ReferenceStatSetTypeF(CONST struct Statement *s)
1735 {
1736 assert(s!=NULL);
1737 assert(s->ref_count);
1738 assert(s->t==REF);
1739 return (s->v.ref.settype);
1740 }
1741
1742 struct VariableList *ReferenceStatVlistF(CONST struct Statement *s)
1743 {
1744 assert(s!=NULL);
1745 assert(s->t==REF);
1746 return(s->v.ref.vl);
1747 }
1748
1749 struct Name *RunStatNameF(CONST struct Statement *s)
1750 {
1751 assert(s && (s->ref_count) && (s->t == RUN));
1752 return s->v.r.proc_name;
1753 }
1754
1755 struct Name *RunStatAccessF(CONST struct Statement *s)
1756 {
1757 assert(s && (s->ref_count) && (s->t == RUN));
1758 return s->v.r.type_name;
1759 }
1760
1761 struct VariableList *FixFreeStatVarsF(CONST struct Statement *s){
1762 assert(s!=NULL);
1763 assert(s->t==FIX || s->t==FREE);
1764 return(s->v.fx.vars);
1765 }
1766
1767 struct Set *CallStatArgsF(CONST struct Statement *s)
1768 {
1769 assert(s!=NULL);
1770 assert(s->t==CALL);
1771 return(s->v.call.args);
1772 }
1773
1774 symchar *CallStatIdF(CONST struct Statement *s)
1775 {
1776 assert(s!=NULL);
1777 assert(s->t==CALL);
1778 return(s->v.call.id);
1779 }
1780
1781 struct Expr *WhileStatExprF(CONST struct Statement *s)
1782 {
1783 assert(s && s->ref_count && (s->t == WHILE));
1784 return s->v.loop.test;
1785 }
1786
1787 struct Expr *AssertStatExprF(CONST struct Statement *s){
1788 assert(s && s->ref_count && (s->t == ASSERT));
1789 return s->v.asserts.test;
1790 }
1791
1792 struct Expr *IfStatExprF(CONST struct Statement *s)
1793 {
1794 assert(s && s->ref_count && (s->t == IF));
1795 return s->v.ifs.test;
1796 }
1797
1798 struct StatementList *WhileStatBlockF(CONST struct Statement *s)
1799 {
1800 assert(s!=NULL);
1801 assert(s->ref_count);
1802 assert(s->t == WHILE);
1803 return s->v.loop.block;
1804 }
1805
1806 struct StatementList *IfStatThenF(CONST struct Statement *s)
1807 {
1808 assert(s!=NULL);
1809 assert(s->ref_count);
1810 assert(s->t == IF);
1811 return s->v.ifs.thenblock;
1812 }
1813
1814 struct StatementList *IfStatElseF(CONST struct Statement *s)
1815 {
1816 assert(s && (s->ref_count) && (s->t == IF));
1817 return s->v.ifs.elseblock;
1818 }
1819
1820
1821 struct Name *WhenStatNameF(CONST struct Statement *s)
1822 {
1823 assert(s && s->ref_count && (s->t == WHEN));
1824 return s->v.w.nptr;
1825 }
1826
1827 void SetWhenName(struct Statement *s, struct Name *n)
1828 {
1829 assert(s && (s->t==WHEN) && (s->v.w.nptr==NULL));
1830 s->v.w.nptr = n;
1831 }
1832
1833 struct VariableList *WhenStatVLF(CONST struct Statement *s)
1834 {
1835 assert(s && s->ref_count && (s->t == WHEN));
1836 return s->v.w.vl;
1837 }
1838
1839 struct WhenList *WhenStatCasesF(CONST struct Statement *s)
1840 {
1841 assert(s && s->ref_count && (s->t == WHEN));
1842 return s->v.w.cases;
1843 }
1844
1845
1846 /*
1847 * Compare functions for WHEN statements. It includes the
1848 * decomposition of the WHEN in the list of variables and
1849 * the list of CASEs. Also, each case is decomposed in
1850 * the set of values and the list of statements. It is
1851 * done here since we are comparing the statement rather
1852 * than only a WhenList structure (when.[ch]).
1853 */
1854
1855 int CompareWhenStatements(CONST struct Statement *s1,
1856 CONST struct Statement *s2)
1857 {
1858 int ctmp; /* temporary comparison result */
1859 unsigned long int ltmp;
1860 struct VariableList *vl1, *vl2;
1861 struct WhenList *cases1,*cases2;
1862 struct Set *val1, *val2;
1863 struct StatementList *sl1, *sl2;
1864
1865 vl1 = WhenStatVL(s1);
1866 vl2 = WhenStatVL(s2);
1867
1868 ctmp = CompareVariableLists(vl1,vl2);
1869 if (ctmp != 0) {
1870 return ctmp;
1871 }
1872
1873 cases1 = WhenStatCases(s1);
1874 cases2 = WhenStatCases(s2);
1875
1876 while ( (cases1!=NULL) && (cases2!=NULL) ) {
1877 val1 = WhenSetList(cases1);
1878 val2 = WhenSetList(cases2);
1879
1880 ctmp = CompareSetStructures(val1,val2);
1881 if (ctmp != 0) {
1882 return ctmp;
1883 }
1884
1885 sl1 = WhenStatementList(cases1);
1886 sl2 = WhenStatementList(cases2);
1887 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
1888 if (ctmp != 0) {
1889 return ctmp;
1890 }
1891 cases1 = NextWhenCase(cases1);
1892 cases2 = NextWhenCase(cases2);
1893 }
1894 return 0;
1895 }
1896
1897 struct StatementList *CondStatListF(CONST struct Statement *s)
1898 {
1899 assert(s && s->ref_count && (s->t == COND));
1900 return s->v.cond.stmts;
1901 }
1902
1903 unsigned CondContainsF(CONST struct Statement *s)
1904 {
1905 assert(s!=NULL);
1906 assert(s->t==COND);
1907 return (s->v.cond.contains);
1908 }
1909
1910 unsigned CondContainsRelationsF(CONST struct Statement *s)
1911 {
1912 assert(s!=NULL);
1913 assert(s->t==COND);
1914 return (s->v.cond.contains & contains_REL);
1915 }
1916
1917 unsigned CondContainsExternalF(CONST struct Statement *s)
1918 {
1919 assert(s!=NULL);
1920 assert(s->t==COND);
1921 return (s->v.cond.contains & contains_EXT);
1922 }
1923
1924
1925 unsigned CondContainsLogRelationsF(CONST struct Statement *s)
1926 {
1927 assert(s!=NULL);
1928 assert(s->t==COND);
1929 return (s->v.cond.contains & contains_LREL);
1930 }
1931
1932 struct Name *FnameStatF(CONST struct Statement *s)
1933 {
1934 assert(s && s->ref_count && (s->t == FNAME));
1935 return s->v.n.wname;
1936 }
1937
1938 int SelectStatNumberStatsF(CONST struct Statement *s)
1939 {
1940 assert(s && s->ref_count && (s->t == SELECT));
1941 return s->v.se.n_statements;
1942 }
1943
1944 struct VariableList *SelectStatVLF(CONST struct Statement *s)
1945 {
1946 assert(s && s->ref_count && (s->t == SELECT));
1947 return s->v.se.vl;
1948 }
1949
1950 struct SelectList *SelectStatCasesF(CONST struct Statement *s)
1951 {
1952 assert(s && s->ref_count && (s->t == SELECT));
1953 return s->v.se.cases;
1954 }
1955
1956 /*
1957 * Compare functions for SELECT statements. It includes the
1958 * decomposition of the SELECT in the list of variables and
1959 * the list of CASEs. Also, each case is decomposed in
1960 * the set of values and the list of statements. It is
1961 * done here since we are comparing the statement rather
1962 * than only a SelectList structure (select.[ch]).
1963 */
1964
1965 int CompareSelectStatements(CONST struct Statement *s1,
1966 CONST struct Statement *s2)
1967 {
1968 int ctmp; /* temporary comparison result */
1969 unsigned long int ltmp;
1970 struct VariableList *vl1, *vl2;
1971 struct SelectList *cases1,*cases2;
1972 struct Set *val1, *val2;
1973 struct StatementList *sl1, *sl2;
1974
1975 vl1 = SelectStatVL(s1);
1976 vl2 = SelectStatVL(s2);
1977
1978 ctmp = CompareVariableLists(vl1,vl2);
1979 if (ctmp != 0) {
1980 return ctmp;
1981 }
1982
1983 cases1 = SelectStatCases(s1);
1984 cases2 = SelectStatCases(s2);
1985
1986 while ( (cases1!=NULL) && (cases2!=NULL) ) {
1987 val1 = SelectSetList(cases1);
1988 val2 = SelectSetList(cases2);
1989
1990 ctmp = CompareSetStructures(val1,val2);
1991 if (ctmp != 0) {
1992 return ctmp;
1993 }
1994
1995 sl1 = SelectStatementList(cases1);
1996 sl2 = SelectStatementList(cases2);
1997 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
1998 if (ctmp != 0) {
1999 return ctmp;
2000 }
2001 cases1 = NextSelectCase(cases1);
2002 cases2 = NextSelectCase(cases2);
2003 }
2004 return 0;
2005 }
2006
2007
2008 unsigned SelectContainsF(CONST struct Statement *s)
2009 {
2010 assert(s!=NULL);
2011 assert(s->t==SELECT);
2012 return (s->v.se.contains);
2013 }
2014
2015 unsigned SelectContainsRelationsF(CONST struct Statement *s)
2016 {
2017 assert(s!=NULL);
2018 assert(s->t==SELECT);
2019 return (s->v.se.contains & contains_REL);
2020 }
2021
2022 unsigned SelectContainsExternalF(CONST struct Statement *s)
2023 {
2024 assert(s!=NULL);
2025 assert(s->t==SELECT);
2026 return (s->v.se.contains & contains_EXT);
2027 }
2028
2029
2030 unsigned SelectContainsLogRelationsF(CONST struct Statement *s)
2031 {
2032 assert(s!=NULL);
2033 assert(s->t==SELECT);
2034 return (s->v.se.contains & contains_LREL);
2035 }
2036
2037 unsigned SelectContainsDefaultsF(CONST struct Statement *s)
2038 {
2039 assert(s!=NULL);
2040 assert(s->t==SELECT);
2041 return (s->v.se.contains & contains_DEF);
2042 }
2043
2044 unsigned SelectContainsCAssignsF(CONST struct Statement *s)
2045 {
2046 assert(s!=NULL);
2047 assert(s->t==SELECT);
2048 return (s->v.se.contains & contains_CAS);
2049 }
2050
2051
2052 unsigned SelectContainsWhenF(CONST struct Statement *s)
2053 {
2054 assert(s!=NULL);
2055 assert(s->t==SELECT);
2056 return (s->v.se.contains & contains_WHEN);
2057 }
2058
2059 unsigned SelectContainsIsaF(CONST struct Statement *s)
2060 {
2061 assert(s!=NULL);
2062 assert(s->t==SELECT);
2063 return (s->v.se.contains & contains_ISA);
2064 }
2065
2066 unsigned SelectContainsIrtF(CONST struct Statement *s)
2067 {
2068 assert(s!=NULL);
2069 assert(s->t==SELECT);
2070 return (s->v.se.contains & contains_IRT);
2071 }
2072
2073 unsigned SelectContainsAlikeF(CONST struct Statement *s)
2074 {
2075 assert(s!=NULL);
2076 assert(s->t==SELECT);
2077 return (s->v.se.contains & contains_AA);
2078 }
2079
2080 unsigned SelectContainsAliasF(CONST struct Statement *s)
2081 {
2082 assert(s!=NULL);
2083 assert(s->t==SELECT);
2084 return (s->v.se.contains & contains_ALI);
2085 }
2086
2087 unsigned SelectContainsArrayF(CONST struct Statement *s)
2088 {
2089 assert(s!=NULL);
2090 assert(s->t==SELECT);
2091 return (s->v.se.contains & contains_ARR);
2092 }
2093
2094 unsigned SelectContainsAtsF(CONST struct Statement *s)
2095 {
2096 assert(s!=NULL);
2097 assert(s->t==SELECT);
2098 return (s->v.se.contains & contains_ATS);
2099 }
2100
2101 unsigned SelectContainsWbtsF(CONST struct Statement *s)
2102 {
2103 assert(s!=NULL);
2104 assert(s->t==SELECT);
2105 return (s->v.se.contains & contains_WBTS);
2106 }
2107
2108 unsigned SelectContainsWnbtsF(CONST struct Statement *s)
2109 {
2110 assert(s!=NULL);
2111 assert(s->t==SELECT);
2112 return (s->v.se.contains & contains_WNBTS);
2113 }
2114
2115 unsigned SelectContainsWillbeF(CONST struct Statement *s)
2116 {
2117 assert(s!=NULL);
2118 assert(s->t==SELECT);
2119 return (s->v.se.contains & contains_WILLBE);
2120 }
2121
2122 unsigned SelectContainsSelectF(CONST struct Statement *s)
2123 {
2124 assert(s!=NULL);
2125 assert(s->t==SELECT);
2126 return (s->v.se.contains & contains_SELECT);
2127 }
2128
2129 unsigned SelectContainsConditionalF(CONST struct Statement *s)
2130 {
2131 assert(s!=NULL);
2132 assert(s->t==SELECT);
2133 return (s->v.se.contains & contains_COND);
2134 }
2135
2136 unsigned SelectContainsIllegalF(CONST struct Statement *s)
2137 {
2138 assert(s!=NULL);
2139 assert(s->t==SELECT);
2140 return (s->v.se.contains & contains_ILL);
2141 }
2142
2143
2144 struct VariableList *SwitchStatVLF(CONST struct Statement *s)
2145 {
2146 assert(s && s->ref_count && (s->t == SWITCH));
2147 return s->v.sw.vl;
2148 }
2149
2150 struct SwitchList *SwitchStatCasesF(CONST struct Statement *s)
2151 {
2152 assert(s && s->ref_count && (s->t == SWITCH));
2153 return s->v.sw.cases;
2154 }
2155
2156 /*
2157 * Compare functions for SWITCH statements. It includes the
2158 * decomposition of the SWITCH in the list of variables and
2159 * the list of CASEs. Also, each case is decomposed in
2160 * the set of values and the list of statements. It is
2161 * done here since we are comparing the statement rather
2162 * than only a SwitchList structure (switch.[ch]).
2163 */
2164
2165 int CompareSwitchStatements(CONST struct Statement *s1,
2166 CONST struct Statement *s2)
2167 {
2168 int ctmp; /* temporary comparison result */
2169 unsigned long int ltmp;
2170 struct VariableList *vl1, *vl2;
2171 struct SwitchList *cases1,*cases2;
2172 struct Set *val1, *val2;
2173 struct StatementList *sl1, *sl2;
2174
2175 vl1 = SwitchStatVL(s1);
2176 vl2 = SwitchStatVL(s2);
2177
2178 ctmp = CompareVariableLists(vl1,vl2);
2179 if (ctmp != 0) {
2180 return ctmp;
2181 }
2182
2183 cases1 = SwitchStatCases(s1);
2184 cases2 = SwitchStatCases(s2);
2185
2186 while ( (cases1!=NULL) && (cases2!=NULL) ) {
2187 val1 = SwitchSetList(cases1);
2188 val2 = SwitchSetList(cases2);
2189
2190 ctmp = CompareSetStructures(val1,val2);
2191 if (ctmp != 0) {
2192 return ctmp;
2193 }
2194
2195 sl1 = SwitchStatementList(cases1);
2196 sl2 = SwitchStatementList(cases2);
2197 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
2198 if (ctmp != 0) {
2199 return ctmp;
2200 }
2201 cases1 = NextSwitchCase(cases1);
2202 cases2 = NextSwitchCase(cases2);
2203 }
2204 return 0;
2205 }
2206
2207
2208 /*********************************************************************\
2209 CompareStatements(s1,s2);
2210 Returns -1,0,1 as s1 is <, ==, > s2.
2211 s1 < s2 if type(s1) < type(s2), exception: NULL > all statements.
2212 For statements of the same type, compared according to
2213 the number of arguments or alphabetically, as appropriate.
2214 We are comparing statement contents, not statement
2215 memory location or origin.
2216 FOR/DO vs FOR/CREATE is considered a different type, so
2217 the 'in a method' location matters. file, line, etc don't, though.
2218 \*********************************************************************/
2219 int CompareStatements(CONST struct Statement *s1, CONST struct Statement *s2)
2220 {
2221 int ctmp; /* temporary comparison result */
2222 unsigned long int ltmp;
2223 if (s1 == s2) return 0;
2224 if (s1==NULL) return 1;
2225 if (s2==NULL) return -1;
2226 if (s1->t > s2->t) return 1;
2227 if (s1->t < s2->t) return -1;
2228 switch (s1->t) {
2229 case ALIASES:
2230 ctmp = CompareNames(AliasStatName(s1),AliasStatName(s2));
2231 if (ctmp != 0) {
2232 return ctmp;
2233 }
2234 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2235 case ARR:
2236 ctmp = CompareVariableLists(ArrayStatAvlNames(s1),ArrayStatAvlNames(s2));
2237 if (ctmp != 0) {
2238 return ctmp;
2239 }
2240 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2241 if (ctmp != 0) {
2242 return ctmp;
2243 }
2244 ctmp = CompareVariableLists(ArrayStatSetName(s1),ArrayStatSetName(s2));
2245 if (ctmp != 0) {
2246 return ctmp;
2247 }
2248 ctmp = ArrayStatIntSet(s1) - ArrayStatIntSet(s2);
2249 if (ctmp != 0) {
2250 if (ctmp ==1) {
2251 return CmpSymchar(GetBaseTypeName(integer_constant_type),
2252 GetBaseTypeName(symbol_constant_type));
2253 } else {
2254 /* ctmp == -1 */
2255 return CmpSymchar(GetBaseTypeName(symbol_constant_type) ,
2256 GetBaseTypeName(integer_constant_type));
2257 }
2258 }
2259 return CompareSetStructures(ArrayStatSetValues(s1),ArrayStatSetValues(s2));
2260 case ISA:
2261 if (GetStatSetType(s1)!=NULL || GetStatSetType(s2) !=NULL) {
2262 if (GetStatSetType(s1) == NULL) { return -1; }
2263 if (GetStatSetType(s2) == NULL) { return 1; }
2264 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2265 if (ctmp != 0) {
2266 return ctmp;
2267 }
2268 }
2269 /* fallthru */
2270 case IRT:
2271 ctmp = CmpSymchar(GetStatType(s1),GetStatType(s2));
2272 if (ctmp != 0) {
2273 return ctmp;
2274 }
2275 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2276 if (ctmp != 0) {
2277 return ctmp;
2278 }
2279 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2280 case WILLBE:
2281 if (GetStatSetType(s1) != NULL || GetStatSetType(s2) != NULL) {
2282 if (GetStatSetType(s1) == NULL) { return -1; }
2283 if (GetStatSetType(s2) == NULL) { return 1; }
2284 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2285 if (ctmp != 0) {
2286 return ctmp;
2287 }
2288 }
2289 ctmp = CmpSymchar(GetStatType(s1),GetStatType(s2));
2290 if (ctmp != 0) {
2291 return ctmp;
2292 }
2293 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2294 if (ctmp != 0) {
2295 return ctmp;
2296 }
2297 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2298 if (ctmp != 0) {
2299 return ctmp;
2300 }
2301 return CompareExprs(GetStatCheckValue(s1),GetStatCheckValue(s2));
2302 case ATS: /* fallthru */
2303 case WBTS: /* fallthru */
2304 case WNBTS: /* fallthru */
2305 case AA:
2306 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2307 case FOR:
2308 if (ForStatIndex(s1)!=ForStatIndex(s2)) {
2309 return CmpSymchar(ForStatIndex(s1),ForStatIndex(s2));
2310 }
2311 if (ForContains(s1)!=ForContains(s2)) {
2312 /* arbitrary but consistent */
2313 return ( ForContains(s1) > ForContains(s2)) ? 1 : -1;
2314 }
2315 if (ForLoopOrder(s1)!=ForLoopOrder(s2)) {
2316 return ( ForLoopOrder(s1) > ForLoopOrder(s2)) ? 1 : -1;
2317 }
2318 if (ForLoopKind(s1)!=ForLoopKind(s2)) {
2319 return ( ForLoopKind(s1) > ForLoopKind(s2)) ? 1 : -1;
2320 }
2321 ctmp = CompareExprs(ForStatExpr(s1),ForStatExpr(s2));
2322 if (ctmp!=0) {
2323 return ctmp;
2324 }
2325 return CompareStatementLists(ForStatStmts(s1),ForStatStmts(s2),&ltmp);
2326 case REL:
2327 ctmp = CompareNames(RelationStatName(s1),RelationStatName(s2));
2328 if (ctmp!=0 &&
2329 /* we need to skip this for system generated names */
2330 !NameAuto(RelationStatName(s1)) &&
2331 !NameAuto(RelationStatName(s2))) {
2332 return ctmp;
2333 }
2334 return CompareExprs(RelationStatExpr(s1),RelationStatExpr(s2));
2335 case LOGREL:
2336 ctmp = CompareNames(LogicalRelStatName(s1),LogicalRelStatName(s2));
2337 if (ctmp!=0 &&
2338 /* we need to skip this for system generated names */
2339 !NameAuto(LogicalRelStatName(s1)) &&
2340 !NameAuto(LogicalRelStatName(s2))) {
2341 return ctmp;
2342 }
2343 return CompareExprs(LogicalRelStatExpr(s1),LogicalRelStatExpr(s2));
2344 case ASGN:
2345 ctmp = CompareNames(DefaultStatVar(s1),DefaultStatVar(s2));
2346 if (ctmp != 0) {
2347 return ctmp;
2348 }
2349 return CompareExprs(DefaultStatRHS(s1),DefaultStatRHS(s2));
2350 case CASGN:
2351 ctmp = CompareNames(AssignStatVar(s1),AssignStatVar(s2));
2352 if (ctmp != 0) {
2353 return ctmp;
2354 }
2355 return CompareExprs(AssignStatRHS(s1),AssignStatRHS(s2));
2356 case RUN:
2357 ctmp = CompareNames(RunStatName(s1),RunStatName(s2));
2358 if (ctmp != 0) {
2359 return ctmp;
2360 }
2361 return CompareNames(RunStatAccess(s1),RunStatAccess(s2));
2362 case WHILE:
2363 ctmp = CompareExprs(WhileStatExpr(s1), WhileStatExpr(s2));
2364 if (ctmp != 0) {
2365 return ctmp;
2366 }
2367 return CompareStatementLists(WhileStatBlock(s1), WhileStatBlock(s2),&ltmp);
2368
2369 case ASSERT:
2370 ctmp = CompareExprs(AssertStatExpr(s1), AssertStatExpr(s2));
2371 return ctmp;
2372
2373 case IF:
2374 ctmp = CompareExprs(IfStatExpr(s1), IfStatExpr(s2));
2375 if (ctmp != 0) {
2376 return ctmp;
2377 }
2378 ctmp = CompareStatementLists(IfStatThen(s1), IfStatThen(s2),&ltmp);
2379 if (ctmp != 0) {
2380 return ctmp;
2381 }
2382 return CompareStatementLists(IfStatElse(s1), IfStatElse(s2),&ltmp);
2383 case WHEN:
2384 ctmp = CompareNames(WhenStatName(s1),WhenStatName(s2));
2385 if (ctmp!=0 &&
2386 /* we need to skip this for system generated names */
2387 !NameAuto(WhenStatName(s1)) &&
2388 !NameAuto(WhenStatName(s2))) {
2389 return ctmp;
2390 }
2391 return CompareWhenStatements(s1,s2);
2392 case FNAME:
2393 return CompareNames(FnameStat(s1),FnameStat(s2));
2394 case SELECT:
2395 if (SelectContains(s1)!=SelectContains(s2)) {
2396 /* arbitrary but consistent */
2397 return ( SelectContains(s1) > SelectContains(s2)) ? 1 : -1;
2398 }
2399 if (SelectStatNumberStats(s1)!=SelectStatNumberStats(s2)) {
2400 /* arbitrary but consistent */
2401 return (SelectStatNumberStats(s1) > SelectStatNumberStats(s2)) ? 1 : -1;
2402 }
2403 return CompareSelectStatements(s1,s2);
2404 case SWITCH:
2405 return CompareSwitchStatements(s1,s2);
2406 case CALL:
2407 if (CallStatId(s1)!=CallStatId(s2)) {
2408 return CmpSymchar(CallStatId(s1),CallStatId(s2));
2409 }
2410 return CompareSetStructures(CallStatArgs(s1),CallStatArgs(s2));
2411 case EXT:
2412 ctmp = strcmp(ExternalStatFuncName(s1),ExternalStatFuncName(s2));
2413 if (ctmp != 0) {
2414 return ctmp;
2415 }
2416 if (ExternalStatMode(s1) != ExternalStatMode(s2)) {
2417 return (ExternalStatMode(s1) > ExternalStatMode(s2)) ? 1 : -1;
2418 }
2419 if (ExternalStatMode(s1) == ek_glass || ExternalStatMode(s1) == ek_black) {
2420 ctmp = CompareNames(ExternalStatNameRelation(s1),ExternalStatNameRelation(s2));
2421 if (ctmp != 0) {
2422 return ctmp;
2423 }
2424 }
2425 if (ExternalStatMode(s1) == ek_glass) {
2426 ctmp = CompareNames(ExternalStatScope(s1),ExternalStatScope(s2));
2427 if (ctmp != 0) {
2428 return ctmp;
2429 }
2430 }
2431 if (ExternalStatMode(s1) == ek_glass) {
2432 ctmp = CompareNames(ExternalStatDataGlassBox(s1),ExternalStatDataGlassBox(s2));
2433 if (ctmp != 0) {
2434 return ctmp;
2435 }
2436 }
2437 if (ExternalStatMode(s1) == ek_black) {
2438 ctmp = CompareNames(ExternalStatDataBlackBox(s1),ExternalStatDataBlackBox(s2));
2439 if (ctmp != 0) {
2440 return ctmp;
2441 }
2442 }
2443 switch (ExternalStatMode(s1)) {
2444 case ek_method:
2445 return CompareVariableLists(ExternalStatVlistMethod(s1),ExternalStatVlistMethod(s2));
2446 case ek_glass:
2447 case ek_black:
2448 return CompareVariableLists(ExternalStatVlistRelation(s1),ExternalStatVlistRelation(s2));
2449 default:
2450 return 1;
2451 }
2452 case REF:
2453 /* need fixing. since both are ill defined, they
2454 * will not be fixed until the definitions are really known.
2455 */
2456 ASC_PANIC("Don't know how to compare REF statements\n");
2457
2458 case COND:
2459 return CompareStatementLists(CondStatList(s1),CondStatList(s2),&ltmp);
2460 case FLOW:
2461 if (FlowStatControl(s1) != FlowStatControl(s2)) {
2462 return (FlowStatControl(s1) > FlowStatControl(s2)) ? 1 : -1;
2463 }
2464 /* FlowStatMessage is considered comment info and so not compared */
2465 return 0;
2466 default:
2467 ERROR_REPORTER_NOLINE(ASC_PROG_ERR,"CompareStatements called with unknown statement");
2468 return 0;
2469 }
2470 }
2471
2472 /* could we merge some of this with plain compare statements via some
2473 *static functions? baa. fix me.
2474 */
2475 int CompareISStatements(CONST struct Statement *s1, CONST struct Statement *s2)
2476 {
2477 unsigned long int ltmp;
2478 struct TypeDescription *d1, *d2;
2479 int ctmp; /* temporary comparison result */
2480
2481 if (s1 == s2) return 0;
2482 if (s1==NULL) return 1;
2483 if (s2==NULL) return -1;
2484 if (s1->t > s2->t) return 1;
2485 if (s1->t < s2->t) return -1;
2486 switch (s1->t) {
2487 case ISA:
2488 /* compare set OF parts */
2489 if (GetStatSetType(s1)!=NULL || GetStatSetType(s2) !=NULL) {
2490 if (GetStatSetType(s1) == NULL) { return -1; }
2491 if (GetStatSetType(s2) == NULL) { return 1; }
2492 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2493 if (ctmp != 0) {
2494 return ctmp;
2495 }
2496 }
2497 /********** FALLTHRU * FALL THROUGH * FALL TO IRT *************/
2498 case IRT:
2499 /* compare basic types */
2500 d1 = FindType(GetStatType(s1));
2501 d2 = FindType(GetStatType(s2));
2502 assert(d1 !=NULL);
2503 assert(d2 !=NULL);
2504 if (d1!=d2 && MoreRefined(d1,d2) != d2) {
2505 if (MoreRefined(d1,d2) == NULL) {
2506 return 1;
2507 } else {
2508 return -1;
2509 }
2510 }
2511 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2512 /* this may be a little too picky comparison of arglists */
2513 if (ctmp != 0) {
2514 return ctmp;
2515 }
2516 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2517 /* IS_A IS_REFINED_TO have not WITH_VALUE part */
2518 case WILLBE:
2519 /* compare set OF parts */
2520 if (GetStatSetType(s1) != NULL || GetStatSetType(s2) != NULL) {
2521 if (GetStatSetType(s1) == NULL) { return -1; }
2522 if (GetStatSetType(s2) == NULL) { return 1; }
2523 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2524 if (ctmp != 0) {
2525 return ctmp;
2526 }
2527 }
2528 /* compare basic types */
2529 d1 = FindType(GetStatType(s1));
2530 d2 = FindType(GetStatType(s2));
2531 assert(d1 !=NULL);
2532 assert(d2 !=NULL);
2533 if (d1!=d2 && MoreRefined(d1,d2) != d2) {
2534 if (MoreRefined(d1,d2) == NULL) {
2535 return 1;
2536 } else {
2537 return -1;
2538 }
2539 }
2540 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2541 /* this may be a little too picky comparison of arglists */
2542 if (ctmp != 0) {
2543 return ctmp;
2544 }
2545 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2546 if (ctmp != 0) {
2547 return ctmp;
2548 }
2549 if (GetStatCheckValue(s1) != NULL) {
2550 return CompareExprs(GetStatCheckValue(s1),GetStatCheckValue(s2));
2551 } else {
2552 return 0;
2553 }
2554 case WBTS: /* fallthru */
2555 case WNBTS:
2556 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2557 case FOR:
2558 if (ForStatIndex(s1)!=ForStatIndex(s2)) {
2559 return CmpSymchar(ForStatIndex(s1),ForStatIndex(s2));
2560 }
2561 if (ForContains(s1)!=ForContains(s2)) {
2562 /* arbitrary but consistent */
2563 return ( ForContains(s1) > ForContains(s2)) ? 1 : -1;
2564 }
2565 if (ForLoopOrder(s1)!=ForLoopOrder(s2)) {
2566 return ( ForLoopOrder(s1) > ForLoopOrder(s2)) ? 1 : -1;
2567 }
2568 if (ForLoopKind(s1)!=ForLoopKind(s2)) {
2569 return ( ForLoopKind(s1) > ForLoopKind(s2)) ? 1 : -1;
2570 }
2571 ctmp = CompareExprs(ForStatExpr(s1),ForStatExpr(s2));
2572 if (ctmp!=0) {
2573 return ctmp;
2574 }
2575 return CompareISLists(ForStatStmts(s1),ForStatStmts(s2),&ltmp);
2576 case LOGREL:
2577 case REL:
2578 return CompareStatements(s1,s2);
2579 case ALIASES:
2580 case ARR:
2581 case ATS: /* fallthru */
2582 case AA:
2583 case ASGN:
2584 case CASGN:
2585 case RUN:
2586 case CALL:
2587 case ASSERT:
2588 case IF:
2589 case WHEN:
2590 case FNAME:
2591 case SELECT:
2592 case SWITCH:
2593 case EXT: /* fallthru */
2594 case REF:
2595 case COND:
2596 case FLOW:
2597 case WHILE:
2598 ERROR_REPORTER_STAT(ASC_PROG_ERR,s1,"CompareISStatements called with incorrect statement");
2599 return -1;
2600 default:
2601 ERROR_REPORTER_STAT(ASC_PROG_ERR,s1,"CompareISStatements called with unknown statement");
2602 return 1;
2603 }
2604 }
2605

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