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

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