|
|
1.1 root 1: /*ident "@(#)ctrans:src/main.c 1.12" */
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 Rights 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 <string.h>
25: #include <libc.h>
26: #include <osfcn.h>
27: #include <fstream.h>
28: #include "size.h"
29: #include "cfront.h"
30: #include "tree_dump.h"
31: #include "template.h"
32: #include "hash.h"
33:
34: char* prog_name = "<<AT&T C++ Translator <(3.0)(PT)> 09/22/90>>";
35: char* src_file_name = "";
36: char* line_format = "\n# %d \"%s\"\n";
37:
38: int dump_tree;
39: int tree_dump_brief = 0;
40: dcn_arg dump_tree_arg;
41:
42: #ifdef unix
43: #include <signal.h>
44:
45: static void core_dump(int = 0)
46: {
47: if (error_count)
48: fprintf(stderr,"sorry, cannot recover from previous error\n");
49: else
50: error('i',"bus error (or something nasty like that)");
51: ext(99);
52: }
53: #endif
54:
55: Plist isf_list;
56: Pstmt st_ilist;
57: Pstmt st_dlist;
58: Ptable sti_tbl;
59: Ptable std_tbl;
60: Plist stat_mem_list;
61:
62: int vtbl_opt = -1; // how to deal with vtbls:
63: // -1 static and defined
64: // 0 external and supposed to be defined elsewhere
65: // 1 external and defined
66: int debug_opt;
67: int gplus_opt; // -g to cc, overrides print optimization
68: int ansi_opt;
69: int strict_opt; // disallow features from the anachronism section
70: // of the manual
71: int warning_opt; // produce more warnings if set
72: bit stmtno = 0;
73:
74: extern simpl_init();
75: extern typ_init();
76: extern syn_init();
77: extern lex_init();
78: extern error_init();
79:
80: char *st_name(char*); // generates names of static ctor, dtor callers, ptbl_vec
81: Pname def_name; // first definition in file
82: Pname pdef_name; // used with ptbl_vec if function is first definition
83:
84: int syn_count = 0; // to set conditional breakpoints to find particular expressions
85: Hash *dumper_node_hash_table;
86:
87: void static
88: clean_dumper_hash_table() {
89: if(!dumper_node_hash_table)
90: return;
91: else {
92: HashWalker hi(*dumper_node_hash_table);
93: while(hi.valid ()) {
94: struct node& n = *(struct node*) hi.key();
95: if(n.permanent == 0 || n.permanent == 3) /* flush deleted nodes */
96: dumper_node_hash_table->del(hi.key());
97: hi.advance();
98: }
99: }
100: }
101:
102: void run()
103: /*
104: run the appropriate stages
105: */
106: {
107: Pname n;
108: templp = new templ_compilation; // canonical instance
109:
110:
111: if(dump_tree) {
112: dumper_node_hash_table =
113: dump_tree_arg.nodes_seen_hash = new pointer_hash (10000);
114: dump_tree_arg.verbose = dt_recursive_1;
115: }
116:
117: while (n=syn()) {
118: if (n == Pname(1)) continue;
119: if (n->n_list) PERM(n->tp);
120:
121: DB( if(Rdebug>=1) error('d',"run: syn(): '%s'", n->string););
122: templp->instantiate_ref_templ();
123:
124: for (Pname nx, nn=n; nn; nn=nx) {
125: Pname rr;
126: ++syn_count;
127: nx = nn->n_list;
128: nn->n_list = 0;
129:
130: DB( if(Rdebug>=1) error('d',"run: dcl(): %n, base: %k",nn,nn->base););
131:
132: if ((rr=nn->dcl(gtbl,EXTERN))==0
133: || nn->base==0
134: || error_count) continue;
135:
136: DB( if(Rdebug>=1) error('d',"run: simpl(): %n",nn););
137:
138: nn->simpl();
139:
140: if (error_count) {
141: if(dump_tree) {
142: display_cfront_node (dump_tree_arg, nn);
143: *dump_tree_arg.output_stream << "---------------------------\n\n";
144: }
145: continue;
146: }
147:
148: DB( if(Rdebug>=1) error('d',"run:print(): %n (%k) tp %t",nn,nn->base,nn->tp););
149:
150: if (nn->base == TNAME)
151: nn->dcl_print(0);
152: else {
153: Ptype t = nn->tp;
154: llxx:
155: switch (t->base) {
156: case TYPE:
157: t = Pbase(t)->b_name->tp; goto llxx;
158: case CLASS:
159: DB( if(Rdebug>=1) fprintf(stderr," -- class\n"););
160: if (vtbl_opt==1 || gplus_opt) n->dcl_print(0);
161: break;
162: case ENUM:
163: DB( if(Rdebug>=1) fprintf(stderr," -- enum\n"););
164: Penum(n->tp)->dcl_print(0);
165: break;
166: case FCT:
167: DB( if(Rdebug>=1) error('d'," -- fct%n inline %d body %d",nn,Pfct(t)->f_inline,Pfct(t)->body););
168: if (Pfct(t)->body==0
169: || (debug_opt==0 && Pfct(t)->f_inline && ((n->n_table!=gtbl) || strcmp(nn->string,"main")))
170: || Pfct(t)->f_imeasure && Pfct(t)->f_inline==0) break;
171: DB( if(Rdebug>=1) error('d',"rr %n inline %d body %d",rr,Pfct(rr->tp)->f_inline,Pfct(rr->tp)->body););
172: rr->dcl_print(0);
173: break;
174:
175: default:
176: DB( if(Rdebug>=1) error('d'," -- %n tpbase: %k",nn,nn->tp->base););
177: // print class def, if appropriate
178: // can't use tsizeof() since this may
179: // print an error if class isn't defined
180: { for(Ptype tx = t;;) {
181: switch ( tx->base ) {
182: case VEC:
183: tx=Pvec(tx)->typ;
184: continue;
185: case TYPE: case COBJ:
186: tx=Pbase(tx)->b_name->tp;
187: continue;
188: }
189: Pclass cl = Pclass(tx);
190: if ( cl->base == CLASS
191: && (cl->defined&(DEFINED|SIMPLIFIED))
192: && cl->c_body==1 )
193: cl->dcl_print(0);
194: break;
195: }
196: }
197: nn->dcl_print(0);
198: }
199: }
200:
201: if(dump_tree) {
202: display_cfront_node (dump_tree_arg, nn);
203: *dump_tree_arg.output_stream << "---------------------------\n\n";
204: }
205:
206: if (error_count) continue;
207:
208: DB( if(Rdebug>=1) error('d',"run: cleanup"););
209: switch (nn->tp->base) { // clean up
210: default:
211: {
212: Pexpr i = nn->n_initializer;
213: DB( if(Rdebug>=1) error('d',"default nn %n i %d",nn,i););
214: if (i && i!=Pexpr(1)) {
215: DEL(i);
216: nn->n_initializer = 0;
217: if (def_name==0 && rr->n_scope != STATIC) {
218: def_name = rr;
219: if (pdef_name == 0) ptbl_init(0);
220: }
221: }
222: break;
223: }
224:
225: case FCT:
226: {
227: Pfct f = Pfct(nn->tp);
228: DB( if(Rdebug>=1) error('d', "function nn: %n local_class: %d %d", nn, local_class, f->local_class ););
229: if (f->body
230: && f->f_inline==0
231: && f->f_imeasure==0) {
232: if ( local_class = f->local_class ) {
233: delete_local();
234: local_class = 0;
235: }
236:
237: if (ansi_opt && f->f_this) {
238: f->f_this->n_table = 0;
239: for (Pname n=f->f_this->n_list; n; n=n->n_list)
240: n->n_table = 0;
241: }
242:
243: DEL(f->body);
244: if (def_name==0) {
245: def_name = rr;
246: if (pdef_name == 0) ptbl_init(0);
247: }
248: }
249: break;
250: }
251:
252: case CLASS:
253: { Pclass cl = Pclass(nn->tp);
254: for (Pname px, p=cl->mem_list; p; p=px) {
255: px = p->n_list;
256: if (p->tp) {
257: switch (p->tp->base) {
258: case FCT:
259: { Pfct f = (Pfct)p->tp;
260: if (f->body) {
261: if (f->f_inline==0
262: && f->f_imeasure==0) {
263: if ( local_class = f->local_class ) {
264: delete_local();
265: local_class = 0;
266: }
267: DEL(f->body);
268: f->body = 0;
269: }
270: }
271: }
272: case CLASS:
273: case ENUM:
274: break;
275: case COBJ:
276: case EOBJ:
277: DEL(p);
278: break;
279: default:
280: delete p;
281: }
282: } else {
283: delete p;
284: }
285: } // for
286: cl->mem_list = 0;
287: cl->permanent = 3;
288: break;
289: }
290: }
291: DEL(nn);
292: }
293: lex_clear();
294: if (dump_tree) clean_dumper_hash_table();
295: }
296: templp->end_of_compilation() ;
297:
298: switch (no_of_undcl) {
299: case 1: {error('w',"undeclaredF%n called",undcl);}
300: case 0: break;
301: default: {error('w',"%d undeclaredFs called; for example%n",no_of_undcl,undcl);}
302: }
303:
304: switch (no_of_badcall) {
305: case 1: {error('w',"%n declaredWoutAs calledWAs",badcall);}
306: case 0: break;
307: default: {error('w',"%d Fs declaredWoutAs calledWAs; for example%n",no_of_badcall,badcall);}
308: }
309:
310: if (error_count) return;
311:
312: int i = 1;
313: for (Pname m=gtbl->get_mem(i); m; m=gtbl->get_mem(++i)) {
314: if (m->base==TNAME
315: || m->n_sto==EXTERN
316: || m->n_stclass == ENUM) continue;
317:
318: Ptype t = m->tp;
319: if (t == 0) continue;
320: switch (t->base) {
321: case CLASS:
322: case ENUM:
323: case OVERLOAD: continue;
324: case COBJ:
325: //case ANON:
326: case VEC: break;
327: case FCT:
328: if (Pfct(t)->f_inline || Pfct(t)->body==0) continue;
329: }
330:
331: //error('d',&m->where,"%n %d %d %s",m,m->n_addr_taken,m->n_used,m->n_sto==STATIC?"static":"");
332: //xxx doesn't check anon union members as their use bits are set differently
333: if (m->n_addr_taken==0
334: && m->n_used==0
335: && m->n_sto == STATIC) { // (static or anon?)
336: for(;;) {
337: //error('d',&m->where," %t tconst(): %d",t,t->tconst());
338: if(t->base==TYPE) {
339: if(t->tconst()) break;
340: t=Pbase(t)->b_name->tp;
341: } else if(t->base==VEC) {
342: t=Pvec(t)->typ;
343: } else {
344: if ( t->tconst() == 0 ) {
345: //error('d',"m%n tp%t t%t",m,m->tp,t);
346: if ( t->base != COBJ )
347: error('w',&m->where,"%n defined but not used",m);
348: else { Pclass cl;
349: cl = Pclass(Pbase(t)->b_name->tp);
350: if ( cl->has_ctor()==0 )
351: if ( cl->csu == ANON )
352: ; //error('w',&m->where,"anonymous union defined but not used");
353: else
354: error('w',&m->where,"%n defined but not used",m);
355: }
356: } // if const
357: break;
358: }
359: } // for
360: } // if static and not used
361: }
362:
363: Pname ctor = 0;
364: Pname dtor = 0;
365: --curloc.line;
366:
367: if (st_ilist) { // make an "init" function;
368: // it calls all constructors for static objects
369: DB( if(Rdebug>=1) error('d',"make sti"); );
370: Pname n = new name( st_name("__sti__") );
371: Pfct f = new fct(void_type,0,1);
372: n->tp = f;
373: f->body = new block(st_ilist->where,0,st_ilist);
374: // f->body->s = st_ilist;
375: f->body->memtbl = sti_tbl;
376: n->n_sto = EXTERN;
377: // assignments here are really initializations:
378: ignore_const++;
379: f->f_linkage = linkage_C;
380: f->sign();
381: (void) n->dcl(gtbl,EXTERN);
382: ignore_const--;
383: n->simpl();
384: n->dcl_print(0);
385: ctor = n;
386: }
387:
388: if (st_dlist) { // make a "done" function;
389: // it calls all destructors for static objects
390: DB( if(Rdebug>=1) error('d',"make std"); );
391: Pname n = new name( st_name("__std__") );
392: Pfct f = new fct(void_type,0,1);
393: n->tp = f;
394: f->body = new block(st_dlist->where,0,st_dlist);
395: // f->body->s = st_dlist;
396: f->body->memtbl = std_tbl;
397: n->n_sto = EXTERN;
398: f->f_linkage = linkage_C;
399: f->sign();
400: (void) n->dcl(gtbl,EXTERN);
401: n->simpl();
402: n->dcl_print(0);
403: dtor = n;
404: }
405:
406: #ifdef PATCH
407: /*For fast load: make a static "__link" */
408: if (ctor || dtor)
409: {
410: printf("static struct __linkl { struct __linkl * next;\n");
411: if ( ansi_opt )
412: printf("void (*ctor)(); void (*dtor)(); } __link = \n");
413: else
414: printf("char (*ctor)(); char (*dtor)(); } __link = \n");
415: // printf("{ (struct __linkl *)0, %s, %s };\n",
416: // ctor_name ? ctor_name : "0",
417: // dtor_name ? dtor_name : "0");
418: putstring("{ (struct __linkl *)0, ");
419: if (ctor) ctor->print(); else putch('0');
420: putch(',');
421: if (dtor) dtor->print(); else putch('0');
422: putstring("};\n");
423: }
424: #endif
425:
426: DB( if(Rdebug>=1) error( 'd', "run: vlist: %d", vlist ); );
427: do {
428: for (vl* v = vlist; v; v = v->next) v->cl->really_print(v->vt);
429: vlist = 0;
430:
431: for (Plist l=isf_list; l; l=l->l) {
432: Pname n = l->f;
433: Pfct f = Pfct(n->tp);
434: DB( if(Rdebug>=1)error('d',"isf %n %t f %d addr %d",n,f,f,n->n_addr_taken); );
435: if (f->base == OVERLOAD) {
436: n = Pgen(f)->fct_list->f; // first fct
437: f = Pfct(n->tp);
438: }
439:
440: if (debug_opt==0 &&
441: n->n_addr_taken) {
442: f->f_inline = 0;
443: if (n->n_dcl_printed<2) {
444: if (warning_opt)
445: error('w',"out-of-line copy of %n created",n);
446: n->dcl_print(0);
447: }
448: }
449: }
450: } while (vlist);
451:
452: if (strict_opt == 0) { // define static members
453: // patch for SysV VAX -g linkage botch
454: for (Plist l=stat_mem_list; l; l=l->l) {
455: Pname n = l->f;
456: // error('d',"stat mem %n %d %d ",n,n->n_initializer,n->n_evaluated);
457: if (n->n_initializer==0 && n->n_evaluated==0) {
458: Ptype t = n->tp;
459: n->n_sto = 0;
460: Pname cn = t->is_cl_obj();
461: if (cn==0) cn = cl_obj_vec;
462: if (cn) (void) t->tsizeof(); // be sure to print class
463: if ((cn && Pclass(cn->tp)->has_ctor())
464: || t->is_ref())
465: ; // force explicit definition
466: else
467: n->dcl_print(0);
468: }
469: }
470: }
471:
472: i = 1;
473: for (Pname nm=ptbl->get_mem(i); nm; nm=ptbl->get_mem(++i)) {
474: DB( if(Rdebug>=1) error('d',"ptbl anme %s string2 %s key:%k",nm->string==0?"???":nm->string2,nm->string2==0?"???":nm->string2,nm->n_key); );
475: if ( nm->n_key == 0 ) { // ptbl used in file, generate definition
476: int str1 = (*src_file_name)?strlen(src_file_name)+2:0; // +2 for __
477: int str2 = strlen(nm->string2) - str1;
478: char *ps = new char[ str2 + 1 ];
479: strncpy( ps, nm->string2, str2 ); // grab vtbl name
480: ps[str2]='\0';
481: ps[2] = 'v';
482: fprintf(out_file,"extern struct __mptr %s[];\n",ps);
483: // fprintf(out_file,"struct __mptr* %s = %s;\n",nm->string2,ps);
484: ptbl_add_pair(nm->string2,ps);
485: delete ps;
486: }
487: }
488:
489: ptbl_init(1);
490: curloc.putline();
491: fprintf(out_file,"\n/* the end */\n");
492: }
493:
494:
495: #ifdef DBG
496: int Adebug = 0;
497: int Ddebug = 0;
498: int Edebug = 0;
499: int Kdebug = 0;
500: int Ldebug = 0;
501: int Mdebug = 0;
502: int Ndebug = 0;
503: int Pdebug = 0;
504: int Rdebug = 0;
505: int Sdebug = 0;
506: int Tdebug = 0;
507: //Ydebug == yydebug initialized in y.tab.c
508: void
509: process_debug_flags( char* p )
510: {
511: // arg to +Dxxx or debugging comments //@!xxx
512: // format of xxx == sequence of any combination of
513: // +flags -- increment flags (default)
514: // -flags -- decrement flags
515: // 0flags -- unset flags
516: // where flags are single chars
517: int incr = 1;
518: char c;
519: fprintf(stderr,"\n*** processing debugging flags '%s'\n",p);
520: while ( c = *p++ ) {
521: switch ( c ) {
522: case '+': incr = 1; break;
523: case '-': incr = -1; break;
524: case '0': incr = 0; break;
525: case ' ': break;
526: // flags...
527: case 'A': if(incr==0) Adebug=0; else Adebug+=incr; break;
528: case 'D': if(incr==0) Ddebug=0; else Ddebug+=incr; break;
529: case 'E': if(incr==0) Edebug=0; else Edebug+=incr; break;
530: case 'K': if(incr==0) Kdebug=0; else Kdebug+=incr; break;
531: case 'L': if(incr==0) Ldebug=0; else Ldebug+=incr; break;
532: case 'M': if(incr==0) Mdebug=0; else Mdebug+=incr; break;
533: case 'N': if(incr==0) Ndebug=0; else Ndebug+=incr; break;
534: case 'P': if(incr==0) Pdebug=0; else Pdebug+=incr; break;
535: case 'R': if(incr==0) Rdebug=0; else Rdebug+=incr; break;
536: case 'S': if(incr==0) Sdebug=0; else Sdebug+=incr; break;
537: case 'T': if(incr==0) Tdebug=0; else Tdebug+=incr; break;
538: case 'Y': if(incr==0) Ydebug=0; else Ydebug+=incr; break;
539: default: error('w',"unknown debugging flag '%c'",c);
540: }
541: }
542: }
543: #endif /*DBG*/
544:
545: int no_of_undcl, no_of_badcall;
546: Pname undcl, badcall;
547:
548: void pt_option(char * ostr)
549: { // options +O[BTo] for PT
550: ostr ++; /* skip the O */
551: switch(*ostr) {
552: default:
553: fprintf(stderr, "cfront: argument syntax: invalidZizedTs option (+O[BTo].");
554: exit(11);
555: case 'B':
556: tree_dump_brief = 1;
557: case 'T':
558: dump_tree = 1;
559: if(0 == *(ostr + 1) || strcmp (ostr, "T-") == 0)
560: dump_tree_arg.output_stream = (ostream*)&cout;
561: else {
562: dump_tree_arg.output_stream
563: = new ofstream (ostr+1, ios::out);
564: if(dump_tree_arg.output_stream->fail()) {
565: perror ("cfront");
566: fprintf (stderr, "Failed to open %s\n", ostr + 1);
567: exit (11);
568: }
569: }
570: break;
571: case 'o':
572: out_file = fopen (ostr+1, "w");
573: if(out_file == NULL) {
574: perror ("cfront");
575: fprintf(stderr, "Failed to open %s\n", ostr+1);
576: exit(11);
577: }
578: break;
579: }
580: }
581:
582: main(int argc, char* argv[])
583: /*
584: read options, initialize, and run
585: */
586: {
587: register char * cp;
588: char* afile = "";
589: #ifdef unix
590:
591: #ifdef COMPLETE_SIG_PF
592: signal(SIGILL,core_dump);
593: signal(SIGIOT,core_dump);
594: signal(SIGEMT,core_dump);
595: signal(SIGFPE,core_dump);
596: signal(SIGBUS,core_dump);
597: signal(SIGSEGV,core_dump);
598: #else
599: typedef void (*ST)(int ...); // trick to circumvent problems with old
600: ST sick = ST(&signal); // (or C) versions <signal.h>
601: (*sick)(SIGILL,core_dump);
602: (*sick)(SIGIOT,core_dump);
603: (*sick)(SIGEMT,core_dump);
604: (*sick)(SIGFPE,core_dump);
605: (*sick)(SIGBUS,core_dump);
606: (*sick)(SIGSEGV,core_dump);
607:
608: #endif
609: #endif
610:
611: // SUM: not needed
612: // #ifdef apollo
613: // set_sbrk_size(1000000); // resets free store size
614: //#else
615: #ifndef apollo
616: //(void) malloc(0); // suppress cashing in V8 malloc
617: #endif
618:
619: error_init();
620:
621: for (int i=1; i<argc; ++i) {
622: switch (*(cp=argv[i])) {
623: case '+':
624: while (*++cp) {
625: switch(*cp) {
626: case 'O':
627: pt_option(cp);
628: goto xx;
629: case 'f':
630: src_file_name = cp+1;
631: goto xx;
632: case 'x': // read cross compilation table
633: if (read_align(afile = cp+1)) {
634: fprintf(stderr,"bad size-table (option +x)\n");
635: exit(11);
636: }
637: goto xx;
638: case 'e':
639: switch (*++cp) {
640: case '0':
641: case '1':
642: vtbl_opt = *cp-'0';
643: break;
644: default:
645: fprintf(stderr,"bad +e option\n");
646: exit(11);
647: }
648: break;
649: case 'd':
650: debug_opt = 1;
651: break;
652: case 'g':
653: gplus_opt = 1;
654: break;
655: case 'D':
656: #ifdef DBG
657: process_debug_flags(++cp);
658: #else
659: error('w',"cfront not compiled for debugging -- +D%s ignored",++cp);
660: #endif
661: goto xx;
662: case 'w':
663: warning_opt = 1;
664: break;
665: case 'a':
666: switch (*++cp) {
667: case '0':
668: case '1':
669: ansi_opt = *cp-'0';
670: break;
671: default:
672: fprintf(stderr,"bad +a option\n");
673: exit(11);
674: }
675: break;
676: case 'p':
677: strict_opt = 1;
678: break;
679: case 'L':
680: line_format = "\n#line %d \"%s\"\n";
681: break;
682: default:
683: fprintf(stderr,"%s: unexpected option: +%c ignored\n",prog_name,*cp);
684:
685: }
686: }
687: xx:
688: break;
689: default:
690: fprintf(stderr,"%s: bad argument \"%s\"\n",prog_name,cp);
691: exit(11);
692: }
693: }
694:
695:
696: fprintf(out_file,line_format+1,1,src_file_name); // strips leading \n
697: fprintf(out_file,"\n/* %s */\n",prog_name);
698: if (*src_file_name) fprintf(out_file,"/* < %s > */\n",src_file_name);
699:
700: // if (Nspy) {
701: // start_time = time(0);
702: // print_align(afile);
703: // }
704: fflush(stderr);
705: otbl_init();
706: lex_init();
707: syn_init();
708: typ_init();
709: simpl_init();
710: scan_started = 1;
711: curloc.putline();
712: if ((BI_IN_BYTE==0) && (SZ_INT==0) && (SZ_WPTR==0))
713: error("no size/alignment values - use +x of provide #ifdef in size.h");
714: run();
715: if(dump_tree) {
716: ostream_printf(*dump_tree_arg.output_stream, "------------ GTBL ------------\n\n");
717: display_cfront_node (dump_tree_arg, ktbl);
718: ostream_printf(*dump_tree_arg.output_stream, "------------ KTBL ------------\n\n");
719: display_cfront_node (dump_tree_arg, ktbl);
720: }
721:
722: // if (Nspy) {
723: // stop_time = time(0);
724: // spy(src_file_name);
725: // }
726: exit( (0<=error_count && error_count<127) ? error_count : 127);
727: }
728:
729: char* st_name(char* pref)
730: /*
731: make name "pref|source_file_name|_" or "pref|source_file_name|_"
732: where non alphanumeric characters are replaced with '_'
733: and add def_name at end to ensure uniqueness
734: */
735: {
736: int prefl = strlen(pref);
737: int strl = prefl + 2; // trailing '_' and 0
738: if (*src_file_name) strl += strlen(src_file_name);
739: char* defs;
740: int defl;
741: if (def_name) {
742: defs = def_name->string;
743: defl = strlen(defs)+1; // '_'
744: }
745: else {
746: defs = 0;
747: defl = 0;
748: }
749: char* name = new char[strl+defl];
750: strcpy(name,pref);
751: if (*src_file_name) strcpy(name+prefl,src_file_name);
752: name[strl-2] = '_';
753: name[strl-1] = 0;
754: // char *p = name;
755: // while ( *++p ) if (!isalpha(*p) && !isdigit(*p)) *p = '_';
756: for (char* p = name; *p; p++) if (!isalpha(*p) && !isdigit(*p)) *p = '_';
757: if (defs) {
758: strcpy(name+strl-1,defs); // after the '_'
759: name[strl+defl-2] = '_';
760: name[strl+defl-1] = 0;
761: }
762: #ifdef DENSE
763: void chop(char*);
764: chop(name);
765: #endif
766:
767: return name;
768: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.