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

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

unix.superglobalmegacorp.com

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