|
|
1.1 ! root 1: /*ident "@(#)ctrans:src/cfront.h 1.2.5.35" */ ! 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: When reading cfront code please remember that C++ was not available ! 11: when it was originally written. Out of necessity cfront is written ! 12: in a style that takes advantage of only few of C++'s features. ! 13: ! 14: cfront.h: ! 15: ! 16: Here is all the class definitions for cfront, and most of the externs ! 17: ! 18: ***********************************************************************/ ! 19: ! 20: /* WARNING: ! 21: This program relies on non-initialized class members being ZERO. ! 22: This will be true as long as they are allocated using the "new" operator ! 23: from alloc.c ! 24: */ ! 25: ! 26: #include "token.h" ! 27: #include "typedef.h" ! 28: ! 29: #ifndef GRAM ! 30: extern char* prog_name; // compiler name and version ! 31: extern int inline_restr; // inline expansion restrictions ! 32: #endif ! 33: ! 34: extern Pname name_free; // free lists ! 35: extern Pexpr expr_free; ! 36: extern Pstmt stmt_free; ! 37: ! 38: /* "spy" counters: */ ! 39: //extern int Nspy; ! 40: //extern int Nline, Ntoken, Nname, Nfree_store, Nalloc, Nfree; ! 41: //extern int Nn, Nbt, Nt, Ne, Ns, Nstr, Nc, Nl; ! 42: //extern int NFn, NFtn, NFpv, NFbt, NFf, NFs, NFc, NFe, NFl; ! 43: ! 44: ///extern TOK lex(); ! 45: extern TOK tlex(); ! 46: extern Pname syn(); ! 47: ! 48: extern void ext(int); ! 49: ! 50: extern char* make_name(TOK); ! 51: extern void make_dummy(); ! 52: extern Pname dummy_fct; ! 53: extern Pname really_dominate(Pname, Pname, bit); ! 54: extern int exact1(Pname, Ptype); ! 55: ! 56: extern int friend_check(Pclass start,Pclass stop, Pfct f); ! 57: ! 58: struct loc // a source file location ! 59: { ! 60: short file; // index into file_name[], or zero ! 61: short line; ! 62: #ifndef GRAM ! 63: void put(FILE*); ! 64: void putline(); ! 65: #endif ! 66: }; ! 67: ! 68: extern Loc curloc; ! 69: extern int curr_file; ! 70: extern char* src_file_name; ! 71: extern loc noloc; // dummy null location ! 72: extern bit binary_val; ! 73: extern bit stmtno; ! 74: ! 75: struct ea { // fudge portable printf-like formatting for error() ! 76: union { ! 77: void* p; ! 78: long i; ! 79: }; ! 80: ! 81: ea(const void* pp) { p = pp; } ! 82: ea(long ii) { i = ii; } ! 83: ea() {} ! 84: }; ! 85: ! 86: extern ea* ea0; ! 87: ! 88: overload error; ! 89: int error(const char*); ! 90: int error(const char*, const ea&, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0); ! 91: int error(int, const char*); ! 92: int error(int, const char*, const ea&, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0); ! 93: int error(loc*, const char*, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0); ! 94: int error(int, loc*, const char*, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0, const ea& = *ea0); ! 95: extern char emode; ! 96: ! 97: extern int error_count; ! 98: extern int vtbl_opt; ! 99: extern int debug_opt; ! 100: extern int warning_opt; ! 101: extern int ansi_opt; ! 102: extern int strict_opt; ! 103: extern FILE* out_file; ! 104: extern FILE* in_file; ! 105: extern char scan_started; ! 106: ! 107: extern int bl_level; ! 108: extern Ptable ktbl; // keywords and typedef names ! 109: extern Ptable gtbl; // global names ! 110: extern Ptable ptbl; ! 111: extern Ptable lcl_tbl; ! 112: extern char* oper_name(TOK); ! 113: extern Pname def_name; ! 114: extern Pname pdef_name; ! 115: extern Pclass ccl; ! 116: extern Pbase defa_type; ! 117: extern Pbase moe_type; ! 118: extern Pbase mptr_type; ! 119: ! 120: #ifndef GRAM ! 121: extern Pstmt Cstmt; // current statement, or 0 ! 122: extern Pname Cdcl; // name currently being declared, or 0 ! 123: ! 124: extern Pbase any_type; ! 125: extern int largest_int; ! 126: #endif ! 127: ! 128: extern Pbase int_type; ! 129: extern Pbase char_type; ! 130: extern Pbase short_type; ! 131: extern Pbase long_type; ! 132: extern Pbase uint_type; ! 133: extern Pbase float_type; ! 134: extern Pbase double_type; ! 135: extern Pbase ldouble_type; ! 136: extern Pbase void_type; ! 137: ! 138: #ifndef GRAM ! 139: extern Pbase uchar_type; ! 140: extern Pbase ushort_type; ! 141: extern Pbase ulong_type; ! 142: extern Ptype Pchar_type; ! 143: extern Ptype Pint_type; ! 144: extern Ptype Pvptr_type; ! 145: extern Ptype Pfctvec_type; ! 146: extern Ptype Pvoid_type; ! 147: extern Pbase zero_type; ! 148: extern Ptype size_t_type; ! 149: ! 150: extern int byte_offset; ! 151: extern int bit_offset; ! 152: extern int max_align; ! 153: extern int const_save; ! 154: extern int const_ptr; ! 155: extern int cm_const_save; ! 156: extern bit const_problem; ! 157: #endif ! 158: ! 159: extern Pexpr dummy; /* the empty expression */ ! 160: extern Pexpr zero; ! 161: extern Pexpr one; ! 162: extern Pname sta_name; /* qualifier for unary :: */ ! 163: ! 164: #define DEL(p) if (p && (p->permanent==0)) p->del() ! 165: #define PERM(p) p->permanent=1 ! 166: #define UNPERM(p) p->permanent=0 ! 167: ! 168: struct node { ! 169: TOK base; ! 170: bit permanent; ! 171: #ifdef DBG ! 172: bit displayed; // avoid invinite recursion in display functions ! 173: bit allocated; // set when not on free list ! 174: long id; ! 175: #endif ! 176: }; ! 177: #ifdef DBG ! 178: extern long node_id; ! 179: extern int Adebug; ! 180: #define DBID() { node::id = ++::node_id; node::allocated=1; displayed=0; \ ! 181: if(Adebug>=1)fprintf(stderr,"\n*** allocated %d base %d\n",id,base); } ! 182: #else ! 183: #define DBID() /**/ ! 184: #endif ! 185: ! 186: struct table : node { ! 187: /* a table is a node only to give it a "base" for debugging */ ! 188: bit init_stat; /* ==0 if block(s) of table not simplified, ! 189: ==1 if simplified but had no initializers, ! 190: ==2 if simplified and had initializers. ! 191: */ ! 192: short size; ! 193: short hashsize; ! 194: short free_slot; /* next free slot in entries */ ! 195: Pname* entries; ! 196: short* hashtbl; ! 197: Pstmt real_block; /* the last block the user wrote, ! 198: not one of the ones cfront created ! 199: */ ! 200: Ptable next; /* table for enclosing scope */ ! 201: Pname t_name; /* name of the table */ ! 202: ! 203: table(short, Ptable, Pname); ! 204: ! 205: Pname look(char*, TOK); ! 206: Pname insert(Pname, TOK); ! 207: #ifndef GRAM ! 208: void grow(int); ! 209: void set_name(Pname n) { t_name = n; }; ! 210: Pname get_mem(int); ! 211: int max() { return free_slot-1; }; ! 212: void dcl_print(TOK,TOK); ! 213: void del(); ! 214: #endif ! 215: }; ! 216: ! 217: #ifndef GRAM ! 218: extern bit Nold; ! 219: extern bit vec_const, fct_const; ! 220: #endif ! 221: ! 222: extern void restore(); ! 223: extern void set_scope(Pname); ! 224: extern Plist modified_tn; ! 225: ! 226: // local class ! 227: extern Plist local_tn; ! 228: extern Plist local_blk; ! 229: extern Plist local_class; ! 230: extern void local_hide( Pname ); ! 231: extern char *make_local_name(Pclass, int=0); ! 232: ! 233: // nested type ! 234: extern Plist nested_tn; ! 235: extern Plist nested_type; ! 236: extern Pname curr_scope; ! 237: extern Pname curr_fct; ! 238: extern void nested_hide(Pname); ! 239: extern int is_empty(Pclass,bit=0); ! 240: ! 241: extern Pbase start_cl(TOK, Pname, Pbcl); ! 242: extern void end_cl(); ! 243: extern Pbase end_enum(Pname, Pname); ! 244: ! 245: /************ types : basic types, aggregates, declarators ************/ ! 246: ! 247: #ifndef GRAM ! 248: extern bit new_type; ! 249: extern Pname cl_obj_vec; ! 250: extern Pname eobj; ! 251: #endif ! 252: ! 253: ! 254: #define DEFINED 01 /* definition fed through ?::dcl() */ ! 255: #define SIMPLIFIED 02 /* in ?::simpl() */ ! 256: #define DEF_SEEN 04 /* definition seen, but not processed */ ! 257: #define REF_SEEN 010 /* reference seen (classdef) */ ! 258: /* used for class members in norm.c */ ! 259: #define IN_ERROR 010 ! 260: ! 261: struct type : node { ! 262: bit defined; /* flags DEF_SEEN, DEFINED, SIMPLIFIED, IN_ERROR ! 263: not used systematically yet ! 264: */ ! 265: bit lex_level; ! 266: Pclass in_class; // nested type ! 267: Pname in_fct; // local type ! 268: char *lcl; ! 269: char *nested_sig; ! 270: char *signature(char*); ! 271: Ptype tlist; ! 272: bit check(Ptype, TOK); ! 273: #ifndef GRAM ! 274: void print(); ! 275: void dcl_print(Pname); ! 276: void base_print(); ! 277: void del(); ! 278: ! 279: Pname is_cl_obj(); /* sets cl_obj_vec */ ! 280: Pptr is_ref(); ! 281: Pptr is_ptr(); ! 282: Pptr is_ptr_or_ref(); ! 283: bit is_unsigned(); ! 284: void dcl(Ptable); ! 285: int tsizeof(int = 0); ! 286: bit tconst(); ! 287: TOK set_const(bit); ! 288: int align(); ! 289: TOK kind(TOK,TOK); ! 290: TOK integral(TOK oo) { return kind(oo,'I'); }; ! 291: TOK numeric(TOK oo) { return kind(oo,'N'); }; ! 292: TOK num_ptr(TOK oo) { return kind(oo,'P'); }; ! 293: bit vec_type(); ! 294: Ptype deref(); ! 295: inline Pptr addrof(); ! 296: Pfct memptr(); ! 297: #endif ! 298: }; ! 299: ! 300: struct enumdef : type { /* ENUM */ ! 301: bit e_body; ! 302: short no_of_enumerators; ! 303: unsigned char strlen; // strlen(string) ! 304: char* string; // name of enum ! 305: Pname mem; ! 306: Pbase e_type; // type representing the enum ! 307: enumdef(Pname n) { base=ENUM; mem=n; }; ! 308: #ifndef GRAM ! 309: void print(); ! 310: void dcl_print(Pname); ! 311: void dcl(Pname, Ptable); ! 312: void simpl(); ! 313: #endif ! 314: }; ! 315: ! 316: struct velem { ! 317: Pname n; ! 318: int offset; ! 319: }; ! 320: ! 321: struct virt { ! 322: Pvirt next; ! 323: velem* virt_init; // vector of vtbl initializers (zero-terminated) ! 324: Pclass vclass; // for class vclass ! 325: char* string; ! 326: bit is_vbase; // vtable for virtual base ! 327: bit printed; ! 328: virt(Pclass cl, velem* v, char* s, bit flag) {vclass=cl; virt_init=v; string=s; is_vbase=flag; next=0; } ! 329: }; ! 330: ! 331: enum { C_VPTR=1, C_XREF=2, C_ASS=4, C_VBASE=8 }; ! 332: ! 333: struct classdef : type { /* CLASS */ ! 334: bit c_body; /* print definition only once */ ! 335: TOK csu; /* CLASS, STRUCT, UNION, or ANON */ ! 336: bit obj_align; ! 337: bit c_xref; ! 338: // 1 set: has vptr(s) ! 339: // 2 set: X(X&) exists ! 340: // 4 set: operator=(X&) exists ! 341: // 8 set: has vbaseptr(s) ! 342: ! 343: bit virt_count; // number of virtual functions ! 344: // starting at max base class virt_count in ! 345: bit virt_merge; // set when no virtual functions, but ! 346: // need to merge virtual base classes ! 347: bit c_abstract; // abstract class: don't instansiate ! 348: bit has_vvtab; // set if class has vtable from virtual base ! 349: unsigned char strlen; // strlen(string) ! 350: Pbcl baselist; // list of base classes ! 351: char* string; /* name of class */ ! 352: Pname mem_list; ! 353: Ptable memtbl; ! 354: int obj_size; ! 355: int real_size; /* obj_size - alignment waste */ ! 356: Plist friend_list; ! 357: Pname pubdef; ! 358: Plist tn_list; // list of member names hiding type names ! 359: Plist nest_list; // list of nested types ! 360: Ptype this_type; ! 361: Pvirt virt_list; // vtbl initializers ! 362: Pname c_ctor; // constuctor: ! 363: // possibly overloaded, possibly inherited ! 364: Pname c_dtor; // destructor ! 365: Pname c_itor; /* constructor X(X&) */ ! 366: Pname conv; /* operator T() chain */ ! 367: struct toknode *c_funqf, *c_funqr; // token Q for parsing function defs after class def ! 368: ! 369: classdef(TOK); ! 370: TOK is_simple() { return (csu==CLASS)?0:csu; }; ! 371: #ifndef GRAM ! 372: void print(); ! 373: void dcl_print(Pname); ! 374: void simpl(); ! 375: ! 376: void print_members(); ! 377: void dcl(Pname, Ptable); ! 378: ! 379: // bit has_friend(Pname); ! 380: bit has_friend(Pclass); ! 381: bit has_friend(Pfct); ! 382: ! 383: bit has_base(Pclass cl); ! 384: bit baseof(Pname); ! 385: bit baseof(Pclass); ! 386: Pclass is_base(char*); ! 387: ! 388: Pname has_oper(TOK); ! 389: Pname has_ctor() { return c_ctor; } ! 390: Pname has_dtor() { return c_dtor; } ! 391: Pname has_itor() { return c_itor; } ! 392: Pname has_ictor(); ! 393: Pname make_itor(int); ! 394: Pexpr find_name(char*, Pclass); ! 395: int do_virtuals(Pvirt, char*, int, bit); ! 396: int all_virt(Pclass, char*, int, bit); ! 397: void add_vtbl(velem*, char*, bit); ! 398: void print_all_vtbls(Pclass); ! 399: void print_vtbl(Pvirt); ! 400: void really_print(Pvirt); ! 401: int check_dup(Pclass, TOK); ! 402: int has_allocated_base(Pclass); ! 403: char *has_allocated_base(char*); ! 404: int get_offset(char*); ! 405: Pbcl get_base(char*); ! 406: Pexpr get_vptr_exp(char*); ! 407: Pexpr find_in_base(char*, Pclass); ! 408: #endif ! 409: }; ! 410: ! 411: #ifndef GRAM ! 412: ! 413: class clist { ! 414: Pclass cl; ! 415: clist* next; ! 416: public: ! 417: clist(Pclass c, clist* n) { cl=c; next=n; } ! 418: int onlist(Pclass); ! 419: void clear(); ! 420: }; ! 421: ! 422: extern clist * vcllist; ! 423: ! 424: struct vl { ! 425: struct vl* next; ! 426: Pvirt vt; ! 427: classdef* cl; ! 428: ! 429: vl(classdef* c, Pvirt v, struct vl* n) ! 430: { cl = c; vt = v; next = n; } ! 431: }; ! 432: ! 433: extern vl* vlist; ! 434: ! 435: extern int nin; ! 436: extern int Nvis; ! 437: extern int Noffset; ! 438: extern TOK Nvirt; ! 439: extern Pexpr Nptr; ! 440: extern Pbcl Nvbc_alloc; ! 441: extern char *Nalloc_base; ! 442: extern Pexpr rptr(Ptype,Pexpr,int); ! 443: extern Pexpr vbase_args(Pfct, Pname); ! 444: extern Pexpr cdvec(Pname,Pexpr,Pclass,Pname,int,Pexpr,Pexpr=0); ! 445: ! 446: extern Pexpr find(char*, Pclass, int); ! 447: extern Pexpr find_name(Pname, Pclass, Ptable, int, Pname); ! 448: extern Pname find_virtual(Pclass,Pname); ! 449: extern Pname vfct(Pclass, char*); ! 450: extern int Vcheckerror; ! 451: extern int vhack; ! 452: extern int ignore_const; ! 453: ! 454: extern int access_control; ! 455: extern int mex; ! 456: extern Pclass mec; ! 457: extern Pclass tcl; ! 458: extern Pname me; ! 459: extern Pfct mef; ! 460: #endif ! 461: ! 462: struct basetype : type ! 463: /* ZTYPE CHAR SHORT INT LONG FLOAT DOUBLE ! 464: FIELD EOBJ COBJ TYPE ANY ! 465: */ ! 466: /* used for gathering all the attributes ! 467: for a list of declarators ! 468: ! 469: ZTYPE is the (generic) type of ZERO ! 470: ANY is the generic type of an undeclared name ! 471: */ ! 472: { ! 473: bit b_unsigned; ! 474: bit b_signed; ! 475: bit b_volatile; ! 476: bit b_const; ! 477: bit b_typedef; ! 478: bit b_inline; ! 479: bit b_virtual; ! 480: bit b_short; ! 481: bit b_long; ! 482: bit b_bits; /* number of bits in field */ ! 483: bit b_offset; // bit offset of field ! 484: TOK b_sto; /* AUTO STATIC EXTERN REGISTER 0 */ ! 485: Pname b_name; /* name of non-basic type */ ! 486: Ptable b_table; /* memtbl for b_name, or 0 */ ! 487: Pname b_xname; /* extra name */ ! 488: union { ! 489: Ptype b_fieldtype; ! 490: char* b_linkage; ! 491: }; ! 492: ! 493: basetype(TOK, Pname); ! 494: ! 495: Pbase type_adj(TOK); ! 496: Pbase base_adj(Pbase); ! 497: Pbase name_adj(Pname); ! 498: Pname aggr(); ! 499: Pbase check(Pname); ! 500: #ifndef GRAM ! 501: void dcl_print(); ! 502: Pbase arit_conv(Pbase); ! 503: #endif ! 504: }; ! 505: ! 506: enum Linkage { linkage_default, linkage_C, linkage_Cplusplus }; ! 507: extern Linkage linkage; ! 508: void set_linkage(char*); ! 509: ! 510: struct fct : type // FCT ! 511: { ! 512: TOK nargs; ! 513: TOK nargs_known; // 0 if unknown, 1 if known, or ELLIPSIS ! 514: bit last_stmt; ! 515: bit f_vdef; // 1 if this is the first virtual definition ! 516: // of this function ! 517: bit f_inline; // 1 if inline, 2 if being expanded, else 0 ! 518: bit f_const; // one if member function that may be called for ! 519: // a const object, else 0 ! 520: bit f_static; // 1 if static member function, else 0 ! 521: short f_virtual; // index in virtual table, or 0 meaning non-virtual ! 522: short f_imeasure; // some measure of the size of an inline function ! 523: Ptype returns; ! 524: Pname argtype; ! 525: Ptype s_returns; ! 526: Pname f_this; ! 527: Pclass memof; // member of class memof ! 528: Pblock body; ! 529: Pname f_init; // base and member initializers ! 530: // Pname f_baseinit; // base initializers ! 531: // // null name => single base class init; ! 532: Pexpr f_expr; // body expanded into an expression ! 533: Pexpr last_expanded; ! 534: Pname f_result; // extra second argument of type X& ! 535: Pname f_args; // argument list including args added by cfront ! 536: Linkage f_linkage; ! 537: char* f_signature; // character encoding of function type ! 538: Plist local_class; // list of local classes ! 539: fct(Ptype, Pname, TOK); ! 540: void argdcl(Pname,Pname); ! 541: #ifndef GRAM ! 542: Ptype normalize(Ptype); ! 543: void dcl_print(); ! 544: void dcl(Pname); ! 545: Pexpr base_init(Pclass, Pexpr, Ptable, int); ! 546: Pexpr mem_init(Pname, Pexpr, Ptable); ! 547: void init_bases(Pclass, Pexpr); ! 548: bit declared() { return nargs_known; }; ! 549: void simpl(); ! 550: int ctor_simpl(Pclass, Pexpr); ! 551: Pstmt dtor_simpl(Pclass, Pexpr); ! 552: Pexpr expand(Pname,Ptable,Pexpr); ! 553: void sign(); ! 554: #endif ! 555: }; ! 556: ! 557: ! 558: struct name_list { ! 559: Pname f; ! 560: Plist l; ! 561: name_list(Pname ff, Plist ll) { f=ff; l=ll; }; ! 562: }; ! 563: ! 564: #ifndef GRAM ! 565: struct gen : type { // OVERLOAD ! 566: Plist fct_list; ! 567: ! 568: gen() { base = OVERLOAD; } ! 569: Pname add(Pname); ! 570: Pname find(Pfct, bit); ! 571: Pname match(Pname, Pfct, bit); ! 572: }; ! 573: #endif ! 574: ! 575: struct pvtyp : type { ! 576: Ptype typ; ! 577: }; ! 578: ! 579: struct vec : pvtyp // VEC ! 580: // typ [ dim ] ! 581: { ! 582: Pexpr dim; ! 583: int size; ! 584: ! 585: vec(Ptype t, Pexpr e) { base=VEC; typ=t; dim=e; DBID(); }; ! 586: #ifndef GRAM ! 587: Ptype normalize(Ptype); ! 588: #endif ! 589: }; ! 590: ! 591: struct ptr : pvtyp // PTR, RPTR i.e. reference ! 592: { ! 593: Pclass memof; // pointer to member of memof: memof::* ! 594: bit rdo; // "*const" ! 595: ! 596: ptr(TOK b, Ptype t) { base=b; typ=t; DBID(); } ! 597: #ifndef GRAM ! 598: Ptype normalize(Ptype); ! 599: #endif ! 600: }; ! 601: ! 602: #ifndef GRAM ! 603: inline Pptr type::addrof() { return new ptr(PTR,this); } ! 604: ! 605: extern bit vrp_equiv; ! 606: #endif ! 607: ! 608: ! 609: /****************************** constants ********************************/ ! 610: ! 611: /* STRING ZERO ICON FCON CCON ID */ ! 612: /* IVAL FVAL LVAL */ ! 613: ! 614: /***************************** expressions ********************************/ ! 615: ! 616: #ifndef GRAM ! 617: extern Pexpr next_elem(); ! 618: extern void new_list(Pexpr); ! 619: extern void list_check(Pname, Ptype, Pexpr, Ptable=0); ! 620: extern Pexpr ref_init(Pptr,Pexpr,Ptable); ! 621: extern Pexpr class_init(Pexpr,Ptype,Pexpr,Ptable); ! 622: extern Pexpr check_cond(Pexpr, TOK, Ptable); ! 623: extern Pexpr ptof(Pfct,Pexpr,Ptable); ! 624: extern void dosimpl(Pexpr, Pname); ! 625: extern int ref_initializer; ! 626: extern int ntok; ! 627: ! 628: extern void ptbl_init(int); ! 629: extern void ptbl_add_pair(char*,char*); ! 630: extern char *ptbl_lookup(char*); ! 631: extern char *st_name(char*); ! 632: #endif ! 633: ! 634: struct expr : node /* PLUS, MINUS, etc. */ ! 635: /* IMPORTANT: all expressions are of sizeof(expr) */ ! 636: /* DEREF => *e1 (e2==0) OR e1[e2] ! 637: UMINUS => -e2 ! 638: INCR (e1==0) => ++e2 ! 639: INCR (e2==0) => e1++ ! 640: CM => e1 , e2 ! 641: ILIST => LC e1 RC (an initializer list) ! 642: a Pexpr may denote a name ! 643: */ ! 644: { ! 645: union { ! 646: Ptype tp; ! 647: int syn_class; ! 648: char *string4; ! 649: }; ! 650: union { ! 651: Pexpr e1; ! 652: long i1; ! 653: char* string; ! 654: }; ! 655: union { ! 656: Pexpr e2; ! 657: int i2; ! 658: char* string2; ! 659: Pexpr n_initializer; ! 660: Ptype tpdef; // local and nested typedef info ! 661: }; ! 662: union { /* used by the derived classes */ ! 663: Ptype tp2; ! 664: Pname fct_name; ! 665: Pexpr cond; ! 666: Pexpr mem; ! 667: Ptype as_type; ! 668: Ptable n_table; ! 669: Pin il; ! 670: char* string3; ! 671: }; ! 672: ! 673: expr(TOK, Pexpr, Pexpr); ! 674: ~expr(); ! 675: #ifndef GRAM ! 676: void del(); ! 677: void print(); ! 678: Pexpr typ(Ptable); ! 679: long eval(); ! 680: unsigned long ueval(long,long); ! 681: int lval(TOK); ! 682: Ptype call_fct(Ptable); ! 683: Pexpr address(); ! 684: Pexpr contents(); ! 685: void simpl(); ! 686: Pexpr expand(); ! 687: bit not_simple(); ! 688: Pexpr try_to_overload(Ptable); ! 689: Pexpr docast(Ptable); ! 690: Pexpr dovalue(Ptable); ! 691: Pexpr donew(Ptable); ! 692: void simpl_new(); ! 693: void simpl_delete(); ! 694: #endif ! 695: }; ! 696: ! 697: struct texpr : expr { // CAST NEW VALUE (also ICALL) ! 698: #ifdef __cplusplus ! 699: texpr(TOK bb, Ptype tt, Pexpr ee) : expr (bb,ee,0) { this=0; tp2=tt; } ! 700: #else ! 701: texpr(TOK bb, Ptype tt, Pexpr ee) : (bb,ee,0) { this=0; tp2=tt; } ! 702: #endif ! 703: ! 704: }; ! 705: ! 706: struct cast : expr { // CAST ! 707: #ifdef __cplusplus ! 708: cast(Ptype tt, Pexpr ee) : expr (CAST,ee,0) { this=0; tp=tp2=tt; } ! 709: #else ! 710: cast(Ptype tt, Pexpr ee) : (CAST,ee,0) { this=0; tp=tp2=tt; } ! 711: #endif ! 712: }; ! 713: ! 714: struct ival : expr { // IVAL ! 715: #ifdef __cplusplus ! 716: ival(long ii) : expr (IVAL,0,0) { this=0; i1 = ii;} ! 717: #else ! 718: ival(long ii) : (IVAL,0,0) { this=0; i1 = ii;} ! 719: #endif ! 720: }; ! 721: ! 722: struct call : expr { // CALL ! 723: #ifdef __cplusplus ! 724: call(Pexpr aa, Pexpr bb) : expr (CALL,aa,bb) { this=0; } ! 725: #else ! 726: call(Pexpr aa, Pexpr bb) : (CALL,aa,bb) { this=0; } ! 727: #endif ! 728: #ifndef GRAM ! 729: void simpl(); ! 730: Pexpr expand(Ptable); ! 731: #endif ! 732: }; ! 733: ! 734: struct qexpr : expr { // QUEST cond ? e1 : e2 ! 735: #ifdef __cplusplus ! 736: qexpr(Pexpr ee, Pexpr ee1, Pexpr ee2) : expr (QUEST,ee1,ee2) { this=0; cond=ee; } ! 737: #else ! 738: qexpr(Pexpr ee, Pexpr ee1, Pexpr ee2) : (QUEST,ee1,ee2) { this=0; cond=ee; } ! 739: #endif ! 740: }; ! 741: ! 742: struct ref : expr { // REF DOT e1->mem OR e1.mem ! 743: #ifdef __cplusplus ! 744: ref(TOK ba, Pexpr a, Pexpr b) : expr (ba,a,0) { this=0; mem=b; } ! 745: #else ! 746: ref(TOK ba, Pexpr a, Pexpr b) : (ba,a,0) { this=0; mem=b; } ! 747: #endif ! 748: }; ! 749: ! 750: struct mdot : expr { // MDOT a.b ! 751: #ifdef __cplusplus ! 752: mdot(char* a, Pexpr b) : expr (MDOT,0,0) { this=0; string2=a; mem=b; } ! 753: #else ! 754: mdot(char* a, Pexpr b) : (MDOT,0,0) { this=0; string2=a; mem=b; } ! 755: #endif ! 756: }; ! 757: ! 758: struct text_expr : expr { // TEXT (vtbl_name) ! 759: #ifdef __cplusplus ! 760: text_expr(char* a, char* b) : expr (TEXT,0,0) ! 761: #else ! 762: text_expr(char* a, char* b) : (TEXT,0,0) ! 763: #endif ! 764: { this=0; string=a; string2=b; } ! 765: }; ! 766: char* vtbl_name(char*,char*); ! 767: /************************* names (are expressions) ****************************/ ! 768: ! 769: struct basecl : node { // NAME => base class ! 770: // VIRTUAL => virtual base class ! 771: TOK ppp; // private / public / protected ! 772: bit allocated; // allocated virtual base ! 773: bit promoted; // non-explicit, promoted virtual base ! 774: Pclass bclass; ! 775: Pexpr init; // base class initializers for ctors ! 776: int ptr_offset; // pointer's relative position in derived class ! 777: int obj_offset; // object's relative position in derived class ! 778: Pname* virt_init; // vector of vtbl table initializers ! 779: basecl* next; ! 780: ! 781: basecl(Pclass cl, basecl* n) { bclass=cl; next=n; promoted=0; init=0;} ! 782: }; ! 783: extern TOK ppbase; ! 784: ! 785: struct name : expr { // NAME TNAME and the keywords in the ktbl ! 786: TOK n_oper; // name of operator or 0 ! 787: TOK n_sto; // EXTERN STATIC AUTO REGISTER ENUM 0 ! 788: TOK n_stclass; // STATIC AUTO REGISTER 0 ! 789: TOK n_scope; // EXTERN STATIC FCT ARG PUBLIC 0 ! 790: TOK n_key; /* for names in table: class */ ! 791: bit n_evaluated; // 0 or n_val holds the value ! 792: bit n_xref; // argument of type X(X&) ! 793: unsigned char lex_level; ! 794: TOK n_protect; // PROTECTED (<=>n_scope==0) or 0 ! 795: bit n_dcl_printed; // 1: declaration printed ! 796: // 2: definition printed ! 797: // 0: declaration not printed ! 798: char *n_anon; // nested anonymous unions ! 799: short n_union; // 0, or union index ! 800: short n_addr_taken; ! 801: short n_used; ! 802: short n_assigned_to; ! 803: Loc where; ! 804: int n_offset; // byte offset in frame or struct ! 805: Pname n_list; ! 806: Pname n_tbl_list; ! 807: union { ! 808: Pname n_qualifier; // name of containing class ! 809: Ptable n_realscope; /* for labels (always entered in ! 810: function table) the table for the ! 811: actual scope in which label occurred. ! 812: */ ! 813: }; ! 814: long n_val; // the value of n_initializer ! 815: // also used as the argument number ! 816: // for inline arguments ! 817: name(char* =0); ! 818: ~name(); ! 819: ! 820: Pname normalize(Pbase, Pblock, bit); ! 821: Pname tdef(); ! 822: Pname tname(TOK); ! 823: void hide(); ! 824: void unhide() { n_key=0; n_list=0; }; ! 825: #ifndef GRAM ! 826: Pname dcl(Ptable,TOK); ! 827: int no_of_names(); ! 828: void use() { n_used++; }; ! 829: void assign(); ! 830: void take_addr(); ! 831: void check_oper(Pname); ! 832: void simpl(); ! 833: void del(); ! 834: void print(); ! 835: void dcl_print(TOK); ! 836: void field_align(); ! 837: Pname dofct(Ptable,TOK); ! 838: #endif ! 839: }; ! 840: ! 841: extern int friend_in_class; ! 842: extern int in_class_dcl; ! 843: ! 844: // from parser ! 845: extern int in_class_decl; ! 846: extern int parsing_class_members; ! 847: extern int in_mem_fct; ! 848: extern int in_arg_list; ! 849: extern Ptype in_typedef; ! 850: extern int defer_check; // redefinition typedef check delay ! 851: extern int declTag; // !1: inline, virtual mod permitted ! 852: extern Pname in_tag; ! 853: extern Pname statStat; ! 854: extern int DECL_TYPE; ! 855: ! 856: /******************** statements *********************************/ ! 857: ! 858: struct stmt : node { /* BREAK CONTINUE DEFAULT */ ! 859: /* IMPORTANT: all statement nodes have sizeof(stmt) */ ! 860: Pstmt s; ! 861: Pstmt s_list; ! 862: Loc where; ! 863: union { ! 864: Pname d; ! 865: Pexpr e2; ! 866: Pstmt has_default; ! 867: int case_value; ! 868: Ptype ret_tp; ! 869: }; ! 870: union { ! 871: Pexpr e; ! 872: bit own_tbl; ! 873: Pstmt s2; ! 874: }; ! 875: Ptable memtbl; ! 876: union { ! 877: Pstmt for_init; ! 878: Pstmt else_stmt; ! 879: Pstmt case_list; ! 880: // bit empty; ! 881: Loc where2; // location of } at end of block ! 882: }; ! 883: ! 884: stmt(TOK, loc, Pstmt); ! 885: ~stmt(); ! 886: #ifndef GRAM ! 887: void del(); ! 888: void print(); ! 889: void dcl(); ! 890: void reached(); ! 891: Pstmt simpl(); ! 892: Pstmt expand(); ! 893: Pstmt copy(); ! 894: #endif ! 895: }; ! 896: ! 897: #ifndef GRAM ! 898: extern char* Neval; ! 899: extern Ptable scope; ! 900: extern Ptable expand_tbl; ! 901: extern Pname expand_fn; ! 902: #endif ! 903: ! 904: struct estmt : stmt /* SM WHILE DO SWITCH RETURN CASE */ ! 905: /* SM (e!=0) => e; ! 906: in particular assignments and function calls ! 907: SM (e==0) => ; (the null statement) ! 908: CASE => case e : s ; ! 909: */ ! 910: { ! 911: #ifdef __cplusplus ! 912: estmt(TOK t, loc ll, Pexpr ee, Pstmt ss) : stmt (t,ll,ss) { this=0; e=ee; } ! 913: #else ! 914: estmt(TOK t, loc ll, Pexpr ee, Pstmt ss) : (t,ll,ss) { this=0; e=ee; } ! 915: #endif ! 916: }; ! 917: ! 918: struct ifstmt : stmt /* IF */ ! 919: // else_stme==0 => if (e) s ! 920: // else_stmt!=0 => if (e) s else else_stmt ! 921: { ! 922: ifstmt(loc ll, Pexpr ee, Pstmt ss1, Pstmt ss2) ! 923: #ifdef __cplusplus ! 924: : stmt (IF,ll,ss1) { this=0; e=ee; else_stmt=ss2; }; ! 925: #else ! 926: : (IF,ll,ss1) { this=0; e=ee; else_stmt=ss2; }; ! 927: #endif ! 928: }; ! 929: ! 930: struct lstmt : stmt /* LABEL GOTO */ ! 931: /* ! 932: d : s ! 933: goto d ! 934: */ ! 935: { ! 936: #ifdef __cplusplus ! 937: lstmt(TOK bb, loc ll, Pname nn, Pstmt ss) : stmt (bb,ll,ss) { this=0; d=nn; } ! 938: #else ! 939: lstmt(TOK bb, loc ll, Pname nn, Pstmt ss) : (bb,ll,ss) { this=0; d=nn; } ! 940: #endif ! 941: }; ! 942: ! 943: struct forstmt : stmt { // FOR ! 944: forstmt(loc ll, Pstmt fss, Pexpr ee1, Pexpr ee2, Pstmt ss) ! 945: #ifdef __cplusplus ! 946: : stmt (FOR,ll,ss) { this=0; for_init=fss; e=ee1; e2=ee2; } ! 947: #else ! 948: : (FOR,ll,ss) { this=0; for_init=fss; e=ee1; e2=ee2; } ! 949: #endif ! 950: }; ! 951: ! 952: struct block : stmt { // BLOCK { d s } ! 953: #ifdef __cplusplus ! 954: block(loc ll, Pname nn, Pstmt ss, loc rr = noloc ) : stmt (BLOCK,ll,ss) ! 955: #else ! 956: block(loc ll, Pname nn, Pstmt ss, loc rr = noloc ) : (BLOCK,ll,ss) ! 957: #endif ! 958: { this=0; d=nn; where2=rr; } ! 959: #ifndef GRAM ! 960: void dcl(Ptable); ! 961: Pstmt simpl(); ! 962: #endif ! 963: }; ! 964: ! 965: #ifndef GRAM ! 966: struct pair : public stmt { // PAIR ! 967: #ifdef __cplusplus ! 968: pair(loc ll, Pstmt a, Pstmt b) : stmt (PAIR,ll,a) { this=0; s2 = b; } ! 969: #else ! 970: pair(loc ll, Pstmt a, Pstmt b) : (PAIR,ll,a) { this=0; s2 = b; } ! 971: #endif ! 972: }; ! 973: #endif ! 974: ! 975: struct nlist { ! 976: Pname head; ! 977: Pname tail; ! 978: nlist(Pname); ! 979: void add(Pname n) { tail->n_list = n; tail = n; }; ! 980: void add_list(Pname); ! 981: }; ! 982: ! 983: extern Pname name_unlist(nlist*); ! 984: ! 985: struct slist { ! 986: Pstmt head; ! 987: Pstmt tail; ! 988: slist(Pstmt s) { /*Nl++;*/ head = tail = s; }; ! 989: void add(Pstmt s) { tail->s_list = s; tail = s; }; ! 990: }; ! 991: ! 992: extern Pstmt stmt_unlist(slist*); ! 993: ! 994: struct elist { ! 995: Pexpr head; ! 996: Pexpr tail; ! 997: elist(Pexpr e) { /*Nl++;*/ head = tail = e; }; ! 998: void add(Pexpr e) { tail->e2 = e; tail = e; }; ! 999: }; ! 1000: ! 1001: extern Pexpr expr_unlist(elist*); ! 1002: ! 1003: #ifndef GRAM ! 1004: extern class dcl_context * cc; ! 1005: ! 1006: struct dcl_context { ! 1007: Pname c_this; /* current fct's "this" */ ! 1008: Ptype tot; /* type of "this" or 0 */ ! 1009: Pname not; /* name of "this"'s class or 0 */ ! 1010: Pclass cot; /* the definition of "this"'s class */ ! 1011: Ptable ftbl; /* current fct's symbol table */ ! 1012: Pname nof; /* current fct's name */ ! 1013: ! 1014: void stack() { cc++; *cc = *(cc-1); }; ! 1015: void unstack() { cc--; }; ! 1016: }; ! 1017: ! 1018: #define MAXCONT 20 ! 1019: extern dcl_context ccvec[MAXCONT]; ! 1020: #endif ! 1021: ! 1022: extern void yyerror(char*); ! 1023: ! 1024: ! 1025: #ifndef GRAM ! 1026: extern char* line_format; ! 1027: ! 1028: extern Plist stat_mem_list; ! 1029: extern Plist isf_list; ! 1030: extern Pstmt st_ilist; ! 1031: extern Pstmt st_dlist; ! 1032: extern Ptable sti_tbl; ! 1033: extern Ptable std_tbl; ! 1034: extern int need_sti( Pexpr e, Ptable tbl = 0, bit is_static_ok = 0 ); ! 1035: Pexpr try_to_coerce(Ptype, Pexpr, char*, Ptable); ! 1036: extern bit can_coerce(Ptype, Ptype); ! 1037: extern Ptype np_promote(TOK, TOK, TOK, Ptype, Ptype, TOK); ! 1038: extern bit enum_promote; ! 1039: extern int suppress_error; ! 1040: extern void new_key(char*, TOK, TOK); ! 1041: extern void delete_local(); ! 1042: ! 1043: extern int over_call(Pname, Pexpr); ! 1044: extern Pname overFound; ! 1045: extern Pname Nover; ! 1046: extern Pname Ncoerce; ! 1047: extern Nover_coerce; ! 1048: struct ia { ! 1049: Pname local; // local variable for argument ! 1050: Pexpr arg; // actual arguments for call ! 1051: Ptype tp; // type of formal argument ! 1052: }; ! 1053: ! 1054: struct iline { ! 1055: Pname fct_name; /* fct called */ ! 1056: Pin i_next; ! 1057: Ptable i_table; ! 1058: int i_slots; // no of arg slots pointer to by i_args ! 1059: ia* i_args; ! 1060: }; ! 1061: ! 1062: extern Pexpr curr_expr; ! 1063: extern Pin curr_icall; ! 1064: #define FUDGE111 11111 ! 1065: #define VTOK 22222 ! 1066: #define ITOR 77 ! 1067: ! 1068: extern Pstmt curr_loop; ! 1069: extern Pblock curr_block; ! 1070: extern Pstmt curr_switch; ! 1071: extern loc last_line; // last #line + number of '\n's output since ! 1072: extern int last_ll; // 0 or line of current stmt/dcl being printed ! 1073: extern FILE* out_file; // output file descriptor ! 1074: extern bit Cast; ! 1075: extern loc no_where; ! 1076: ! 1077: extern no_of_undcl; ! 1078: extern no_of_badcall; ! 1079: extern Pname undcl, badcall; ! 1080: ! 1081: extern long str_to_long(const char*); ! 1082: extern int c_strlen(const char* s); ! 1083: #endif ! 1084: ! 1085: #ifndef GRAM ! 1086: extern Pname vec_new_fct; ! 1087: extern Pname new_fct; ! 1088: extern Pname del_fct; ! 1089: extern Pname vec_del_fct; ! 1090: ! 1091: extern int Nstd; // standard coercion used (derived* =>base* or int=>long or ...) ! 1092: ! 1093: extern int stcount; // number of names generated using make_name() ! 1094: ! 1095: Pexpr replace_temp(Pexpr,Pexpr); ! 1096: void make_res(Pfct); ! 1097: ! 1098: extern int Pchecked; ! 1099: Pexpr ptr_init(Pptr,Pexpr,Ptable); ! 1100: Pexpr call_ctor(Ptable, Pexpr p, Pexpr ctor, Pexpr args, int d = REF, Pexpr vb_args = 0); ! 1101: Pexpr call_dtor(Pexpr p, Pexpr dtor, Pexpr arg = 0, int d = DOT, Pexpr vb_args = 0); ! 1102: void check_visibility(Pname, Pname, Pclass, Ptable, Pname); ! 1103: ! 1104: int make_assignment(Pname); ! 1105: ! 1106: extern Pname make_tmp(char, Ptype, Ptable); ! 1107: Pexpr init_tmp(Pname, Pexpr, Ptable); ! 1108: ! 1109: extern int is_unique_base(Pclass, char*, int, int = 0); ! 1110: extern Pexpr rptr(Ptype, Pexpr, int); ! 1111: ! 1112: extern int read_align(char*); ! 1113: extern void new_init(); ! 1114: ! 1115: extern void Eprint(Pexpr); ! 1116: extern Pexpr cast_cptr(Pclass ccl, Pexpr ee, Ptable tbl, int real_cast); ! 1117: extern Pexpr mptr_assign(Pexpr,Pexpr); ! 1118: extern Pclass Mptr; ! 1119: ! 1120: #endif ! 1121: ! 1122: extern bit fake_sizeof; // suppress error message for ``int v[];'' ! 1123: ! 1124: extern TOK lalex(); ! 1125: ! 1126: ! 1127: #ifdef DBG ! 1128: extern void display_expr( Pexpr, char* = 0, int = 0 ); ! 1129: extern void display_stmt( Pstmt, char* = 0, int = 0 ); ! 1130: extern void display_type( Ptype ); ! 1131: extern void display_namelist( Plist, char* = 0, int = 0 ); ! 1132: ! 1133: extern fprintf(const FILE*, const char* ...); ! 1134: extern void process_debug_flags( char* ); ! 1135: #define DB(a) a ! 1136: extern int Adebug; // allocation (ctor/del) debugging ! 1137: extern int Ddebug; // dcl debugging ! 1138: extern int Edebug; // expr debugging ! 1139: extern int Ldebug; // lex/lalex debugging ! 1140: extern int Mdebug; // trace function matching ! 1141: extern int Ndebug; // norm debugging ! 1142: extern int Pdebug; // print debugging ! 1143: extern int Rdebug; // run() debugging ! 1144: extern int Sdebug; // simpl debugging ! 1145: extern int Tdebug; // typ debugging ! 1146: #define Ydebug yydebug ! 1147: extern int Ydebug; // yacc debugging ! 1148: ! 1149: #else ! 1150: ! 1151: #define DB(a) /**/ ! 1152: ! 1153: #endif ! 1154: ! 1155: /* end */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.