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

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

unix.superglobalmegacorp.com

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