Annotation of researchv8dc/cmd/cyntax/cem/fix.c, revision 1.1

1.1     ! root        1: #include       "cem.h"
        !             2: #define        STD_OBJ 1
        !             3: #include       "stdobj.h"
        !             4: #include       "symbol.h"
        !             5: #include       "type.h"
        !             6: 
        !             7: /*
        !             8:  *     Type fixing routines.
        !             9:  */
        !            10: 
        !            11: static char    *interned;
        !            12: 
        !            13: /*
        !            14:  *     Fix up a type.  First pass.  Intern all basetypes and enums
        !            15:  *     and modifications of these.
        !            16:  */
        !            17: static void
        !            18: fix_pure_simple(n, x)
        !            19: type   **n;
        !            20: int    x;
        !            21: {
        !            22:        register type   *p;
        !            23: 
        !            24:        p = *n;
        !            25: 
        !            26:        switch (p->t_type)
        !            27:        {
        !            28:        case t_arrayof:
        !            29:        case t_bitfield:
        !            30:        case t_dimless:
        !            31:        case t_ftnreturning:
        !            32:        case t_ptrto:
        !            33:                if (!interned[p->t_sub.index])
        !            34:                        return;
        !            35: 
        !            36:                p->t_subtype = type_trans[p->t_sub.index];
        !            37:                break;
        !            38: 
        !            39:        case t_basetype:
        !            40:        case t_enum:
        !            41:                break;
        !            42: 
        !            43:        case t_structof:
        !            44:                if ((p = lookup_hash(p->d.s->s_file, p->d.s->s_line)) != NULL)
        !            45:                {
        !            46:                        interned[x] = 1;
        !            47:                        delete_type(*n);
        !            48:                        *n = p;
        !            49:                }
        !            50: 
        !            51:                return;
        !            52: 
        !            53:        case t_unionof:
        !            54:                if ((p = lookup_hash(p->d.u->u_file, p->d.u->u_line)) != NULL)
        !            55:                {
        !            56:                        interned[x] = 1;
        !            57:                        delete_type(*n);
        !            58:                        *n = p;
        !            59:                }
        !            60: 
        !            61:                return;
        !            62: 
        !            63:        default:
        !            64:                fprintf(stderr, "%s: unknown type in fix_pure_simple\n", my_name);
        !            65:                exit(1);
        !            66:        }
        !            67: 
        !            68:        interned[x] = 1;
        !            69:        *n = find_type(p);
        !            70: }
        !            71: 
        !            72: /*
        !            73:  *     Fix up a type.  Second pass.  Intern structs and unions with
        !            74:  *     exclusively pure components.
        !            75:  */
        !            76: static int
        !            77: fix_pure_complex(n, x)
        !            78: type   **n;
        !            79: int    x;
        !            80: {
        !            81:        register s_elt  *s;
        !            82:        register u_elt  *u;
        !            83:        register type   *p;
        !            84: 
        !            85:        if (interned[x])
        !            86:                return 0;
        !            87: 
        !            88:        p = *n;
        !            89: 
        !            90:        switch (p->t_type)
        !            91:        {
        !            92:        case t_arrayof:
        !            93:        case t_bitfield:
        !            94:        case t_dimless:
        !            95:        case t_ftnreturning:
        !            96:        case t_ptrto:
        !            97:                if (!interned[p->t_sub.index])
        !            98:                        return 0;
        !            99: 
        !           100:                p->t_subtype = type_trans[p->t_sub.index];
        !           101:                break;
        !           102: 
        !           103:        case t_basetype:
        !           104:        case t_enum:
        !           105:                return 0;
        !           106: 
        !           107:        case t_structof:
        !           108:                for (s = p->d.s->s_list; s != NULL; s = s->s_next)
        !           109:                {
        !           110:                        if (!interned[s->s_ptype.index])
        !           111:                                return 0;
        !           112:                }
        !           113: 
        !           114:                for (s = p->d.s->s_list; s != NULL; s = s->s_next)
        !           115:                        s->s_type = type_trans[s->s_ptype.index];
        !           116: 
        !           117:                break;
        !           118: 
        !           119:        case t_unionof:
        !           120:                for (u = p->d.u->u_list; u != NULL; u = u->u_next)
        !           121:                {
        !           122:                        if (!interned[u->u_ptype.index])
        !           123:                                return 0;
        !           124:                }
        !           125: 
        !           126:                for (u = p->d.u->u_list; u != NULL; u = u->u_next)
        !           127:                        u->u_type = type_trans[u->u_ptype.index];
        !           128: 
        !           129:                break;
        !           130: 
        !           131:        default:
        !           132:                fprintf(stderr, "%s: unknown type in fix_pure_complex\n", my_name);
        !           133:                exit(1);
        !           134:        }
        !           135: 
        !           136:        interned[x] = 1;
        !           137:        *n = find_type(p);
        !           138:        return 1;
        !           139: }
        !           140: 
        !           141: /*
        !           142:  *     Fix up a type.  Final pass.  Fill in subtypes.
        !           143:  */
        !           144: static void
        !           145: elab_complex(p, x)
        !           146: register type  *p;
        !           147: int            x;
        !           148: {
        !           149:        register s_elt  *s;
        !           150:        register u_elt  *u;
        !           151: 
        !           152:        if (interned[x])
        !           153:                return;
        !           154: 
        !           155:        p->t_index = new_type_index++;
        !           156: 
        !           157:        switch (p->t_type)
        !           158:        {
        !           159:        case t_arrayof:
        !           160:        case t_bitfield:
        !           161:        case t_dimless:
        !           162:        case t_ftnreturning:
        !           163:        case t_ptrto:
        !           164:                p->t_subtype = type_trans[p->t_sub.index];
        !           165:                break;
        !           166: 
        !           167:        case t_basetype:
        !           168:        case t_enum:
        !           169:                break;
        !           170: 
        !           171:        case t_structof:
        !           172:                for (s = p->d.s->s_list; s != NULL; s = s->s_next)
        !           173:                        s->s_type = type_trans[s->s_ptype.index];
        !           174: 
        !           175:                break;
        !           176: 
        !           177:        case t_unionof:
        !           178:                for (u = p->d.u->u_list; u != NULL; u = u->u_next)
        !           179:                        u->u_type = type_trans[u->u_ptype.index];
        !           180: 
        !           181:                break;
        !           182: 
        !           183:        default:
        !           184:                fprintf(stderr, "%s: unknown type in elab_complex\n", my_name);
        !           185:                exit(1);
        !           186:        }
        !           187: }
        !           188: 
        !           189: /*
        !           190:  *     Fix the types in the type translation table.  If they are 'pure'
        !           191:  *     intern them else elaborate them.
        !           192:  */
        !           193: void
        !           194: fix_types(n)
        !           195: register long  n;
        !           196: {
        !           197:        register char   *p;
        !           198:        register type   **v;
        !           199:        register int    have_fixed;
        !           200:        register int    i;
        !           201: 
        !           202:        v = type_trans;
        !           203:        p = (char *)salloc(n * sizeof (char));
        !           204:        interned = p;
        !           205:        i = n;
        !           206: 
        !           207:        while (--i >= 0)
        !           208:                *p++ = 0;
        !           209: 
        !           210:        for (i = 1; i < n; i++)
        !           211:                fix_pure_simple(&v[i], i);
        !           212: 
        !           213:        do
        !           214:        {
        !           215:                have_fixed = 0;
        !           216: 
        !           217:                for (i = 1; i < n; i++)
        !           218:                {
        !           219:                        if (fix_pure_complex(&v[i], i))
        !           220:                                have_fixed = 1;
        !           221:                }
        !           222:        }
        !           223:        while (have_fixed);
        !           224: 
        !           225:        for (i = 1; i < n; i++)
        !           226:                elab_complex(v[i], i);
        !           227: 
        !           228:        free(interned);
        !           229: }

unix.superglobalmegacorp.com

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