Annotation of cci/usr/src/bin/cdb/ty.c, revision 1.1

1.1     ! root        1: static char sccsid[] = "@(#)ty.c       2.16";
        !             2: 
        !             3: #include <ctype.h>
        !             4: #include "cdb.h"
        !             5: #include "macdefs.h"
        !             6: 
        !             7: #ifdef BSD41
        !             8: #define crockValue -1
        !             9: #define cbSbSafe 1024
        !            10: #else
        !            11: #define crockValue ""
        !            12: #define cbSbSafe 256
        !            13: #endif
        !            14: char   vsbSafe[cbSbSafe];      /* where we stick names of things */
        !            15: char   *vsbNextSafe = vsbSafe; /* next available place */
        !            16: 
        !            17: /*                                        v - that is the fConstant field */
        !            18: #ifdef SUN
        !            19: TYR    atyCnChar = {
        !            20:        crockValue,  stValue, true,  0, 0,0,0,0,0,0, btChar,  0};
        !            21: TYR    atyChar =   {
        !            22:        crockValue,  stValue, false, 0, 0,0,0,0,0,0, btChar,  0};
        !            23: TYR    atyCnShort ={
        !            24:        crockValue,  stValue, true,  0, 0,0,0,0,0,0, btShort, 0};
        !            25: TYR    atyShort =  {
        !            26:        crockValue,  stValue, false, 0, 0,0,0,0,0,0, btShort, 0};
        !            27: TYR    atyCnInt =  {
        !            28:        crockValue,  stValue, true,  0, 0,0,0,0,0,0, btInt,   0};
        !            29: TYR    atyInt =    {
        !            30:        crockValue,  stValue, false, 0, 0,0,0,0,0,0, btInt,   0};
        !            31: TYR    atyCnLong = {
        !            32:        crockValue,  stValue, true,  0, 0,0,0,0,0,0, btLong,  0};
        !            33: TYR    atyLong =   {
        !            34:        crockValue,  stValue, false, 0, 0,0,0,0,0,0, btLong,  0};
        !            35: TYR    atyCnFloat ={
        !            36:        crockValue,  stValue, true,  0, 0,0,0,0,0,0, btFloat, 0};
        !            37: TYR    atyFloat =  {
        !            38:        crockValue,  stValue, false, 0, 0,0,0,0,0,0, btFloat, 0};
        !            39: #else
        !            40: TYR    atyCnChar = {
        !            41:        crockValue,  stValue, true,  0, btChar,  0,0,0,0,0,0, 0};
        !            42: TYR    atyChar =   {
        !            43:        crockValue,  stValue, false, 0, btChar,  0,0,0,0,0,0, 0};
        !            44: TYR    atyCnShort ={
        !            45:        crockValue,  stValue, true,  0, btShort, 0,0,0,0,0,0, 0};
        !            46: TYR    atyShort =  {
        !            47:        crockValue,  stValue, false, 0, btShort, 0,0,0,0,0,0, 0};
        !            48: TYR    atyCnInt =  {
        !            49:        crockValue,  stValue, true,  0, btInt,   0,0,0,0,0,0, 0};
        !            50: TYR    atyInt =    {
        !            51:        crockValue,  stValue, false, 0, btInt,   0,0,0,0,0,0, 0};
        !            52: TYR    atyCnLong = {
        !            53:        crockValue,  stValue, true,  0, btLong,  0,0,0,0,0,0, 0};
        !            54: TYR    atyLong =   {
        !            55:        crockValue,  stValue, false, 0, btLong,  0,0,0,0,0,0, 0};
        !            56: TYR    atyCnFloat ={
        !            57:        crockValue,  stValue, true,  0, btFloat, 0,0,0,0,0,0, 0};
        !            58: TYR    atyFloat =  {
        !            59:        crockValue,  stValue, false, 0, btFloat, 0,0,0,0,0,0, 0};
        !            60: #endif
        !            61: TYR    atyZeros;
        !            62: 
        !            63: export pTYR    vtyZeros;
        !            64: export pTYR    vtyChar, vtyCnChar;
        !            65: export pTYR    vtyShort, vtyCnShort;
        !            66: export pTYR    vtyInt, vtyCnInt;
        !            67: export pTYR    vtyLong, vtyCnLong;
        !            68: export pTYR    vtyFloat, vtyCnFloat;
        !            69: 
        !            70: /* most of this type code is NOT needed if we have berkely symbol tables */
        !            71: #ifndef BSD41
        !            72: export int     vityMac;        /* # TY's in current decl file */
        !            73: int    vityBase, vityLim;      /* bounds on the ty cache */
        !            74: int    vcTyCache;              /* # of things actually in cache */
        !            75: #define cTyCacheMax    100
        !            76: TYR    vtyCache[cTyCacheMax];  /* buffer where we stick type stuff */
        !            77: int    vity;           /* index of TY of current interest */
        !            78: pTYR   vtyCur;         /* TY of current interest */
        !            79: #define cbTyCache sizeof(vtyCache)
        !            80: 
        !            81: #define fDoForward     true
        !            82: #define fDoBackward    false
        !            83: 
        !            84: /* S E T   T Y   C A C H E */
        !            85: 
        !            86: local void SetTyCache(ity)
        !            87: int    ity;
        !            88: {
        !            89:        int             ityTemp, cRead;
        !            90:        long    l1, l2, offset;
        !            91: 
        !            92:        if ( ((ity >= vityBase) AND (ity < vityLim-(cTyMax-1)))
        !            93:            OR ((ity == vityLim-(cTyMax-1)) AND (vityLim == vityMac)) ) {
        !            94:                return; /* it is already in there, somewhere */
        !            95:        } /* if */
        !            96:        ityTemp = (ity / cTyCacheMax) * cTyCacheMax; /* adjust to 'page' boundary */
        !            97:        if ((ity+(cTyMax-1)) % cTyCacheMax == 0)
        !            98:                ityTemp += (cTyMax-1);  /* allow room for a possible second TYR */
        !            99:        l1 = ityTemp;
        !           100:        l2 = cbTYR;
        !           101:        offset = l1 * l2;
        !           102:        if (lseek(vfnDecl, offset, 0) < 0L) {
        !           103:                Panic("Bad seek in SetTyCache");
        !           104:        } /* if */
        !           105:        if ((cRead=read(vfnDecl, vtyCache, cbTyCache)) < 0)
        !           106:                Panic("Bad read in SetTyCache");
        !           107:        vcTyCache = cRead / cbTYR;
        !           108:        vityBase = ityTemp;
        !           109:        vityLim = vityBase + vcTyCache;
        !           110: } /* SetTyCache */
        !           111: 
        !           112: 
        !           113: /* S E T   T Y */
        !           114: 
        !           115: local void SetTy(ity)
        !           116: int    ity;
        !           117: {
        !           118:        if (ity < 0 OR ity >= vityMac)
        !           119:                Panic("ity out of bounds in SetTy - %d", ity);
        !           120:        vity = ity;
        !           121:        SetTyCache(ity);
        !           122:        vtyCur = vtyCache + (ity-vityBase);
        !           123: } /* SetTy */
        !           124: 
        !           125: 
        !           126: /* S E T   T Y   N E X T */
        !           127: 
        !           128: local void SetTyNext(ity, fForward)
        !           129: FLAGT  fForward;
        !           130: {
        !           131:        if ((ity < 0) OR (ity >= vityMac))
        !           132:                Panic("ity out of bounds in SetTyNext - %d", ity);
        !           133:        vity = ity + ((fForward) ? -1 : 1);
        !           134:        if (vity < 0)
        !           135:                vity = 0;
        !           136:        else if (vity >= vityMac)
        !           137:                vity = vityMac - 1;
        !           138:        SetTy(vity);
        !           139: } /* SetTyNext */
        !           140: 
        !           141: 
        !           142: /* F   N E X T   T Y */
        !           143: 
        !           144: local FLAGT FNextTy(fForward, sbVar, stLook1, stLook2, stStop1, stStop2)
        !           145: FLAGT  fForward;
        !           146: char   *sbVar;
        !           147: int    stLook1, stLook2, stStop1, stStop2;
        !           148: {
        !           149:        int             i, st, ityEnd, dity, ity;
        !           150: 
        !           151:        if (vityMac == 0)
        !           152:                return(false);  /* there is no valid decl file open */
        !           153:        dity = (fForward) ? 1 : -1;
        !           154:        ity = vity + dity;
        !           155:        while ((ity >= 0) AND (ity < vityMac)) {
        !           156:                SetTyCache(ity);
        !           157:                ityEnd = (fForward) ? vityLim : vityBase-1;
        !           158:                for (i = ity; ity != ityEnd; i+=dity, ity+=dity) {
        !           159:                        vtyCur = vtyCache + i;
        !           160:                        st = vtyCur->td.st & 0x00ff;
        !           161:                        if (  (st == stLook1)
        !           162:                            OR (st == stLook2)
        !           163:                            OR ((sbVar != sbNil)
        !           164:                            AND (stLook1 == 0)
        !           165:                            AND (stLook2 == 0))) {
        !           166:                                if ((sbVar == sbNil)
        !           167:                                    OR (FProcCmp(vtyCur->sbVar, sbVar)) ) {
        !           168:                                        SetTy(ity);
        !           169:                                        return(true);
        !           170:                                } /* if */
        !           171:                        } 
        !           172:                        else if (st == stStop1 OR st == stStop2) {
        !           173:                                return(false);
        !           174:                        } /* if */
        !           175:                } /* for */
        !           176:        } /* while */
        !           177:        return(false);
        !           178: } /* FNextTY */
        !           179: 
        !           180: 
        !           181: /* I T Y   F   S B   L N */
        !           182: 
        !           183: local int ItyFSbLn(sbVar, ln)
        !           184: char   *sbVar;
        !           185: int    ln;
        !           186: {
        !           187:        int             ity;
        !           188:        FLAGT   fFoundBlock;
        !           189: 
        !           190:        if ((vfnDecl == fnNil)
        !           191:            OR (ln <= 0))
        !           192:                return(ityNil);
        !           193: 
        !           194:        /* first we find a block mark with a line number GREATER than ln */
        !           195:        SetTyNext(0, fDoForward);
        !           196:        fFoundBlock = false;
        !           197:        while (FNextTy(fDoForward, sbNil, stLBrac, stRBrac, 0, 0)) {
        !           198:                if (vtyCur->valTy > ln) {
        !           199:                        fFoundBlock = true;
        !           200:                        break;
        !           201:                } /* if */
        !           202:        } /* while */
        !           203:        if (!fFoundBlock) {
        !           204:                /* this could happen when looking for a formal of the
        !           205:                         * last procedure in a file, and the procedure does not have
        !           206:                         * any locals.
        !           207:                         */
        !           208:                ity = vityMac-1;        /* this might not be quite right - kludge */
        !           209:                SetTyNext(ity, fDoBackward);
        !           210:        } /* if */
        !           211: 
        !           212:        /* now we back up and find the name (if it's there) */
        !           213:        if (FNextTy(fDoBackward, sbVar, 0, 0, 0, 0)) {
        !           214:                return(vity);
        !           215:        } /* if */
        !           216:        return(ityNil);
        !           217: } /* ItyFSbLn */
        !           218: 
        !           219: 
        !           220: /* I N I T   T Y   C A C H E */
        !           221: 
        !           222: export void InitTyCache()
        !           223: {
        !           224:        vityBase = 0;
        !           225:        vityLim = 0;
        !           226:        SetTyCache(0);
        !           227: } /* InitTyCache */
        !           228: #endif
        !           229: 
        !           230: 
        !           231: /* S B   S A F E */
        !           232: 
        !           233: export SBT SbSafe(sb)
        !           234: char   *sb;
        !           235: {
        !           236:        int             i;
        !           237:        SBT             sbRet;
        !           238:        char    *sbT;
        !           239: 
        !           240:        /* this guy sticks names in a temporarily safe place */
        !           241:        /* find the null or : */
        !           242:        for (sbT = sb; *sbT != chNull; sbT++)
        !           243:                if (*sbT == ':')
        !           244:                        break;
        !           245:        i = sbT - sb + 1;
        !           246:        if (vsbNextSafe+i >= vsbSafe+cbSbSafe)
        !           247:                /* would run off end of buffer */
        !           248:                vsbNextSafe = vsbSafe;  /* reuse the buffer */
        !           249:        strncpy(vsbNextSafe, sb, i);
        !           250: #ifdef BSD41
        !           251:        sbRet = bitHigh | (SBT)vsbNextSafe;
        !           252: #else
        !           253:        sbRet = vsbNextSafe;
        !           254: #endif
        !           255:        vsbNextSafe[i-1] = chNull;
        !           256:        vsbNextSafe += i;
        !           257:        return(sbRet);
        !           258: } /* SbSafe */
        !           259: 
        !           260: 
        !           261: /* S B   I N   S A F E */
        !           262: 
        !           263: export char * SbInSafe(iss)
        !           264: long   iss;
        !           265: {
        !           266:        return( SbInCore(SbSafe(SbInCore(iss))) );
        !           267: }
        !           268: 
        !           269: 
        !           270: #ifdef BSD42
        !           271: 
        !           272: /* I S S   F   I D B */
        !           273: 
        !           274: local long IssFIdb(idb, iss)
        !           275: int    idb;
        !           276: long   iss;
        !           277: {
        !           278:        int             ifd, cbTarget;
        !           279:        long    isym, issMac;
        !           280:        char    *sbSym, *sbT1, *sbT2, sbIdb[10];
        !           281: 
        !           282:        /* given a DBX type number and a maximum iss, find the
        !           283:             * definition of the type.
        !           284:             * Return the index into string space.
        !           285:             */
        !           286: 
        !           287:        /* first we find beginning of THIS file's symbols */
        !           288:        issMac = iss + 1;
        !           289:        ifd = vifdNil;
        !           290:        if (vifd != vifdNil) {
        !           291:                SetSym(vrgFd[vifd].isym);
        !           292:                if (vsymCur->sbSym < issMac) {
        !           293:                        SetSym(vrgFd[vifd+1].isym);
        !           294:                        if (vsymCur->sbSym >= issMac)
        !           295:                                ifd = vifd;
        !           296:                }
        !           297:        }
        !           298:        if (ifd == vifdNil) {
        !           299:                for (ifd=0; ifd < vifdMac; ifd++) {
        !           300:                        SetSym(vrgFd[ifd].isym);
        !           301:                        if (vsymCur->sbSym >= issMac) {
        !           302:                                ifd--;
        !           303:                                break;
        !           304:                        }
        !           305:                } /* for */
        !           306:        } /* if */
        !           307:        sprintf(sbIdb, "%d", idb);
        !           308:        cbTarget = strlen(sbIdb);
        !           309:        isym = vrgFd[ifd].isym
        !           310: #ifdef SUN
        !           311:            + 12;       /* skip file sym + standard 11 types*/
        !           312: #else
        !           313:        + 13;   /* skip file sym + standard 12 types*/
        !           314: #endif
        !           315:        SetSym(isym);
        !           316:        while (vsymCur->sbSym < issMac) {
        !           317:                sbT1 = sbSym = SbInCore(vsymCur->sbSym);
        !           318:                while ((sbT2 = strchr(sbT1, '=')) != sbNil) {
        !           319:                        /* a cadidate */
        !           320:                        if (FHdrCmp(sbIdb, sbT2-cbTarget)) {
        !           321:                                /* found it! */
        !           322:                                return(vsymCur->sbSym + (1+(sbT2-sbSym)));
        !           323:                        }
        !           324:                        sbT1 = sbT2 + 1; /* move past '=', see if there is another one */
        !           325:                } /* while */
        !           326:                isym++;
        !           327:                SetSym(isym);
        !           328:        } /* while */
        !           329:        Panic("Can't find idb: %d in ifd: %d", idb, ifd);
        !           330: } /* IssFIdb */
        !           331: 
        !           332: 
        !           333: /* T Y   F   I D B */
        !           334: 
        !           335: local void TyFIdb(rgTy, idb)
        !           336: pTYR   rgTy;
        !           337: int    idb;
        !           338: {
        !           339:        int             bt;
        !           340:        /* these are the standard DBX types */
        !           341:        switch (idb) {
        !           342:        case 1: 
        !           343:                bt = btInt;     
        !           344:                break;
        !           345:        case 2: 
        !           346:                bt = btChar;    
        !           347:                break;
        !           348:        case 3: 
        !           349:                bt = btLong;    
        !           350:                break;
        !           351:        case 4: 
        !           352:                bt = btShort;   
        !           353:                break;
        !           354:        case 5: 
        !           355:                bt = btUChar;   
        !           356:                break;
        !           357:        case 6: 
        !           358:                bt = btUShort;  
        !           359:                break;
        !           360:        case 7: 
        !           361:                bt = btULong;   
        !           362:                break;
        !           363:        case 8: 
        !           364:                bt = btUInt;    
        !           365:                break;
        !           366:        case 9: 
        !           367:                bt = btFloat;   
        !           368:                break;
        !           369:        case 10: 
        !           370:                bt = btDouble; 
        !           371:                break;
        !           372:        case 11: 
        !           373:                bt = btNil; 
        !           374:                break;
        !           375:        } /* switch */
        !           376:        rgTy->td.bt = bt;
        !           377: } /* TyFIdb */
        !           378: 
        !           379: 
        !           380: /* I S S   F   S T A R T */
        !           381: 
        !           382: export long IssFStart(iss)
        !           383: {
        !           384:        char    *sb;
        !           385:        /* given an iss at the beginning of a struct, union or enum definition
        !           386:             * return the iss of the NAME of this thing
        !           387:             * We have something like "FOOR:t18=s12....." and iss is pointing
        !           388:             * at the 's' after the '='.
        !           389:             */
        !           390:        do {
        !           391:                sb = SbInCore(--iss);
        !           392:        } 
        !           393:        while ((*sb != chNull) AND (*sb != ';'));
        !           394:        return(++iss);
        !           395: } /* IssFStart */
        !           396: 
        !           397: 
        !           398: /* T Y   F   S C A N   D B X */
        !           399: 
        !           400: local void TyFScanDbx(rgTy, iss)
        !           401: pTYR   rgTy;
        !           402: long   iss;
        !           403: {
        !           404:        int             i, idb;
        !           405:        char    ch;
        !           406:        char    *sb;
        !           407:        pXTYR   xty;
        !           408: 
        !           409:        printf("TyFScanDBX caled with 0x%x and %d\n",rgTy, iss);
        !           410:        xty = (pXTYR) (rgTy + 1); /* in case anyone needs it */
        !           411:        while (true) {
        !           412:                sb = SbInCore(iss);
        !           413:                printf("-1- sb :%s:\n",sb);
        !           414:                ch = *sb;
        !           415:                switch (ch) {
        !           416:                case chNull:
        !           417:                case ',':
        !           418:                case ';':
        !           419:                        return;
        !           420:                case '0': 
        !           421:                case '1': 
        !           422:                case '2': 
        !           423:                case '3': 
        !           424:                case '4':
        !           425:                case '5': 
        !           426:                case '6': 
        !           427:                case '7': 
        !           428:                case '8': 
        !           429:                case '9':
        !           430:                        idb = atoi(sb);
        !           431:                        printf("-2- idb : %d\n",idb);
        !           432:                        while (isdigit(*sb)) {
        !           433:                                sb++;
        !           434:                                iss++;
        !           435:                        }
        !           436:                        printf("-3- iss:%d sb:%s:\n", iss,sb);
        !           437:                        if (*sb == '=')
        !           438:                                break;  /* continue onwards */
        !           439:                        if (idb <= 11) {
        !           440:                                TyFIdb(rgTy, idb);
        !           441:                                return;
        !           442:                        } 
        !           443:                        else {
        !           444:                                iss = IssFIdb(idb, iss);
        !           445:                        }
        !           446:                        continue;
        !           447:                        break;
        !           448:                case '*':
        !           449:                        FAdjTd(rgTy, tqPtr);
        !           450:                        break;
        !           451:                case '=':
        !           452:                        break;
        !           453:                case 'a':
        !           454:                        /* we expect this to look like 'ar1;0;#1;#2;
        !           455:                                         * where 0 is the lower bounds (always for C),
        !           456:                                         *       #1 is the upper bound,
        !           457:                                         *       #2 is the element type (possibley another array)
        !           458:                                         */
        !           459:                        sb++;
        !           460:                        if ((*sb++ != 'r')
        !           461:                            OR (*sb++ != '1')
        !           462:                            OR (*sb++ != ';')
        !           463:                            OR (*sb++ != '0')
        !           464:                            OR (*sb++ != ';'))
        !           465:                                Panic("Lost in array spec??");
        !           466:                        iss += 6;
        !           467:                        i = atoi(sb);   /* get the size of the dimension */
        !           468:                        while (isdigit(*sb) OR (*sb == '-')) {
        !           469:                                sb++;
        !           470:                                iss++;
        !           471:                        }
        !           472:                        if (*sb++ != ';')
        !           473:                                Panic("Lost in array spec");
        !           474:                        if (xty->rgDim[1] == 0) {
        !           475:                                if (TqFTy(rgTy, 1) != tqArray)
        !           476:                                        FAdjTd(rgTy, tqArray);
        !           477:                                xty->st = stExtend;
        !           478:                                if (xty->rgDim[0] == 0)
        !           479:                                        xty->rgDim[0] = i;
        !           480:                                else
        !           481:                                        xty->rgDim[1] = i;
        !           482:                        }
        !           483:                        /* we should have sb pointing at the type number.
        !           484:                                         * loop will continue and go find it for us.
        !           485:                                         */
        !           486:                        break;
        !           487:                case 'e':
        !           488:                        rgTy[0].td.bt = btEType;
        !           489:                        xty->st = stExtend;
        !           490:                        xty->issRef = IssFStart(iss);
        !           491:                        return;
        !           492:                case 'f':
        !           493:                case 'F':
        !           494:                        rgTy[0].td.st = stProc;
        !           495:                        break;
        !           496:                case 'G':
        !           497:                        rgTy[0].td.st = stGlobal;
        !           498:                        break;
        !           499:                case 'v':       /* 'vaires' parameter - i.e. REFerenced */
        !           500:                case 'p':
        !           501:                        rgTy[0].td.st = stParam;
        !           502:                        break;
        !           503:                case 'r':       /* I don't know what this means!!! */
        !           504:                        break;
        !           505:                case 'V':       /* 'local' static */
        !           506:                case 'S':       /* 'global' static */
        !           507:                        rgTy[0].td.st = stStatic;
        !           508:                        break;
        !           509:                case 's':
        !           510:                case 'u':
        !           511:                        rgTy[0].td.bt = (ch == 's') ? btStruct : btUnion;
        !           512:                        xty->st = stExtend;
        !           513:                        xty->issRef = IssFStart(iss);
        !           514:                        xty->cb = atoi(++sb);   /* size in bytes */
        !           515:                        return;
        !           516:                case 'T':       /* tag - named type */
        !           517:                case 't':       /* type */
        !           518:                        break;
        !           519:                } /* switch */
        !           520:                iss++;
        !           521:        } /* while */
        !           522: } /* TyFScanDbx */
        !           523: 
        !           524: 
        !           525: /* T Y   F   4 2 */
        !           526: 
        !           527: export void TyF42(rgTy, isym)
        !           528: pTYR   rgTy;
        !           529: long   isym;
        !           530: {
        !           531:        char    *sb, *sbStart;
        !           532:        long    iss;
        !           533:        pTYR    ty;
        !           534: 
        !           535:        SetSym(isym);
        !           536:        iss = vsymCur->sbSym;
        !           537:        sbStart = SbInCore(iss);
        !           538:        sb = strchr(sbStart, ':');
        !           539:        if (sb == sbNil) {
        !           540:                /* sdb symbol - what you see is what you get */
        !           541:                rgTy[0] = *((pTYR) vsymCur);
        !           542:                SetSym(isym+1);
        !           543:                rgTy[1] = *((pTYR) vsymCur);
        !           544:        } 
        !           545:        else {
        !           546:                /* dbx symbol */
        !           547:                ty = (pTYR) vsymCur;
        !           548:                rgTy[0] = rgTy[1] = *vtyZeros;
        !           549:                rgTy->sbVar = SbSafe(sbStart);  /* copies up to ':' */
        !           550:                rgTy->td.st = ty->td.st;
        !           551:                rgTy->valTy = ty->valTy;
        !           552:                iss += sb - sbStart;
        !           553:                TyFScanDbx(rgTy, iss, isym);
        !           554:                SetSym(isym);
        !           555:        }
        !           556: } /* TyF42 */
        !           557: 
        !           558: 
        !           559: /* T Y   F   F I E L D */
        !           560: 
        !           561: local void TyFField(ty, iss)
        !           562: pTYR   ty;
        !           563: long   iss;
        !           564: {
        !           565:        int             i, offset, width;
        !           566:        char    *sbF, *sbS, sbTemp[100];
        !           567: 
        !           568:        /* somewhere in this symbol is the field info, stuff it in ty */
        !           569:        sbF = SbInCore(ty->sbVar);
        !           570:        sprintf(sbTemp, "%s:", sbF);
        !           571:        sbS = SbInCore(iss);
        !           572:        i = IFSbSb(sbS, sbTemp);        /* moving window search */
        !           573:        if ((i == -1)
        !           574:            OR ((sbS[i-1] != ';') AND (!isdigit(sbS[i-1]))) )
        !           575:                return; /* caller can detect fact because ty->td.bt == btNil */
        !           576:        iss += i + strlen(sbTemp);
        !           577:        TyFScanDbx(ty, iss);    /* this will build the type info */
        !           578:        sbS = 1 + strchr(SbInCore(iss), ',');
        !           579:        sscanf(sbS,"%d,%d", &offset, &width);
        !           580:        if (((ty->td.bt == btUInt) AND (width != SZINT))
        !           581:            OR ((offset % SZCHAR) != 0)
        !           582:            OR ((width % SZCHAR) != 0)) {
        !           583:                /* this MUST be a bit field */
        !           584:                if ((ty->td.bt != btUInt) OR (width > SZINT))
        !           585:                        Panic("Confused looking at bit field %s @ %ld", sbF, iss);
        !           586:                ty->td.width = width;
        !           587:                ty->td.bt = btUInt;
        !           588:                ty->valTy = offset;
        !           589:        } 
        !           590:        else {
        !           591:                ty->td.width = 0;
        !           592:                ty->valTy = offset / SZCHAR;
        !           593:        }
        !           594: } /* TyFField */
        !           595: 
        !           596: 
        !           597: /* T Y   F   L O O K U P */
        !           598: 
        !           599: local void TyFLookup(tyStruct, tyField)
        !           600: pTYR   tyStruct, tyField;
        !           601: {
        !           602:        long    iss;
        !           603:        pXTYR   xty;
        !           604: 
        !           605:        /* given a structure, see if the field is a member. If so,
        !           606:             * return its type stuff.  If not, see if we can find a
        !           607:             * field by this name and use it.  This search is user
        !           608:             * selectable.
        !           609:             */
        !           610:        if ( ((tyStruct->td.bt == btStruct) OR (tyStruct->td.bt == btUnion))
        !           611:            AND (tyStruct[1].td.st == stExtend) ) {
        !           612:                xty = (pXTYR) (tyStruct+1);
        !           613:                iss = xty->issRef; /* this is already absolute because of TyFScanDbx */
        !           614:                TyFField(tyField, iss);
        !           615:                if (tyField->td.bt != btNil)
        !           616:                        return;
        !           617:                UError("No such field name %s for %s %s",
        !           618:                SbInSafe(tyField->sbVar),
        !           619:                (tyStruct->td.bt==btStruct) ? "struct" : "union",
        !           620:                SbInSafe(iss) );
        !           621:        }
        !           622: 
        !           623:        /* we get here if it wasn't a structure, OR it did not have a field
        !           624:             * name as referenced.  We will now go looking for something reasonable.
        !           625:             * We do not currently do the scan. This means you can't reference
        !           626:             * a field name not part of the appropriate struct/union.
        !           627:             */
        !           628: 
        !           629: } /* TyFLookup */
        !           630: 
        !           631: 
        !           632: #endif
        !           633: 
        !           634: /* ------------------ Back to normal ------------------------ */
        !           635: 
        !           636: 
        !           637: /* I N I T   T Y */
        !           638: 
        !           639: export void InitTy()
        !           640: {
        !           641:        /* set up standard type descriptors */
        !           642:        vtyZeros = &atyZeros;
        !           643:        vtyCnChar = &atyCnChar;
        !           644:        vtyChar = &atyChar;
        !           645:        vtyCnShort = &atyCnShort;
        !           646:        vtyShort = &atyShort;
        !           647:        vtyCnInt = &atyCnInt;
        !           648:        vtyInt = &atyInt;
        !           649:        vtyCnLong = &atyCnLong;
        !           650:        vtyLong = &atyLong;
        !           651:        vtyCnFloat = &atyCnFloat;
        !           652:        vtyFloat = &atyFloat;
        !           653: } /* InitTy */
        !           654: 
        !           655: 
        !           656: /* F   I N T   F   T Y */
        !           657: 
        !           658: export FLAGT FIntFTy(ty)
        !           659: pTYR   ty;
        !           660: {
        !           661:        if (tqPtr == TqFTy(ty, 1))
        !           662:                return(true);
        !           663:        switch (ty->td.bt) {
        !           664:        case btInt:
        !           665:        case btUInt:
        !           666:        case btUShort:
        !           667:        case btShort:
        !           668:        case btLong:
        !           669:        case btULong:
        !           670:        case btChar:
        !           671:        case btUChar:
        !           672:        case btFArg:    /* is this one right??? - kludge */
        !           673:        case btEMember: 
        !           674:                return(true);
        !           675:        case btNil:
        !           676:        case btFloat:
        !           677:        case btDouble:
        !           678:        case btEType:
        !           679:        case btUnion:
        !           680:        case btStruct:  
        !           681:                return(false);
        !           682:        } /* switch */
        !           683:        return(false);
        !           684: } /* FIntFTy */
        !           685: 
        !           686: 
        !           687: /* M A X   F   T Y   T Y */
        !           688: 
        !           689: export FLAGT MaxFTyTy(rgTyMax, rgTy1, rgTy2)
        !           690: pTYR   rgTyMax, rgTy1, rgTy2;
        !           691: {
        !           692:        if (FIntFTy(rgTy1) AND FIntFTy(rgTy2)) {
        !           693:                if (CbFTy(rgTy1) >= CbFTy(rgTy2))
        !           694:                        CopyTy(rgTyMax, rgTy1);
        !           695:                else
        !           696:                        CopyTy(rgTyMax, rgTy2);
        !           697:                return(true);
        !           698:        } /* if */
        !           699:        return(false);
        !           700: } /* MaxFTyTy */
        !           701: 
        !           702: 
        !           703: /* C O P Y   T Y */
        !           704: 
        !           705: export void CopyTy(tyDest, tySrc)
        !           706: pTYR   tyDest, tySrc;
        !           707: {
        !           708:        *tyDest++ = *tySrc++;
        !           709:        *tyDest = *tySrc;
        !           710: } /* CopyTy */
        !           711: 
        !           712: 
        !           713: /* T Y   F   G L O B A L */
        !           714: 
        !           715: export void TyFGlobal(rgTy, sbVar)
        !           716: pTYR   rgTy;
        !           717: char   *sbVar;
        !           718: {
        !           719: 
        !           720: #ifdef SYSIII
        !           721:        if (vfnDecl != fnNil) {
        !           722:                SetTyNext(vityMac-1, fDoBackward);
        !           723:                if (FNextTy(fDoBackward, sbVar, 0, 0, 0, 0)) {
        !           724:                        CopyTy(rgTy, vtyCur);
        !           725:                        return;
        !           726:                } /* if */
        !           727:        } /* if */
        !           728:        rgTy[0] = *vtyInt;      /* this could easily be WRONG! */
        !           729:        strncpy(rgTy[0].sbVar, sbVar, 8);
        !           730: #endif
        !           731: #ifdef BSD41
        !           732:        long    isymSave;
        !           733:        pTYR    ty;
        !           734: 
        !           735:        isymSave = visym;
        !           736:        SetSym(isym0);
        !           737:        if (FNextSym(stGlobal, stStatic, 0, sbVar, FProcCmp)) {
        !           738: #ifdef BSD42
        !           739:                TyF42(rgTy, visym);
        !           740: #else
        !           741:                ty = (pTYR) vsymCur;
        !           742:                rgTy[0] = *ty;
        !           743:                SetSym(visym+1);
        !           744:                ty = (pTYR) vsymCur;
        !           745:                rgTy[1] = *ty;
        !           746: #endif
        !           747:        } 
        !           748:        else {
        !           749:                rgTy[0] = *vtyInt;
        !           750:        } /* if */
        !           751:        SetSym(isymSave);
        !           752: #endif
        !           753: } /* TyFGlobal */
        !           754: 
        !           755: 
        !           756: /* T Y   F   L O C A L */
        !           757: 
        !           758: export void TyFLocal(rgTy, sbVar, isym)
        !           759: pTYR   rgTy;
        !           760: char   *sbVar;
        !           761: long   isym;
        !           762: {
        !           763: 
        !           764: #ifdef BSD41
        !           765:        /* with BSD symbols, the location info for locals is same sym as type */
        !           766:        long    isymSave;
        !           767:        pTYR    ty;
        !           768: 
        !           769:        isymSave = isym;
        !           770: #ifdef BSD42
        !           771:        TyF42(rgTy, isym);
        !           772: #else
        !           773:        SetSym(isym);
        !           774:        ty = (pTYR) vsymCur;
        !           775:        rgTy[0] = *ty;
        !           776:        SetSym(visym+1);
        !           777:        ty = (pTYR) vsymCur;
        !           778:        rgTy[1] = *ty;
        !           779: #endif
        !           780:        SetSym(isymSave);
        !           781: #else
        !           782:        int             cb, ln, ity;
        !           783:        long    isymSave;
        !           784: 
        !           785:        isymSave = isym;
        !           786:        ln = IlnFIsym(isym);
        !           787:        if ( (vfnDecl == fnNil)
        !           788:            OR ((ity = ItyFSbLn(sbVar, ln)) == ityNil) ) {
        !           789:                cb = CbFLocal(isym);
        !           790:                SetSym(isymSave);
        !           791:                if (cb == 1)
        !           792:                        CopyTy(rgTy, vtyChar);
        !           793:                else if (cb != 4)
        !           794:                        CopyTy(rgTy, vtyInt);
        !           795:                else 
        !           796:                    CopyTy(rgTy, vtyLong);
        !           797:                /* this could easily be WRONG! */
        !           798:        } 
        !           799:        else {
        !           800:                SetSym(isymSave);
        !           801:                SetTy(ity);
        !           802:                CopyTy(rgTy, vtyCur);
        !           803:        } /* if */
        !           804:        rgTy->td.st = stValue;
        !           805:        if (vsymCur->type == N_REG)
        !           806:                rgTy->td.st = stReg;
        !           807:        else if (FHdrCmp(vsbProcHdr, vsymCur->sbSym))
        !           808:                rgTy->td.st = stProc;
        !           809:        strncpy(rgTy->sbVar, sbVar, cbVarMax-1);
        !           810:        rgTy->sbVar[cbVarMax-1] = chNull;
        !           811: #endif
        !           812: } /* TyFLocal */
        !           813: 
        !           814: 
        !           815: /* T Q   F   T Y */
        !           816: 
        !           817: export int TqFTy(ty, cnt)
        !           818: pTYR   ty;
        !           819: int    cnt;
        !           820: {
        !           821: #ifdef REGULUS
        !           822:        return(tqNil);
        !           823: #else
        !           824:        switch (cnt) {
        !           825:        case 1: 
        !           826:                return(ty->td.tq1);
        !           827:        case 2: 
        !           828:                return(ty->td.tq2);
        !           829:        case 3: 
        !           830:                return(ty->td.tq3);
        !           831:        case 4: 
        !           832:                return(ty->td.tq4);
        !           833:        case 5: 
        !           834:                return(ty->td.tq5);
        !           835:        case 6: 
        !           836:                return(ty->td.tq6);
        !           837:        } /* switch */
        !           838: #endif
        !           839: } /* TqFTy */
        !           840: 
        !           841: 
        !           842: /* F   A D J   T D */
        !           843: 
        !           844: export FLAGT FAdjTd(ty, tq)
        !           845: pTYR   ty;
        !           846: int    tq;
        !           847: {
        !           848:        pTDR    td;
        !           849: #ifdef REGULUS
        !           850:        return(true);
        !           851: #else
        !           852:        td = &(ty->td);
        !           853:        if (tq != tqNil) {
        !           854:                if (td->tq6 != tqNil) {
        !           855:                        /* all seats are taken */
        !           856:                        return(false);
        !           857:                } 
        !           858:                else {
        !           859:                        td->tq6 = td->tq5;
        !           860:                        td->tq5 = td->tq4;
        !           861:                        td->tq4 = td->tq3;
        !           862:                        td->tq3 = td->tq2;
        !           863:                        td->tq2 = td->tq1;
        !           864:                        td->tq1 = tq;
        !           865:                } /* if */
        !           866:        } 
        !           867:        else {
        !           868:                td->tq1 = td->tq2;
        !           869:                td->tq2 = td->tq3;
        !           870:                td->tq3 = td->tq4;
        !           871:                td->tq4 = td->tq5;
        !           872:                td->tq5 = td->tq6;
        !           873:                td->tq6 = tqNil;
        !           874:        } /* if */
        !           875:        return(true);
        !           876: #endif
        !           877: } /* FAdjTd */
        !           878: 
        !           879: 
        !           880: /* C B   F   T Y */
        !           881: 
        !           882: export int CbFTy(ty)
        !           883: pTYR   ty;
        !           884: {
        !           885:        int             tq;
        !           886:        pXTYR   xty;
        !           887: 
        !           888:        if (ty == tyNil)
        !           889:                return(0);
        !           890: 
        !           891:        if (ty->td.width != 0)
        !           892:                return(-1);     /* a bit field */
        !           893: 
        !           894:        tq = TqFTy(ty, 1);
        !           895:        if (tq != tqNil)
        !           896:                return(CBPOINT);        /* treat it as a pointer */
        !           897: 
        !           898:        switch (ty->td.bt) {
        !           899:        case btNil:     
        !           900:                return(0);
        !           901:        case btInt:
        !           902:        case btUInt:    
        !           903:                return(CBINT);
        !           904:        case btUShort:
        !           905:        case btShort:   
        !           906:                return(CBSHORT);
        !           907:        case btLong:
        !           908:        case btULong:   
        !           909:                return(CBLONG);
        !           910:        case btChar:
        !           911:        case btUChar:   
        !           912:                return(1);
        !           913:        case btFloat:   
        !           914:                return(CBFLOAT);
        !           915:        case btDouble:  
        !           916:                return(CBDOUBLE);
        !           917:        case btFArg:
        !           918:        case btEType:
        !           919:        case btEMember: 
        !           920:                return(CBINT);
        !           921:        case btUnion:
        !           922:        case btStruct:  
        !           923:                /* the following boils down to 'if !BSD41 OR (BSD41 AND !BSD42)' */
        !           924: #ifdef BSD41
        !           925: #ifndef BSD42
        !           926:                if (ty[1].td.st != stLeng)
        !           927:                        return(CBINT);
        !           928:                return(ty[1].valTy);
        !           929: #else
        !           930:                if (ty[1].td.st != stExtend) {
        !           931:                        if (ty[1].td.st == stLeng)
        !           932:                                return(ty[1].valTy);
        !           933:                        else
        !           934:                                return(CBINT);
        !           935:                }
        !           936:                xty = (pXTYR) (ty + 1);
        !           937:                return(xty->cb);
        !           938: #endif
        !           939: #else
        !           940:                if (ty[1].td.st != stExtend) {
        !           941:                        if (ty[1].td.st == stLeng)
        !           942:                                return(ty[1].valTy);
        !           943:                        else
        !           944:                                return(CBINT);
        !           945:                }
        !           946:                xty = (pXTYR) (ty + 1);
        !           947:                return(xty->cb);
        !           948: #endif
        !           949:        } /* switch */
        !           950:        return(0);
        !           951: } /* CbFTy */
        !           952: 
        !           953: 
        !           954: /*  A D R   F   F I E L D */
        !           955: 
        !           956: export long AdrFField(adrLong, tyStruct, tyField)
        !           957: long   adrLong;
        !           958: pTYR   tyStruct, tyField;
        !           959: {
        !           960:        long    isymSave;
        !           961:        char    *sbField;
        !           962:        pTYR    ty;
        !           963:        int             issSave;
        !           964: 
        !           965: #ifdef BSD41
        !           966:        issSave = tyField[0].sbVar;     /* wipe everything clean but the name */
        !           967:        tyField[0] = *vtyZeros;
        !           968:        tyField[1] = *vtyZeros;
        !           969:        tyField[0].sbVar = issSave;
        !           970: #ifdef BSD42
        !           971:        TyFLookup(tyStruct, tyField);   /* does all the 4.2 crap */
        !           972: #endif
        !           973:        if (tyField[0].td.bt == btNil) {
        !           974:                /* this SUCKS! It is because <4.2 Berkeley compilers have
        !           975:                     * neanderthal ideas about binding (ie. they don't) field
        !           976:                     * names to the parent structure.
        !           977:                     */
        !           978:                isymSave = visym;
        !           979:                sbField = SbInSafe(tyField->sbVar);
        !           980:                SetSym(vrgFd[vifd].isym);
        !           981:                if (!FNextSym(stStruct, 0, stSource, sbField, FProcCmp))
        !           982:                        if (vfPascal)
        !           983:                                UError("Sorry, Berkeley Pascal does not give me the field names");
        !           984:                        else
        !           985:                                UError("No such field name: %s", sbField);
        !           986:                ty = (pTYR) vsymCur;
        !           987:                tyField[0] = *ty;
        !           988:                SetSym(visym+1);
        !           989:                ty = (pTYR) vsymCur;
        !           990:                tyField[1] = *ty;
        !           991:                SetSym(isymSave);
        !           992:                if (tyField->td.st != stStruct)
        !           993:                        UError("'%s' is not a field name", SbInCore(tyField->sbVar));
        !           994:        } /* if */
        !           995: 
        !           996:        if (tyField->td.width != 0) {
        !           997:                adrLong += tyField->valTy / SZCHAR; /* set to nearest byte boundary */
        !           998:                tyField->valTy %= SZCHAR;
        !           999:        } 
        !          1000:        else {
        !          1001:                adrLong += tyField->valTy;      /* add its offset to base address */
        !          1002:        }
        !          1003:        return(adrLong);
        !          1004: #endif
        !          1005: } /* AdrFField */

unix.superglobalmegacorp.com

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