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