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

Contents of /trunk/base/generic/compiler/statement.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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