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

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