/[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 423 - (show annotations) (download) (as text)
Mon Apr 3 23:15:49 2006 UTC (18 years, 2 months ago) by ben.allan
File MIME type: text/x-csrc
File size: 59100 byte(s)
Fixed instatiation of blackbox (and probably glassbox)
relations, for poorly tested definitions of 'fix'.
Blackbox evaluation is still broken.

There seems to be some chaos around win32_lean_and_mean
in ascConfig.h

updated reconfig. setenv TKROOT /where/is/tk8.3dir before 
running and all is good.
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 IF:
997 result->v.ifs.test = CopyExprList(s->v.ifs.test);
998 result->v.ifs.thenblock = CopyListToModify(s->v.ifs.thenblock);
999 if (s->v.ifs.elseblock!=NULL) {
1000 result->v.ifs.elseblock = CopyListToModify(s->v.ifs.elseblock);
1001 } else {
1002 result->v.ifs.elseblock = NULL;
1003 }
1004 break;
1005 case WHEN:
1006 result->v.w.nptr = CopyName(s->v.w.nptr);
1007 result->v.w.vl = CopyVariableList(s->v.w.vl);
1008 result->v.w.cases = CopyWhenList(s->v.w.cases);
1009 break;
1010 case FNAME:
1011 result->v.n.wname = CopyName(s->v.n.wname);
1012 break;
1013 case SELECT:
1014 result->v.se.vl = CopyVariableList(s->v.se.vl);
1015 result->v.se.cases = CopySelectList(s->v.se.cases);
1016 result->v.se.n_statements = s->v.se.n_statements;
1017 result->v.se.contains = s->v.se.contains;
1018 break;
1019 case SWITCH:
1020 result->v.sw.vl = CopyVariableList(s->v.sw.vl);
1021 result->v.sw.cases = CopySwitchList(s->v.sw.cases);
1022 break;
1023 case COND:
1024 result->v.cond.stmts = CopyListToModify(s->v.cond.stmts);
1025 break;
1026 case FLOW:
1027 result->v.flow.fc = s->v.flow.fc;
1028 break;
1029 case WHILE:
1030 result->v.loop.test = CopyExprList(s->v.loop.test);
1031 if (s->v.loop.block!=NULL) {
1032 result->v.loop.block = CopyListToModify(s->v.loop.block);
1033 } else {
1034 result->v.loop.block = NULL;
1035 }
1036 break;
1037 }
1038 return result;
1039 }
1040
1041 unsigned int GetStatContextF(CONST struct Statement *s)
1042 {
1043 assert(s!=NULL);
1044 switch (s->t) {
1045 case ALIASES:
1046 case ARR:
1047 case ISA:
1048 case WILLBE:
1049 case IRT:
1050 case AA:
1051 case ATS:
1052 case WBTS:
1053 case WNBTS:
1054 case REL:
1055 case LOGREL:
1056 case ASGN:
1057 case CASGN:
1058 case FOR:
1059 case CALL:
1060 case EXT:
1061 case REF:
1062 case RUN:
1063 case FIX:
1064 case FREE:
1065 case ASSERT:
1066 case IF:
1067 case WHEN:
1068 case FNAME:
1069 case SELECT:
1070 case SWITCH:
1071 case COND:
1072 case WHILE:
1073 case FLOW:
1074 return s->context;
1075 default:
1076 ERROR_REPORTER_STAT(ASC_PROG_ERR,s,"GetStatContext called on incorrect statement type.");
1077 return context_MODEL;
1078 }
1079 }
1080
1081 void SetStatContext(struct Statement *s, unsigned int c)
1082 {
1083 assert(s!=NULL);
1084 switch (s->t) {
1085 case ALIASES:
1086 case ARR:
1087 case ISA:
1088 case WILLBE:
1089 case IRT:
1090 case AA:
1091 case ATS:
1092 case WBTS:
1093 case WNBTS:
1094 case REL:
1095 case LOGREL:
1096 case ASGN:
1097 case CASGN:
1098 case FOR:
1099 case CALL:
1100 case EXT:
1101 case REF:
1102 case RUN:
1103 case FIX:
1104 case FREE:
1105 case ASSERT:
1106 case IF:
1107 case WHEN:
1108 case FNAME:
1109 case SELECT:
1110 case SWITCH:
1111 case COND:
1112 case WHILE:
1113 case FLOW:
1114 s->context = c;
1115 break;
1116 default:
1117 Asc_Panic(2, "SetStatContext",
1118 "SetStatContext called on incorrect statement type.\n");
1119 break;
1120 }
1121 }
1122
1123 void MarkStatContext(struct Statement *s, unsigned int c)
1124 {
1125 assert(s!=NULL);
1126 switch (s->t) {
1127 case ALIASES:
1128 case ARR:
1129 case ISA:
1130 case WILLBE:
1131 case IRT:
1132 case AA:
1133 case ATS:
1134 case WBTS:
1135 case WNBTS:
1136 case REL:
1137 case LOGREL:
1138 case ASGN:
1139 case CASGN:
1140 case FOR:
1141 case CALL:
1142 case EXT:
1143 case REF:
1144 case RUN:
1145 case FIX:
1146 case FREE:
1147 case ASSERT:
1148 case IF:
1149 case WHEN:
1150 case FNAME:
1151 case SELECT:
1152 case SWITCH:
1153 case COND:
1154 case WHILE:
1155 case FLOW:
1156 s->context |= c;
1157 break;
1158 default:
1159 Asc_Panic(2, "MarkStatContext",
1160 "MarkStatContext called on incorrect statement type.\n");
1161 break;
1162 }
1163 }
1164
1165 struct VariableList *GetStatVarList(CONST struct Statement *s)
1166 {
1167 assert(s!=NULL);
1168 assert(s->ref_count);
1169 assert( (s->t==ISA) ||
1170 (s->t==WILLBE) ||
1171 (s->t==IRT) ||
1172 (s->t==AA) ||
1173 (s->t==ATS) ||
1174 (s->t==WBTS) ||
1175 (s->t==WNBTS) ||
1176 (s->t==ARR) ||
1177 (s->t==ALIASES)
1178 );
1179 switch (s->t) {
1180 case ISA:
1181 case WILLBE:
1182 case IRT:
1183 return (s)->v.i.vl;
1184 case AA:
1185 case ATS:
1186 case WBTS:
1187 case WNBTS:
1188 return (s)->v.a.vl;
1189 case ALIASES:
1190 case ARR:
1191 return (s)->v.ali.vl;
1192 default:
1193 return NULL;
1194 }
1195 }
1196
1197 symchar *GetStatTypeF(CONST struct Statement *s)
1198 {
1199 assert(s!=NULL);
1200 assert(s->ref_count);
1201 assert((s->t==ISA) || (s->t==IRT) || (s->t==WILLBE));
1202 return s->v.i.type;
1203 }
1204
1205 CONST struct Set *GetStatTypeArgsF(CONST struct Statement *s)
1206 {
1207 assert(s!=NULL);
1208 assert(s->ref_count);
1209 assert((s->t==ISA) || (s->t==IRT) || (s->t==WILLBE));
1210 return s->v.i.typeargs;
1211 }
1212
1213 unsigned int GetStatNeedsArgs(CONST struct Statement *s)
1214 {
1215 CONST struct TypeDescription *d;
1216 assert(s!=NULL);
1217 assert(s->ref_count);
1218 assert((s->t==ISA) || (s->t==IRT));
1219 d = FindType(s->v.i.type);
1220 if (d==NULL || GetBaseType(d) != model_type) {
1221 return 0;
1222 }
1223 return GetModelParameterCount(d);
1224 }
1225
1226 symchar *GetStatSetTypeF(CONST struct Statement *s)
1227 {
1228 assert(s!=NULL);
1229 assert(s->ref_count);
1230 assert(s->t==ISA || s->t==WILLBE);
1231 return s->v.i.settype;
1232 }
1233
1234 CONST struct Expr *GetStatCheckValueF(CONST struct Statement *s)
1235 {
1236 assert(s!=NULL);
1237 assert(s->ref_count);
1238 assert(s->t==WILLBE);
1239 return s->v.i.checkvalue;
1240 }
1241
1242 CONST struct Name *AliasStatNameF(CONST struct Statement *s)
1243 {
1244 assert(s!=NULL);
1245 assert(s->ref_count);
1246 assert(s->t==ALIASES);
1247 return s->v.ali.u.nptr;
1248 }
1249
1250 CONST struct VariableList *ArrayStatAvlNamesF(CONST struct Statement *s)
1251 {
1252 assert(s!=NULL);
1253 assert(s->ref_count);
1254 assert(s->t==ARR);
1255 return s->v.ali.u.avlname;
1256 }
1257
1258 CONST struct VariableList *ArrayStatSetNameF(CONST struct Statement *s)
1259 {
1260 assert(s!=NULL);
1261 assert(s->ref_count);
1262 assert(s->t==ARR);
1263 return s->v.ali.c.setname;
1264 }
1265
1266 int ArrayStatIntSetF(CONST struct Statement *s)
1267 {
1268 assert(s!=NULL);
1269 assert(s->ref_count);
1270 assert(s->t==ARR);
1271 return s->v.ali.c.intset;
1272 }
1273
1274 CONST struct Set *ArrayStatSetValuesF(CONST struct Statement *s)
1275 {
1276 assert(s!=NULL);
1277 assert(s->ref_count);
1278 assert(s->t==ARR);
1279 return s->v.ali.c.setvals;
1280 }
1281
1282 symchar *ForStatIndexF(CONST struct Statement *s)
1283 {
1284 assert(s!=NULL);
1285 assert(s->ref_count);
1286 assert(s->t==FOR);
1287 return s->v.f.index;
1288 }
1289
1290 struct Expr *ForStatExprF(CONST struct Statement *s)
1291 {
1292 assert(s!=NULL);
1293 assert(s->ref_count);
1294 assert(s->t==FOR);
1295 return s->v.f.e;
1296 }
1297
1298 struct StatementList *ForStatStmtsF(CONST struct Statement *s)
1299 {
1300 assert(s!=NULL);
1301 assert(s->ref_count);
1302 assert(s->t == FOR);
1303 return s->v.f.stmts;
1304 }
1305
1306 enum ForOrder ForLoopOrderF(CONST struct Statement *s)
1307 {
1308 assert(s!=NULL);
1309 assert(s->t==FOR);
1310 return s->v.f.order;
1311 }
1312
1313 enum ForKind ForLoopKindF(CONST struct Statement *s)
1314 {
1315 assert(s!=NULL);
1316 assert(s->t==FOR);
1317 return s->v.f.kind;
1318 }
1319
1320
1321 unsigned ForContainsF(CONST struct Statement *s)
1322 {
1323 assert(s!=NULL);
1324 assert(s->t==FOR);
1325 return (s->v.f.contains);
1326 }
1327
1328 unsigned ForContainsRelationsF(CONST struct Statement *s)
1329 {
1330 assert(s!=NULL);
1331 assert(s->t==FOR);
1332 return (s->v.f.contains & contains_REL);
1333 }
1334
1335
1336 unsigned ForContainsLogRelationsF(CONST struct Statement *s)
1337 {
1338 assert(s!=NULL);
1339 assert(s->t==FOR);
1340 return (s->v.f.contains & contains_LREL);
1341 }
1342
1343 unsigned ForContainsDefaultsF(CONST struct Statement *s)
1344 {
1345 assert(s!=NULL);
1346 assert(s->t==FOR);
1347 return (s->v.f.contains & contains_DEF);
1348 }
1349
1350 unsigned ForContainsCAssignsF(CONST struct Statement *s)
1351 {
1352 assert(s!=NULL);
1353 assert(s->t==FOR);
1354 return (s->v.f.contains & contains_CAS);
1355 }
1356
1357
1358 unsigned ForContainsWhenF(CONST struct Statement *s)
1359 {
1360 assert(s!=NULL);
1361 assert(s->t==FOR);
1362 return (s->v.f.contains & contains_WHEN);
1363 }
1364
1365 unsigned ForContainsIsaF(CONST struct Statement *s)
1366 {
1367 assert(s!=NULL);
1368 assert(s->t==FOR);
1369 return (s->v.f.contains & contains_ISA);
1370 }
1371
1372 unsigned ForContainsIrtF(CONST struct Statement *s)
1373 {
1374 assert(s!=NULL);
1375 assert(s->t==FOR);
1376 return (s->v.f.contains & contains_IRT);
1377 }
1378
1379 unsigned ForContainsAlikeF(CONST struct Statement *s)
1380 {
1381 assert(s!=NULL);
1382 assert(s->t==FOR);
1383 return (s->v.f.contains & contains_AA);
1384 }
1385
1386 unsigned ForContainsAliasF(CONST struct Statement *s)
1387 {
1388 assert(s!=NULL);
1389 assert(s->t==FOR);
1390 return (s->v.f.contains & contains_ALI);
1391 }
1392
1393 unsigned ForContainsArrayF(CONST struct Statement *s)
1394 {
1395 assert(s!=NULL);
1396 assert(s->t==FOR);
1397 return (s->v.f.contains & contains_ARR);
1398 }
1399
1400 unsigned ForContainsAtsF(CONST struct Statement *s)
1401 {
1402 assert(s!=NULL);
1403 assert(s->t==FOR);
1404 return (s->v.f.contains & contains_ATS);
1405 }
1406
1407 unsigned ForContainsWbtsF(CONST struct Statement *s)
1408 {
1409 assert(s!=NULL);
1410 assert(s->t==FOR);
1411 return (s->v.f.contains & contains_WBTS);
1412 }
1413
1414 unsigned ForContainsWnbtsF(CONST struct Statement *s)
1415 {
1416 assert(s!=NULL);
1417 assert(s->t==FOR);
1418 return (s->v.f.contains & contains_WNBTS);
1419 }
1420
1421 unsigned ForContainsWillbeF(CONST struct Statement *s)
1422 {
1423 assert(s!=NULL);
1424 assert(s->t==FOR);
1425 return (s->v.f.contains & contains_WILLBE);
1426 }
1427
1428 unsigned ForContainsSelectF(CONST struct Statement *s)
1429 {
1430 assert(s!=NULL);
1431 assert(s->t==FOR);
1432 return (s->v.f.contains & contains_SELECT);
1433 }
1434
1435 unsigned ForContainsConditionalF(CONST struct Statement *s)
1436 {
1437 assert(s!=NULL);
1438 assert(s->t==FOR);
1439 return (s->v.f.contains & contains_COND);
1440 }
1441
1442 unsigned ForContainsIllegalF(CONST struct Statement *s)
1443 {
1444 assert(s!=NULL);
1445 assert(s->t==FOR);
1446 return (s->v.f.contains & contains_ILL);
1447 }
1448
1449 struct Name *DefaultStatVarF(CONST struct Statement *s)
1450 {
1451 assert(s!=NULL);
1452 assert(s->ref_count);
1453 assert(s->t==ASGN);
1454 return s->v.asgn.nptr;
1455 }
1456
1457 struct Name *AssignStatVarF(CONST struct Statement *s)
1458 {
1459 assert(s!=NULL);
1460 assert(s->ref_count);
1461 assert(s->t==CASGN);
1462 return s->v.asgn.nptr;
1463 }
1464
1465 struct Expr *DefaultStatRHSF(CONST struct Statement *s)
1466 {
1467 assert(s!=NULL);
1468 assert(s->ref_count);
1469 assert(s->t==ASGN);
1470 return s->v.asgn.rhs;
1471 }
1472
1473
1474 struct Expr *AssignStatRHSF(CONST struct Statement *s)
1475 {
1476 assert(s!=NULL);
1477 assert(s->ref_count);
1478 assert(s->t==CASGN);
1479 return s->v.asgn.rhs;
1480 }
1481
1482 struct Name *RelationStatNameF(CONST struct Statement *s)
1483 {
1484 assert(s!=NULL);
1485 assert(s->ref_count);
1486 assert(s->t==REL);
1487 return s->v.rel.nptr;
1488 }
1489
1490 struct Expr *RelationStatExprF(CONST struct Statement *s)
1491 {
1492 assert(s!=NULL);
1493 assert(s->ref_count);
1494 assert(s->t==REL);
1495 return s->v.rel.relation;
1496 }
1497
1498 struct Name *LogicalRelStatNameF(CONST struct Statement *s)
1499 {
1500 assert(s!=NULL);
1501 assert(s->ref_count);
1502 assert(s->t==LOGREL);
1503 return s->v.lrel.nptr;
1504 }
1505
1506 struct Expr *LogicalRelStatExprF(CONST struct Statement *s)
1507 {
1508 assert(s!=NULL);
1509 assert(s->ref_count);
1510 assert(s->t==LOGREL);
1511 return s->v.lrel.logrel;
1512 }
1513
1514 int ExternalStatModeF(CONST struct Statement *s)
1515 {
1516 assert(s!=NULL);
1517 assert(s->t==EXT);
1518 return(s->v.ext.mode);
1519 }
1520
1521 struct Name *ExternalStatNameF(CONST struct Statement *s)
1522 {
1523 assert(s!=NULL);
1524 assert(s->t==EXT);
1525 return(s->v.ext.nptr);
1526 }
1527
1528 struct Name *ExternalStatDataF(CONST struct Statement *s)
1529 {
1530 assert(s!=NULL);
1531 assert(s->t==EXT);
1532 return(s->v.ext.data);
1533 }
1534
1535 struct Name *ExternalStatScopeF(CONST struct Statement *s)
1536 {
1537 assert(s!=NULL);
1538 assert(s->t==EXT);
1539 return(s->v.ext.scope);
1540 }
1541
1542 struct VariableList *ExternalStatVlistF(CONST struct Statement *s)
1543 {
1544 assert(s!=NULL);
1545 assert(s->t==EXT);
1546 return(s->v.ext.vl);
1547 }
1548
1549 CONST char *ExternalStatFuncNameF(CONST struct Statement *s)
1550 {
1551 assert(s!=NULL);
1552 assert(s->t==EXT);
1553 return(s->v.ext.extcall);
1554 }
1555
1556 int ReferenceStatModeF(CONST struct Statement *s)
1557 {
1558 assert(s!=NULL);
1559 assert(s->t==REF);
1560 return(s->v.ref.mode);
1561 }
1562
1563 symchar *ReferenceStatNameF(CONST struct Statement *s)
1564 {
1565 assert(s!=NULL);
1566 assert(s->t==REF);
1567 return(s->v.ref.ref_name);
1568 }
1569
1570 symchar *ReferenceStatSetTypeF(CONST struct Statement *s)
1571 {
1572 assert(s!=NULL);
1573 assert(s->ref_count);
1574 assert(s->t==REF);
1575 return (s->v.ref.settype);
1576 }
1577
1578 struct VariableList *ReferenceStatVlistF(CONST struct Statement *s)
1579 {
1580 assert(s!=NULL);
1581 assert(s->t==REF);
1582 return(s->v.ref.vl);
1583 }
1584
1585 struct Name *RunStatNameF(CONST struct Statement *s)
1586 {
1587 assert(s && (s->ref_count) && (s->t == RUN));
1588 return s->v.r.proc_name;
1589 }
1590
1591 struct Name *RunStatAccessF(CONST struct Statement *s)
1592 {
1593 assert(s && (s->ref_count) && (s->t == RUN));
1594 return s->v.r.type_name;
1595 }
1596
1597 struct VariableList *FixFreeStatVarsF(CONST struct Statement *s){
1598 assert(s!=NULL);
1599 assert(s->t==FIX || s->t==FREE);
1600 return(s->v.fx.vars);
1601 }
1602
1603 struct Set *CallStatArgsF(CONST struct Statement *s)
1604 {
1605 assert(s!=NULL);
1606 assert(s->t==CALL);
1607 return(s->v.call.args);
1608 }
1609
1610 symchar *CallStatIdF(CONST struct Statement *s)
1611 {
1612 assert(s!=NULL);
1613 assert(s->t==CALL);
1614 return(s->v.call.id);
1615 }
1616
1617 struct Expr *WhileStatExprF(CONST struct Statement *s)
1618 {
1619 assert(s && s->ref_count && (s->t == WHILE));
1620 return s->v.loop.test;
1621 }
1622
1623 struct Expr *AssertStatExprF(CONST struct Statement *s){
1624 assert(s && s->ref_count && (s->t == ASSERT));
1625 return s->v.asserts.test;
1626 }
1627
1628 struct Expr *IfStatExprF(CONST struct Statement *s)
1629 {
1630 assert(s && s->ref_count && (s->t == IF));
1631 return s->v.ifs.test;
1632 }
1633
1634 struct StatementList *WhileStatBlockF(CONST struct Statement *s)
1635 {
1636 assert(s!=NULL);
1637 assert(s->ref_count);
1638 assert(s->t == WHILE);
1639 return s->v.loop.block;
1640 }
1641
1642 struct StatementList *IfStatThenF(CONST struct Statement *s)
1643 {
1644 assert(s!=NULL);
1645 assert(s->ref_count);
1646 assert(s->t == IF);
1647 return s->v.ifs.thenblock;
1648 }
1649
1650 struct StatementList *IfStatElseF(CONST struct Statement *s)
1651 {
1652 assert(s && (s->ref_count) && (s->t == IF));
1653 return s->v.ifs.elseblock;
1654 }
1655
1656
1657 struct Name *WhenStatNameF(CONST struct Statement *s)
1658 {
1659 assert(s && s->ref_count && (s->t == WHEN));
1660 return s->v.w.nptr;
1661 }
1662
1663 void SetWhenName(struct Statement *s, struct Name *n)
1664 {
1665 assert(s && (s->t==WHEN) && (s->v.w.nptr==NULL));
1666 s->v.w.nptr = n;
1667 }
1668
1669 struct VariableList *WhenStatVLF(CONST struct Statement *s)
1670 {
1671 assert(s && s->ref_count && (s->t == WHEN));
1672 return s->v.w.vl;
1673 }
1674
1675 struct WhenList *WhenStatCasesF(CONST struct Statement *s)
1676 {
1677 assert(s && s->ref_count && (s->t == WHEN));
1678 return s->v.w.cases;
1679 }
1680
1681
1682 /*
1683 * Compare functions for WHEN statements. It includes the
1684 * decomposition of the WHEN in the list of variables and
1685 * the list of CASEs. Also, each case is decomposed in
1686 * the set of values and the list of statements. It is
1687 * done here since we are comparing the statement rather
1688 * than only a WhenList structure (when.[ch]).
1689 */
1690
1691 int CompareWhenStatements(CONST struct Statement *s1,
1692 CONST struct Statement *s2)
1693 {
1694 int ctmp; /* temporary comparison result */
1695 unsigned long int ltmp;
1696 struct VariableList *vl1, *vl2;
1697 struct WhenList *cases1,*cases2;
1698 struct Set *val1, *val2;
1699 struct StatementList *sl1, *sl2;
1700
1701 vl1 = WhenStatVL(s1);
1702 vl2 = WhenStatVL(s2);
1703
1704 ctmp = CompareVariableLists(vl1,vl2);
1705 if (ctmp != 0) {
1706 return ctmp;
1707 }
1708
1709 cases1 = WhenStatCases(s1);
1710 cases2 = WhenStatCases(s2);
1711
1712 while ( (cases1!=NULL) && (cases2!=NULL) ) {
1713 val1 = WhenSetList(cases1);
1714 val2 = WhenSetList(cases2);
1715
1716 ctmp = CompareSetStructures(val1,val2);
1717 if (ctmp != 0) {
1718 return ctmp;
1719 }
1720
1721 sl1 = WhenStatementList(cases1);
1722 sl2 = WhenStatementList(cases2);
1723 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
1724 if (ctmp != 0) {
1725 return ctmp;
1726 }
1727 cases1 = NextWhenCase(cases1);
1728 cases2 = NextWhenCase(cases2);
1729 }
1730 return 0;
1731 }
1732
1733 struct StatementList *CondStatListF(CONST struct Statement *s)
1734 {
1735 assert(s && s->ref_count && (s->t == COND));
1736 return s->v.cond.stmts;
1737 }
1738
1739 unsigned CondContainsF(CONST struct Statement *s)
1740 {
1741 assert(s!=NULL);
1742 assert(s->t==COND);
1743 return (s->v.cond.contains);
1744 }
1745
1746 unsigned CondContainsRelationsF(CONST struct Statement *s)
1747 {
1748 assert(s!=NULL);
1749 assert(s->t==COND);
1750 return (s->v.cond.contains & contains_REL);
1751 }
1752
1753
1754 unsigned CondContainsLogRelationsF(CONST struct Statement *s)
1755 {
1756 assert(s!=NULL);
1757 assert(s->t==COND);
1758 return (s->v.cond.contains & contains_LREL);
1759 }
1760
1761 struct Name *FnameStatF(CONST struct Statement *s)
1762 {
1763 assert(s && s->ref_count && (s->t == FNAME));
1764 return s->v.n.wname;
1765 }
1766
1767 int SelectStatNumberStatsF(CONST struct Statement *s)
1768 {
1769 assert(s && s->ref_count && (s->t == SELECT));
1770 return s->v.se.n_statements;
1771 }
1772
1773 struct VariableList *SelectStatVLF(CONST struct Statement *s)
1774 {
1775 assert(s && s->ref_count && (s->t == SELECT));
1776 return s->v.se.vl;
1777 }
1778
1779 struct SelectList *SelectStatCasesF(CONST struct Statement *s)
1780 {
1781 assert(s && s->ref_count && (s->t == SELECT));
1782 return s->v.se.cases;
1783 }
1784
1785 /*
1786 * Compare functions for SELECT statements. It includes the
1787 * decomposition of the SELECT in the list of variables and
1788 * the list of CASEs. Also, each case is decomposed in
1789 * the set of values and the list of statements. It is
1790 * done here since we are comparing the statement rather
1791 * than only a SelectList structure (select.[ch]).
1792 */
1793
1794 int CompareSelectStatements(CONST struct Statement *s1,
1795 CONST struct Statement *s2)
1796 {
1797 int ctmp; /* temporary comparison result */
1798 unsigned long int ltmp;
1799 struct VariableList *vl1, *vl2;
1800 struct SelectList *cases1,*cases2;
1801 struct Set *val1, *val2;
1802 struct StatementList *sl1, *sl2;
1803
1804 vl1 = SelectStatVL(s1);
1805 vl2 = SelectStatVL(s2);
1806
1807 ctmp = CompareVariableLists(vl1,vl2);
1808 if (ctmp != 0) {
1809 return ctmp;
1810 }
1811
1812 cases1 = SelectStatCases(s1);
1813 cases2 = SelectStatCases(s2);
1814
1815 while ( (cases1!=NULL) && (cases2!=NULL) ) {
1816 val1 = SelectSetList(cases1);
1817 val2 = SelectSetList(cases2);
1818
1819 ctmp = CompareSetStructures(val1,val2);
1820 if (ctmp != 0) {
1821 return ctmp;
1822 }
1823
1824 sl1 = SelectStatementList(cases1);
1825 sl2 = SelectStatementList(cases2);
1826 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
1827 if (ctmp != 0) {
1828 return ctmp;
1829 }
1830 cases1 = NextSelectCase(cases1);
1831 cases2 = NextSelectCase(cases2);
1832 }
1833 return 0;
1834 }
1835
1836
1837 unsigned SelectContainsF(CONST struct Statement *s)
1838 {
1839 assert(s!=NULL);
1840 assert(s->t==SELECT);
1841 return (s->v.se.contains);
1842 }
1843
1844 unsigned SelectContainsRelationsF(CONST struct Statement *s)
1845 {
1846 assert(s!=NULL);
1847 assert(s->t==SELECT);
1848 return (s->v.se.contains & contains_REL);
1849 }
1850
1851
1852 unsigned SelectContainsLogRelationsF(CONST struct Statement *s)
1853 {
1854 assert(s!=NULL);
1855 assert(s->t==SELECT);
1856 return (s->v.se.contains & contains_LREL);
1857 }
1858
1859 unsigned SelectContainsDefaultsF(CONST struct Statement *s)
1860 {
1861 assert(s!=NULL);
1862 assert(s->t==SELECT);
1863 return (s->v.se.contains & contains_DEF);
1864 }
1865
1866 unsigned SelectContainsCAssignsF(CONST struct Statement *s)
1867 {
1868 assert(s!=NULL);
1869 assert(s->t==SELECT);
1870 return (s->v.se.contains & contains_CAS);
1871 }
1872
1873
1874 unsigned SelectContainsWhenF(CONST struct Statement *s)
1875 {
1876 assert(s!=NULL);
1877 assert(s->t==SELECT);
1878 return (s->v.se.contains & contains_WHEN);
1879 }
1880
1881 unsigned SelectContainsIsaF(CONST struct Statement *s)
1882 {
1883 assert(s!=NULL);
1884 assert(s->t==SELECT);
1885 return (s->v.se.contains & contains_ISA);
1886 }
1887
1888 unsigned SelectContainsIrtF(CONST struct Statement *s)
1889 {
1890 assert(s!=NULL);
1891 assert(s->t==SELECT);
1892 return (s->v.se.contains & contains_IRT);
1893 }
1894
1895 unsigned SelectContainsAlikeF(CONST struct Statement *s)
1896 {
1897 assert(s!=NULL);
1898 assert(s->t==SELECT);
1899 return (s->v.se.contains & contains_AA);
1900 }
1901
1902 unsigned SelectContainsAliasF(CONST struct Statement *s)
1903 {
1904 assert(s!=NULL);
1905 assert(s->t==SELECT);
1906 return (s->v.se.contains & contains_ALI);
1907 }
1908
1909 unsigned SelectContainsArrayF(CONST struct Statement *s)
1910 {
1911 assert(s!=NULL);
1912 assert(s->t==SELECT);
1913 return (s->v.se.contains & contains_ARR);
1914 }
1915
1916 unsigned SelectContainsAtsF(CONST struct Statement *s)
1917 {
1918 assert(s!=NULL);
1919 assert(s->t==SELECT);
1920 return (s->v.se.contains & contains_ATS);
1921 }
1922
1923 unsigned SelectContainsWbtsF(CONST struct Statement *s)
1924 {
1925 assert(s!=NULL);
1926 assert(s->t==SELECT);
1927 return (s->v.se.contains & contains_WBTS);
1928 }
1929
1930 unsigned SelectContainsWnbtsF(CONST struct Statement *s)
1931 {
1932 assert(s!=NULL);
1933 assert(s->t==SELECT);
1934 return (s->v.se.contains & contains_WNBTS);
1935 }
1936
1937 unsigned SelectContainsWillbeF(CONST struct Statement *s)
1938 {
1939 assert(s!=NULL);
1940 assert(s->t==SELECT);
1941 return (s->v.se.contains & contains_WILLBE);
1942 }
1943
1944 unsigned SelectContainsSelectF(CONST struct Statement *s)
1945 {
1946 assert(s!=NULL);
1947 assert(s->t==SELECT);
1948 return (s->v.se.contains & contains_SELECT);
1949 }
1950
1951 unsigned SelectContainsConditionalF(CONST struct Statement *s)
1952 {
1953 assert(s!=NULL);
1954 assert(s->t==SELECT);
1955 return (s->v.se.contains & contains_COND);
1956 }
1957
1958 unsigned SelectContainsIllegalF(CONST struct Statement *s)
1959 {
1960 assert(s!=NULL);
1961 assert(s->t==SELECT);
1962 return (s->v.se.contains & contains_ILL);
1963 }
1964
1965
1966 struct VariableList *SwitchStatVLF(CONST struct Statement *s)
1967 {
1968 assert(s && s->ref_count && (s->t == SWITCH));
1969 return s->v.sw.vl;
1970 }
1971
1972 struct SwitchList *SwitchStatCasesF(CONST struct Statement *s)
1973 {
1974 assert(s && s->ref_count && (s->t == SWITCH));
1975 return s->v.sw.cases;
1976 }
1977
1978 /*
1979 * Compare functions for SWITCH statements. It includes the
1980 * decomposition of the SWITCH in the list of variables and
1981 * the list of CASEs. Also, each case is decomposed in
1982 * the set of values and the list of statements. It is
1983 * done here since we are comparing the statement rather
1984 * than only a SwitchList structure (switch.[ch]).
1985 */
1986
1987 int CompareSwitchStatements(CONST struct Statement *s1,
1988 CONST struct Statement *s2)
1989 {
1990 int ctmp; /* temporary comparison result */
1991 unsigned long int ltmp;
1992 struct VariableList *vl1, *vl2;
1993 struct SwitchList *cases1,*cases2;
1994 struct Set *val1, *val2;
1995 struct StatementList *sl1, *sl2;
1996
1997 vl1 = SwitchStatVL(s1);
1998 vl2 = SwitchStatVL(s2);
1999
2000 ctmp = CompareVariableLists(vl1,vl2);
2001 if (ctmp != 0) {
2002 return ctmp;
2003 }
2004
2005 cases1 = SwitchStatCases(s1);
2006 cases2 = SwitchStatCases(s2);
2007
2008 while ( (cases1!=NULL) && (cases2!=NULL) ) {
2009 val1 = SwitchSetList(cases1);
2010 val2 = SwitchSetList(cases2);
2011
2012 ctmp = CompareSetStructures(val1,val2);
2013 if (ctmp != 0) {
2014 return ctmp;
2015 }
2016
2017 sl1 = SwitchStatementList(cases1);
2018 sl2 = SwitchStatementList(cases2);
2019 ctmp = CompareStatementLists(sl1,sl2,&ltmp);
2020 if (ctmp != 0) {
2021 return ctmp;
2022 }
2023 cases1 = NextSwitchCase(cases1);
2024 cases2 = NextSwitchCase(cases2);
2025 }
2026 return 0;
2027 }
2028
2029
2030 /*********************************************************************\
2031 CompareStatements(s1,s2);
2032 Returns -1,0,1 as s1 is <, ==, > s2.
2033 s1 < s2 if type(s1) < type(s2), exception: NULL > all statements.
2034 For statements of the same type, compared according to
2035 the number of arguments or alphabetically, as appropriate.
2036 We are comparing statement contents, not statement
2037 memory location or origin.
2038 FOR/DO vs FOR/CREATE is considered a different type, so
2039 the 'in a method' location matters. file, line, etc don't, though.
2040 \*********************************************************************/
2041 int CompareStatements(CONST struct Statement *s1, CONST struct Statement *s2)
2042 {
2043 int ctmp; /* temporary comparison result */
2044 unsigned long int ltmp;
2045 if (s1 == s2) return 0;
2046 if (s1==NULL) return 1;
2047 if (s2==NULL) return -1;
2048 if (s1->t > s2->t) return 1;
2049 if (s1->t < s2->t) return -1;
2050 switch (s1->t) {
2051 case ALIASES:
2052 ctmp = CompareNames(AliasStatName(s1),AliasStatName(s2));
2053 if (ctmp != 0) {
2054 return ctmp;
2055 }
2056 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2057 case ARR:
2058 ctmp = CompareVariableLists(ArrayStatAvlNames(s1),ArrayStatAvlNames(s2));
2059 if (ctmp != 0) {
2060 return ctmp;
2061 }
2062 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2063 if (ctmp != 0) {
2064 return ctmp;
2065 }
2066 ctmp = CompareVariableLists(ArrayStatSetName(s1),ArrayStatSetName(s2));
2067 if (ctmp != 0) {
2068 return ctmp;
2069 }
2070 ctmp = ArrayStatIntSet(s1) - ArrayStatIntSet(s2);
2071 if (ctmp != 0) {
2072 if (ctmp ==1) {
2073 return CmpSymchar(GetBaseTypeName(integer_constant_type),
2074 GetBaseTypeName(symbol_constant_type));
2075 } else {
2076 /* ctmp == -1 */
2077 return CmpSymchar(GetBaseTypeName(symbol_constant_type) ,
2078 GetBaseTypeName(integer_constant_type));
2079 }
2080 }
2081 return CompareSetStructures(ArrayStatSetValues(s1),ArrayStatSetValues(s2));
2082 case ISA:
2083 if (GetStatSetType(s1)!=NULL || GetStatSetType(s2) !=NULL) {
2084 if (GetStatSetType(s1) == NULL) { return -1; }
2085 if (GetStatSetType(s2) == NULL) { return 1; }
2086 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2087 if (ctmp != 0) {
2088 return ctmp;
2089 }
2090 }
2091 /* fallthru */
2092 case IRT:
2093 ctmp = CmpSymchar(GetStatType(s1),GetStatType(s2));
2094 if (ctmp != 0) {
2095 return ctmp;
2096 }
2097 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2098 if (ctmp != 0) {
2099 return ctmp;
2100 }
2101 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2102 case WILLBE:
2103 if (GetStatSetType(s1) != NULL || GetStatSetType(s2) != NULL) {
2104 if (GetStatSetType(s1) == NULL) { return -1; }
2105 if (GetStatSetType(s2) == NULL) { return 1; }
2106 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2107 if (ctmp != 0) {
2108 return ctmp;
2109 }
2110 }
2111 ctmp = CmpSymchar(GetStatType(s1),GetStatType(s2));
2112 if (ctmp != 0) {
2113 return ctmp;
2114 }
2115 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2116 if (ctmp != 0) {
2117 return ctmp;
2118 }
2119 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2120 if (ctmp != 0) {
2121 return ctmp;
2122 }
2123 return CompareExprs(GetStatCheckValue(s1),GetStatCheckValue(s2));
2124 case ATS: /* fallthru */
2125 case WBTS: /* fallthru */
2126 case WNBTS: /* fallthru */
2127 case AA:
2128 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2129 case FOR:
2130 if (ForStatIndex(s1)!=ForStatIndex(s2)) {
2131 return CmpSymchar(ForStatIndex(s1),ForStatIndex(s2));
2132 }
2133 if (ForContains(s1)!=ForContains(s2)) {
2134 /* arbitrary but consistent */
2135 return ( ForContains(s1) > ForContains(s2)) ? 1 : -1;
2136 }
2137 if (ForLoopOrder(s1)!=ForLoopOrder(s2)) {
2138 return ( ForLoopOrder(s1) > ForLoopOrder(s2)) ? 1 : -1;
2139 }
2140 if (ForLoopKind(s1)!=ForLoopKind(s2)) {
2141 return ( ForLoopKind(s1) > ForLoopKind(s2)) ? 1 : -1;
2142 }
2143 ctmp = CompareExprs(ForStatExpr(s1),ForStatExpr(s2));
2144 if (ctmp!=0) {
2145 return ctmp;
2146 }
2147 return CompareStatementLists(ForStatStmts(s1),ForStatStmts(s2),&ltmp);
2148 case REL:
2149 ctmp = CompareNames(RelationStatName(s1),RelationStatName(s2));
2150 if (ctmp!=0 &&
2151 /* we need to skip this for system generated names */
2152 !NameAuto(RelationStatName(s1)) &&
2153 !NameAuto(RelationStatName(s2))) {
2154 return ctmp;
2155 }
2156 return CompareExprs(RelationStatExpr(s1),RelationStatExpr(s2));
2157 case LOGREL:
2158 ctmp = CompareNames(LogicalRelStatName(s1),LogicalRelStatName(s2));
2159 if (ctmp!=0 &&
2160 /* we need to skip this for system generated names */
2161 !NameAuto(LogicalRelStatName(s1)) &&
2162 !NameAuto(LogicalRelStatName(s2))) {
2163 return ctmp;
2164 }
2165 return CompareExprs(LogicalRelStatExpr(s1),LogicalRelStatExpr(s2));
2166 case ASGN:
2167 ctmp = CompareNames(DefaultStatVar(s1),DefaultStatVar(s2));
2168 if (ctmp != 0) {
2169 return ctmp;
2170 }
2171 return CompareExprs(DefaultStatRHS(s1),DefaultStatRHS(s2));
2172 case CASGN:
2173 ctmp = CompareNames(AssignStatVar(s1),AssignStatVar(s2));
2174 if (ctmp != 0) {
2175 return ctmp;
2176 }
2177 return CompareExprs(AssignStatRHS(s1),AssignStatRHS(s2));
2178 case RUN:
2179 ctmp = CompareNames(RunStatName(s1),RunStatName(s2));
2180 if (ctmp != 0) {
2181 return ctmp;
2182 }
2183 return CompareNames(RunStatAccess(s1),RunStatAccess(s2));
2184 case WHILE:
2185 ctmp = CompareExprs(WhileStatExpr(s1), WhileStatExpr(s2));
2186 if (ctmp != 0) {
2187 return ctmp;
2188 }
2189 return CompareStatementLists(WhileStatBlock(s1), WhileStatBlock(s2),&ltmp);
2190
2191 case ASSERT:
2192 ctmp = CompareExprs(AssertStatExpr(s1), AssertStatExpr(s2));
2193 return ctmp;
2194
2195 case IF:
2196 ctmp = CompareExprs(IfStatExpr(s1), IfStatExpr(s2));
2197 if (ctmp != 0) {
2198 return ctmp;
2199 }
2200 ctmp = CompareStatementLists(IfStatThen(s1), IfStatThen(s2),&ltmp);
2201 if (ctmp != 0) {
2202 return ctmp;
2203 }
2204 return CompareStatementLists(IfStatElse(s1), IfStatElse(s2),&ltmp);
2205 case WHEN:
2206 ctmp = CompareNames(WhenStatName(s1),WhenStatName(s2));
2207 if (ctmp!=0 &&
2208 /* we need to skip this for system generated names */
2209 !NameAuto(WhenStatName(s1)) &&
2210 !NameAuto(WhenStatName(s2))) {
2211 return ctmp;
2212 }
2213 return CompareWhenStatements(s1,s2);
2214 case FNAME:
2215 return CompareNames(FnameStat(s1),FnameStat(s2));
2216 case SELECT:
2217 if (SelectContains(s1)!=SelectContains(s2)) {
2218 /* arbitrary but consistent */
2219 return ( SelectContains(s1) > SelectContains(s2)) ? 1 : -1;
2220 }
2221 if (SelectStatNumberStats(s1)!=SelectStatNumberStats(s2)) {
2222 /* arbitrary but consistent */
2223 return (SelectStatNumberStats(s1) > SelectStatNumberStats(s2)) ? 1 : -1;
2224 }
2225 return CompareSelectStatements(s1,s2);
2226 case SWITCH:
2227 return CompareSwitchStatements(s1,s2);
2228 case CALL:
2229 if (CallStatId(s1)!=CallStatId(s2)) {
2230 return CmpSymchar(CallStatId(s1),CallStatId(s2));
2231 }
2232 return CompareSetStructures(CallStatArgs(s1),CallStatArgs(s2));
2233 case EXT:
2234 ctmp = strcmp(ExternalStatFuncName(s1),ExternalStatFuncName(s2));
2235 if (ctmp != 0) {
2236 return ctmp;
2237 }
2238 if (ExternalStatMode(s1) != ExternalStatMode(s2)) {
2239 return (ExternalStatMode(s1) > ExternalStatMode(s2)) ? 1 : -1;
2240 }
2241 ctmp = CompareNames(ExternalStatName(s1),ExternalStatName(s2));
2242 if (ctmp != 0) {
2243 return ctmp;
2244 }
2245 ctmp = CompareNames(ExternalStatScope(s1),ExternalStatScope(s2));
2246 if (ctmp != 0) {
2247 return ctmp;
2248 }
2249 ctmp = CompareNames(ExternalStatData(s1),ExternalStatData(s2));
2250 if (ctmp != 0) {
2251 return ctmp;
2252 }
2253 return CompareVariableLists(ExternalStatVlist(s1),ExternalStatVlist(s2));
2254 case REF:
2255 /* need fixing. since both are ill defined, they
2256 * will not be fixed until the definitions are really known.
2257 */
2258 Asc_Panic(2, NULL, "Don't know how to compare REF statements\n");
2259 exit(2);/* Needed to keep gcc from whining */
2260 case COND:
2261 return CompareStatementLists(CondStatList(s1),CondStatList(s2),&ltmp);
2262 case FLOW:
2263 if (FlowStatControl(s1) != FlowStatControl(s2)) {
2264 return (FlowStatControl(s1) > FlowStatControl(s2)) ? 1 : -1;
2265 }
2266 /* FlowStatMessage is considered comment info and so not compared */
2267 return 0;
2268 default:
2269 ERROR_REPORTER_NOLINE(ASC_PROG_ERR,"CompareStatements called with unknown statement");
2270 return 0;
2271 }
2272 }
2273
2274 /* could we merge some of this with plain compare statements via some
2275 *static functions? baa. fix me.
2276 */
2277 int CompareISStatements(CONST struct Statement *s1, CONST struct Statement *s2)
2278 {
2279 unsigned long int ltmp;
2280 struct TypeDescription *d1, *d2;
2281 int ctmp; /* temporary comparison result */
2282
2283 if (s1 == s2) return 0;
2284 if (s1==NULL) return 1;
2285 if (s2==NULL) return -1;
2286 if (s1->t > s2->t) return 1;
2287 if (s1->t < s2->t) return -1;
2288 switch (s1->t) {
2289 case ISA:
2290 /* compare set OF parts */
2291 if (GetStatSetType(s1)!=NULL || GetStatSetType(s2) !=NULL) {
2292 if (GetStatSetType(s1) == NULL) { return -1; }
2293 if (GetStatSetType(s2) == NULL) { return 1; }
2294 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2295 if (ctmp != 0) {
2296 return ctmp;
2297 }
2298 }
2299 /********** FALLTHRU * FALL THROUGH * FALL TO IRT *************/
2300 case IRT:
2301 /* compare basic types */
2302 d1 = FindType(GetStatType(s1));
2303 d2 = FindType(GetStatType(s2));
2304 assert(d1 !=NULL);
2305 assert(d2 !=NULL);
2306 if (d1!=d2 && MoreRefined(d1,d2) != d2) {
2307 if (MoreRefined(d1,d2) == NULL) {
2308 return 1;
2309 } else {
2310 return -1;
2311 }
2312 }
2313 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2314 /* this may be a little too picky comparison of arglists */
2315 if (ctmp != 0) {
2316 return ctmp;
2317 }
2318 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2319 /* IS_A IS_REFINED_TO have not WITH_VALUE part */
2320 case WILLBE:
2321 /* compare set OF parts */
2322 if (GetStatSetType(s1) != NULL || GetStatSetType(s2) != NULL) {
2323 if (GetStatSetType(s1) == NULL) { return -1; }
2324 if (GetStatSetType(s2) == NULL) { return 1; }
2325 ctmp = CmpSymchar(GetStatSetType(s1),GetStatSetType(s2));
2326 if (ctmp != 0) {
2327 return ctmp;
2328 }
2329 }
2330 /* compare basic types */
2331 d1 = FindType(GetStatType(s1));
2332 d2 = FindType(GetStatType(s2));
2333 assert(d1 !=NULL);
2334 assert(d2 !=NULL);
2335 if (d1!=d2 && MoreRefined(d1,d2) != d2) {
2336 if (MoreRefined(d1,d2) == NULL) {
2337 return 1;
2338 } else {
2339 return -1;
2340 }
2341 }
2342 ctmp = CompareSetStructures(GetStatTypeArgs(s1),GetStatTypeArgs(s2));
2343 /* this may be a little too picky comparison of arglists */
2344 if (ctmp != 0) {
2345 return ctmp;
2346 }
2347 ctmp = CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2348 if (ctmp != 0) {
2349 return ctmp;
2350 }
2351 if (GetStatCheckValue(s1) != NULL) {
2352 return CompareExprs(GetStatCheckValue(s1),GetStatCheckValue(s2));
2353 } else {
2354 return 0;
2355 }
2356 case WBTS: /* fallthru */
2357 case WNBTS:
2358 return CompareVariableLists(GetStatVarList(s1),GetStatVarList(s2));
2359 case FOR:
2360 if (ForStatIndex(s1)!=ForStatIndex(s2)) {
2361 return CmpSymchar(ForStatIndex(s1),ForStatIndex(s2));
2362 }
2363 if (ForContains(s1)!=ForContains(s2)) {
2364 /* arbitrary but consistent */
2365 return ( ForContains(s1) > ForContains(s2)) ? 1 : -1;
2366 }
2367 if (ForLoopOrder(s1)!=ForLoopOrder(s2)) {
2368 return ( ForLoopOrder(s1) > ForLoopOrder(s2)) ? 1 : -1;
2369 }
2370 if (ForLoopKind(s1)!=ForLoopKind(s2)) {
2371 return ( ForLoopKind(s1) > ForLoopKind(s2)) ? 1 : -1;
2372 }
2373 ctmp = CompareExprs(ForStatExpr(s1),ForStatExpr(s2));
2374 if (ctmp!=0) {
2375 return ctmp;
2376 }
2377 return CompareISLists(ForStatStmts(s1),ForStatStmts(s2),&ltmp);
2378 case LOGREL:
2379 case REL:
2380 return CompareStatements(s1,s2);
2381 case ALIASES:
2382 case ARR:
2383 case ATS: /* fallthru */
2384 case AA:
2385 case ASGN:
2386 case CASGN:
2387 case RUN:
2388 case CALL:
2389 case ASSERT:
2390 case IF:
2391 case WHEN:
2392 case FNAME:
2393 case SELECT:
2394 case SWITCH:
2395 case EXT: /* fallthru */
2396 case REF:
2397 case COND:
2398 case FLOW:
2399 case WHILE:
2400 ERROR_REPORTER_STAT(ASC_PROG_ERR,s1,"CompareISStatements called with incorrect statement");
2401 return -1;
2402 default:
2403 ERROR_REPORTER_STAT(ASC_PROG_ERR,s1,"CompareISStatements called with unknown statement");
2404 return 1;
2405 }
2406 }
2407

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