/[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 978 - (show annotations) (download) (as text)
Wed Dec 20 10:26:04 2006 UTC (17 years, 6 months ago) by johnpye
File MIME type: text/x-csrc
File size: 23023 byte(s)
Failed 'ASSERT' statements in a METHOD now cause the statement to be output (as well as its location).
Improved code docs/GPL header for a few files.
Added support for 'ASSERT' in WriteStatement.
Added new WriteStatementError that included var-arg support.
Fixed ASC_ASSERT_RANGE in AscPanic.
1 /* ASCEND modelling environment
2 Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly
3 Copyright (C) 2006 Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//** @file
20 Temporary Statement Output routines
21 *//*
22 by Tom Epperly
23 Last in CVS: $Revision: 1.41 $ $Date: 1998/04/21 23:49:55 $ $Author: ballan $
24 */
25
26 #define INDENTATION 4
27
28 #include <utilities/ascConfig.h>
29 #include <utilities/ascMalloc.h>
30 #include <utilities/error.h>
31 #include <general/list.h>
32 #include <general/dstring.h>
33 #include "compiler.h"
34 #include "fractions.h"
35 #include "dimen.h"
36 #include "functype.h"
37 #include "expr_types.h"
38 #include "stattypes.h"
39 #include "statement.h"
40 #include "statio.h"
41 #include "exprio.h"
42 #include "nameio.h"
43 #include "when.h"
44 #include "select.h"
45 #include "switch.h"
46 #include "bit.h"
47 #include "vlistio.h"
48 #include "slist.h"
49 #include "setio.h"
50 #include "child.h"
51 #include "type_desc.h"
52 #include "type_descio.h"
53 #include "module.h"
54 #include "forvars.h"
55 #include "find.h"
56 #include "symtab.h"
57 #include "braced.h"
58 #include "instance_enum.h"
59 #include "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 ek_method: /* Procedural */
443 FPRINTF(f," EXTERNAL %s(",ExternalStatFuncName(s));
444 WriteVariableList(f,ExternalStatVlistMethod(s));
445 FPRINTF(f,")\n");
446 break;
447 case ek_glass: /* Glassbox Declarative */
448 if (ExternalStatNameRelation(s)!=NULL) {
449 WriteName(f,ExternalStatNameRelation(s));
450 FPRINTF(f," : ");
451 }
452 FPRINTF(f," %s(",ExternalStatFuncName(s));
453 WriteVariableList(f,ExternalStatVlistRelation(s));
454 FPRINTF(f," : INPUT/OUTPUT");
455 if (ExternalStatDataGlassBox(s)!=NULL) {
456 FPRINTF(f,", ");
457 WriteName(f,ExternalStatDataGlassBox(s));
458 FPRINTF(f," : DATA");
459 }
460 FPRINTF(f,")\n");
461 break;
462 case ek_black: /* Blackbox Declarative */
463 if (ExternalStatNameRelation(s)!=NULL) {
464 WriteName(f,ExternalStatNameRelation(s));
465 FPRINTF(f," : ");
466 }
467 FPRINTF(f," %s(",ExternalStatFuncName(s));
468 WriteVariableList(f,ExternalStatVlistRelation(s));
469 FPRINTF(f," : INPUT/OUTPUT");
470 if (ExternalStatDataBlackBox(s)!=NULL) {
471 FPRINTF(f,", ");
472 WriteName(f,ExternalStatDataBlackBox(s));
473 FPRINTF(f," : DATA");
474 }
475 FPRINTF(f,")\n");
476 break;
477 }
478 break;
479 case REF:
480 WriteVariableList(f,ReferenceStatVlist(s));
481 switch (ReferenceStatMode(s)) {
482 case 0:
483 FPRINTF(f," _IS_ ");
484 break;
485 case 1:
486 FPRINTF(f," _REFERS_ ");
487 break;
488 }
489 FPRINTF(f,"%s\n;",SCP(ReferenceStatName(s)));
490 break;
491 case CASGN:
492 WriteName(f,AssignStatVar(s));
493 FPRINTF(f," :== ");
494 WriteExpr(f,AssignStatRHS(s));
495 FPRINTF(f,";\n");
496 break;
497 case ASGN:
498 WriteName(f,DefaultStatVar(s));
499 FPRINTF(f," := ");
500 WriteExpr(f,DefaultStatRHS(s));
501 FPRINTF(f,";\n");
502 break;
503 case RUN:
504 FPRINTF(f,"RUN ");
505 if ( (n=RunStatAccess(s))!=NULL ) { /* class/model/atom access */
506 WriteName(f,n);
507 FPRINTF(f,"::");
508 WriteName(f,RunStatName(s));
509 FPRINTF(f,";\n");
510 } else {
511 WriteName(f,RunStatName(s));
512 FPRINTF(f,";\n");
513 }
514 break;
515 case FIX:
516 FPRINTF(f,"FIX ");
517 WriteVariableList(f,FixFreeStatVars(s));
518 FPRINTF(f,";\n");
519 break;
520 case FREE:
521 FPRINTF(f,"FREE ");
522 WriteVariableList(f,FixFreeStatVars(s));
523 FPRINTF(f,";\n");
524 break;
525 case CALL:
526 FPRINTF(f,"CALL %s(",SCP(CallStatId(s)));
527 WriteSet(f,CallStatArgs(s));
528 FPRINTF(f,");\n");
529 break;
530 case ASSERT:
531 FPRINTF(f,"ASSERT ");
532 WriteExpr(f,AssertStatExpr(s));
533 FPRINTF(f,"\n");
534 break;
535 case WHILE:
536 FPRINTF(f,"WHILE (");
537 WriteExpr(f,WhileStatExpr(s));
538 FPRINTF(f,") DO\n");
539 WriteStatementList(f,WhileStatBlock(s),i+INDENTATION);
540 Indent(f,i);
541 FPRINTF(f,"END WHILE;\n");
542 break;
543 case FLOW:
544 FPRINTF(f,"%s",SCP(StatementTypeString(s)));
545 if (FlowStatMessage(s) != NULL) {
546 FPRINTF(f," {%s}",BCS(FlowStatMessage(s)));
547 }
548 FPRINTF(f,";\n");
549 break;
550 case IF:
551 FPRINTF(f,"IF (");
552 WriteExpr(f,IfStatExpr(s));
553 FPRINTF(f,") THEN\n");
554 WriteStatementList(f,IfStatThen(s),i+INDENTATION);
555 if (IfStatElse(s)!=NULL) {
556 Indent(f,i);
557 FPRINTF(f,"ELSE\n");
558 WriteStatementList(f,IfStatElse(s),i+INDENTATION);
559 }
560 Indent(f,i);
561 FPRINTF(f,"END IF;\n");
562 break;
563 case WHEN:
564 if (WhenStatName(s)!=NULL) {
565 WriteName(f,WhenStatName(s));
566 FPRINTF(f," : ");
567 }
568 FPRINTF(f,"WHEN ");
569 WriteVariableList(f,WhenStatVL(s));
570 FPRINTF(f,"\n");
571 WriteWhenList(f,WhenStatCases(s),i);
572 Indent(f,i);
573 FPRINTF(f,"END;\n");
574 break;
575 case FNAME:
576 FPRINTF(f,"USE ");
577 WriteName(f,FnameStat(s));
578 FPRINTF(f,";\n");
579 break;
580 case SELECT:
581 FPRINTF(f,"SELECT ");
582 WriteVariableList(f,SelectStatVL(s));
583 FPRINTF(f,"\n");
584 WriteSelectList(f,SelectStatCases(s),i);
585 Indent(f,i);
586 FPRINTF(f,"END;\n");
587 break;
588 case SWITCH:
589 FPRINTF(f,"SWITCH ");
590 WriteVariableList(f,SwitchStatVL(s));
591 FPRINTF(f,"\n");
592 WriteSwitchList(f,SwitchStatCases(s),i);
593 Indent(f,i);
594 FPRINTF(f,"END;\n");
595 break;
596 case COND:
597 FPRINTF(f,"CONDITIONAL \n ");
598 WriteStatementList(f,CondStatList(s),i+INDENTATION);
599 Indent(f,i);
600 FPRINTF(f,"END;\n");
601 break;
602 default:
603 FPRINTF(f,"<Implemented statement type in WriteStatement>");
604 break;
605 }
606 }
607
608 /*
609 * Modified to avoid printing twice the statements inside a SELECT
610 * VRR. But the "jumping" of the statements is only for the outermost
611 * SELECT, the nested SELECTs do not require it.
612 */
613 void WriteStatementList(FILE *f, CONST struct StatementList *sl, int i)
614 {
615 register unsigned long len,c;
616 register CONST struct gl_list_t *l;
617 struct Statement *stat;
618 l = GetList(sl);
619 len = gl_length(l);
620 for(c=1; c<=len; c++) {
621 stat = (struct Statement *)gl_fetch(l,c);
622 WriteStatement(f,stat,i);
623 if (StatementType(stat)== SELECT && !StatInSELECT(stat)) {
624 c = c + SelectStatNumberStats(stat);
625 }
626 }
627 }
628
629 /*
630 * Modified to avoid printing twice the statements inside a SELECT
631 * VRR.
632 */
633 void WriteDiffStatementList(FILE *f, CONST struct StatementList *sl1,
634 CONST struct StatementList *sl2, int i)
635 {
636 register unsigned long len1,len2,c;
637 register CONST struct gl_list_t *l;
638 struct Statement *stat;
639 l = GetList(sl1);
640 len1=gl_length(l);
641 l = GetList(sl2);
642 len2 = gl_length(l);
643 for(c=(1+len1);c<=len2;c++) {
644 stat = (struct Statement *)gl_fetch(l,c);
645 WriteStatement(f,stat,i);
646 if (StatementType(stat)== SELECT) {
647 c = c + SelectStatNumberStats(stat);
648 }
649 }
650 }
651
652 void WriteStatementSuppressed(FILE *f, CONST struct Statement *stat)
653 {
654 if (stat!=NULL) {
655 FPRINTF(f," Incorrect statement (final warning) at %s:%lu\n",
656 Asc_ModuleBestName(StatementModule(stat)),
657 StatementLineNum(stat));
658 FPRINTF(f,
659 " All future occurences of this statement will be ignored.\n\n");
660 } else {
661 FPRINTF(f," Suppressing NULL STATEMENT!!! How odd! Expect crash.\n");
662 }
663 }
664
665 void WriteStatementError(const error_severity_t sev
666 , const struct Statement *stat
667 , const int outputstatement
668 , const char *fmt
669 , ...
670 ){
671 va_list args;
672 int res;
673
674 error_reporter_start(sev,Asc_ModuleFileName(stat->mod),stat->linenum,SCP(StatementTypeString(stat)));
675 va_start(args,fmt);
676 vfprintf_error_reporter(ASCERR,fmt,args);
677 va_end(args);
678 if(outputstatement){
679 FPRINTF(ASCERR,"\n");
680 WriteStatement(ASCERR,stat,4);
681 }
682 error_reporter_end_flush();
683 }
684
685 void WriteStatementErrorMessage(FILE *f, CONST struct Statement *stat,
686 CONST char *message, int noisy,int level)
687 {
688 /* old behavior */
689 const char *filename=NULL;
690 int line=0;
691 if(stat!=NULL){
692 filename=Asc_ModuleBestName(StatementModule(stat));
693 line=StatementLineNum(stat);
694 }
695
696 if(level < 0){
697 level = 1;
698 }
699
700 error_severity_t sev;
701
702 switch(level){
703 case 1: sev = ASC_USER_NOTE; break;
704 case 2: sev = ASC_USER_WARNING; break;
705 case 3: sev = ASC_USER_ERROR; break;
706 default:
707 sev = ASC_PROG_ERR;
708 }
709
710 error_reporter_start(sev,filename,line,NULL);
711 FPRINTF(ASCERR,"%s\n",message);
712
713 if(stat!=NULL){
714 /* write some more detail */
715 g_show_statement_detail = ((noisy!=0) ? 1 : 0);
716 WriteStatement(ASCERR,stat,2);
717 g_show_statement_detail = 1;
718
719 if (GetEvaluationForTable()!=NULL) {
720 WriteForTable(ASCERR,GetEvaluationForTable());
721 }
722 }else{
723 FPRINTF(f,"NULL STATEMENT!");
724 }
725
726 error_reporter_end_flush();
727 CONSOLE_DEBUG("MESSAGE OUTPUT");
728 }
729
730 CONST char *StatioLabel(int level)
731 {
732 if (level >4 || level <1) {
733 level = 0;
734 }
735 return g_statio_label[level];
736 }
737
738 int *GetStatioSuppressions(void) {
739 /* WILLBE is the last element of the stattype enum. */
740 int *table;
741 table = ASC_NEW_ARRAY_CLEAR(int,WILLBE+1);
742 assert(table!=NULL);
743 return table;
744 }
745
746 void DestroySuppressions(int *table)
747 {
748 assert(table!=NULL);
749 ascfree(table);
750 }
751
752
753 void WriteStatementErrorSparse(FILE *f,
754 CONST struct Statement *stat,
755 CONST char *message, int *ignore)
756 {
757 assert(ignore!=NULL);
758 g_statio_suppressions = ignore;
759 if (!SUP(stat)) {
760 if (message) FPRINTF(f,message);
761 if (stat ){
762 FPRINTF(f," %s:%lu\n",
763 Asc_ModuleBestName(StatementModule(stat)),
764 StatementLineNum(stat));
765 WriteStatement(f,stat,0);
766 if (GetEvaluationForTable()!=NULL) {
767 WriteForTable(f,GetEvaluationForTable());
768 FPRINTF(f,"\n");
769 }
770 } else {
771 FPRINTF(f,"NULL STATEMENT!!!\n");
772 }
773 }
774 g_statio_suppressions = NULL;
775 }
776
777 symchar *StatementTypeString(CONST struct Statement *s)
778 {
779 static symchar *error_statement_sym;
780 assert(s!=NULL);
781 if (g_statio_stattypenames[0]==NULL) {
782 error_statement_sym = AddSymbol("Unknown-statement-type");
783 g_statio_stattypenames[ALIASES] = AddSymbol("ALIASES");
784 g_statio_stattypenames[ISA] = AddSymbol("IS_A");
785 g_statio_stattypenames[ARR] = AddSymbol("ALIASES/IS_A");
786 g_statio_stattypenames[IRT] = AddSymbol("IS_REFINED_TO");
787 g_statio_stattypenames[ATS] = AddSymbol("ARE_THE_SAME");
788 g_statio_stattypenames[AA] = AddSymbol("ARE_ALIKE");
789 g_statio_stattypenames[FOR] = AddSymbol("FOR");
790 g_statio_stattypenames[REL] = GetBaseTypeName(relation_type);
791 g_statio_stattypenames[LOGREL] = GetBaseTypeName(logrel_type);
792 g_statio_stattypenames[ASGN] = AddSymbol("Assignment");
793 g_statio_stattypenames[CASGN] = AddSymbol("Constant assignment");
794 g_statio_stattypenames[RUN] = AddSymbol("RUN");
795 g_statio_stattypenames[IF] = AddSymbol("IF");
796 g_statio_stattypenames[WHEN] = GetBaseTypeName(when_type);
797 g_statio_stattypenames[FNAME] = AddSymbol("FNAME");
798 g_statio_stattypenames[SELECT] = AddSymbol("SELECT");
799 g_statio_stattypenames[SWITCH] = AddSymbol("SWITCH");
800 g_statio_stattypenames[EXT] = AddSymbol("EXTERNAL");
801 g_statio_stattypenames[CALL] = AddSymbol("CALL");
802 g_statio_stattypenames[ASSERT] = AddSymbol("ASSERT");
803 g_statio_stattypenames[FLOW] = AddSymbol("<flow-control>");
804 g_statio_stattypenames[WHILE] = AddSymbol("WHILE");
805 g_statio_stattypenames[REF] = AddSymbol("_IS_");
806 g_statio_stattypenames[COND] = AddSymbol("CONDITIONAL");
807 g_statio_stattypenames[WBTS] = AddSymbol("WILL_BE_THE_SAME");
808 g_statio_stattypenames[WNBTS] = AddSymbol("WILL_NOT_BE_THE_SAME");
809 g_statio_stattypenames[WILLBE] = AddSymbol("WILL_BE");
810 g_statio_flowtypenames[fc_return] = AddSymbol("RETURN");
811 g_statio_flowtypenames[fc_continue] = AddSymbol("CONTINUE");
812 g_statio_flowtypenames[fc_stop] = AddSymbol("STOP");
813 g_statio_flowtypenames[fc_break] = AddSymbol("BREAK");
814 g_statio_flowtypenames[fc_fallthru] = AddSymbol("FALL_THROUGH");
815 }
816 switch(StatementType(s)) {
817 case ALIASES:
818 case ISA:
819 case ARR:
820 case IRT:
821 case ATS:
822 case AA:
823 case FOR:
824 case REL:
825 case LOGREL:
826 case ASGN:
827 case CASGN:
828 case RUN:
829 case IF:
830 case WHEN:
831 case FNAME:
832 case SELECT:
833 case SWITCH:
834 case EXT:
835 case CALL:
836 case ASSERT:
837 case REF:
838 case COND:
839 case WBTS:
840 case WNBTS:
841 case WILLBE:
842 case WHILE:
843 /* It's a massive fall through to check that we know the statement */
844 return g_statio_stattypenames[StatementType(s)];
845 case FLOW:
846 return g_statio_flowtypenames[FlowStatControl(s)];
847 default:
848 return error_statement_sym;
849 }
850 }
851
852 void Asc_StatErrMsg_NotAllowedMethod(FILE *f
853 , CONST struct Statement *stat
854 , CONST char *suggestion
855 ){
856 (void)f;
857 error_reporter(ASC_USER_ERROR,Asc_ModuleBestName(StatementModule(stat))
858 , StatementLineNum(stat), NULL
859 , "In a METHOD, %s statements are not allowed. %s"
860 , SCP(StatementTypeString(stat))
861 , suggestion
862 );
863 }
864
865 void Asc_StatErrMsg_NotAllowedDeclarative(FILE *f
866 , CONST struct Statement *stat
867 , CONST char * suggestion
868 ){
869 (void)f;
870 error_reporter(ASC_USER_ERROR,Asc_ModuleBestName(StatementModule(stat))
871 , StatementLineNum(stat), NULL
872 , "In a MODEL's declarative section, %s statements not allowed. %s"
873 , SCP(StatementTypeString(stat))
874 , suggestion
875 );
876 }

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