00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef lint
00014 static char vcid[] = "$Id: error.c,v 1.3 1995/07/11 01:53:03 duchier Exp $";
00015 #endif
00016
00017 #include "extern.h"
00018 #include "print.h"
00019 #include "types.h"
00020 #include "login.h"
00021 #include "lefun.h"
00022 #include "parser.h"
00023 #ifndef OS2_PORT
00024 #include "built_ins.h"
00025 #else
00026 #include "built_in.h"
00027 #endif
00028
00029 #ifdef OS2_PORT
00030 #define VarArgInit(format) va_start(VarArg, format);
00031
00032 #define VarArgNext(t) va_arg(VarArg, t)
00033 #define VarArgEnd() va_end(VarArg)
00034 #define vinfoline(format, outfile, xxxx) { \
00035 for (p=format;p && *p; p++) \
00036 { \
00037 if (*p == '%') \
00038 { \
00039 p++; \
00040 switch (*p) \
00041 { \
00042 case 'd': \
00043 case 'x': \
00044 buffer[0] = '%'; \
00045 buffer[1] = *p; \
00046 buffer[2] = 0; \
00047 lng2 = VarArgNext(unsigned long); \
00048 fprintf(outfile, buffer, lng2); \
00049 break; \
00050 case 's': \
00051 buffer[0] = '%'; \
00052 buffer[1] = *p; \
00053 buffer[2] = 0; \
00054 cptr = VarArgNext(char *); \
00055 fprintf(outfile, buffer, cptr); \
00056 break; \
00057 case 'C': \
00058 \
00059 pil = VarArgNext(ptr_int_list); \
00060 print_code(outfile,pil); \
00061 break; \
00062 case 'P': \
00063 psi = VarArgNext(ptr_psi_term); \
00064 display_psi(outfile,psi); \
00065 break; \
00066 case 'O': \
00067 kind = VarArgNext(operator); \
00068 print_operator_kind(outfile,kind); \
00069 break; \
00070 case 'T': \
00071 assert(outfile==stderr); \
00072 t = VarArgNext(def_type); \
00073 print_def_type(t); \
00074 break; \
00075 case 'E': \
00076 assert(outfile==stderr); \
00077 psi_term_error(); \
00078 break; \
00079 case '%': \
00080 putc(*p,outfile); \
00081 break; \
00082 default: \
00083 fprintf(outfile,"<%c follows %% : report bug >", *p); \
00084 break; \
00085 } \
00086 } \
00087 else \
00088 putc(*p,outfile); \
00089 } \
00090 VarArgEnd(); \
00091 }
00092 #endif
00093
00094
00095 #include "error.h"
00096
00097 long warningflag=TRUE;
00098 long quietflag=FALSE;
00099 long trace=FALSE;
00100 long verbose=FALSE;
00101 long stepflag;
00102 long steptrace;
00103 long stepcount;
00104
00105
00106 static long depth_gs()
00107 {
00108 long i=0;
00109 ptr_goal g=goal_stack;
00110
00111 while (g) { i++; g=g->next; }
00112 return i;
00113 }
00114
00115
00116
00117 static long depth_cs()
00118 {
00119 long i=0;
00120 ptr_choice_point c=choice_stack;
00121
00122 while (c) { i++; c=c->next; }
00123 return i;
00124 }
00125
00126
00127
00128 static long depth_ts()
00129 {
00130 ptr_stack t=undo_stack;
00131 long i=0;
00132
00133 while (t) { i++; t=t->next; }
00134 return i;
00135 }
00136
00137
00138 void stack_info(outfile)
00139 FILE *outfile;
00140 {
00141
00142 if (verbose) {
00143 long gn,cn,tn;
00144 fprintf(outfile,"*** Stack depths [");
00145 gn=depth_gs();
00146 cn=depth_cs();
00147 tn=depth_ts();
00148 fprintf(outfile,"%ld goal%s, %ld choice point%s, %ld trail entr%s",
00149 gn,(gn!=1?"s":""),
00150 cn,(cn!=1?"s":""),
00151 tn,(tn!=1?"ies":"y"));
00152 fprintf(outfile,"]\n");
00153 }
00154 }
00155
00156
00157
00158
00159 #ifndef OS2_PORT
00160 void vinfoline();
00161 #endif
00162
00163 #ifndef OS2_PORT
00164 void outputline(format,VarArgBase)
00165 char *format;
00166 VarArgBaseDecl
00167 #else
00168 void outputline(char *format,VarArgBase)
00169 #endif
00170 {
00171 VarArgDecl;
00172 VarArgInit(format);
00173 vinfoline(format,output_stream, VarArg);
00174 }
00175 #ifndef OS2_PORT
00176 void traceline(format, VarArgBase)
00177 char *format;
00178 VarArgBaseDecl
00179 #else
00180 void traceline(char *format,VarArgBase)
00181 #endif
00182 {
00183 VarArgDecl;
00184
00185
00186
00187 VarArgInit(format);
00188
00189 if ((trace == 2) && (format[0] != 'p')) return;
00190 tracing();
00191
00192 vinfoline(format, stdout, VarArg);
00193 }
00194 #ifndef OS2_PORT
00195 void infoline(format, VarArgBase)
00196 char *format;
00197 VarArgBaseDecl
00198 #else
00199 void infoline(char *format,VarArgBase)
00200 #endif
00201
00202 {
00203 VarArgDecl;
00204
00205 VarArgInit(format);
00206
00207 vinfoline(format, stdout, VarArg);
00208 }
00209 #ifndef OS2_PORT
00210 void warningline(format, VarArgBase)
00211 char *format;
00212 VarArgBaseDecl
00213 #else
00214 void warningline(char *format,VarArgBase)
00215 #endif
00216 {
00217 VarArgDecl;
00218
00219
00220 VarArgInit(format);
00221
00222 if(quietflag) return;
00223 fprintf(stderr,"*** Warning: ");
00224 vinfoline(format, stderr, VarArg);
00225 }
00226
00227
00228 #ifndef OS2_PORT
00229 void Errorline(format, VarArgBase)
00230 char *format;
00231 VarArgBaseDecl
00232 #else
00233 void Errorline(char *format,VarArgBase)
00234 #endif
00235
00236 {
00237 VarArgDecl;
00238 #ifdef DJD_DEBUG
00239 printf("format = %x %s\n",format,format);fflush(stdout);
00240 #endif
00241
00242 VarArgInit(format);
00243
00244 fprintf(stderr,"*** Error: ");
00245 #ifdef DJD_DEBUG
00246 printf("format2 = %x %s\n",format,format);
00247 #endif
00248 vinfoline(format, stderr, VarArg);
00249
00250 #ifdef CLIFE
00251 exit(0);
00252 #endif
00253 }
00254 #ifndef OS2_PORT
00255 void Syntaxerrorline(format, VarArgBase)
00256 char *format;
00257 VarArgBaseDecl
00258 #else
00259 void Syntaxerrorline(char *format,VarArgBase)
00260 #endif
00261
00262 {
00263 VarArgDecl;
00264
00265 VarArgInit(format);
00266
00267 if(parse_ok) {
00268 parse_ok=FALSE;
00269 fprintf(stderr,"*** Syntax error: ");
00270 vinfoline(format, stderr, VarArg);
00271 }
00272 }
00273
00274
00275
00276
00277
00278
00279
00280 void init_trace()
00281 {
00282 trace=FALSE;
00283 stepflag=FALSE;
00284 stepcount=0;
00285 }
00286
00287
00288
00289 void reset_step()
00290 {
00291 if (stepcount>0) {
00292 stepcount=0;
00293 stepflag=TRUE;
00294 }
00295 }
00296
00297 void tracing()
00298 {
00299 long i;
00300 long indent;
00301
00302 printf("T%04ld",goal_count);
00303 printf(" C%02ld",depth_cs());
00304 indent=depth_gs();
00305 if (indent>=MAX_TRACE_INDENT) printf(" G%02ld",indent);
00306 indent = indent % MAX_TRACE_INDENT;
00307 for (i=indent; i>=0; i--) printf(" ");
00308 steptrace=TRUE;
00309 }
00310
00311
00312 void new_trace(newtrace)
00313 long newtrace;
00314 {
00315 trace = newtrace;
00316 printf("*** Tracing is turned ");
00317 printf(trace?"on.":"off.");
00318 if (trace == 2) printf(" Only for Proves");
00319 printf("\n");
00320 }
00321
00322 void new_step(newstep)
00323 long newstep;
00324 {
00325 stepflag = newstep;
00326 printf("*** Single stepping is turned ");
00327 printf(stepflag?"on.\n":"off.\n");
00328 new_trace(stepflag);
00329 steptrace=FALSE;
00330 }
00331
00332 void set_trace_to_prove()
00333 {
00334 new_trace(2);
00335 }
00336
00337 void toggle_trace()
00338 {
00339 new_trace(trace?0:1);
00340 }
00341
00342
00343 void toggle_step()
00344 {
00345 new_step(!stepflag);
00346 }
00347
00348
00349
00350
00351
00352 void perr(str)
00353 char *str;
00354 {
00355 fprintf(stderr,str);
00356 }
00357
00358 void perr_s(s1,s2)
00359 char *s1,*s2;
00360 {
00361 fprintf(stderr,s1,s2);
00362 }
00363
00364 void perr_s2(s1,s2,s3)
00365 char *s1,*s2,*s3;
00366 {
00367 fprintf(stderr,s1,s2,s3);
00368 }
00369
00370 void perr_i(str,i)
00371 char *str;
00372 long i;
00373 {
00374 fprintf(stderr,str,i);
00375 }
00376
00377
00378 long warning()
00379 {
00380 if (warningflag) perr("*** Warning: ");
00381 return warningflag;
00382 }
00383
00384
00385 long warningx()
00386 {
00387 if (warningflag) perr("*** Warning");
00388 return warningflag;
00389 }
00390
00391
00392
00393 void report_error_main(g,s,s2)
00394 ptr_psi_term g;
00395 char *s, *s2;
00396 {
00397 FILE *f;
00398
00399 perr_s2("*** %s: %s in '",s2,s);
00400 display_psi_stderr(g);
00401 perr("'.\n");
00402 }
00403
00404
00405
00406
00407
00408
00409
00410
00411 void report_error(g,s)
00412 ptr_psi_term g;
00413 char *s;
00414 {
00415 report_error_main(g,s,"Error");
00416 }
00417
00418
00419
00420
00421
00422
00423
00424
00425 long reportAndAbort(g,s)
00426 ptr_psi_term g;
00427 char *s;
00428 {
00429 report_error_main(g,s,"Error");
00430 return abort_life();
00431 }
00432
00433
00434
00435
00436
00437
00438
00439 void report_warning(g,s)
00440 ptr_psi_term g;
00441 char *s;
00442 {
00443 if (warningflag) report_error_main(g,s,"Warning");
00444 }
00445
00446
00447
00448 void report_error2_main(g,s,s2)
00449 ptr_psi_term g;
00450 char *s, *s2;
00451 {
00452 FILE *f;
00453
00454 perr_s("*** %s: argument '",s2);
00455 display_psi_stderr(g);
00456 perr_s("' %s.\n",s);
00457 }
00458
00459
00460
00461
00462
00463
00464
00465 void report_error2(g,s)
00466 ptr_psi_term g;
00467 char *s;
00468 {
00469 report_error2_main(g,s,"Error");
00470 }
00471
00472
00473
00474
00475
00476
00477
00478 void report_warning2(g,s)
00479 ptr_psi_term g;
00480 char *s;
00481 {
00482 if (warningflag) report_error2_main(g,s,"Warning");
00483 }
00484
00485
00486
00487
00488
00489 void nonnum_warning(t,arg1,arg2)
00490 ptr_psi_term t,arg1,arg2;
00491 {
00492 if (!curried &&
00493 ((arg1 && !overlap_type(arg1->type,real)) ||
00494 (arg2 && !overlap_type(arg2->type,real)))) {
00495 report_warning(t,"non-numeric argument(s)");
00496 }
00497 }
00498
00499
00500
00501
00502
00503 long nonint_warning(arg, val, msg)
00504 ptr_psi_term arg;
00505 REAL val;
00506 char *msg;
00507 {
00508 long err=FALSE;
00509
00510 if (val!=floor(val)) {
00511 report_warning2(arg, msg);
00512 err=TRUE;
00513 }
00514 return err;
00515 }
00516
00517 long bit_and_warning(arg, val)
00518 ptr_psi_term arg;
00519 REAL val;
00520 {
00521 return nonint_warning(arg,val,"of bitwise 'and' operation is not an integer");
00522 }
00523
00524 long bit_or_warning(arg, val)
00525 ptr_psi_term arg;
00526 REAL val;
00527 {
00528 return nonint_warning(arg,val,"of bitwise 'or' operation is not an integer");
00529 }
00530
00531 long bit_not_warning(arg, val)
00532 ptr_psi_term arg;
00533 REAL val;
00534 {
00535 return nonint_warning(arg,val,"of bitwise 'not' operation is not an integer");
00536 }
00537
00538 long int_div_warning(arg, val)
00539 ptr_psi_term arg;
00540 REAL val;
00541 {
00542 return nonint_warning(arg,val,"of integer division is not an integer");
00543 }
00544
00545 long mod_warning(arg, val,zero)
00546 ptr_psi_term arg;
00547 REAL val;
00548 int zero;
00549 {
00550 int err;
00551
00552 err=nonint_warning(arg,val,"of modulo operation is not an integer");
00553 if(!err && zero && val==0) {
00554 Errorline("division by 0 in modulo operation\n");
00555 err=TRUE;
00556 }
00557 return err;
00558 }
00559
00560 long shift_warning(dir, arg, val)
00561 long dir;
00562 ptr_psi_term arg;
00563 REAL val;
00564 {
00565 if (dir)
00566 return nonint_warning(arg,val,"of right shift operation is not an integer");
00567 else
00568 return nonint_warning(arg,val,"of left shift operation is not an integer");
00569 }
00570
00571