Annotation of researchv10no/cmd/cfront/cfront2.00/typ.c, revision 1.1

1.1     ! root        1: /*ident        "@(#)ctrans:src/typ.c   1.2.4.19" */
        !             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: typ.c:
        !            11: 
        !            12: 
        !            13: ***************************************************************************/
        !            14:  
        !            15: #include "cfront.h"
        !            16: #include "size.h"
        !            17: 
        !            18: Pbase short_type;
        !            19: Pbase int_type;
        !            20: Pbase char_type;
        !            21: Pbase long_type;
        !            22: 
        !            23: Pbase uchar_type;
        !            24: Pbase ushort_type;
        !            25: Pbase uint_type;
        !            26: Pbase ulong_type;
        !            27: 
        !            28: Pbase zero_type;
        !            29: Pbase float_type;
        !            30: Pbase double_type;
        !            31: Pbase ldouble_type;
        !            32: Pbase void_type;
        !            33: Pbase any_type;
        !            34: 
        !            35: Ptype Pint_type;
        !            36: Ptype Pchar_type;
        !            37: Ptype Pvoid_type;
        !            38: Ptype Pfctvec_type;
        !            39: 
        !            40: Ptable gtbl;
        !            41: Ptable any_tbl; 
        !            42: 
        !            43: Pname Cdcl;
        !            44: Pstmt Cstmt;
        !            45: 
        !            46: bit new_type;
        !            47: extern int suppress_error;
        !            48: 
        !            49: void echeck(Ptype t1, Ptype t2)
        !            50: /*
        !            51:        t1 is an enum, t2 is assigned to it
        !            52: */
        !            53: {
        !            54:        if (t1 == t2) return;
        !            55: 
        !            56: //error('d',"echeck(%t,%t) %d %d",t1,t2,t1->base,t2->base);
        !            57: //error('d',"se %d",suppress_error);
        !            58:        if (t1->base==EOBJ
        !            59:        && t2->base==EOBJ
        !            60:        && Pbase(t1)->b_name->tp == Pbase(t2)->b_name->tp) return;
        !            61: 
        !            62:        error(strict_opt?0:'w',"%t assigned to %t",t2,t1);
        !            63: }
        !            64: 
        !            65: 
        !            66: Ptype np_promote(TOK oper, TOK r1, TOK r2, Ptype t1, Ptype t2, TOK p)
        !            67: /*
        !            68:        an arithmetic operator "oper" is applied to "t1" and "t2",
        !            69:        types t1 and t2 has been checked and belongs to catagories
        !            70:        "r1" and "r2", respectively:
        !            71:                A       ANY
        !            72:                Z       ZERO
        !            73:                I       CHAR, SHORT, INT, LONG, FIELD, or EOBJ
        !            74:                F       FLOAT DOUBLE LDOUBLE
        !            75:                P       PTR (to something) or VEC (of something)
        !            76:        test for compatability of the operands,
        !            77:        if (p) return the promoted result type
        !            78: */
        !            79: {
        !            80:        if (r2 == 'A') return t1;
        !            81: 
        !            82: //error('d',"promote(%t,%t,%k)",t1,t2,oper);
        !            83: //     if (r1!='P' && r2=='P' && t2->check(Pvoid_type,0)==0) {
        !            84: //             error("%k of %t",oper,Pvoid_type);
        !            85: //             return any_type;
        !            86: //     }
        !            87: 
        !            88:        switch (r1) {
        !            89:        case 'A':       return t2;
        !            90:        case 'Z':
        !            91:                switch (r2) {
        !            92:                case 'Z':               return int_type;
        !            93:                case 'I':
        !            94:                case 'F':               return (p) ? Pbase(t2)->arit_conv(0) : 0;
        !            95:                case 'P':               return t2;
        !            96:                default:        error('i',"zero(%d)",r2);
        !            97:                }
        !            98:        case 'I':
        !            99:                switch (r2) {
        !           100:                case 'Z': t2 = 0;
        !           101:                case 'I':
        !           102:                case 'F': return (p) ? Pbase(t1)->arit_conv(Pbase(t2)) : 0;
        !           103:                case 'P': switch (oper) {
        !           104:                        case PLUS:
        !           105:                        case ASPLUS:    break;
        !           106:                        default:        error("int%kP",oper); return any_type;
        !           107:                        }
        !           108:                        return t2;
        !           109:                case FCT: error("int%kF",oper); return any_type;
        !           110:                default: error('i',"int(%d)",r2); return any_type;
        !           111:                }
        !           112:        case 'F':
        !           113:                switch (r2) {
        !           114:                case 'Z': t2 = 0;
        !           115:                case 'I':
        !           116:                case 'F': return (p) ? Pbase(t1)->arit_conv(Pbase(t2)) : 0;
        !           117:                case 'P': error("float%kP",oper); return any_type;
        !           118:                case FCT: error("float%kF",oper); return any_type;
        !           119:                default: error('i',"float(%d)",r2); return any_type;
        !           120:                }
        !           121:        case 'P':
        !           122:        //      if (t1->check(Pvoid_type,0)==0) {
        !           123:        //              error("%k of %t",oper,Pvoid_type);
        !           124:        //              return any_type;
        !           125:        //      }
        !           126: 
        !           127:                switch (r2) {
        !           128:                case 'Z': return t1;
        !           129:                case 'I':
        !           130:                        switch (oper) {
        !           131:                        case PLUS:
        !           132:                        case MINUS:
        !           133:                        case ASPLUS:
        !           134:                        case ASMINUS: break;
        !           135:                        default: error("P%k int",oper); return any_type;
        !           136:                        }
        !           137:                        return t1;
        !           138:                case 'F': error("P%k float",oper); return any_type;
        !           139:                case 'P':
        !           140:                        if (t1->check(t2,ASSIGN)) {
        !           141:                                switch (oper) {
        !           142:                                case EQ:
        !           143:                                case NE:
        !           144:                                case LE:
        !           145:                                case GE:
        !           146:                                case GT:
        !           147:                                case LT:
        !           148:                                case QUEST:
        !           149:                                        if (t2->check(t1,ASSIGN) == 0) goto zz;
        !           150:                                }
        !           151:                                error("T mismatch:%t %k%t",t1,oper,t2);
        !           152:                                return any_type;
        !           153:                        }
        !           154:                        zz:
        !           155:                        switch (oper) {
        !           156:                        case MINUS:
        !           157:                        case ASMINUS:   return int_type;
        !           158:                        case PLUS:
        !           159:                        case ASPLUS:    error("P +P"); return any_type;
        !           160:                        default:        return t1;
        !           161:                        }
        !           162:                case FCT:       return t1;
        !           163:                default:        error('i',"P(%d)",r2);
        !           164:                }
        !           165:        case FCT:
        !           166:                error("F%k%t",oper,t2);
        !           167:                return any_type;
        !           168:        default:
        !           169:                error('i',"np_promote(%d,%d)",r1,r2);
        !           170:        }
        !           171: }
        !           172: 
        !           173: TOK type::kind(TOK oper, TOK v)
        !           174: /*     v ==    'I'     integral
        !           175:                'N'     numeric
        !           176:                'P'     numeric or pointer
        !           177: */
        !           178: {
        !           179:        Ptype t = this;
        !           180:        if (this == 0) error('i',"type::kind(): this==0");
        !           181: xx:
        !           182:        switch (t->base) {
        !           183:        case ANY:       return 'A';
        !           184:        case ZTYPE:     return 'Z';
        !           185:        case FIELD:
        !           186:        case CHAR:
        !           187:        case SHORT:
        !           188:        case INT:
        !           189:        case LONG:
        !           190:        case EOBJ:      return 'I';
        !           191:        case FLOAT:
        !           192:        case LDOUBLE:
        !           193:        case DOUBLE:    if (v == 'I') error("float operand for %k",oper);       return 'F';
        !           194:        case VEC://     if (v != 'P') error("V operand for %k",oper);   return 'P';
        !           195:        case PTR:       if (v != 'P') error("P operand for %k",oper);
        !           196:                        switch (oper) {
        !           197:                        case INCR:
        !           198:                        case DECR:
        !           199:                        case MINUS:
        !           200:                        case PLUS:
        !           201:                        case ASMINUS:
        !           202:                        case ASPLUS:
        !           203:                                if (t->base==PTR
        !           204:                                && (Pptr(t)->memof || Pptr(t)->typ->base==FCT))
        !           205:                                        error("%t operand of%k",this,oper);
        !           206:                                else
        !           207:                                        Pptr(t)->typ->tsizeof(); // get increment
        !           208:                                break;
        !           209:                        default:
        !           210:                                if (t->base==PTR
        !           211:                                && (Pptr(t)->memof || Pptr(t)->typ->base==FCT))
        !           212:                                        error("%t operand of%k",this,oper);
        !           213:                        case ANDAND:
        !           214:                        case OROR:
        !           215:                        case ASSIGN:
        !           216:                        case NE:
        !           217:                        case EQ:
        !           218:                        case IF:
        !           219:                        case WHILE:
        !           220:                        case DO:
        !           221:                        case FOR:
        !           222:                        case QUEST:
        !           223:                        case NOT:
        !           224:                                        break;
        !           225:                        
        !           226:                        }
        !           227:                        return 'P';
        !           228:        case RPTR:      error("R operand for %k",oper);                 return 'A';
        !           229:        case TYPE:      t = Pbase(t)->b_name->tp;                       goto xx;
        !           230:        case FCT:       if (v != 'P') error("F operand for %k",oper);   return FCT;
        !           231:        case OVERLOAD:  error("overloaded operand for %k",oper);        return 'A';
        !           232:        case CLASS:
        !           233:        case ENUM:      error("%k operand for %k",base,oper);           return 'A';
        !           234:        default:        error("%t operand for %k",this,oper);           return 'A';
        !           235:        }
        !           236: }
        !           237: 
        !           238: void type::dcl(Ptable tbl)
        !           239: /*
        !           240:        go through the type (list) and
        !           241:        (1) evaluate vector dimensions
        !           242:        (2) evaluate field sizes
        !           243:        (3) lookup struct tags, etc.
        !           244:        (4) handle implicit tag declarations
        !           245: */
        !           246: {
        !           247: static arg_fudge;
        !           248: 
        !           249:        Ptype t = this;
        !           250: 
        !           251:        if (this == 0) error('i',"T::dcl(this==0)");
        !           252:        if (tbl->base != TABLE) error('i',"T::dcl(%d)",tbl->base);
        !           253: 
        !           254: xx:
        !           255: //error('d',"type::dcl %k",t->base);
        !           256:        switch (t->base) {
        !           257:        case TYPE:
        !           258:                t = Pbase(t)->b_name->tp;
        !           259:                goto xx;
        !           260:        case PTR:
        !           261:        case RPTR:
        !           262:        {       Pptr p = Pptr(t);
        !           263:                t = p->typ;
        !           264:                if (t->base == TYPE) {
        !           265:                        Ptype tt = Pbase(t)->b_name->tp;
        !           266:                        if (tt->base == FCT) p->typ = tt;
        !           267:                        return;
        !           268:                }
        !           269:                goto xx;
        !           270:        }
        !           271: 
        !           272:        case VEC:
        !           273:        {       Pvec v = Pvec(t);
        !           274:                Pexpr e = v->dim;
        !           275:                if (e) {
        !           276:                        Ptype et;
        !           277:                        v->dim = e = e->typ(tbl);
        !           278:                        et = e->tp;
        !           279:                        if (et->integral(0) == 'A') {
        !           280:                                error("UN in array dimension");
        !           281:                        }
        !           282:                        else {
        !           283:                                long i;
        !           284:                                Neval = 0;
        !           285:                                i = e->eval();
        !           286:                                if (Neval == 0) {
        !           287:                                        if (largest_int<i)
        !           288:                                                error("array dimension too large");
        !           289:                                        v->size = int(i);
        !           290: extern Ptable lcl_tbl;
        !           291: // error( 'd', "lcl_tbl: %d", lcl_tbl );
        !           292:                                if ( lcl_tbl == 0 )
        !           293: 
        !           294:                                        DEL(v->dim);
        !           295:                                        v->dim = 0;
        !           296:                                }
        !           297: 
        !           298:                                if (new_type) {
        !           299:                                        if (Neval)
        !           300:                                                ;
        !           301:                                        else if (i == 0)
        !           302:                                                v->dim = zero;
        !           303:                                        else if (i < 0) {
        !           304:                                                error("negative array dimension");
        !           305:                                                i = 1;
        !           306:                                        }
        !           307:                                }
        !           308:                                else {
        !           309:                                        if (Neval)
        !           310:                                                error("%s",Neval);
        !           311:                                        else if (i == 0)
        !           312:                                                error('w',"array dimension == 0");
        !           313:                                        else if (i < 0) {
        !           314:                                                error("negative array dimension");
        !           315:                                                i = 1;
        !           316:                                        }
        !           317:                                }
        !           318:                        }
        !           319:                }
        !           320:                t = v->typ;
        !           321:        llx:
        !           322:                switch (t->base) {
        !           323:                case TYPE:
        !           324:                        t = Pbase(t)->b_name->tp;
        !           325:                        goto llx;
        !           326:                case FCT:
        !           327:                        v->typ = t;
        !           328:                        break;
        !           329:                case VEC:                               
        !           330:                        if (Pvec(t)->dim==0 && Pvec(t)->size==0) error("null dimension (something like [][] seen)");
        !           331:                        if (arg_fudge) {
        !           332:                                v->base = PTR;  // X[12][10] ==> X(*)[10]
        !           333:                                Pptr(v)->rdo = 0;
        !           334:                                Pptr(v)->memof = 0;
        !           335:                        }
        !           336:                }
        !           337:                goto xx;
        !           338:        }
        !           339: 
        !           340:        case FCT:
        !           341:        {       Pfct f = Pfct(t);
        !           342: void dargs(Pname, Pfct, Ptable);
        !           343:                if (f->argtype) dargs(0,f,tbl);
        !           344:                for (Pname n=f->argtype; n; n = n->n_list) {
        !           345:                        arg_fudge++;
        !           346:                        n->tp->dcl(tbl);
        !           347:                        arg_fudge--;
        !           348:                }
        !           349:                Pname cn = f->returns->is_cl_obj();
        !           350:                if (cn && Pclass(cn->tp)->has_itor())
        !           351:                        make_res(f);
        !           352:                else if (f->f_this == 0)
        !           353:                        f->f_args = f->argtype;
        !           354:                t = f->returns;
        !           355:                goto xx;
        !           356:        }
        !           357: 
        !           358:        case FIELD:
        !           359:        {       Pbase f = Pbase(t);
        !           360:                Pexpr e = Pexpr(f->b_name);
        !           361:                long i;
        !           362:                Ptype et;
        !           363:                e = e->typ(tbl);
        !           364:                f->b_name = Pname(e);
        !           365:                et = e->tp;
        !           366:                if (et->integral(0) == 'A') {
        !           367:                        error("UN in field size");
        !           368:                        i = 1;
        !           369:                }
        !           370:                else {
        !           371:                        Neval = 0;
        !           372:                        i = e->eval();
        !           373:                        if (Neval)
        !           374:                                error("%s",Neval);
        !           375:                        else if (i < 0) {
        !           376:                                error("negative field size");
        !           377:                                i = 1;
        !           378:                        }
        !           379:                        else if (f->b_fieldtype->tsizeof()*BI_IN_BYTE < i)
        !           380:                                error("field size > sizeof(%t)",f->b_fieldtype);
        !           381:                        DEL(e);
        !           382:                }
        !           383:                f->b_bits = int(i);
        !           384:                f->b_name = 0;
        !           385:                break;
        !           386:        }
        !           387:        }
        !           388: }
        !           389: 
        !           390: bit vrp_equiv;         // vector == pointer equivalence used in check()
        !           391: bit const_problem;     // types differs only in const
        !           392: int vhack;
        !           393: int Vcheckerror;
        !           394: 
        !           395: bit type::check(Ptype t, TOK oper)
        !           396: /*
        !           397:        check if "this" can be combined with "t" by the operator "oper"
        !           398: 
        !           399:        used for check of
        !           400:                        assignment types                (oper==ASSIGN)
        !           401:                        declaration compatability       (oper==0)
        !           402:                        argument types                  (oper==ARG)
        !           403:                        return types                    (oper==RETURN)
        !           404:                        overloaded function name match  (oper==OVERLOAD)
        !           405:                        overloaded function coercion    (oper==COERCE)
        !           406:                        virtual function match          (oper==VIRTUAL)
        !           407: 
        !           408:        NOT for arithmetic operators
        !           409: 
        !           410:        return 1 if the check failed
        !           411: 
        !           412:        checking of const const* and *const is a mess
        !           413: */
        !           414: {
        !           415:        Ptype t1 = this;
        !           416:        Ptype t2 = t;
        !           417:        Ptype tt1 = this;
        !           418:        Ptype tt2 = t;
        !           419:        int cnst1 = 0;
        !           420:        int cnst2 = 0;
        !           421:        TOK b1, b2;
        !           422:        bit first = 1;
        !           423:        TOK r;
        !           424:        int vv;
        !           425:        int ptr_count = 0;
        !           426:        int fct_seen = 0;
        !           427:        int over;
        !           428:        Pptr p1 = 0;
        !           429:        Pptr p2 = 0;
        !           430:        int p_count = 0;
        !           431: 
        !           432: //error('d',"check %k %t %t",oper,t1,t2);
        !           433:        if (t1==0 || t2==0) error('i',"check(%p,%p,%d)",t1,t2,oper);
        !           434: 
        !           435:        if (oper==VIRTUAL) {
        !           436:                vv = 1;
        !           437:                Vcheckerror = 0;
        !           438:                oper = 0;
        !           439:        }
        !           440:        else
        !           441:                vv = 0;
        !           442: 
        !           443:        if (oper == OVERLOAD) {
        !           444:                over = 1;
        !           445:                oper = 0;
        !           446:        }
        !           447:        else
        !           448:                over = 0;
        !           449: 
        !           450:        const_problem = 0;
        !           451: 
        !           452:        while (t1 && t2) {
        !           453:        top:
        !           454: //error('d',"top: %t (%d) %t (%d)",t1,t1->base,t2,t2->base);
        !           455:                if (t1 == t2) {
        !           456:                        if (cnst1==cnst2) return 0;
        !           457:                        if (oper) {
        !           458: //error('d',"oper %d cnst1 %d cnst2 %d ptr %d",oper,cnst1,cnst2,tt1->is_ptr());
        !           459:                                if (tt1 = tt1->is_ptr()) {
        !           460: 
        !           461:                                        // const* = int*
        !           462:                                        if (cnst2<cnst1) return 0;
        !           463: 
        !           464:                                        // int* = int *const
        !           465:                                        if (cnst2==1 && tt2->tconst()) {
        !           466:                                                // check for int* = const *const
        !           467:                                                tt2 = tt2->is_ptr();
        !           468:                                                if (tt2->tconst()) return 1;
        !           469:                                                return 0;
        !           470:                                        }
        !           471:                                }
        !           472:                                else {  // int = const allowed
        !           473:                                        if (oper==ARG || cnst1<cnst2) return 0;
        !           474:                                }
        !           475:                        }
        !           476:                        else {
        !           477:                                if (p_count && p1->rdo+cnst1==p2->rdo+cnst2)
        !           478:                                        return 0;
        !           479:                        //      const_problem = 1;
        !           480:                        }
        !           481: 
        !           482:                        const_problem = 1;
        !           483:                        return 1;
        !           484:                }
        !           485: 
        !           486:                if (t1->base == ANY || t2->base == ANY) return 0;
        !           487: 
        !           488:                b1 = t1->base;
        !           489:                switch (b1) {
        !           490:                case TYPE:
        !           491:                        if (Pbase(t1)->b_const) cnst1++;
        !           492:                        t1 = Pbase(t1)->b_name->tp;
        !           493:                        goto top;
        !           494:                }
        !           495: 
        !           496:                b2 = t2->base;
        !           497:                switch (b2) {
        !           498:                case TYPE:
        !           499:                        if (Pbase(t2)->b_const) cnst2++;
        !           500:                        t2 = Pbase(t2)->b_name->tp;
        !           501:                        goto top;
        !           502:                }
        !           503: 
        !           504: //error('d',"oper %k b1 %k b2 %k",oper,b1,b2);
        !           505:                if (b1 != b2) {
        !           506:                        switch (b1) {
        !           507:                        case PTR:
        !           508:                                switch (b2) {
        !           509:                                case VEC:
        !           510:                                        if (ptr_count) return 1;
        !           511:                                        // ptr/vec equivalence does not
        !           512:                                        // apply to declaration matching
        !           513:                                        t1 = Pptr(t1)->typ;
        !           514:                                        t2 = Pvec(t2)->typ;
        !           515:                                        if (oper == 0 && over==0) return 1;
        !           516:                                        ptr_count++;
        !           517:                                        first = 0;
        !           518:                                        goto top;
        !           519:                                case FCT:
        !           520:                                        t1 = Pptr(t1)->typ;
        !           521:                                        if (t1->base!=VOID) 
        !           522:                                                if (first==0 || t1->base!=b2) return 1;
        !           523:                                        first = 0;
        !           524:                                        goto top;
        !           525:                                }
        !           526:                                first = 0;
        !           527:                                break;
        !           528: 
        !           529:                         case FCT:
        !           530:                                 switch( b2 ) {
        !           531:                                 case PTR:
        !           532:                                         t2 = Pptr(t2)->typ;
        !           533:                                         if (t1->base!=VOID
        !           534:                                        && (first==0||t2->base!=b1)) return 1;
        !           535:                                         first = 0;
        !           536:                                         goto top;
        !           537:                                 }
        !           538:                                 first = 0;
        !           539:                                 break;
        !           540: 
        !           541:                        case VEC:
        !           542:                                switch (b2) {
        !           543:                                case PTR:
        !           544:                                        if (ptr_count) return 1;
        !           545:                                        t1 = Pvec(t1)->typ;
        !           546:                                        t2 = Pptr(t2)->typ;
        !           547:                                        switch (oper) {
        !           548:                                        case ARG:
        !           549:                                        case ASSIGN:
        !           550:                                        case COERCE:
        !           551:                                                break;
        !           552:                                        case 0:
        !           553:                                                if (over) break;
        !           554:                                        default:
        !           555:                                                return 1;
        !           556:                                        }
        !           557:                                        ptr_count++;
        !           558:                                        first = 0;
        !           559:                                        goto top;
        !           560:                                }
        !           561:                                first = 0;
        !           562:                                break;
        !           563:                        }
        !           564:                        goto base_check; 
        !           565:                }
        !           566: 
        !           567:                switch (b1) {
        !           568:                case VEC:
        !           569: //error('d',"vec %k %d %d",oper,Pvec(t1)->size,Pvec(t2)->size);
        !           570:                        if (first==0 && Pvec(t1)->size!=Pvec(t2)->size) return 1;
        !           571:                        first = 0;
        !           572:                        t1 = Pvec(t1)->typ;
        !           573:                        t2 = Pvec(t2)->typ;
        !           574:                        ptr_count++;
        !           575:                        break;
        !           576: 
        !           577:                case PTR:
        !           578:                case RPTR:
        !           579:                        first = 0;
        !           580:                        p1 = Pptr(t1);
        !           581:                        p2 = Pptr(t2);
        !           582:                        p_count++;
        !           583: 
        !           584:                        if (p1->memof != p2->memof) {
        !           585:                                t1 = p1->typ;
        !           586:                                t2 = p2->typ;
        !           587:                                while (t1->base == TYPE) t1 = Pbase(t1)->b_name->tp;
        !           588:                                while (t2->base == TYPE) t2 = Pbase(t2)->b_name->tp;
        !           589:                                if (t1 != t2) {
        !           590:                                        if (p1->memof==0
        !           591:                                        || p2->memof==0
        !           592:                                        || p1->memof->baseof(p2->memof)==0)
        !           593:                                                return 1;
        !           594:                                        Nstd++;
        !           595:                                }
        !           596:                        }
        !           597: 
        !           598:                        t1 = p1->typ;
        !           599:                        t2 = p2->typ;
        !           600:                        ptr_count++;
        !           601: 
        !           602:                        if (oper==0) {
        !           603:                                if (p1->rdo+cnst1!=p2->rdo+cnst2
        !           604:                                && cnst1+Pbase(t1)->b_const!=cnst2+Pbase(t2)->b_const) {
        !           605:                                        // const_problem only if nothing
        !           606:                                        // more serious is wrong
        !           607:                                        if (t1->check(t2,0) == 0) const_problem = 1;
        !           608:                                        return 1;
        !           609:                                }
        !           610: 
        !           611:                                if (b1==RPTR && t1->tconst()!=t2->tconst())
        !           612:                                        const_problem = 1;
        !           613:                        }
        !           614:                        break;
        !           615: 
        !           616:                case FCT:
        !           617:                        first = 0;
        !           618:                {       Pfct f1 = Pfct(t1);
        !           619:                        Pfct f2 = Pfct(t2);
        !           620:                        Pname a1 = f1->argtype;
        !           621:                        Pname a2 = f2->argtype;
        !           622:                        TOK k1 = f1->nargs_known;
        !           623:                        TOK k2 = f2->nargs_known;
        !           624:                        int n1 = f1->nargs;
        !           625:                        int n2 = f2->nargs;
        !           626: //error('d',"f1%t f2%t",f1,f2);
        !           627:                        if (f1->memof != f2->memof) {
        !           628:                                if (f1->memof==0 && f2->f_this==0)      //SSS
        !           629:                                        goto sss;
        !           630:                                if (vv == 0)    // match even if private base class
        !           631:                                        if (f1->memof==0
        !           632:                                        || f2->memof==0
        !           633:                                        || f1->memof->baseof(f2->memof)==0) return 1;
        !           634:                                Nstd++;
        !           635:                                sss:;   //SSS
        !           636:                        }
        !           637: 
        !           638:                        if (k1 != k2) return 1;
        !           639: 
        !           640:                        if (n1!=n2 && k1 && k2) {
        !           641:                                goto aaa;
        !           642:                        }
        !           643:                        else if (a1 && a2) {
        !           644:                                int i = 0;
        !           645:                                while (a1 && a2) {
        !           646:                                        i++;
        !           647:                                        if (a1->tp->check(a2->tp,over?OVERLOAD:0)) return 1;
        !           648:                                        a1 = a1->n_list;
        !           649:                                        a2 = a2->n_list;
        !           650:                                }
        !           651:                                if (a1 || a2) goto aaa;
        !           652:                        }
        !           653:                        else if (a1 || a2) {
        !           654:                        aaa:
        !           655: //error('d',"aaa k1 %d k2 %d",k1,k2);
        !           656:                                if (k1 == ELLIPSIS) {
        !           657:                                        switch (oper) {
        !           658:                                        case 0:
        !           659:                                                if (a2 && k2==0) break;
        !           660:                                                return 1;
        !           661:                                        case ASSIGN:
        !           662:                                                if (a2 && k2==0) break;
        !           663:                                                return 1;
        !           664:                                        case ARG:
        !           665:                                                if (a1) return 1;
        !           666:                                                break;
        !           667:                                //      case OVERLOAD:
        !           668:                                        case COERCE:
        !           669:                                                return 1;
        !           670:                                        }
        !           671:                                }
        !           672:                                else if (k2 == ELLIPSIS) {
        !           673:                                        return 1;
        !           674:                                }
        !           675:                                else if (k1 || k2) {
        !           676:                                        return 1;
        !           677:                                }
        !           678:                        }
        !           679: 
        !           680:                        t1 = f1->returns;
        !           681:                        t2 = f2->returns;
        !           682:                        fct_seen = 1;
        !           683: 
        !           684:                        switch (oper) { //CCC
        !           685:                        case 0:
        !           686:                                if (f1->f_const!=f2->f_const) {
        !           687:                                        if (t1->check(t2,0)==0) const_problem = 1;
        !           688:                                        return 1;
        !           689:                                //      if (vv == 0) return 1;
        !           690:                                //      Vcheckerror = 1;
        !           691:                                }
        !           692:                                break;
        !           693:                        default:        // really pointer to function
        !           694:                                if (f1->f_const && f2->f_const==0) return 1;
        !           695:                        }
        !           696: 
        !           697: 
        !           698:                        if (vv && t1->check(t2,0)) { Vcheckerror = 1; return 1; }
        !           699:                }
        !           700:                        break;
        !           701: 
        !           702:                case FIELD:
        !           703:                        goto field_check;
        !           704:                case CHAR:
        !           705:                case SHORT:
        !           706:                case INT:
        !           707:                case LONG:
        !           708:                        goto int_check;
        !           709:                case FLOAT:
        !           710:                case DOUBLE:
        !           711:                case LDOUBLE:
        !           712:                        goto float_check;
        !           713:                case EOBJ:
        !           714:                        goto enum_check;
        !           715:                case COBJ:
        !           716:                        goto cla_check;
        !           717:                case ZTYPE:
        !           718:                case VOID:
        !           719:                        return 0;
        !           720:                default:
        !           721:                        error('i',"T::check(o=%d %d %d)",oper,b1,b2);
        !           722:                }
        !           723:        }
        !           724: 
        !           725:        if (t1 || t2) {
        !           726:                const_problem = 0;      // not a problem: the type itself is bad
        !           727:                return 1;
        !           728:        }
        !           729:        return 0;
        !           730: 
        !           731: field_check:
        !           732:        switch (oper) {
        !           733:        case 0:
        !           734:        case ARG:
        !           735:                error('i',"check field?");
        !           736:        }
        !           737:        return 0;
        !           738: 
        !           739: enum_check:
        !           740: //error('d',"enum check %t %t",t1,t2);
        !           741:        if (Pbase(t1)->b_name->tp != Pbase(t2)->b_name->tp) goto base_check;
        !           742:        goto const_check;
        !           743: 
        !           744: float_check:
        !           745:        if (first==0 && b1!=b2 && b2!=ZTYPE) return 1;
        !           746:        // no break
        !           747: 
        !           748: int_check:
        !           749: //error('d',"int_check");
        !           750:        if (Pbase(t1)->b_unsigned != Pbase(t2)->b_unsigned) {
        !           751:                if (first == 0) return 1;
        !           752:                if (oper /*&& oper!=OVERLOAD*/)
        !           753:                        Nstd++;
        !           754:                else
        !           755:                        return 1;
        !           756:        }
        !           757:        // no break
        !           758: 
        !           759: const_check:
        !           760: //error('d',"const_check %t (%d) %t (%d)",t1,t1->tconst(),t2,t2->tconst());
        !           761:        if (oper==0) {
        !           762: //error('d',"oper==0: t1 %t t2 %t cnst1 %d cnst2 %d",t1,t2,cnst1,cnst2);
        !           763:                if (t1->tconst()+cnst1!=t2->tconst()+cnst2) {
        !           764:                        const_problem = 1;
        !           765:                        return 1;
        !           766:                }
        !           767:        }
        !           768:        else if (first==0) {
        !           769:                if (t1->tconst()+cnst1==0 && t2->tconst()+cnst2) {
        !           770: //error('d',"t1 %t t2 %t cnst1 %d cnst2 %d",t1,t2,cnst1,cnst2);
        !           771: //error('d',"tt1 %t %d cnst1 %d cnst2 %d",tt1,tt1->is_ptr(),cnst1,cnst2);
        !           772: //error('d',"tt2 %t",tt2);
        !           773:                        if (tt1->is_ptr()) {
        !           774:                                if (fct_const || vec_const) cnst2--;
        !           775: 
        !           776:                                // const* = int*
        !           777:                                if (cnst2-tt2->tconst()<cnst1-tt1->tconst()) return 0;
        !           778: 
        !           779:                                // int* = *const
        !           780:                                if (cnst2==1 && tt2->tconst()) return 0;
        !           781: 
        !           782:                                // const T* = const T*
        !           783:                                if (t2->tconst()+cnst2==t1->tconst()+cnst1) return 0;
        !           784:                        }
        !           785:                        else {  // int = const allowed
        !           786:                                if (cnst1<cnst2) return 0;
        !           787:                        }
        !           788:                        const_problem = 1;
        !           789:                        return 1;
        !           790:                }
        !           791:                else {  // const* vs int *const
        !           792: /*
        !           793:  //error('d',"t1 %t cnst1 %d t2 %t cnst2 %d",t1,cnst1,t2,cnst2);
        !           794:                        if (tt1->is_ptr()) {
        !           795:                                int tt1c = tt1->tconst();
        !           796:                                int tt2c = tt2->tconst() - fct_const - vec_const;
        !           797:  //error('d',"tt1c %d tt2c %d",tt1c,tt2c);
        !           798:                                if (tt1c<tt2c) return 1;
        !           799:                                int t1c = t1->tconst();
        !           800:                                int t2c = t2->tconst() - fct_const - vec_const;
        !           801:  //error('d',"t1c %d t2c %d",t1c,t2c);
        !           802:                                if (cnst1+t1c<cnst2+t2c) return 1;
        !           803:                                if (tt2c<tt1c   // *const = *
        !           804:                                && cnst1+t1c>cnst2+t2c) // T = constT
        !           805:                                        return 1;
        !           806:                        }
        !           807: */
        !           808:                        
        !           809:                }
        !           810:        }
        !           811:        else {
        !           812: //error('d',"first t1 %t t2 %t cnst1 %d cnst2 %d",t1,t2,cnst1,cnst2);
        !           813:        }
        !           814: //error('d',"return 0");
        !           815:        return 0;
        !           816: 
        !           817: cla_check:
        !           818:        {       Pname n1 = Pbase(t1)->b_name;
        !           819:                Pname n2 = Pbase(t2)->b_name;
        !           820: //error('d',"cla_check %n %n ptr_count %d",n1,n2,ptr_count);
        !           821:                if (n1 == n2) goto const_check;
        !           822: 
        !           823:                if (/*first || */1<ptr_count || fct_seen) return 1;
        !           824: 
        !           825:                switch (oper) {
        !           826:                case ARG:
        !           827:                case ASSIGN:
        !           828:                case RETURN:
        !           829:                case COERCE:
        !           830:                {       extern TOK ppbase;
        !           831:                        ppbase = PUBLIC;
        !           832:                        if (Pclass(n2->tp)->is_base(n1->string)) {
        !           833:                                if (ppbase!=PUBLIC) {
        !           834:                                        const_problem = 0;
        !           835:                                //      vrp_equiv = 0;
        !           836:                                        return 1;       // private or protected base
        !           837:                                }
        !           838:                                Nstd++;
        !           839:                                goto const_check;
        !           840:                        }
        !           841:                }
        !           842:                        // no break
        !           843:                case 0:
        !           844:                case OVERLOAD:
        !           845:                        const_problem = 0;
        !           846:                //      vrp_equiv = 0;
        !           847:                        return 1;
        !           848:                }
        !           849: 
        !           850:                goto const_check;
        !           851:        }
        !           852: 
        !           853: base_check:
        !           854: //error('d',"base_check t1=%t t2=%t oper=%d %s",t1,t2,oper,first?"first":"");
        !           855: //error('d',"ptr_count %d",ptr_count);
        !           856:        if (oper)
        !           857:        if (first || 1!=ptr_count) {
        !           858:                if (b1==VOID || b2==VOID) return 1;
        !           859:        }
        !           860:        else {
        !           861:                if (b1 == VOID) {               // check for void* = T*
        !           862:                        register Ptype tpx = this;
        !           863:                tpxloop:
        !           864:                        switch (tpx->base) {    // t1 == void*
        !           865:                        default:
        !           866:                                        const_problem = 0;
        !           867:                                        return 1;
        !           868:                        case VOID:      break;
        !           869:                        case PTR:
        !           870:                        case VEC:       tpx = Pvec(tpx)->typ;
        !           871:                                        goto tpxloop;
        !           872:                        case TYPE:      tpx = Pbase(tpx)->b_name->tp;
        !           873:                                        goto tpxloop;
        !           874:                        }
        !           875: 
        !           876:                        tpx = t;
        !           877:                bloop:
        !           878:                        switch (tpx->base) {    // t2 == T*
        !           879:                        default:
        !           880:                                        const_problem = 0;
        !           881:                                        return 1;
        !           882:                        case VEC:
        !           883:                        case PTR:
        !           884:                        case FCT:       Nstd++;
        !           885:                                //      return 0;
        !           886:                                        goto const_check; // prevent void* = const*
        !           887:                        case TYPE:      tpx = Pbase(tpx)->b_name->tp;
        !           888:                                        goto bloop;
        !           889:                        }
        !           890:                }
        !           891: 
        !           892:                if (b2 != ZTYPE) {
        !           893:                        const_problem = 0;
        !           894:                        return 1;
        !           895:                }
        !           896:        }
        !           897: //error('d',"oper %d b1 %d b2 %d cp %d",oper,b1,b2,const_problem);
        !           898:        switch (oper) {
        !           899:        case 0:
        !           900:                if (b1 != b2) {
        !           901:                        const_problem = 0; // we have a bigger problem
        !           902:                //      vrp_equiv = 0;
        !           903:                }
        !           904:                return 1;
        !           905:        case COERCE:    // could probably be merged with the cases below
        !           906:                switch (b1) {
        !           907:                case EOBJ:
        !           908:                //      echeck(t1,t2);
        !           909:                case ZTYPE:
        !           910:                case CHAR:
        !           911:                case SHORT:
        !           912:                case INT:
        !           913:                        switch (b2) {
        !           914:                                case LONG:
        !           915:                                case FLOAT:
        !           916:                                case DOUBLE:
        !           917:                                case LDOUBLE:
        !           918:        //                              Nstd++;
        !           919:                                case EOBJ:
        !           920:                                case ZTYPE:
        !           921:                                case CHAR:
        !           922:                                case SHORT:
        !           923:                                case INT:
        !           924:                                case FIELD:
        !           925: Nstd++;
        !           926:                                        if (b1 == EOBJ) echeck(t1,t2);
        !           927:                                        goto const_check;
        !           928:                        }
        !           929:                        return 1;
        !           930:                case LONG:      // char, short, and int promotes to long
        !           931:                        switch (b2) {
        !           932:                                case FLOAT:
        !           933:                                case DOUBLE:
        !           934:                                case LDOUBLE:
        !           935:                        case ZTYPE:
        !           936:                        case EOBJ:
        !           937:                        case CHAR:
        !           938:                        case SHORT:
        !           939:                        case INT:
        !           940:                        case FIELD:
        !           941:                                Nstd++;
        !           942:                                goto const_check;
        !           943:                        }
        !           944:                        return 1;
        !           945:                case FLOAT:
        !           946:                //      switch (b2) {
        !           947:                //      case ZTYPE:
        !           948:                //              Nstd++;
        !           949:                //      case FLOAT:
        !           950:                //      case DOUBLE:
        !           951:                //              goto const_check;
        !           952:                //      }
        !           953:                //      return 1;
        !           954:                case DOUBLE:    // char, short, int, and float promotes to double
        !           955:                case LDOUBLE:
        !           956:                        switch (b2) {
        !           957:                        case LONG:
        !           958:                        case ZTYPE:
        !           959:                        case EOBJ:
        !           960:                        case CHAR:
        !           961:                        case SHORT:
        !           962:                        case INT:
        !           963:                //              Nstd++;
        !           964:                        case FLOAT:
        !           965:                        case DOUBLE:
        !           966:                        case LDOUBLE:
        !           967: Nstd++;
        !           968:                                goto const_check;
        !           969:                        }
        !           970:                        return 1;
        !           971:                case PTR:
        !           972:                        switch (b2) {
        !           973:                        case ZTYPE:
        !           974:                                Nstd++;
        !           975:                                goto const_check;
        !           976:                        }
        !           977:                case RPTR:
        !           978:                case VEC:
        !           979:                case COBJ:
        !           980:                case FCT:
        !           981:                        return 1;
        !           982:                }
        !           983:        case ARG:
        !           984:        case ASSIGN:
        !           985:        case RETURN:
        !           986:                switch (b1) {
        !           987:                case COBJ:
        !           988:                        return 1;
        !           989:                case EOBJ:
        !           990:                //      echeck(t1,t2);  
        !           991:                case ZTYPE:
        !           992:                case CHAR:
        !           993:                case SHORT:
        !           994:                case INT:
        !           995:                case LONG:
        !           996:                        suppress_error++;
        !           997:                        r = t2->num_ptr(ASSIGN);
        !           998:                        suppress_error--;
        !           999:                        switch (r) {
        !          1000:                        case 'F':
        !          1001:                        //      if (oper!=ARG) error('w',"%t assigned to%t",t2,t1);
        !          1002:                                break;
        !          1003:                        case 'A':
        !          1004:                        case 'P':
        !          1005:                        case FCT:       return 1;
        !          1006:                        }
        !          1007:                        if (b1 == EOBJ) echeck(t1,t2);  
        !          1008:                        break;
        !          1009:                case FLOAT:
        !          1010:                case DOUBLE:
        !          1011:                case LDOUBLE:
        !          1012:                        suppress_error++;
        !          1013:                        r = t2->numeric(ASSIGN);
        !          1014:                        suppress_error--;
        !          1015:                        switch (r) {    
        !          1016:                        case 'A':
        !          1017:                        case 'P':
        !          1018:                        case FCT:       return 1;
        !          1019:                        }
        !          1020:                        break;
        !          1021:                case VEC:
        !          1022:                        return 1;
        !          1023:                case PTR:
        !          1024:                        suppress_error++;
        !          1025:                        r = t2->num_ptr(ASSIGN);
        !          1026:                        suppress_error--;
        !          1027:                        switch (r) {
        !          1028:                        case 'A':
        !          1029:                        case 'I':
        !          1030:                        case 'F':       return 1;
        !          1031:                        case FCT:       if (Pptr(t1)->typ->base != FCT) return 1;
        !          1032:                        }
        !          1033:                        break;
        !          1034:                case RPTR:
        !          1035:                        return 1;
        !          1036:                case FCT:
        !          1037:                        switch (oper) {
        !          1038:                        case ARG:
        !          1039:                        case ASSIGN:
        !          1040:                                return 1;
        !          1041:                        }
        !          1042:                }       
        !          1043:                break;
        !          1044:        }
        !          1045:        goto const_check;
        !          1046: }
        !          1047: 

unix.superglobalmegacorp.com

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