|
|
1.1 ! root 1: /*ident "@(#)ctrans:src/main.c 1.6.7.37" */ ! 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: main.c: ! 11: ! 12: Initialize global environment ! 13: Read argument line ! 14: Start compilation ! 15: Clean up and exit ! 16: ! 17: **************************************************************************/ ! 18: ! 19: #ifdef __cplusplus ! 20: #include <stdlib.h> ! 21: #endif ! 22: ! 23: #include <ctype.h> ! 24: #include "cfront.h" ! 25: ! 26: char* prog_name = "<<AT&T C++ Translator 2.00 06/30/89>>"; ! 27: char* src_file_name; ! 28: char* line_format = "\n# %d \"%s\"\n"; ! 29: ! 30: #ifdef unix ! 31: #include <signal.h> ! 32: ! 33: static void core_dump(int = 0) ! 34: { ! 35: if (error_count) ! 36: fprintf(stderr,"sorry, cannot recover from previous error\n"); ! 37: else { ! 38: extern void print_loc(); ! 39: print_loc(); ! 40: error('i',"bus error (or something nasty like that)"); ! 41: } ! 42: ext(99); ! 43: } ! 44: #endif ! 45: ! 46: Plist isf_list; ! 47: Pstmt st_ilist; ! 48: Pstmt st_dlist; ! 49: Ptable sti_tbl; ! 50: Ptable std_tbl; ! 51: Plist stat_mem_list; ! 52: ! 53: int Nfile;// = 1; ! 54: int vtbl_opt = -1; // how to deal with vtbls: ! 55: // -1 static and defined ! 56: // 0 external and supposed to be defined elsewhere ! 57: // 1 external and defined ! 58: int debug_opt; ! 59: int ansi_opt; ! 60: int strict_opt; // disallow features from the anachronism section ! 61: // of the manual ! 62: int warning_opt; // produce more warnings if set ! 63: ! 64: extern simpl_init(); ! 65: extern typ_init(); ! 66: extern syn_init(); ! 67: extern lex_init(); ! 68: extern error_init(); ! 69: ! 70: static char *st_name(char*); // generates names of static ctor, dtor callers ! 71: static Pname def_name; ! 72: ! 73: void run() ! 74: /* ! 75: run the appropriate stages ! 76: */ ! 77: { ! 78: Pname n; ! 79: ! 80: while (n=syn()) { ! 81: if (n == Pname(1)) continue; ! 82: if (n->n_list) PERM(n->tp); ! 83: ! 84: //printf( "\nrun: syn(): %s", n->string ); ! 85: ! 86: for (Pname nx, nn=n; nn; nn=nx) { ! 87: Pname rr; ! 88: nx = nn->n_list; ! 89: nn->n_list = 0; ! 90: ! 91: //error('d',"run: dcl(): %s",nn->string); ! 92: ! 93: if ((rr=nn->dcl(gtbl,EXTERN))==0 ! 94: || nn->base==0 ! 95: || error_count) continue; ! 96: ! 97: //error('d',"run: simpl(): %n",nn); ! 98: ! 99: nn->simpl(); ! 100: ! 101: if (error_count) continue; ! 102: ! 103: //error('d',"run:print(): %n (%k) tp %t",nn,nn->base,nn->tp); ! 104: ! 105: if (nn->base == TNAME) ! 106: nn->dcl_print(0); ! 107: else { ! 108: Ptype t = nn->tp; ! 109: llxx: ! 110: switch (t->base) { ! 111: case TYPE: ! 112: t = Pbase(t)->b_name->tp; goto llxx; ! 113: case CLASS: ! 114: if (vtbl_opt==1) n->dcl_print(0); ! 115: break; ! 116: case ENUM: ! 117: Penum(n->tp)->dcl_print(0); ! 118: break; ! 119: case FCT: ! 120: //error('d',"fct%n inline %d body %d",nn,Pfct(t)->f_inline,Pfct(t)->body); ! 121: if (Pfct(t)->body==0 ! 122: || (debug_opt==0 && Pfct(t)->f_inline) ! 123: || Pfct(t)->f_imeasure && Pfct(t)->f_inline==0) break; ! 124: //error('d',"rr %n inline %d body %d",rr,Pfct(rr->tp)->f_inline,Pfct(rr->tp)->body); ! 125: rr->dcl_print(0); ! 126: break; ! 127: ! 128: default: ! 129: nn->dcl_print(0); ! 130: } ! 131: } ! 132: ! 133: if (error_count) continue; ! 134: ! 135: switch (nn->tp->base) { // clean up ! 136: default: ! 137: { Pexpr i = nn->n_initializer; ! 138: //error('d',"default nn %n i %d",nn,i); ! 139: if (i && i!=Pexpr(1)) { ! 140: DEL(i); ! 141: nn->n_initializer = 0; ! 142: if (def_name==0) def_name = rr; ! 143: } ! 144: break; ! 145: } ! 146: ! 147: case FCT: ! 148: { ! 149: Pfct f = Pfct(nn->tp); ! 150: if (f->body ! 151: && f->f_inline==0 ! 152: && f->f_imeasure==0) { ! 153: extern void delete_local(); ! 154: // error('d', "main() nn: %n local_class: %d %d", nn, local_class, f->local_class ); ! 155: // modification for local classes defined within inline functions ! 156: if ( local_class = f->local_class ) { ! 157: delete_local(); ! 158: local_class = 0; ! 159: } ! 160: DEL(f->body); ! 161: if (def_name==0) def_name = rr; ! 162: } ! 163: break; ! 164: } ! 165: ! 166: case CLASS: ! 167: { Pclass cl = Pclass(nn->tp); ! 168: for (Pname px, p=cl->mem_list; p; p=px) { ! 169: px = p->n_list; ! 170: if (p->tp) ! 171: switch (p->tp->base) { ! 172: case FCT: ! 173: { Pfct f = (Pfct)p->tp; ! 174: if (f->body) { ! 175: if (f->f_inline==0 ! 176: && f->f_imeasure==0) { ! 177: extern void delete_local(); ! 178: // error('d', "main() member_fct nn: %n local_class: %d", nn, f->local_class ); ! 179: // modification for local classes defined within inline functions ! 180: if ( local_class = f->local_class ) { ! 181: delete_local(); ! 182: local_class = 0; ! 183: } ! 184: DEL(f->body); ! 185: f->body = 0; ! 186: } ! 187: } ! 188: } ! 189: case CLASS: ! 190: case ENUM: ! 191: break; ! 192: case COBJ: ! 193: case EOBJ: ! 194: DEL(p); ! 195: break; ! 196: default: ! 197: delete p; ! 198: } ! 199: else { ! 200: delete p; ! 201: } ! 202: } ! 203: cl->mem_list = 0; ! 204: cl->permanent = 3; ! 205: break; ! 206: } ! 207: } ! 208: DEL(nn); ! 209: } ! 210: lex_clear(); ! 211: } ! 212: ! 213: switch (no_of_undcl) { ! 214: case 1: {error('w',"undeclaredF%n called",undcl);} ! 215: case 0: break; ! 216: default: {error('w',"%d undeclaredFs called; for example%n",no_of_undcl,undcl);} ! 217: } ! 218: ! 219: switch (no_of_badcall) { ! 220: case 1: {error('w',"%n declaredWoutAs calledWAs",badcall);} ! 221: case 0: break; ! 222: default: {error('w',"%d Fs declaredWoutAs calledWAs; for example%n",no_of_badcall,badcall);} ! 223: } ! 224: ! 225: if (error_count) return; ! 226: ! 227: int i = 1; ! 228: for (Pname m=gtbl->get_mem(i); m; m=gtbl->get_mem(++i)) { ! 229: if (m->base==TNAME ! 230: || m->n_sto==EXTERN ! 231: || m->n_stclass == ENUM) continue; ! 232: ! 233: Ptype t = m->tp; ! 234: if (t == 0) continue; ! 235: ll: ! 236: switch (t->base) { ! 237: case TYPE: t=Pbase(t)->b_name->tp; goto ll; ! 238: case CLASS: ! 239: case ANON: ! 240: case ENUM: ! 241: case COBJ: ! 242: case OVERLOAD: ! 243: case VEC: continue; ! 244: case FCT: ! 245: if (Pfct(t)->f_inline || Pfct(t)->body==0) continue; ! 246: } ! 247: ! 248: if (m->n_addr_taken==0 ! 249: && m->n_used==0 ! 250: && m->tp->tconst()==0 ! 251: && m->n_sto == STATIC) ! 252: error('w',&m->where,"%n defined but not used",m); ! 253: } ! 254: ! 255: Pname ctor = 0; ! 256: Pname dtor = 0; ! 257: --curloc.line; ! 258: ! 259: if (st_ilist) { // make an "init" function; ! 260: // it calls all constructors for static objects ! 261: Pname n = new name( st_name("__sti__") ); ! 262: Pfct f = new fct(void_type,0,1); ! 263: n->tp = f; ! 264: f->body = new block(st_ilist->where,0,st_ilist); ! 265: // f->body->s = st_ilist; ! 266: f->body->memtbl = sti_tbl; ! 267: n->n_sto = EXTERN; ! 268: // assignments here are really initializations: ! 269: extern int ignore_const; ! 270: ignore_const++; ! 271: set_linkage("C"); ! 272: (void) n->dcl(gtbl,EXTERN); ! 273: set_linkage(0); ! 274: ignore_const--; ! 275: n->simpl(); ! 276: n->dcl_print(0); ! 277: ctor = n; ! 278: } ! 279: ! 280: if (st_dlist) { // make a "done" function; ! 281: // it calls all destructors for static objects ! 282: Pname n = new name( st_name("__std__") ); ! 283: Pfct f = new fct(void_type,0,1); ! 284: n->tp = f; ! 285: f->body = new block(st_dlist->where,0,st_dlist); ! 286: // f->body->s = st_dlist; ! 287: f->body->memtbl = std_tbl; ! 288: n->n_sto = EXTERN; ! 289: set_linkage("C"); ! 290: (void) n->dcl(gtbl,EXTERN); ! 291: set_linkage(0); ! 292: n->simpl(); ! 293: n->dcl_print(0); ! 294: dtor = n; ! 295: } ! 296: ! 297: ! 298: #ifdef PATCH ! 299: /*For fast load: make a static "__link" */ ! 300: if (ctor || dtor) ! 301: { ! 302: printf("static struct __linkl { struct __linkl * next;\n"); ! 303: printf("char (*ctor)(); char (*dtor)(); } __link = \n"); ! 304: // printf("{ (struct __linkl *)0, %s, %s };\n", ! 305: // ctor_name ? ctor_name : "0", ! 306: // dtor_name ? dtor_name : "0"); ! 307: putstring("{ (struct __linkl *)0, "); ! 308: if (ctor) ctor->print(); else putch('0'); ! 309: putch(','); ! 310: if (dtor) dtor->print(); else putch('0'); ! 311: putstring("};\n"); ! 312: } ! 313: #endif ! 314: ! 315: // error( 'd', "run: vlist: %d", vlist ); ! 316: do { ! 317: for (vl* v = vlist; v; v = v->next) v->cl->really_print(v->vt); ! 318: vlist = 0; ! 319: ! 320: for (Plist l=isf_list; l; l=l->l) { ! 321: Pname n = l->f; ! 322: Pfct f = Pfct(n->tp); ! 323: //error('d',"isf %n %t f %d addr %d",n,f,f,n->n_addr_taken); ! 324: if (f->base == OVERLOAD) { ! 325: n = Pgen(f)->fct_list->f; // first fct ! 326: f = Pfct(n->tp); ! 327: } ! 328: ! 329: if (debug_opt==0 && n->n_addr_taken) { ! 330: f->f_inline = 0; ! 331: if (n->n_dcl_printed<2) n->dcl_print(0); ! 332: } ! 333: } ! 334: } while (vlist); ! 335: ! 336: if (strict_opt == 0) { // define static members ! 337: // patch for SysV VAX -g linkage botch ! 338: for (Plist l=stat_mem_list; l; l=l->l) { ! 339: Pname n = l->f; ! 340: //error('d',"stat mem %n %d %d ",n,n->n_initializer,n->n_evaluated); ! 341: if (n->n_initializer==0 && n->n_evaluated==0) { ! 342: Ptype t = n->tp; ! 343: n->n_sto = 0; ! 344: Pname cn = t->is_cl_obj(); ! 345: if (cn) (void) t->tsizeof(); // be sure to print class ! 346: if ((cn && Pclass(cn->tp)->has_ctor()) ! 347: || t->is_ref()) ! 348: ; // force explicit definition ! 349: else ! 350: n->dcl_print(0); ! 351: } ! 352: } ! 353: } ! 354: ! 355: curloc.putline(); ! 356: fprintf(out_file,"\n/* the end */\n"); ! 357: } ! 358: ! 359: char* afile = ""; ! 360: ! 361: int no_of_undcl, no_of_badcall; ! 362: Pname undcl, badcall; ! 363: ! 364: main(int argc, char* argv[]) ! 365: /* ! 366: read options, initialize, and run ! 367: */ ! 368: { ! 369: register char * cp; ! 370: #ifdef unix ! 371: ! 372: #ifdef COMPLETE_SIG_PF ! 373: signal(SIGILL,core_dump); ! 374: signal(SIGIOT,core_dump); ! 375: signal(SIGEMT,core_dump); ! 376: signal(SIGFPE,core_dump); ! 377: signal(SIGBUS,core_dump); ! 378: signal(SIGSEGV,core_dump); ! 379: #else ! 380: typedef void (*ST)(int ...); // trick to circumvent problems with old ! 381: ST sick = ST(&signal); // (or C) versions <signal.h> ! 382: (*sick)(SIGILL,core_dump); ! 383: (*sick)(SIGIOT,core_dump); ! 384: (*sick)(SIGEMT,core_dump); ! 385: (*sick)(SIGFPE,core_dump); ! 386: (*sick)(SIGBUS,core_dump); ! 387: (*sick)(SIGSEGV,core_dump); ! 388: ! 389: #endif ! 390: #endif ! 391: ! 392: // SUM: not needed ! 393: // #ifdef apollo ! 394: // set_sbrk_size(1000000); // resets free store size ! 395: //#else ! 396: #ifndef apollo ! 397: (void) malloc(0); // suppress cashing in V8 malloc ! 398: #endif ! 399: ! 400: error_init(); ! 401: ! 402: for (int i=1; i<argc; ++i) { ! 403: switch (*(cp=argv[i])) { ! 404: case '+': ! 405: while (*++cp) { ! 406: switch(*cp) { ! 407: case 'f': ! 408: src_file_name = cp+1; ! 409: goto xx; ! 410: case 'x': // read cross compilation table ! 411: if (read_align(afile = cp+1)) { ! 412: fprintf(stderr,"bad size-table (option +x)\n"); ! 413: exit(11); ! 414: } ! 415: goto xx; ! 416: case 'e': ! 417: switch (*++cp) { ! 418: case '0': ! 419: case '1': ! 420: vtbl_opt = *cp-'0'; ! 421: break; ! 422: default: ! 423: fprintf(stderr,"bad +e option\n"); ! 424: exit(11); ! 425: } ! 426: break; ! 427: case 'd': ! 428: debug_opt = 1; ! 429: break; ! 430: case 'w': ! 431: warning_opt = 1; ! 432: break; ! 433: case 'a': ! 434: switch (*++cp) { ! 435: case '0': ! 436: case '1': ! 437: ansi_opt = *cp-'0'; ! 438: break; ! 439: default: ! 440: fprintf(stderr,"bad +a option\n"); ! 441: exit(11); ! 442: } ! 443: break; ! 444: case 'p': ! 445: strict_opt = 1; ! 446: break; ! 447: case 'L': ! 448: line_format = "\n#line %d \"%s\"\n"; ! 449: break; ! 450: default: ! 451: fprintf(stderr,"%s: unexpected option: +%c ignored\n",prog_name,*cp); ! 452: ! 453: } ! 454: } ! 455: xx: ! 456: break; ! 457: default: ! 458: fprintf(stderr,"%s: bad argument \"%s\"\n",prog_name,cp); ! 459: exit(11); ! 460: } ! 461: } ! 462: ! 463: ! 464: fprintf(out_file,line_format+1,1,src_file_name?src_file_name:""); // strips leading \n ! 465: fprintf(out_file,"\n/* %s */\n",prog_name); ! 466: if (src_file_name) fprintf(out_file,"/* < %s > */\n",src_file_name); ! 467: ! 468: // if (Nspy) { ! 469: // start_time = time(0); ! 470: // print_align(afile); ! 471: // } ! 472: fflush(stderr); ! 473: otbl_init(); ! 474: lex_init(); ! 475: syn_init(); ! 476: typ_init(); ! 477: simpl_init(); ! 478: scan_started = 1; ! 479: curloc.putline(); ! 480: run(); ! 481: // if (Nspy) { ! 482: // stop_time = time(0); ! 483: // spy(src_file_name); ! 484: // } ! 485: exit( (0<=error_count && error_count<127) ? error_count : 127); ! 486: } ! 487: ! 488: char* st_name(char* pref) ! 489: /* ! 490: make name "pref|source_file_name|_" or "pref|source_file_name|_" ! 491: where non alphanumeric characters are replaced with '_' ! 492: and add def_name at end to ensure uniqueness ! 493: */ ! 494: { ! 495: int prefl = strlen(pref); ! 496: int strl = prefl + 2; // trailing '_' and 0 ! 497: if (src_file_name) strl += strlen(src_file_name); ! 498: char* defs; ! 499: int defl; ! 500: if (def_name) { ! 501: defs = def_name->string; ! 502: defl = strlen(defs)+1; // '_' ! 503: } ! 504: else { ! 505: defs = 0; ! 506: defl = 0; ! 507: } ! 508: char* name = new char[strl+defl]; ! 509: strcpy(name,pref); ! 510: if (src_file_name) strcpy(name+prefl,src_file_name); ! 511: name[strl-2] = '_'; ! 512: name[strl-1] = 0; ! 513: // char *p = name; ! 514: // while ( *++p ) if (!isalpha(*p) && !isdigit(*p)) *p = '_'; ! 515: for (char* p = name; *p; p++) if (!isalpha(*p) && !isdigit(*p)) *p = '_'; ! 516: if (defs) { ! 517: strcpy(name+strl-1,defs); // after the '_' ! 518: name[strl+defl-2] = '_'; ! 519: name[strl+defl-1] = 0; ! 520: } ! 521: #ifdef DENSE ! 522: void chop(char*); ! 523: chop(name); ! 524: #endif ! 525: ! 526: return name; ! 527: } ! 528:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.