Annotation of researchv10no/cmd/cfront/optcfront/norm2.c, revision 1.1

1.1     ! root        1: /*ident        "@(#)ctrans:src/norm2.c 1.4" */
        !             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: norm2.c:
        !            11: 
        !            12:        "normalization" handles problems which could have been handled
        !            13:        by the syntax analyser; but has not been done. The idea is
        !            14:        to simplify the grammar and the actions associated with it,
        !            15:        and to get a more robust error handling
        !            16: 
        !            17: ****************************************************************************/
        !            18: 
        !            19: #include "cfront.h"
        !            20: #include "size.h"
        !            21: 
        !            22: #ifdef DBG
        !            23: long node_id = 0;
        !            24: #define DBCHECK() if(node::allocated) error('i',"allocated node (id %d, base%k) on free list! (src: \"%s\", %d",node::id,node::base,__FILE__,__LINE__);
        !            25: #else
        !            26: #define DBCHECK() /**/
        !            27: #endif
        !            28: 
        !            29: fct::fct(Ptype t, Pname arg, TOK known)
        !            30: {
        !            31:        base = FCT;
        !            32:        nargs_known = known;
        !            33:        returns = t;
        !            34:        argtype = arg; 
        !            35:        DBID();
        !            36: 
        !            37:        if (arg==0 || arg->base==ELIST) return;
        !            38: //error('d',"fct::fct %d sig %d",this,f_signature);
        !            39:        register Pname n;
        !            40:        Pname pn = 0;
        !            41:        for (n=arg; n; pn=n,n=n->n_list) {
        !            42:                if( n->n_sto==EXTERN ) error("externA");
        !            43:                if( n->n_sto==STATIC ) error("static used forA%n",arg);
        !            44:  
        !            45:                switch (n->tp->base) {
        !            46:                case VOID:
        !            47:                        argtype = 0;
        !            48:                        nargs_known = 1;
        !            49:                        if(n->n_initializer)
        !            50:                                error("voidFA");
        !            51:                        else if (n->string)
        !            52:                                error("voidFA%n",n);
        !            53:                        else if (nargs || n->n_list) {
        !            54:                                error("voidFA");
        !            55:                                nargs_known = 0;
        !            56:                        }
        !            57:                        nargs = 0;
        !            58:                        break;
        !            59:                case CLASS:
        !            60:                case ENUM:
        !            61:                        error("%k defined inAL (will not be in scope at point of call)",n->tp->base);
        !            62:                        if (n == argtype)
        !            63:                                argtype = n->n_list;
        !            64:                        else
        !            65:                                pn->n_list = n->n_list;
        !            66:                        break;
        !            67:                default:
        !            68:                        nargs++;
        !            69:                }
        !            70:        }
        !            71: }
        !            72: 
        !            73: expr::expr(TOK ba, Pexpr a, Pexpr b)
        !            74: {
        !            75:        DBCHECK();
        !            76: 
        !            77:        base = ba;
        !            78:        e1 = a;
        !            79:        e2 = b;
        !            80:        DBID();
        !            81: }
        !            82: 
        !            83: stmt::stmt(TOK ba, loc ll, Pstmt a)
        !            84: {
        !            85:        DBCHECK();
        !            86: 
        !            87:        base = ba;
        !            88:        where = ll;
        !            89:        s=a;
        !            90:        DBID();
        !            91: }
        !            92: 
        !            93: classdef::classdef(TOK b)
        !            94: {
        !            95:        base = CLASS;
        !            96:        csu = b;
        !            97:        memtbl = new table(CTBLSIZE,0,0);
        !            98:        DBID();
        !            99: }
        !           100: 
        !           101: classdef::~classdef()
        !           102: {
        !           103:        delete memtbl;
        !           104: }
        !           105: 
        !           106: basetype::basetype(TOK b, Pname n)
        !           107: {
        !           108:        switch (b) {
        !           109:        case 0:                         break;
        !           110:        case TYPEDEF:   b_typedef = 1;  break;
        !           111:        case INLINE:    b_inline = 1;   break;
        !           112:        case VIRTUAL:   b_virtual = 1;  break;
        !           113:        case CONST:     b_const = 1;    break;
        !           114:        case UNSIGNED:  b_unsigned = 1; break;
        !           115:        case FRIEND:
        !           116:        case OVERLOAD:
        !           117:        case EXTERN:
        !           118:        case STATIC:
        !           119:        case AUTO:
        !           120:        case REGISTER:  b_sto = b;      break;
        !           121:        case SHORT:     b_short = 1;    break;
        !           122:        case LONG:      b_long = 1;     break;
        !           123:        case ANY:
        !           124:        case ZTYPE:
        !           125:        case VOID:
        !           126:        case CHAR:
        !           127:        case INT:
        !           128:        case FLOAT:
        !           129:        case LDOUBLE:
        !           130:        case DOUBLE:    base = b;       break;
        !           131:        case TYPE:
        !           132:        case COBJ:
        !           133:        case EOBJ:
        !           134:        case FIELD:
        !           135:        case ASM:
        !           136:                base = b;
        !           137:                b_name = n;
        !           138:                break;
        !           139:        case SIGNED:
        !           140:        case VOLATILE:
        !           141:                error('w',"\"%k\" not implemented (ignored)",b);
        !           142:                break;
        !           143:        default:
        !           144:                error('i',"badBT:%k",b);
        !           145:        }
        !           146:        DBID();
        !           147: }
        !           148: 
        !           149: name::name(char* s) : expr(NAME,0,0)
        !           150: {
        !           151:        // DBCHECK() called in expr::expr()
        !           152:        string = s;
        !           153:        where = curloc;
        !           154:        lex_level = bl_level;
        !           155: }
        !           156: 
        !           157: nlist::nlist(Pname n)
        !           158: {
        !           159:        head = n;
        !           160:        for (Pname nn=n; nn->n_list; nn=nn->n_list);
        !           161:        tail = nn;
        !           162: }
        !           163: 
        !           164: void nlist::add_list(Pname n)
        !           165: {
        !           166:        if (n->tp && (n->tp->defined & IN_ERROR)) return;
        !           167: 
        !           168:        tail->n_list = n;
        !           169:        for (Pname nn=n; nn->n_list; nn=nn->n_list);
        !           170:        tail = nn;
        !           171: }
        !           172: 
        !           173: Pname name_unlist(Pnlist l)
        !           174: {
        !           175:        if (l == 0) return 0;
        !           176:        Pname n = l->head;
        !           177: 
        !           178:        delete l;
        !           179:        return n;
        !           180: }
        !           181: 
        !           182: Pstmt stmt_unlist(Pslist l)
        !           183: {
        !           184:        if (l == 0) return 0;
        !           185:        Pstmt s = l->head;
        !           186: //     NFl++;
        !           187: 
        !           188:        delete l;
        !           189:        return s;
        !           190: }
        !           191: 
        !           192: Pexpr expr_unlist(Pelist l)
        !           193: {
        !           194:        if (l == 0) return 0;
        !           195:        Pexpr e = l->head;
        !           196: //     NFl++;
        !           197: 
        !           198:        delete l;
        !           199:        return e;
        !           200: }
        !           201: 
        !           202: void sig_name(Pname n)
        !           203: {
        !           204:        static char buf[256];
        !           205:        buf[0] = '_';
        !           206:        buf[1] = '_';
        !           207:        buf[2] = 'o';
        !           208:        buf[3] = 'p';
        !           209:        char* p = n->tp->signature(buf+4);
        !           210:        if (255 < p-buf) error('i',"sig_name():N buffer overflow");
        !           211:        char *s = new char [ p - buf + 1 ];
        !           212:        strcpy(s,buf);
        !           213:        n->string = s;
        !           214:        n->tp = 0;
        !           215: }
        !           216: 
        !           217: Ptype tok_to_type(TOK b)
        !           218: {
        !           219:        Ptype t;
        !           220:        switch (b) {
        !           221:        case CHAR:      t = char_type; break;
        !           222:        case SHORT:     t = short_type; break;
        !           223:        case LONG:      t = long_type; break;
        !           224:        case UNSIGNED:  t = uint_type; break;
        !           225:        case FLOAT:     t = float_type; break;
        !           226:        case DOUBLE:    t = double_type; break;
        !           227:        case LDOUBLE:   t = ldouble_type; break;
        !           228:        case VOID:      t = void_type; break;
        !           229:        default:        error("illegalK:%k",b);
        !           230:        case INT:       t = int_type;
        !           231:        }
        !           232:        return t;
        !           233: }
        !           234: 
        !           235: Pbase defa_type;
        !           236: Pbase moe_type;
        !           237: Pexpr dummy;
        !           238: Pexpr zero;
        !           239: 
        !           240: Pclass ccl;
        !           241: Plist modified_tn = 0;
        !           242: 
        !           243: Plist local_tn = 0;
        !           244: Plist local_blk = 0;
        !           245: Plist local_class = 0;
        !           246: 
        !           247: Plist nested_tn = 0;
        !           248: Plist nested_type = 0;
        !           249: 
        !           250: void memptrdcl(Pname bn, Pname tn, Ptype ft, Pname n)
        !           251: {
        !           252:        Pptr p = new ptr(PTR,0);
        !           253:        p->memof = Pclass(Pbase(bn->tp)->b_name->tp);
        !           254:        Pbase b = new basetype(TYPE,tn);
        !           255:        PERM(p);
        !           256:        Pfct f = Pfct(ft);
        !           257:        Ptype t = n->tp;
        !           258:        if (t) {
        !           259:                p->typ = t;
        !           260:        ltlt:
        !           261:                switch (t->base) {
        !           262:                case PTR:
        !           263:                case RPTR:
        !           264:                case VEC:
        !           265:                        if (Pptr(t)->typ == 0) {
        !           266:                                Pptr(t)->typ = b;
        !           267:                                break;
        !           268:                        }
        !           269:                        t = Pptr(t)->typ;
        !           270:                        goto ltlt;
        !           271:                default:
        !           272:                        error('s',"P toMFT too complicated");
        !           273:                }
        !           274:        }
        !           275:        else
        !           276:        p->typ = b;     
        !           277:        f->returns = p;
        !           278:        n->tp = f;
        !           279: }

unix.superglobalmegacorp.com

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