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

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

unix.superglobalmegacorp.com

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