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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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