|
|
1.1 ! root 1: /* ident "@(#)ctrans:src/discrim.c 1.2" */ ! 2: /************ add copyright ********************** ! 3: * union discriminator functions for nodes in cfront. ! 4: * all return 0 for none, ! 5: * -1 for bad union index, -2 for inconsistent ! 6: * or otherwise messed up nodes ! 7: */ ! 8: #include "cfront.h" ! 9: #define DEFINE_TOKEN_CLASS_TABLE ! 10: #include "node_classes.h" ! 11: ! 12: int basetype::discriminator(int which_union) ! 13: { ! 14: switch(which_union) ! 15: { ! 16: case 0: ! 17: switch(base) { ! 18: case FIELD: return 1; ! 19: case FCT: return 2; ! 20: default: return discrim_none_valid; ! 21: } ! 22: default: ! 23: return discrim_bad_index; ! 24: } ! 25: } ! 26: ! 27: int fct::discriminator(int) ! 28: { ! 29: return discrim_bad_index; ! 30: } ! 31: ! 32: int expr::discriminator(int which_union) ! 33: { ! 34: switch(which_union) { ! 35: case 0: ! 36: return 1; /* tp, never syn_class */ ! 37: case 1: /* e1, i1, string */ ! 38: switch(base) { ! 39: case DEREF: ! 40: case ICALL: ! 41: case REF: ! 42: case DOT: ! 43: case VALUE: ! 44: case SIZEOF: ! 45: case NEW: ! 46: case GNEW: ! 47: case DELETE: ! 48: case CAST: ! 49: case CALL: ! 50: case G_CALL: ! 51: case ASSIGN: ! 52: case EQ: ! 53: case NE: ! 54: case GT: ! 55: case GE: ! 56: case LE: ! 57: case LT: ! 58: case ELIST: ! 59: case ILIST: ! 60: case QUEST: ! 61: case CM: ! 62: case G_CM: ! 63: case PLUS: ! 64: case MINUS: ! 65: case MUL: ! 66: case DIV: ! 67: case MOD: ! 68: case LS: ! 69: case RS: ! 70: case AND: ! 71: case OR: ! 72: case ER: ! 73: case ANDAND: ! 74: case OROR: ! 75: case ASOR: ! 76: case ASER: ! 77: case ASAND: ! 78: case ASPLUS: ! 79: case ASMINUS: ! 80: case ASMUL: ! 81: case ASMOD: ! 82: case ASDIV: ! 83: case ASLS: ! 84: case ASRS: ! 85: case DECR: ! 86: case INCR: ! 87: return 1; ! 88: case MDOT: ! 89: case IVAL: ! 90: return 2; ! 91: case TNAME: ! 92: case NAME: ! 93: case ICON: ! 94: case FCON: ! 95: case CCON: ! 96: case ID: ! 97: case STRING: ! 98: case TEXT: ! 99: return 3; ! 100: default: return discrim_none_valid; ! 101: } ! 102: case 2: /* e2, i2, string2, n_initializer */ ! 103: /* i2 is a complete mystery. It is set to 1, ! 104: and never referenced. But I'm not sure that ! 105: someone somewhere doesn't test one of the other ! 106: union elements for equal to 1, so therefore this test. */ ! 107: if(i2 == 1)return 2; ! 108: switch(base) { ! 109: case DELETE: ! 110: case VALUE: ! 111: case ICALL: ! 112: case CALL: ! 113: case G_CALL: ! 114: case ASSIGN: ! 115: case EQ: ! 116: case NE: ! 117: case GT: ! 118: case GE: ! 119: case LE: ! 120: case LT: ! 121: case DEREF: ! 122: case ELIST: ! 123: case QUEST: ! 124: case CM: ! 125: case G_CM: ! 126: case UMINUS: ! 127: case NOT: ! 128: case COMPL: ! 129: case ADDROF: ! 130: case G_ADDROF: ! 131: case PLUS: ! 132: case MINUS: ! 133: case MUL: ! 134: case DIV: ! 135: case MOD: ! 136: case LS: ! 137: case RS: ! 138: case AND: ! 139: case OR: ! 140: case ER: ! 141: case ANDAND: ! 142: case OROR: ! 143: case ASOR: ! 144: case ASER: ! 145: case ASAND: ! 146: case ASPLUS: ! 147: case ASMINUS: ! 148: case ASMUL: ! 149: case ASMOD: ! 150: case ASDIV: ! 151: case ASLS: ! 152: case ASRS: ! 153: case DECR: ! 154: case INCR: ! 155: case NEW: /*- the placement expression list hangs off e2 -*/ ! 156: return 1; ! 157: case TEXT: ! 158: return 3; ! 159: case NAME: ! 160: case TNAME: ! 161: /* The n_initializer field is used for TNAMEs when describing base */ ! 162: /* class initializations. The TNAME refers to the base class, and */ ! 163: /* the actuals arguments are hung off the n_initializer list */ ! 164: return 4; ! 165: default: return discrim_none_valid; ! 166: } ! 167: case 3: /* tp2, fct_name, cond, mem, as_type, n_table, il, query_this */ ! 168: switch(base) { ! 169: case VALUE: ! 170: case SIZEOF: ! 171: case NEW: ! 172: case GNEW: ! 173: case CAST: ! 174: return 1; ! 175: case CALL: ! 176: case G_CALL: ! 177: return 2; ! 178: case QUEST: ! 179: return 3; ! 180: case REF: ! 181: case DOT: ! 182: case MDOT: ! 183: return 4; ! 184: case ASOR: ! 185: case ASER: ! 186: case ASAND: ! 187: case ASPLUS: ! 188: case ASMINUS: ! 189: case ASMUL: ! 190: case ASMOD: ! 191: case ASDIV: ! 192: case ASLS: ! 193: case ASRS: ! 194: case DECR: ! 195: case INCR: ! 196: case ASSIGN: ! 197: return 5; ! 198: ! 199: case NAME: ! 200: case TNAME: ! 201: if (Pname(this)->n_oper==TYPE && ! 202: (strcmp(Pname(this)->string, "_type")==0)) { ! 203: // error('d',"string %s n_oper: %k", string, Pname(this)->n_oper); ! 204: return 3; ! 205: } ! 206: return 6; ! 207: ! 208: case ICALL: ! 209: case ANAME: ! 210: return 7; ! 211: ! 212: default: return discrim_none_valid; ! 213: } ! 214: ! 215: default: ! 216: return discrim_bad_index; ! 217: } ! 218: } ! 219: ! 220: int name::discriminator (int which_union) ! 221: { ! 222: switch(which_union) { ! 223: case 0: /* n_qualifier, n_realscope */ ! 224: if(base == LABEL) return 2; ! 225: else return 1; ! 226: default: ! 227: return discrim_bad_index; ! 228: } ! 229: } ! 230: ! 231: int stmt::discriminator (int which_union) ! 232: { ! 233: switch(which_union) { ! 234: case 0: /* d, e2, has_default, case_value, ret_tp */ ! 235: switch(base) { ! 236: case BLOCK: ! 237: case GOTO: ! 238: case LABEL: ! 239: case DCL: ! 240: return 1; ! 241: case FOR: ! 242: return 2; ! 243: case SWITCH: ! 244: return 3; ! 245: case PAIR: ! 246: case RETURN: ! 247: return 4; ! 248: default: return discrim_none_valid; ! 249: } ! 250: case 1: /* e, own_tbl, s2 */ ! 251: switch(base) { ! 252: case FOR: ! 253: case IF: ! 254: case WHILE: ! 255: case DO: ! 256: case RETURN: ! 257: case SWITCH: ! 258: case SM: ! 259: case SM_PARAM: ! 260: case CASE: ! 261: return 1; ! 262: case BLOCK: ! 263: return 2; ! 264: case PAIR: ! 265: return 3; ! 266: default: ! 267: return discrim_none_valid; ! 268: } ! 269: case 2: /* for_init, else_stmt, case_list */ ! 270: switch(base) { ! 271: case FOR: ! 272: return 1; ! 273: case IF: ! 274: return 2; ! 275: case SWITCH: ! 276: case CASE: ! 277: return 3; ! 278: default: ! 279: return discrim_none_valid; ! 280: } ! 281: default: ! 282: return discrim_bad_index; ! 283: } ! 284: } ! 285: ! 286: static node_class token_to_class_map[DUMMY_LAST_NODE]; ! 287: static char map_initialized; ! 288: ! 289: node_class classify_node (Pnode node, int& error) ! 290: { ! 291: int ncx; ! 292: node_class nclass; ! 293: ! 294: error = 0; ! 295: ! 296: if (! map_initialized) { ! 297: map_initialized = 1 ; ! 298: for(ncx = 0; ncx < sizeof (token_classes) / sizeof (token_class); ! 299: ncx ++) ! 300: token_to_class_map[token_classes[ncx].token] ! 301: = token_classes[ncx].nclass; ! 302: } ! 303: ! 304: if (!((node->base > 0) && (node->base < DUMMY_LAST_NODE))) { ! 305: error = 1; ! 306: return nc_unused; ! 307: } ! 308: ! 309: nclass = token_to_class_map[node->base]; ! 310: ! 311: switch(nclass) { ! 312: case nc_fct: ! 313: case nc_name: ! 314: if(node->baseclass) nclass = nc_baseclass; ! 315: } ! 316: ! 317: return nclass; ! 318: } ! 319: ! 320: node_class classify_node (Pnode node) ! 321: { ! 322: int err; ! 323: node_class nclass = classify_node (node, err); ! 324: if(err) error ('i', "failed to classify node."); ! 325: return nclass; ! 326: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.