stage3/narrow_candidate_datatypes.cc
changeset 472 d26759a2274a
parent 470 d2cd05c5e01a
child 478 b13feab3b918
equal deleted inserted replaced
471:da650a87662d 472:d26759a2274a
   887 
   887 
   888 void *narrow_candidate_datatypes_c::narrow_conditional_flow_control_IL_instruction(symbol_c *symbol) {
   888 void *narrow_candidate_datatypes_c::narrow_conditional_flow_control_IL_instruction(symbol_c *symbol) {
   889 	/* if the next IL instructions needs us to provide a datatype other than a bool, 
   889 	/* if the next IL instructions needs us to provide a datatype other than a bool, 
   890 	 * then we have an internal compiler error - most likely in fill_candidate_datatypes_c 
   890 	 * then we have an internal compiler error - most likely in fill_candidate_datatypes_c 
   891 	 */
   891 	 */
   892 	if ((NULL != symbol->datatype) && (!is_type(symbol->datatype, bool_type_name_c))) ERROR;
   892 	if ((NULL != symbol->datatype) && (!is_ANY_BOOL_compatible(symbol->datatype))) ERROR;
   893 	if (symbol->candidate_datatypes.size() > 1) ERROR;
   893 	if (symbol->candidate_datatypes.size() > 1) ERROR;
   894 
   894 
   895 	/* NOTE: If there is no IL instruction following this CALC, CALCN, JMPC, JMPC, ..., instruction,
   895 	/* NOTE: If there is no IL instruction following this CALC, CALCN, JMPC, JMPC, ..., instruction,
   896 	 *       we must still provide a bool_type_name_c datatype (if possible, i.e. if it exists in the candidate datatype list).
   896 	 *       we must still provide a bool_type_name_c datatype (if possible, i.e. if it exists in the candidate datatype list).
   897 	 *       If it is not possible, we set it to NULL
   897 	 *       If it is not possible, we set it to NULL
   898 	 */
   898 	 */
   899 	if (symbol->candidate_datatypes.size() == 0)    symbol->datatype = NULL;
   899 	if (symbol->candidate_datatypes.size() == 0)    symbol->datatype = NULL;
   900 	else    symbol->datatype = symbol->candidate_datatypes[0]; /* i.e. a bool_type_name_c! */
   900 	else    symbol->datatype = symbol->candidate_datatypes[0]; /* i.e. a bool_type_name_c! */
   901 	if ((NULL != symbol->datatype) && (!is_type(symbol->datatype, bool_type_name_c))) ERROR;
   901 	if ((NULL != symbol->datatype) && (!is_ANY_BOOL_compatible(symbol->datatype))) ERROR;
   902 
   902 
   903 	/* set the required datatype of the previous IL instruction, i.e. a bool_type_name_c! */
   903 	/* set the required datatype of the previous IL instruction, i.e. a bool_type_name_c! */
   904 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
   904 	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
   905 	return NULL;
   905 	return NULL;
   906 }
   906 }
  1398 /* B 3.2.3 Selection Statements */
  1398 /* B 3.2.3 Selection Statements */
  1399 /********************************/
  1399 /********************************/
  1400 
  1400 
  1401 void *narrow_candidate_datatypes_c::visit(if_statement_c *symbol) {
  1401 void *narrow_candidate_datatypes_c::visit(if_statement_c *symbol) {
  1402 	for(unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) {
  1402 	for(unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) {
  1403 		if (is_type(symbol->expression->candidate_datatypes[i], bool_type_name_c))
  1403 		if (is_ANY_BOOL_compatible(symbol->expression->candidate_datatypes[i]))
  1404 			symbol->expression->datatype = symbol->expression->candidate_datatypes[i];
  1404 			symbol->expression->datatype = symbol->expression->candidate_datatypes[i];
  1405 	}
  1405 	}
  1406 	symbol->expression->accept(*this);
  1406 	symbol->expression->accept(*this);
  1407 	if (NULL != symbol->statement_list)
  1407 	if (NULL != symbol->statement_list)
  1408 		symbol->statement_list->accept(*this);
  1408 		symbol->statement_list->accept(*this);
  1414 }
  1414 }
  1415 
  1415 
  1416 
  1416 
  1417 void *narrow_candidate_datatypes_c::visit(elseif_statement_c *symbol) {
  1417 void *narrow_candidate_datatypes_c::visit(elseif_statement_c *symbol) {
  1418 	for (unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) {
  1418 	for (unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) {
  1419 		if (is_type(symbol->expression->candidate_datatypes[i], bool_type_name_c))
  1419 		if (is_ANY_BOOL_compatible(symbol->expression->candidate_datatypes[i]))
  1420 			symbol->expression->datatype = symbol->expression->candidate_datatypes[i];
  1420 			symbol->expression->datatype = symbol->expression->candidate_datatypes[i];
  1421 	}
  1421 	}
  1422 	symbol->expression->accept(*this);
  1422 	symbol->expression->accept(*this);
  1423 	if (NULL != symbol->statement_list)
  1423 	if (NULL != symbol->statement_list)
  1424 		symbol->statement_list->accept(*this);
  1424 		symbol->statement_list->accept(*this);