Annotation of researchv10no/cmd/cfront/cfront2.00/cfront.h, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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