Annotation of coherent/d/bin/cc/c/n1/node.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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