stage3/narrow_candidate_datatypes.cc
changeset 457 67d8b07bac22
parent 456 ca8d98289ff9
child 459 01f6664bf8c5
equal deleted inserted replaced
456:ca8d98289ff9 457:67d8b07bac22
    62 		symbol->datatype = datatype;  
    62 		symbol->datatype = datatype;  
    63 }
    63 }
    64 
    64 
    65 
    65 
    66 
    66 
       
    67 /* Only set the symbol's desired datatype to 'datatype' if that datatype is in the candidate_datatype list */
       
    68 static void set_datatype_in_prev_il_instruction(symbol_c *datatype, il_instruction_c *symbol) {
       
    69 	for (unsigned int i = 0; i < symbol->prev_il_instruction.size(); i++)
       
    70 		set_datatype(datatype, symbol->prev_il_instruction[i]);
       
    71 }
       
    72 
       
    73 
    67 
    74 
    68 bool narrow_candidate_datatypes_c::is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]) {
    75 bool narrow_candidate_datatypes_c::is_widening_compatible(symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, const struct widen_entry widen_table[]) {
    69 	for (int k = 0; NULL != widen_table[k].left;  k++) {
    76 	for (int k = 0; NULL != widen_table[k].left;  k++) {
    70 		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
    77 		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
    71 		        && (typeid(*right_type)  == typeid(*widen_table[k].right))
    78 		        && (typeid(*right_type)  == typeid(*widen_table[k].right))
   501 // SYM_REF2(il_instruction_c, label, il_instruction)
   508 // SYM_REF2(il_instruction_c, label, il_instruction)
   502 // void *visit(instruction_list_c *symbol);
   509 // void *visit(instruction_list_c *symbol);
   503 void *narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) {
   510 void *narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) {
   504 	if (NULL == symbol->il_instruction) {
   511 	if (NULL == symbol->il_instruction) {
   505 		/* this empty/null il_instruction cannot generate the desired datatype. We pass on the request to the previous il instruction. */
   512 		/* this empty/null il_instruction cannot generate the desired datatype. We pass on the request to the previous il instruction. */
   506 		if (NULL != symbol->prev_il_instruction)
   513 		set_datatype_in_prev_il_instruction(symbol->datatype, symbol);
   507 			symbol->prev_il_instruction->datatype = symbol->datatype;
       
   508 	} else {
   514 	} else {
   509 		/* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (remember: we are iterating backwards!) */
   515 		/* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (remember: we are iterating backwards!) */
   510 		symbol->il_instruction->datatype = symbol->datatype;
   516 		if (symbol->prev_il_instruction.size() > 1) ERROR; /* This assertion is only valid for now. Remove it once flow_control_analysis_c is complete */
   511 		prev_il_instruction = symbol->prev_il_instruction;
   517 		if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
       
   518 		else                                          prev_il_instruction = symbol->prev_il_instruction[0];
   512 		symbol->il_instruction->accept(*this);
   519 		symbol->il_instruction->accept(*this);
   513 		prev_il_instruction = NULL;
   520 		prev_il_instruction = NULL;
   514 	}
   521 	}
   515 	return NULL;
   522 	return NULL;
   516 }
   523 }
   655 }
   662 }
   656 
   663 
   657 
   664 
   658 // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
   665 // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
   659 void *narrow_candidate_datatypes_c::visit(il_simple_instruction_c *symbol)	{
   666 void *narrow_candidate_datatypes_c::visit(il_simple_instruction_c *symbol)	{
   660   prev_il_instruction = symbol->prev_il_instruction;
   667   if (symbol->prev_il_instruction.size() > 1) ERROR; /* This assertion is only valid for now. Remove it once flow_control_analysis_c is complete */
       
   668   if (symbol->prev_il_instruction.size() == 0)   prev_il_instruction = NULL;
       
   669   else                                           prev_il_instruction = symbol->prev_il_instruction[0];
   661   symbol->il_simple_instruction->datatype = symbol->datatype;
   670   symbol->il_simple_instruction->datatype = symbol->datatype;
   662   symbol->il_simple_instruction->accept(*this);
   671   symbol->il_simple_instruction->accept(*this);
   663   prev_il_instruction = NULL;
   672   prev_il_instruction = NULL;
   664   return NULL;
   673   return NULL;
   665 }
   674 }