Annotation of researchv10no/cmd/cfront/ooptcfront/cfront.h, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.