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

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