|
|
1.1 ! root 1: /*ident "@(#)ctrans:src/error.c 1.1.3.15" */ ! 2: /************************************************************************** ! 3: ! 4: C++ source for cfront, the C++ compiler front-end ! 5: written in the computer science research center of Bell Labs ! 6: ! 7: Copyright (c) 1984 AT&T, Inc. All rigths Reserved ! 8: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC. ! 9: ! 10: error.c : ! 11: ! 12: write error messages ! 13: ! 14: Until scan_started != 0 no context can be assumed ! 15: ! 16: ***************************************************************************/ ! 17: ! 18: #ifdef __cplusplus ! 19: #include <stdlib.h> ! 20: #endif ! 21: ! 22: #include "cfront.h" ! 23: #include "size.h" ! 24: #include "template.h" ! 25: ! 26: int error_count; ! 27: static int no_of_warnings; ! 28: char scan_started; ! 29: extern char emode; ! 30: ! 31: #define ERRTRACE 20 ! 32: ! 33: static char* abbrev_tbl[] = { ! 34: " argument", ! 35: " base", ! 36: " class", ! 37: " declaration", ! 38: " expression", ! 39: " function", ! 40: "G", ! 41: "H", ! 42: " initialize", ! 43: "J", ! 44: " constructor", // 'K' ! ! 45: " list", ! 46: " member", ! 47: " name", ! 48: " object", ! 49: " pointer", ! 50: " qualifie", ! 51: " reference", ! 52: " statement", ! 53: " type", ! 54: " undefined", ! 55: " variable", ! 56: " with", ! 57: " expected", // 'X' ! 58: "Y", ! 59: "Z", ! 60: }; ! 61: ! 62: ea* ea0; ! 63: ! 64: void error_init() ! 65: { ! 66: static char errbuf[BUFSIZ]; ! 67: setbuf(stderr,errbuf); ! 68: ea0 = new ea; ! 69: } ! 70: ! 71: #define INTERNAL 127 ! 72: ! 73: void ext(int n) ! 74: { ! 75: int useit=n; // to avoid n not used warning during build ! 76: // for testing only ! 77: // if (n == INTERNAL) ! 78: // abort(); ! 79: exit(error_count?error_count:1); ! 80: } ! 81: ! 82: void print_loc() ! 83: { ! 84: loc* sl = (Cstmt) ? &Cstmt->where : 0; ! 85: loc* dl = (Cdcl && (Cdcl->base==NAME || Cdcl->base==TNAME)) ? &Cdcl->where : 0; ! 86: if (sl && dl && sl->file==dl->file) { // Cstmt and Cdcl in same file ! 87: if (sl->line<=dl->line) { ! 88: if (curloc.file==dl->file && curloc.line<dl->line) ! 89: // hack to compensate for YACC's ! 90: // bad manners in the use of line numbers ! 91: sl->put(out_file); ! 92: else ! 93: dl->put(out_file); ! 94: } ! 95: else ! 96: sl->put(out_file); ! 97: } ! 98: else if (sl && sl->file==curr_file) // Cstmt in current file ! 99: sl->put(out_file); ! 100: else if (dl && dl->file==curr_file) // Cdcl in current file ! 101: dl->put(out_file); ! 102: else ! 103: curloc.put(out_file); ! 104: } ! 105: ! 106: static void print_context() ! 107: { ! 108: putc('\n',out_file); ! 109: } ! 110: ! 111: static char in_error = 0; ! 112: loc dummy_loc; ! 113: ! 114: void yyerror(char* s) ! 115: { ! 116: error(s); ! 117: } ! 118: ! 119: int error(const char* s) ! 120: { ! 121: return error(0,s); ! 122: } ! 123: ! 124: int error(int t, const char* s) ! 125: { ! 126: return error(t,&dummy_loc,s,*ea0,*ea0,*ea0,*ea0); ! 127: } ! 128: ! 129: int error(const char* s, const ea& a0, const ea& a1, const ea& a2, const ea& a3) ! 130: { ! 131: return error(0,&dummy_loc,s,a0,a1,a2,a3); ! 132: } ! 133: ! 134: int error(loc* lc, const char* s, const ea& a0, const ea& a1, const ea& a2, const ea& a3) ! 135: { ! 136: return error(0,lc,s,a0,a1,a2,a3); ! 137: } ! 138: ! 139: int error(int t, const char* s, const ea& a0, const ea& a1, const ea& a2, const ea& a3) ! 140: { ! 141: return error(t,&dummy_loc,s,a0,a1,a2,a3); ! 142: } ! 143: ! 144: int suppress_error; ! 145: ! 146: int error(int t, loc* lc, const char* s, const ea& a0, const ea& a1, const ea& a2, const ea& a3) ! 147: /* ! 148: "int" not "void" because of "pch" in lex.c ! 149: ! 150: legal error types are: ! 151: 'w' warning (not counted in error count) ! 152: 'd' debug ! 153: 's' "not implemented" message ! 154: 'l' "compiler limit exceeded" message ! 155: 0 error ! 156: 'i' internal error (causes abort) ! 157: 't' error while printing error message ! 158: */ ! 159: { ! 160: if (suppress_error) return 0; ! 161: ! 162: if (in_error++) ! 163: if (t == 't') ! 164: t = 'i'; ! 165: else if (4 < in_error) { ! 166: fprintf(stderr,"\nOops!, error while handling error\n"); ! 167: ext(13); ! 168: } ! 169: ! 170: FILE * of = out_file; ! 171: out_file = stderr; ! 172: ! 173: if (!scan_started || t=='t') ! 174: putch('\n'); ! 175: else if (lc != &dummy_loc) ! 176: lc->put(out_file); ! 177: else ! 178: print_loc(); ! 179: ! 180: switch (t) { ! 181: case 0: ! 182: putstring("error: "); ! 183: break; ! 184: case 'w': ! 185: no_of_warnings++; ! 186: putstring("warning: "); ! 187: break; ! 188: case 'l': ! 189: putstring("compiler limit exceeded: "); ! 190: break; ! 191: case 's': ! 192: putstring("sorry, not implemented: "); ! 193: break; ! 194: case 'i': ! 195: if (error_count++) { ! 196: fprintf(out_file,"sorry, %s cannot recover from earlier errors\n",prog_name); ! 197: ext(INTERNAL); ! 198: } ! 199: else ! 200: fprintf(out_file,"internal %s error: ",prog_name); ! 201: } ! 202: ! 203: ea argv[4]; ! 204: ea* a = argv; ! 205: argv[0] = a0; ! 206: argv[1] = a1; ! 207: argv[2] = a2; ! 208: argv[3] = a3; ! 209: ! 210: int c; ! 211: ! 212: while (c = *s++) { ! 213: if ('A'<=c && c<='Z') ! 214: putstring(abbrev_tbl[c-'A']); ! 215: else if (c == '%') { ! 216: switch (c = *s++) { ! 217: case 'k': // TOK assumed passed as an int ! 218: { TOK x = TOK(a->i); ! 219: if (0<x && x<=MAXTOK && keys[x]) ! 220: fprintf(out_file," %s",keys[x]); ! 221: else ! 222: fprintf(out_file," token(%d)",x); ! 223: break; ! 224: } ! 225: case 't': // Ptype ! 226: { Ptype tt = Ptype(a->p); ! 227: if (tt == 0) break; ! 228: ! 229: putch(' '); ! 230: ! 231: extern int ntok; ! 232: int nt = ntok; ! 233: emode = 1; ! 234: tt->dcl_print(0); ! 235: emode = 0; ! 236: ntok = nt; ! 237: break; ! 238: } ! 239: case 'n': // Pname ! 240: { Pname nn = Pname(a->p); ! 241: if (nn && nn->string) { ! 242: // suppress generated class names: ! 243: if (nn->string[0]=='_' ! 244: && nn->string[1]=='_' ! 245: && nn->string[2]=='C') break; ! 246: emode = 1; ! 247: putch(' '); ! 248: nn->print(); ! 249: emode = 0; ! 250: } ! 251: else ! 252: putstring(" ?"); ! 253: break; ! 254: } ! 255: case 'p': // pointer ! 256: { char* f = sizeof(char*)==sizeof(int)?" %d":" %ld"; ! 257: fprintf(out_file,f,a->p); ! 258: break; ! 259: } ! 260: case 'c': // char assumed passed as an int ! 261: putch(a->i); ! 262: break; ! 263: ! 264: case 'd': // int ! 265: fprintf(out_file," %d",a->i); ! 266: break; ! 267: ! 268: case 's': // char* ! 269: char *s = ((char *)a->p); ! 270: if ( s ) ! 271: putst((char*)a->p); ! 272: break; ! 273: } ! 274: a++; ! 275: } ! 276: else ! 277: putch(c); ! 278: } ! 279: ! 280: if (!scan_started && t!='d') ext(4); ! 281: /* ! 282: switch (t) { ! 283: case 'd': ! 284: case 't': ! 285: case 'w': ! 286: putch('\n'); ! 287: break; ! 288: default: ! 289: */ ! 290: print_context(); ! 291: /* ! 292: } ! 293: */ ! 294: templ_inst::head->print_error_loc() ; ! 295: ! 296: fflush(stderr); ! 297: /* now we may want to carry on */ ! 298: ! 299: out_file = of; ! 300: ! 301: switch (t) { ! 302: case 't': ! 303: if (--in_error) return 0; ! 304: case 'i': ! 305: ext(INTERNAL); ! 306: case 0: ! 307: case 'l': ! 308: case 's': ! 309: if (MAXERR<++error_count) { ! 310: fprintf(stderr,"Sorry, too many errors\n"); ! 311: ext(7); ! 312: } ! 313: } ! 314: ! 315: in_error = 0; ! 316: return 0; ! 317: } ! 318: /* ODI Notes - ! 319: template expansion context ! 320: */ ! 321:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.