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

Contents of /trunk/ascend/compiler/statio.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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