Annotation of coherent/b/bin/c/n1/node.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * n1/node.c
        !             3:  * Utility routines for the manipulation of expression tree nodes.
        !             4:  */
        !             5: 
        !             6: #ifdef   vax
        !             7: #include "INC$LIB:cc1.h"
        !             8: #else
        !             9: #include "cc1.h"
        !            10: #endif
        !            11: 
        !            12: /*
        !            13:  * Fabricate a node for an integer constant.
        !            14:  */
        !            15: TREE *
        !            16: ivalnode(n) ival_t n;
        !            17: {
        !            18:        register TREE *tp;
        !            19: 
        !            20:        tp = alocnode();
        !            21:        tp->t_op = ICON;
        !            22:        tp->t_type = IVAL_T;
        !            23:        tp->t_ival = n;
        !            24:        return tp;
        !            25: }
        !            26: 
        !            27: /*
        !            28:  * Fabricate a node for a long constant.
        !            29:  */
        !            30: TREE *
        !            31: lvalnode(n) lval_t n;
        !            32: {
        !            33:        register TREE *tp;
        !            34: 
        !            35:        tp = alocnode();
        !            36:        tp->t_op = LCON;
        !            37:        tp->t_type = LVAL_T;
        !            38:        tp->t_lval = n;
        !            39:        return tp;
        !            40: }
        !            41: 
        !            42: /*
        !            43:  * Fabricate a node, either a long or an integer,
        !            44:  * given the type and the long value.
        !            45:  */
        !            46: TREE *
        !            47: gvalnode(t, n) lval_t n;
        !            48: {
        !            49:        if (islong(t))
        !            50:                return lvalnode(n);
        !            51:        else
        !            52:                return ivalnode((ival_t)n);
        !            53: }
        !            54: 
        !            55: /*
        !            56:  * Copy a node.
        !            57:  */
        !            58: TREE *
        !            59: copynode(tp1) TREE *tp1;
        !            60: {
        !            61:        register TREE *tp2;
        !            62: 
        !            63:        tp2 = alocnode();
        !            64:        *tp2 = *tp1;            /* Union assign */
        !            65:        return tp2;
        !            66: }
        !            67: 
        !            68: /*
        !            69:  * Make up a node.
        !            70:  * Fill in the op and the type.
        !            71:  */
        !            72: TREE *
        !            73: makenode(op, t, s)
        !            74: {
        !            75:        register TREE *tp;
        !            76: 
        !            77:        tp = alocnode();
        !            78:        tp->t_op = op;
        !            79:        tp->t_type = t;
        !            80:        if (issized(t))
        !            81:                tp->t_size = s;
        !            82:        return tp;
        !            83: }
        !            84: 
        !            85: /*
        !            86:  * Make up a node.
        !            87:  * Fill in the op, the type and the left subtree.
        !            88:  */
        !            89: TREE *
        !            90: leftnode(op, lp, t, s)
        !            91: TREE *lp;
        !            92: {
        !            93:        register TREE *tp;
        !            94: 
        !            95:        tp = makenode(op, t, s);
        !            96:        tp->t_lp = lp;
        !            97:        return tp;
        !            98: }
        !            99: 
        !           100: /*
        !           101:  * Strip off conversions.
        !           102:  */
        !           103: TREE *
        !           104: basenode(tp)
        !           105: register TREE *tp;
        !           106: {
        !           107:        register op;
        !           108: 
        !           109:        while ((op=tp->t_op)==CONVERT || op==CAST)
        !           110:                tp = tp->t_lp;
        !           111:        return tp;
        !           112: }
        !           113: 
        !           114: /*
        !           115:  * Get a new tree node.
        !           116:  * Just abort if there is no space left; this should not happen.
        !           117:  */
        !           118: TREE *
        !           119: alocnode()
        !           120: {
        !           121:        register TREE *tp;
        !           122: 
        !           123:        tp = talloc();
        !           124:        tp->t_treg = NONE;
        !           125:        tp->t_rreg = NONE;
        !           126:        return tp;
        !           127: }
        !           128: 
        !           129: /*
        !           130:  * Check if a tree node is a fixed point constant of some type.
        !           131:  */
        !           132: isfxcon(tp) TREE *tp;
        !           133: {
        !           134:        register op;
        !           135: 
        !           136:        if ((op=tp->t_op)==ICON || op==LCON)
        !           137:                return 1;
        !           138:        return 0;
        !           139: }
        !           140: 
        !           141: /*
        !           142:  * Grab numeric value.
        !           143:  */
        !           144: lval_t
        !           145: grabnval(tp) register TREE *tp;
        !           146: {
        !           147:        register op;
        !           148: 
        !           149:        op = tp->t_op;
        !           150:        if (op == ICON) {
        !           151:                if (isuns(tp->t_type))
        !           152:                        return ((unsigned) tp->t_ival);
        !           153:                return tp->t_ival;
        !           154:        }
        !           155:        if (op == LCON)
        !           156:                return tp->t_lval;
        !           157:        cbotch("grabnval");
        !           158: }
        !           159: 
        !           160: /*
        !           161:  * Is this tree node a constant 'n'?
        !           162:  * Note that 'n' is an integer (not a long).
        !           163:  */
        !           164: isnval(tp, n) register TREE *tp;
        !           165: {
        !           166:        long v;
        !           167: 
        !           168:        if (isfxcon(tp)) {
        !           169:                v = grabnval(tp);
        !           170:                if (v == n)
        !           171:                        return 1;
        !           172:        }
        !           173:        return 0;
        !           174: }
        !           175: 
        !           176: /*
        !           177:  * Make a LEAF node.
        !           178:  */
        !           179: TREE *
        !           180: leafnode(tp) register TREE *tp;
        !           181: {
        !           182:        return leftnode(LEAF, tp, tp->t_type, tp->t_size);
        !           183: }
        !           184: 
        !           185: /* end of n1/node.c */

unix.superglobalmegacorp.com

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