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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (show annotations) (download) (as text)
Fri Jan 27 04:23:20 2006 UTC (14 years, 5 months ago) by johnpye
File MIME type: text/x-csrc
File size: 22080 byte(s)
Updating for Jerry's new error_reporter syntax, bug #179
1 /*
2 * Temporary Statement Output routines
3 * by Tom Epperly
4 * Version: $Revision: 1.41 $
5 * Version control file: $RCSfile: statio.c,v $
6 * Date last modified: $Date: 1998/04/21 23:49:55 $
7 * Last modified by: $Author: ballan $
8 *
9 * This file is part of the Ascend Language Interpreter.
10 *
11 * Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
12 *
13 * The Ascend Language Interpreter is free software; you can redistribute
14 * it and/or modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of the
16 * License, or (at your option) any later version.
17 *
18 * The Ascend Language Interpreter is distributed in hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with the program; if not, write to the Free Software Foundation, Inc., 675
25 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
26 */
27 #define INDENTATION 4
28
29 #include "utilities/ascConfig.h"
30 #include "utilities/ascMalloc.h"
31 #include "general/list.h"
32 #include "general/dstring.h"
33 #include "compiler/compiler.h"
34 #include "compiler/fractions.h"
35 #include "compiler/dimen.h"
36 #include "compiler/functype.h"
37 #include "compiler/types.h"
38 #include "compiler/stattypes.h"
39 #include "compiler/statement.h"
40 #include "compiler/statio.h"
41 #include "compiler/exprio.h"
42 #include "compiler/nameio.h"
43 #include "compiler/when.h"
44 #include "compiler/select.h"
45 #include "compiler/switch.h"
46 #include "compiler/bit.h"
47 #include "compiler/vlistio.h"
48 #include "compiler/slist.h"
49 #include "compiler/setio.h"
50 #include "compiler/child.h"
51 #include "compiler/type_desc.h"
52 #include "compiler/type_descio.h"
53 #include "compiler/module.h"
54 #include "compiler/forvars.h"
55 #include "compiler/find.h"
56 #include "compiler/symtab.h"
57 #include "compiler/braced.h"
58 #include "compiler/instance_enum.h"
59 #include "compiler/cmpfunc.h"
60
61 #ifndef lint
62 static CONST char StatementIOID[] = "$Id: statio.c,v 1.41 1998/04/21 23:49:55 ballan Exp $";
63 #endif
64
65 static int g_show_statement_detail = 1;
66 /* global to control display detail. It's default value 1 means
67 * print the expression with relations. On occasion this is burdensome
68 * and the expression can be suppressed by setting this variable to
69 * any value other than 1.
70 * It should generally be restored to the default state after temporary
71 * modification.
72 */
73
74 static int *g_statio_suppressions = NULL;
75 /* SIS returns TRUE if we do care about suppressions */
76 #define GSS (g_statio_suppressions!=NULL)
77 /* SUP(s) returns TRUE if statement s is to be suppressed */
78 #define SUP(s) g_statio_suppressions[StatementType(s)]
79
80 static const char *g_statio_label[5] = {
81 "Asc-WSEM-bug:",
82 "Asc-Style: ",
83 "Asc-Warning: ",
84 "Asc-Error: ",
85 "Asc-Fatal: "
86 };
87
88 /*
89 * g_statio_stattypenames maps to the enum stat_t to strings from the
90 * symbol table.
91 */
92 /*
93 * ANSI ASSUMPTION: the contents of g_statio_stattypenames will be
94 * NULL on startup.
95 */
96 static
97 symchar *g_statio_stattypenames[WILLBE+1];
98 /* typenames for the subclasses of FLOW statement */
99 static
100 symchar *g_statio_flowtypenames[fc_stop+1];
101
102 static
103 void Indent(FILE *f, register int i)
104 {
105 register int tabs;
106 if (i<=0) return;
107 tabs = i / 8;
108 while (tabs--) PUTC('\t',f);
109 i %= 8;
110 while (i--) PUTC(' ',f);
111 }
112
113 /* return a string of the kind */
114 static
115 char *ForKindString(enum ForKind fk)
116 {
117 switch (fk) {
118 case fk_create:
119 return "CREATE";
120 case fk_do:
121 return "DO";
122 case fk_check:
123 return "CHECK";
124 case fk_expect:
125 return "EXPECT";
126 default:
127 return "ERRFOR";
128 }
129 }
130
131 static
132 void WriteOrder(FILE *f, enum ForOrder o)
133 {
134 switch(o){
135 case f_increasing: FPRINTF(f," INCREASING"); break;
136 case f_decreasing: FPRINTF(f," DECREASING"); break;
137 default: break;
138 }
139 }
140
141 static
142 void WriteWhenNode(FILE *f,struct WhenList *w, int i)
143 {
144 register struct Set *set;
145 Indent(f,i);
146 set = WhenSetList(w);
147 if (set!=NULL){
148 FPRINTF(f,"CASE ");
149 WriteSet(f,set);
150 }
151 else FPRINTF(f,"OTHERWISE");
152 FPRINTF(f," :\n");
153 WriteStatementList(f,WhenStatementList(w),i+INDENTATION);
154 }
155
156 static
157 void WriteWhenList(FILE *f, struct WhenList *w, int i)
158 {
159 while (w!=NULL) {
160 WriteWhenNode(f,w,i);
161 w = NextWhenCase(w);
162 }
163 }
164
165 static
166 void WriteSelectNode(FILE *f, struct SelectList *sel, int i)
167 {
168 register struct Set *set;
169 Indent(f,i);
170 set = SelectSetList(sel);
171 if (set!=NULL){
172 FPRINTF(f,"CASE ");
173 WriteSet(f,set);
174 } else {
175 FPRINTF(f,"OTHERWISE");
176 }
177 FPRINTF(f," :\n");
178 WriteStatementList(f,SelectStatementList(sel),i+INDENTATION);
179 }
180
181 static
182 void WriteSelectList(FILE *f, struct SelectList *sel, int i)
183 {
184 while (sel!=NULL) {
185 WriteSelectNode(f,sel,i);
186 sel = NextSelectCase(sel);
187 }
188 }
189
190 static
191 void WriteSwitchNode(FILE *f, struct SwitchList *sw, int i)
192 {
193 register struct Set *set;
194 Indent(f,i);
195 set = SwitchSetList(sw);
196 if (set!=NULL){
197 FPRINTF(f,"CASE ");
198 WriteSet(f,set);
199 } else {
200 FPRINTF(f,"OTHERWISE");
201 }
202 FPRINTF(f," :\n");
203 WriteStatementList(f,SwitchStatementList(sw),i+INDENTATION);
204 }
205
206 static
207 void WriteSwitchList(FILE *f, struct SwitchList *sw, int i)
208 {
209 while (sw!=NULL) {
210 WriteSwitchNode(f,sw,i);
211 sw = NextSwitchCase(sw);
212 }
213 }
214
215 struct gl_list_t *GetTypeNamesFromStatList(CONST struct StatementList *sl)
216 {
217 register unsigned long len,c;
218 register CONST struct gl_list_t *l=NULL;
219 struct gl_list_t *found=NULL;
220 struct Statement *s=NULL;
221 symchar *td;
222
223 found=gl_create(20L);
224 if (!sl) return found;
225 l = GetList(sl);
226 len = gl_length(l);
227 for(c=1;c<=len;) {
228 s=(struct Statement *)gl_fetch(l,c++);
229 td=NULL;
230 switch(StatementType(s)) {
231 case ISA:
232 case WILLBE:
233 if (GetStatSetType(s)==NULL)
234 td = GetStatType(s);
235 else
236 td = GetStatSetType(s);
237 break;
238 case IRT:
239 td= GetStatType(s);
240 break;
241 case ALIASES:
242 case ARR: /* possible bug. ben */
243 case ATS:
244 case WBTS:
245 case WNBTS:
246 case REL:
247 case LOGREL:
248 case AA:
249 case FOR: /* that this isn't handled further may be a bug */
250 case ASGN:
251 case CASGN:
252 case RUN:
253 case IF:
254 case WHEN:
255 case FNAME:
256 case SELECT:
257 case SWITCH:
258 case COND:
259 case CALL:
260 case FLOW:
261 case WHILE:
262 case EXT:
263 case REF: /* that this isn't handled may be a bug */
264 break;
265 default:
266 break;
267 }
268 if (td) gl_insert_sorted(found,(VOIDPTR)td,(CmpFunc)CmpSymchar);
269 }
270 return found;
271 }
272
273 unsigned long StatementListLength(CONST struct StatementList *sl)
274 {
275 if (sl==NULL) return 0L;
276 if (GetList(sl) == NULL) return 0L;
277 return gl_length(GetList(sl));
278 }
279
280 void WriteStatement(FILE *f, CONST struct Statement *s, int i)
281 {
282 struct Name *n;
283 assert(s!=NULL);
284 if (GSS && SUP(s)) return;
285 Indent(f,i);
286 if (StatWrong(s)) {
287 FPRINTF(f,"(* ERROR *) ");
288 }
289 switch(StatementType(s)) {
290 case ALIASES:
291 WriteVariableList(f,GetStatVarList(s));
292 FPRINTF(f," ALIASES ");
293 WriteName(f,AliasStatName(s));
294 FPRINTF(f,";\n");
295 break;
296 case ARR:
297 WriteVariableList(f,ArrayStatAvlNames(s));
298 FPRINTF(f," ALIASES (");
299 WriteVariableList(f,GetStatVarList(s));
300
301 FPRINTF(f,")\n");
302 Indent(f,i+2);
303 FPRINTF(f,"WHERE ");
304 WriteVariableList(f,ArrayStatSetName(s));
305 FPRINTF(f," IS_A set OF %s",
306 SCP(ArrayStatIntSet(s)?
307 GetBaseTypeName(integer_constant_type):
308 GetBaseTypeName(symbol_constant_type)));
309 if (ArrayStatSetValues(s) != NULL) {
310 FPRINTF(f," WITH_VALUE (");
311 WriteSet(f,ArrayStatSetValues(s));
312 FPRINTF(f,");\n");
313 } else {
314 FPRINTF(f,";\n");
315 }
316 break;
317 case ISA:
318 WriteVariableList(f,GetStatVarList(s));
319 if (GetStatSetType(s)==NULL) {
320 FPRINTF(f," IS_A %s",SCP(GetStatType(s)));
321 if (GetStatTypeArgs(s) != NULL) {
322 FPRINTF(f,"(");
323 WriteSet(f,GetStatTypeArgs(s));
324 FPRINTF(f,");\n");
325 } else {
326 FPRINTF(f,";\n");
327 }
328 } else {
329 /* no parameters to sets */
330 FPRINTF(f," IS_A %s OF %s;\n",
331 SCP(GetStatType(s)),SCP(GetStatSetType(s)));
332 }
333 break;
334 case WILLBE:
335 WriteVariableList(f,GetStatVarList(s));
336 if (GetStatSetType(s)==NULL) {
337 FPRINTF(f," WILL_BE %s",SCP(GetStatType(s)));
338 if (GetStatTypeArgs(s) != NULL) {
339 FPRINTF(f,"(");
340 WriteSet(f,GetStatTypeArgs(s));
341 FPRINTF(f,")");
342 }
343 } else {
344 FPRINTF(f," WILL_BE %s OF %s",
345 SCP(GetStatType(s)),SCP(GetStatSetType(s)));
346 }
347 if (GetStatCheckValue(s)!=NULL ) {
348 FPRINTF(f," WITH_VALUE ");
349 WriteExpr(f,GetStatCheckValue(s));
350 }
351 FPRINTF(f,";\n");
352 break;
353 case IRT:
354 WriteVariableList(f,GetStatVarList(s));
355 FPRINTF(f," IS_REFINED_TO %s",SCP(GetStatType(s)));
356 if (GetStatTypeArgs(s) != NULL) {
357 FPRINTF(f,"(");
358 WriteSet(f,GetStatTypeArgs(s));
359 FPRINTF(f,");\n");
360 } else {
361 FPRINTF(f,";\n");
362 }
363 break;
364 case ATS:
365 WriteVariableList(f,GetStatVarList(s));
366 FPRINTF(f," ARE_THE_SAME;\n");
367 break;
368 case WBTS:
369 WriteVariableList(f,GetStatVarList(s));
370 FPRINTF(f," WILL_BE_THE_SAME;\n");
371 break;
372 case WNBTS:
373 WriteVariableList(f,GetStatVarList(s));
374 FPRINTF(f," WILL_NOT_BE_THE_SAME;\n");
375 break;
376 case AA:
377 WriteVariableList(f,GetStatVarList(s));
378 FPRINTF(f," ARE_ALIKE;\n");
379 break;
380 case FOR:
381 {
382 FPRINTF(f,"FOR %s IN ",SCP(ForStatIndex(s)));
383 WriteExpr(f,ForStatExpr(s));
384 WriteOrder(f,ForLoopOrder(s));
385 #ifndef NDEBUG
386 if (g_show_statement_detail==1) {
387 FPRINTF(f," %s (*<contains%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>*)\n",
388 ForKindString(ForLoopKind(s)),
389 (ForContainsRelations(s)) ? " rel" : "",
390 (ForContainsLogRelations(s)) ? " lrel" : "",
391 (ForContainsDefaults(s)) ? " def" : "",
392 (ForContainsCAssigns(s)) ? " con" : "",
393 (ForContainsWhen(s)) ? " when" : "",
394 (ForContainsIsa(s)) ? " isa" : "",
395 (ForContainsSelect(s)) ? " select" : "",
396 (ForContainsConditional(s)) ? " conditional" : "",
397 (ForContainsWillbe(s)) ? " wb" : "",
398 (ForContainsAlike(s)) ? " aa" : "",
399 (ForContainsAlias(s)) ? " ali" : "",
400 (ForContainsArray(s)) ? " arr" : "",
401 (ForContainsWbts(s)) ? " wbts" : "",
402 (ForContainsAts(s)) ? " ats" : "",
403 (ForContainsIrt(s)) ? " irt" : ""
404 );
405 } else {
406 FPRINTF(f," %s\n", ForKindString(ForLoopKind(s)));
407 }
408 #else
409 FPRINTF(f," %s\n", ForKindString(ForLoopKind(s)));
410 #endif
411 WriteStatementList(f,ForStatStmts(s),i+INDENTATION);
412 Indent(f,i);
413 FPRINTF(f,"END;\n");
414 break;
415 }
416 case REL:
417 if (RelationStatName(s)!=NULL) {
418 WriteName(f,RelationStatName(s));
419 FPRINTF(f," : ");
420 }
421 if (g_show_statement_detail==1) {
422 WriteExpr(f,RelationStatExpr(s));
423 FPRINTF(f,";\n");
424 } else {
425 FPRINTF(f,"(details suppressed);\n");
426 }
427 break;
428 case LOGREL:
429 if (LogicalRelStatName(s)!=NULL) {
430 WriteName(f,LogicalRelStatName(s));
431 FPRINTF(f," : ");
432 }
433 if (g_show_statement_detail==1) {
434 WriteExpr(f,LogicalRelStatExpr(s));
435 FPRINTF(f,";\n");
436 } else {
437 FPRINTF(f,"(details suppressed);\n");
438 }
439 break;
440 case EXT:
441 switch (ExternalStatMode(s)) {
442 case 0: /* Procedural */
443 FPRINTF(f," EXTERNAL %s(",ExternalStatFuncName(s));
444 WriteVariableList(f,ExternalStatVlist(s));
445 FPRINTF(f,")\n");
446 break;
447 case 1: /* Glassbox Declarative */
448 case 2: /* Blackbox Declarative */
449 if (ExternalStatName(s)!=NULL) {
450 WriteName(f,ExternalStatName(s));
451 FPRINTF(f," : ");
452 }
453 FPRINTF(f," %s(",ExternalStatFuncName(s));
454 WriteVariableList(f,ExternalStatVlist(s));
455 FPRINTF(f," : INPUT/OUTPUT");
456 if (ExternalStatData(s)!=NULL) {
457 FPRINTF(f,", ");
458 WriteName(f,ExternalStatData(s));
459 FPRINTF(f," : DATA");
460 }
461 FPRINTF(f,")\n");
462 break;
463 }
464 break;
465 case REF:
466 WriteVariableList(f,ReferenceStatVlist(s));
467 switch (ReferenceStatMode(s)) {
468 case 0:
469 FPRINTF(f," _IS_ ");
470 break;
471 case 1:
472 FPRINTF(f," _REFERS_ ");
473 break;
474 }
475 FPRINTF(f,"%s\n;",SCP(ReferenceStatName(s)));
476 break;
477 case CASGN:
478 WriteName(f,AssignStatVar(s));
479 FPRINTF(f," :== ");
480 WriteExpr(f,AssignStatRHS(s));
481 FPRINTF(f,";\n");
482 break;
483 case ASGN:
484 WriteName(f,DefaultStatVar(s));
485 FPRINTF(f," := ");
486 WriteExpr(f,DefaultStatRHS(s));
487 FPRINTF(f,";\n");
488 break;
489 case RUN:
490 FPRINTF(f,"RUN ");
491 if ( (n=RunStatAccess(s))!=NULL ) { /* class/model/atom access */
492 WriteName(f,n);
493 FPRINTF(f,"::");
494 WriteName(f,RunStatName(s));
495 FPRINTF(f,";\n");
496 } else {
497 WriteName(f,RunStatName(s));
498 FPRINTF(f,";\n");
499 }
500 break;
501 case FIX:
502 FPRINTF(f,"FIX ");
503 WriteVariableList(f,FixStatVars(s));
504 FPRINTF(f,";\n");
505 break;
506 case CALL:
507 FPRINTF(f,"CALL %s(",SCP(CallStatId(s)));
508 WriteSet(f,CallStatArgs(s));
509 FPRINTF(f,");\n");
510 break;
511 case WHILE:
512 FPRINTF(f,"WHILE (");
513 WriteExpr(f,WhileStatExpr(s));
514 FPRINTF(f,") DO\n");
515 WriteStatementList(f,WhileStatBlock(s),i+INDENTATION);
516 Indent(f,i);
517 FPRINTF(f,"END WHILE;\n");
518 break;
519 case FLOW:
520 FPRINTF(f,"%s",SCP(StatementTypeString(s)));
521 if (FlowStatMessage(s) != NULL) {
522 FPRINTF(f," {%s}",BCS(FlowStatMessage(s)));
523 }
524 FPRINTF(f,";\n");
525 break;
526 case IF:
527 FPRINTF(f,"IF (");
528 WriteExpr(f,IfStatExpr(s));
529 FPRINTF(f,") THEN\n");
530 WriteStatementList(f,IfStatThen(s),i+INDENTATION);
531 if (IfStatElse(s)!=NULL) {
532 Indent(f,i);
533 FPRINTF(f,"ELSE\n");
534 WriteStatementList(f,IfStatElse(s),i+INDENTATION);
535 }
536 Indent(f,i);
537 FPRINTF(f,"END IF;\n");
538 break;
539 case WHEN:
540 if (WhenStatName(s)!=NULL) {
541 WriteName(f,WhenStatName(s));
542 FPRINTF(f," : ");
543 }
544 FPRINTF(f,"WHEN ");
545 WriteVariableList(f,WhenStatVL(s));
546 FPRINTF(f,"\n");
547 WriteWhenList(f,WhenStatCases(s),i);
548 Indent(f,i);
549 FPRINTF(f,"END;\n");
550 break;
551 case FNAME:
552 FPRINTF(f,"USE ");
553 WriteName(f,FnameStat(s));
554 FPRINTF(f,";\n");
555 break;
556 case SELECT:
557 FPRINTF(f,"SELECT ");
558 WriteVariableList(f,SelectStatVL(s));
559 FPRINTF(f,"\n");
560 WriteSelectList(f,SelectStatCases(s),i);
561 Indent(f,i);
562 FPRINTF(f,"END;\n");
563 break;
564 case SWITCH:
565 FPRINTF(f,"SWITCH ");
566 WriteVariableList(f,SwitchStatVL(s));
567 FPRINTF(f,"\n");
568 WriteSwitchList(f,SwitchStatCases(s),i);
569 Indent(f,i);
570 FPRINTF(f,"END;\n");
571 break;
572 case COND:
573 FPRINTF(f,"CONDITIONAL \n ");
574 WriteStatementList(f,CondStatList(s),i+INDENTATION);
575 Indent(f,i);
576 FPRINTF(f,"END;\n");
577 break;
578 default:
579 FPRINTF(f,"Unknown\n");
580 break;
581 }
582 }
583
584 /*
585 * Modified to avoid printing twice the statements inside a SELECT
586 * VRR. But the "jumping" of the statements is only for the outermost
587 * SELECT, the nested SELECTs do not require it.
588 */
589 void WriteStatementList(FILE *f, CONST struct StatementList *sl, int i)
590 {
591 register unsigned long len,c;
592 register CONST struct gl_list_t *l;
593 struct Statement *stat;
594 l = GetList(sl);
595 len = gl_length(l);
596 for(c=1; c<=len; c++) {
597 stat = (struct Statement *)gl_fetch(l,c);
598 WriteStatement(f,stat,i);
599 if (StatementType(stat)== SELECT && !StatInSELECT(stat)) {
600 c = c + SelectStatNumberStats(stat);
601 }
602 }
603 }
604
605 /*
606 * Modified to avoid printing twice the statements inside a SELECT
607 * VRR.
608 */
609 void WriteDiffStatementList(FILE *f, CONST struct StatementList *sl1,
610 CONST struct StatementList *sl2, int i)
611 {
612 register unsigned long len1,len2,c;
613 register CONST struct gl_list_t *l;
614 struct Statement *stat;
615 l = GetList(sl1);
616 len1=gl_length(l);
617 l = GetList(sl2);
618 len2 = gl_length(l);
619 for(c=(1+len1);c<=len2;c++) {
620 stat = (struct Statement *)gl_fetch(l,c);
621 WriteStatement(f,stat,i);
622 if (StatementType(stat)== SELECT) {
623 c = c + SelectStatNumberStats(stat);
624 }
625 }
626 }
627
628 void WriteStatementSuppressed(FILE *f, CONST struct Statement *stat)
629 {
630 if (stat!=NULL) {
631 FPRINTF(f," Incorrect statement (final warning) at %s:%lu\n",
632 Asc_ModuleBestName(StatementModule(stat)),
633 StatementLineNum(stat));
634 FPRINTF(f,
635 " All future occurences of this statement will be ignored.\n\n");
636 } else {
637 FPRINTF(f," Suppressing NULL STATEMENT!!! How odd! Expect crash.\n");
638 }
639 }
640
641 void WriteStatementErrorMessage(FILE *f, CONST struct Statement *stat,
642 CONST char *message, int noisy,int level)
643 {
644 /* old behavior */
645 const char *filename=NULL;
646 int line=0;
647 if(stat!=NULL){
648 filename=Asc_ModuleBestName(StatementModule(stat));
649 line=StatementLineNum(stat);
650 }
651
652 if (level == 0 || level ==3 ){
653 error_reporter_start(ASC_USER_ERROR,filename,line,NULL);
654 FPRINTF(f,"%s\n",message);
655 }else if(level < 0){
656 error_reporter_start(ASC_PROG_NOTE,filename,line,NULL);
657 FPRINTF(f,"%s\n",message);
658 }else{
659 error_reporter_start(ASC_USER_ERROR, filename, line,NULL);
660 FPRINTF(f,"%s%s\n",StatioLabel(level), message);
661 }
662
663 if(stat!=NULL){
664
665 /* write some more detail */
666 g_show_statement_detail = ((noisy!=0) ? 1 : 0);
667 WriteStatement(ASCERR,stat,2);
668 g_show_statement_detail = 1;
669
670 if (GetEvaluationForTable()!=NULL) {
671 WriteForTable(ASCERR,GetEvaluationForTable());
672 }
673 }else{
674 FPRINTF(f,"NULL STATEMENT!");
675 }
676
677 error_reporter_end_flush();
678 }
679
680 CONST char *StatioLabel(int level)
681 {
682 if (level >4 || level <1) {
683 level = 0;
684 }
685 return g_statio_label[level];
686 }
687
688 int *GetStatioSuppressions(void) {
689 /* WILLBE is the last element of the stattype enum. */
690 int *table;
691 table = (int *)asccalloc(1,sizeof(int)*(WILLBE+1));
692 assert(table!=NULL);
693 return table;
694 }
695
696 void DestroySuppressions(int *table)
697 {
698 assert(table!=NULL);
699 ascfree(table);
700 }
701
702
703 void WriteStatementErrorSparse(FILE *f,
704 CONST struct Statement *stat,
705 CONST char *message, int *ignore)
706 {
707 assert(ignore!=NULL);
708 g_statio_suppressions = ignore;
709 if (!SUP(stat)) {
710 if (message) FPRINTF(f,message);
711 if (stat ){
712 FPRINTF(f," %s:%lu\n",
713 Asc_ModuleBestName(StatementModule(stat)),
714 StatementLineNum(stat));
715 WriteStatement(f,stat,0);
716 if (GetEvaluationForTable()!=NULL) {
717 WriteForTable(f,GetEvaluationForTable());
718 FPRINTF(f,"\n");
719 }
720 } else {
721 FPRINTF(f,"NULL STATEMENT!!!\n");
722 }
723 }
724 g_statio_suppressions = NULL;
725 }
726
727 symchar *StatementTypeString(CONST struct Statement *s)
728 {
729 static symchar *error_statement_sym;
730 assert(s!=NULL);
731 if (g_statio_stattypenames[0]==NULL) {
732 error_statement_sym = AddSymbol("Unknown-statement-type");
733 g_statio_stattypenames[ALIASES] = AddSymbol("ALIASES");
734 g_statio_stattypenames[ISA] = AddSymbol("IS_A");
735 g_statio_stattypenames[ARR] = AddSymbol("ALIASES/IS_A");
736 g_statio_stattypenames[IRT] = AddSymbol("IS_REFINED_TO");
737 g_statio_stattypenames[ATS] = AddSymbol("ARE_THE_SAME");
738 g_statio_stattypenames[AA] = AddSymbol("ARE_ALIKE");
739 g_statio_stattypenames[FOR] = AddSymbol("FOR");
740 g_statio_stattypenames[REL] = GetBaseTypeName(relation_type);
741 g_statio_stattypenames[LOGREL] = GetBaseTypeName(logrel_type);
742 g_statio_stattypenames[ASGN] = AddSymbol("Assignment");
743 g_statio_stattypenames[CASGN] = AddSymbol("Constant assignment");
744 g_statio_stattypenames[RUN] = AddSymbol("RUN");
745 g_statio_stattypenames[IF] = AddSymbol("IF");
746 g_statio_stattypenames[WHEN] = GetBaseTypeName(when_type);
747 g_statio_stattypenames[FNAME] = AddSymbol("FNAME");
748 g_statio_stattypenames[SELECT] = AddSymbol("SELECT");
749 g_statio_stattypenames[SWITCH] = AddSymbol("SWITCH");
750 g_statio_stattypenames[EXT] = AddSymbol("EXTERNAL");
751 g_statio_stattypenames[CALL] = AddSymbol("CALL");
752 g_statio_stattypenames[FLOW] = AddSymbol("<flow-control>");
753 g_statio_stattypenames[WHILE] = AddSymbol("WHILE");
754 g_statio_stattypenames[REF] = AddSymbol("_IS_");
755 g_statio_stattypenames[COND] = AddSymbol("CONDITIONAL");
756 g_statio_stattypenames[WBTS] = AddSymbol("WILL_BE_THE_SAME");
757 g_statio_stattypenames[WNBTS] = AddSymbol("WILL_NOT_BE_THE_SAME");
758 g_statio_stattypenames[WILLBE] = AddSymbol("WILL_BE");
759 g_statio_flowtypenames[fc_return] = AddSymbol("RETURN");
760 g_statio_flowtypenames[fc_continue] = AddSymbol("CONTINUE");
761 g_statio_flowtypenames[fc_stop] = AddSymbol("STOP");
762 g_statio_flowtypenames[fc_break] = AddSymbol("BREAK");
763 g_statio_flowtypenames[fc_fallthru] = AddSymbol("FALL_THROUGH");
764 }
765 switch(StatementType(s)) {
766 case ALIASES:
767 case ISA:
768 case ARR:
769 case IRT:
770 case ATS:
771 case AA:
772 case FOR:
773 case REL:
774 case LOGREL:
775 case ASGN:
776 case CASGN:
777 case RUN:
778 case IF:
779 case WHEN:
780 case FNAME:
781 case SELECT:
782 case SWITCH:
783 case EXT:
784 case CALL:
785 case REF:
786 case COND:
787 case WBTS:
788 case WNBTS:
789 case WILLBE:
790 case WHILE:
791 /* It's a massive fall through to check that we know the statement */
792 return g_statio_stattypenames[StatementType(s)];
793 case FLOW:
794 return g_statio_flowtypenames[FlowStatControl(s)];
795 default:
796 return error_statement_sym;
797 }
798 }
799
800 void Asc_StatErrMsg_NotAllowedMethod(FILE *f,
801 CONST struct Statement *stat)
802 {
803 FPRINTF(f,
804 "%sIn the method at %s:%lu.\n"
805 " %s statements are not allowed.\n",
806 StatioLabel(3),
807 Asc_ModuleBestName(StatementModule(stat)),
808 StatementLineNum(stat),
809 SCP(StatementTypeString(stat)));
810 }
811
812 void Asc_StatErrMsg_NotAllowedDeclarative(FILE *f,
813 CONST struct Statement *stat)
814 {
815 FPRINTF(f,
816 "%sIn the declarative section %s:%lu.\n"
817 " %s statements are not allowed.\n",
818 StatioLabel(3),
819 Asc_ModuleBestName(StatementModule(stat)),
820 StatementLineNum(stat),
821 SCP(StatementTypeString(stat)));
822 }

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