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