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

Contents of /trunk/base/generic/compiler/procio.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: 12224 byte(s)
Updating for Jerry's new error_reporter syntax, bug #179
1 /*
2 * Temporary Procedure Output
3 * by Tom Epperly
4 * Created: 1/10/90
5 * Version: $Revision: 1.11 $
6 * Version control file: $RCSfile: procio.c,v $
7 * Date last modified: $Date: 1998/05/12 19:57:43 $
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 along
25 * with the program; if not, write to the Free Software Foundation, Inc., 675
26 * Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING.
27 */
28 #include<math.h>
29 #include<stdio.h>
30 #include "utilities/ascConfig.h"
31 #include "utilities/ascMalloc.h"
32 #include "compiler/compiler.h"
33 #include "general/dstring.h"
34 #include "general/list.h"
35 #include "compiler/fractions.h"
36 #include "compiler/dimen.h"
37 #include "compiler/functype.h"
38 #include "compiler/types.h"
39 #include "compiler/stattypes.h"
40 #include "compiler/statement.h"
41 #include "compiler/slist.h"
42 #include "compiler/statio.h"
43 #include "compiler/instance_enum.h"
44 #include "compiler/instance_io.h"
45 #include "compiler/nameio.h"
46 #include "compiler/module.h"
47 #include "compiler/proc.h"
48 #include "compiler/watchpt.h"
49 #include "compiler/procframe.h"
50 #include "compiler/initialize.h"
51 #include "compiler/procio.h"
52
53 #ifndef lint
54 static CONST char ProcedureIORCSid[] = "$Id: procio.c,v 1.11 1998/05/12 19:57:43 ballan Exp $";
55 #endif
56
57
58 void WriteInitWarn(struct procFrame *fm, char *str)
59 {
60 CONSOLE_DEBUG("...");
61 WriteStatementErrorMessage(fm->err, fm->stat, str, 0,2);
62 }
63
64 void WriteInitErr(struct procFrame *fm, char *str)
65 {
66 WSEM(fm->err,fm->stat,str);
67 FFLUSH(fm->err);
68 }
69
70 void ProcWriteCaseError(struct procFrame *fm, int arm, int pos)
71 {
72 static char nostr[] = "";
73 char *fmt;
74 char *tail;
75 char armstr[20];
76 char errmsg[100];
77
78 sprintf(armstr,"in arm %d.",arm);
79
80 switch (fm->ErrNo) {
81 case Proc_instance_not_found:
82 fmt = "NULL (as yet unmade) instance for SWITCH argument %d %s";
83 tail = nostr;
84 break;
85 case Proc_name_not_found:
86 fmt = "Undefined name for SWITCH argument %d %s";
87 tail = nostr;
88 break;
89 case Proc_illegal_name_use:
90 fmt = "Incorrect name (subscript?) for SWITCH argument %d %s";
91 tail = nostr;
92 break;
93 case Proc_CallError:
94 fmt = "Unexpected 'OK' message for SWITCH argument %d %s";
95 tail = nostr;
96 break;
97 case Proc_case_undefined_value:
98 fmt = "Variable %d value UNDEFINED in SWITCH %s";
99 tail = nostr;
100 break;
101 case Proc_case_boolean_mismatch:
102 fmt = "Nonboolean instance for argument %d %s";
103 tail = armstr;
104 break;
105 case Proc_case_integer_mismatch:
106 fmt = "Noninteger instance for argument %d %s";
107 tail = armstr;
108 break;
109 case Proc_case_symbol_mismatch:
110 fmt = "Nonsymbol instance for argument %d %s";
111 tail = armstr;
112 break;
113 case Proc_case_wrong_index:
114 fmt = "Incorrect index expression in AnalyzeSwitchCase";
115 tail = nostr;
116 break;
117 case Proc_case_wrong_value:
118 fmt = "Wrong value expression in AnalyzeSwitchCase";
119 tail = nostr;
120 break;
121 case Proc_case_extra_values:
122 fmt = "Multiple instances for a variable in a SWITCH statement";
123 tail = nostr;
124 break;
125 default:
126 fmt = "Confusion in ProcWriteCaseError, %d %s";
127 tail = armstr;
128 break;
129 }
130 sprintf(errmsg,fmt,pos,tail);
131 WriteInitErr(fm,errmsg);
132 }
133
134 void ProcWriteIfError(struct procFrame *fm, CONST char *cname)
135 {
136 char em[85];
137 char cn[20];
138
139 CONSOLE_DEBUG("...");
140
141 if (strlen(cname) > 19) {
142 strncpy(cn,cname,19);
143 cn[19] = '\0';
144 } else {
145 strcpy(cn,cname);
146 }
147 switch (fm->ErrNo) {
148 case Proc_if_expr_error_emptyintersection:
149 sprintf(em,"%s expression - empty set intersection",cn);
150 break;
151 case Proc_if_expr_error_emptychoice:
152 sprintf(em,"%s expression - CHOICE on empty set",cn);
153 break;
154 case Proc_if_expr_error_dimensionconflict:
155 sprintf(em,"%s expression - real dimensionality conflict",cn);
156 break;
157 case Proc_if_expr_error_undefinedvalue:
158 sprintf(em,"%s expression - unassigned variable value",cn);
159 break;
160 case Proc_if_expr_error_incorrectname:
161 sprintf(em,"%s expression - name of impossible variable",cn);
162 break;
163 case Proc_if_expr_error_typeconflict:
164 sprintf(em,"%s expression - type conflict of operands",cn);
165 break;
166 case Proc_if_expr_error_nameunfound:
167 sprintf(em,"%s expression - variable not found",cn);
168 break;
169 case Proc_if_expr_error_confused:
170 sprintf(em,"evaluating confusing %s expression",cn);
171 break;
172 case Proc_if_real_expr:
173 sprintf(em,"%s (expression) : real valued expression illegal",cn);
174 break;
175 case Proc_if_integer_expr:
176 sprintf(em,"%s (expression) : integer valued expression illegal",cn);
177 break;
178 case Proc_if_symbol_expr:
179 sprintf(em,"%s (expression) : symbol valued expression illegal",cn);
180 break;
181 case Proc_if_set_expr:
182 sprintf(em,"%s (expression) : set valued expression illegal",cn);
183 break;
184 case Proc_if_not_logical:
185 sprintf(em,"%s (expression) : expression is not boolean-valued",cn);
186 break;
187 case Proc_infinite_loop:
188 sprintf(em,"%s (expression) : looping infinitely?",cn);
189 break;
190 case Proc_stop:
191 sprintf(em,"Found %s statement in METHOD",cn);
192 break;
193 default:
194 sprintf(em,"%s unexpected error message",cn);
195 break;
196 }
197 CONSOLE_DEBUG("...");
198 WriteInitErr(fm,em);
199 CONSOLE_DEBUG("...");
200 }
201
202 void ProcWriteAssignmentError(struct procFrame *fm)
203 {
204 switch (fm->ErrNo) {
205 case Proc_nonatom_assignment:
206 WriteInitErr(fm,"Assignment to a non-atomic instance");
207 break;
208 case Proc_noninteger_assignment:
209 WriteInitErr(fm,"Right hand side of assignment is not an integer");
210 break;
211 case Proc_declarative_constant_assignment:
212 WriteInitErr(fm, "Assignment to a set or constant instance");
213 break;
214 case Proc_nonconsistent_assignment:
215 WriteInitErr(fm,"Dimensionally inconsistent assignment");
216 break;
217 case Proc_nonreal_assignment:
218 WriteInitErr(fm, "Right hand side of assignment is not a real expression");
219 break;
220 case Proc_nonboolean_assignment:
221 WriteInitErr(fm,"Right hand side of assignment is not a boolean");
222 break;
223 case Proc_nonsymbol_assignment:
224 WriteInitErr(fm,"Right hand side of assignment is not a symbol");
225 break;
226 case Proc_nonsense_assignment:
227 WriteInitErr(fm,"Assignment to bogus instance type.");
228 break;
229 case Proc_rhs_error:
230 WriteInitErr(fm,"Error evaluating assignment right hand side");
231 break;
232 case Proc_lhs_error:
233 WriteInitErr(fm,"Undefined or NULL instance in left hand side of :=.");
234 break;
235 default:
236 WriteInitErr(fm,"Assignment (:=) unexpected error message");
237 break;
238 }
239 }
240
241 void ProcWriteForError(struct procFrame *fm)
242 {
243 switch (fm->ErrNo) {
244 case Proc_for_duplicate_index:
245 WriteInitErr(fm,"FOR/DO uses duplicate index variable.");
246 break;
247 case Proc_for_set_err:
248 WriteInitErr(fm,"Error evaluating FOR/DO index set.");
249 break;
250 case Proc_for_not_set:
251 WriteInitErr(fm,"FOR/DO index expression is not a set");
252 break;
253 default:
254 WriteInitErr(fm,"FOR/DO unexpected error message.");
255 break;
256 }
257 }
258
259 /* error messages for oldstyle external functions */
260 void ProcWriteExtError(struct procFrame *fm, CONST char *funcname,
261 enum ProcExtError peerr, int pos)
262 {
263 char *errmsg;
264 assert(funcname != NULL);
265 errmsg = (char *)ascmalloc(80+strlen(funcname));
266 switch (peerr) {
267 case PE_unloaded:
268 WriteInitErr(fm,"External function has not been loaded.");
269 break;
270 case PE_nulleval:
271 WriteInitErr(fm,"Nonexistent Evaluation for old-style external function.");
272 break;
273 case PE_argswrong:
274 WriteInitErr(fm,"Incorrect arguments to old-style external function.");
275 break;
276 case PE_badarg:
277 switch (fm->ErrNo) {
278 case Proc_instance_not_found:
279 sprintf(errmsg,
280 "EXTERNAL %s: NULL (as yet unmade) instance for argument %d.",
281 funcname,pos);
282 WriteStatementErrorMessage(fm->err,fm->stat,errmsg, 0,3);
283 break;
284 case Proc_name_not_found:
285 sprintf(errmsg,"EXTERNAL %s: Undefined name for argument %d.",
286 funcname, pos);
287 WriteStatementErrorMessage(fm->err,fm->stat,errmsg, 0,3);
288 break;
289 case Proc_illegal_name_use:
290 sprintf(errmsg,
291 "EXTERNAL %s: Incorrect name (subscript?) for argument %d.",
292 funcname, pos);
293 WriteStatementErrorMessage(fm->err,fm->stat,errmsg, 0,3);
294 break;
295 case Proc_bad_name:
296 sprintf(errmsg,"EXTERNAL %s: Unknown error message for argument %u.",
297 funcname, pos);
298 WriteStatementErrorMessage(fm->err,fm->stat,errmsg, 0,3);
299 FPRINTF(fm->err," Expect crash soon!\n");
300 break;
301 case Proc_CallError:
302 sprintf(errmsg,"EXTERNAL %s: Unexpected 'OK' message for argument %u.",
303 funcname, pos);
304 WriteStatementErrorMessage(fm->err,fm->stat,errmsg, 0,3);
305 fm->ErrNo = Proc_CallError;
306 default:
307 break;
308 }
309 break;
310 case PE_evalerr:
311 WriteInitErr(fm,"Error in evaluating external function.");
312 break;
313 }
314 ascfree(errmsg);
315 }
316
317 void ProcWriteStackCheck(struct procFrame *fm,
318 struct Name *class, struct Name *name)
319 {
320 int unwind = 0;
321 if ( fm->ErrNo == Proc_return) {
322 return;
323 }
324 if(fm->stat != NULL){
325 error_reporter_start(ASC_PROG_ERROR,SCP(Asc_ModuleBestName(StatementModule(fm->stat))),StatementLineNum(fm->stat),NULL);
326 }else{
327 error_reporter_start(ASC_PROG_ERROR,NULL,0,NULL);
328 }
329
330 if (fm->ErrNo == Proc_stack_exceeded_this_frame) {
331 /* stack error message not suppressible */
332 unwind = 1;
333 FPRINTF(fm->err,
334 "Initialization stack overflow (possible recursion) in call to\n");
335 } else {
336 if (fm->gen & WP_BTUIFSTOP || fm->ErrNo == Proc_stack_exceeded) {
337 unwind = 1;
338 FPRINTF(fm->err," In call to");
339 }
340 }
341 if (!unwind) {
342 return;
343 }
344 FPRINTF(fm->err," METHOD ");
345 if (class != NULL) {
346 WriteName(fm->err,class);
347 FPRINTF(fm->err,"::");
348 }
349 WriteName(fm->err,name);
350 FPRINTF(fm->err," (depth %d) in instance %s\n", fm->depth, fm->cname);
351
352 error_reporter_end_flush();
353 }
354
355 void ProcWriteRunError(struct procFrame *fm)
356 {
357 char *errmsg;
358 errmsg = "Unexpected RUN statement error";
359 switch (fm->ErrNo) {
360 case Proc_bad_name:
361 errmsg = "Bad method name in RUN statement";
362 break;
363 case Proc_proc_not_found:
364 errmsg = "Method not found in RUN statement";
365 break;
366 case Proc_illegal_name_use:
367 errmsg = "Illegal name use in RUN statement";
368 break;
369 case Proc_type_not_found:
370 errmsg = "Type name not found in RUN statement";
371 break;
372 case Proc_illegal_type_use:
373 errmsg = "Unconformable types in RUN statement";
374 break;
375 case Proc_stack_exceeded_this_frame:
376 case Proc_stack_exceeded:
377 errmsg = "METHOD call too deeply nested in statement";
378 break;
379 default:
380 errmsg = "Type name not found in RUN statement";
381 break;
382 }
383 WriteInitErr(fm,errmsg);
384 }
385
386 void ProcWriteFixError(struct procFrame *fm, struct Name *var){
387 char errmsg[255];
388 char *name;
389 name = WriteNameString(var);
390 strcpy(errmsg,"Unexpected FIX statement error");
391 switch(fm->ErrNo){
392 case Proc_type_not_found:
393 strcpy(errmsg, "Bad setup for FIX statement (Is 'solver_var' present in the library?)");
394 break;
395 case Proc_illegal_type_use:
396 strcpy(errmsg, "Incorrect type for variable being fixed (must be a refined solver_var)");
397 break;
398 case Proc_bad_name:
399 strcpy(errmsg, "Unknown variable in FIX statement");
400 break;
401 }
402 strcat(errmsg,", for variable '");
403 strncat(errmsg,name,40);
404 strcat(errmsg,"'");
405 ascfree(name);
406 WriteInitErr(fm,errmsg);
407 }
408

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