stage3/fill_candidate_datatypes.cc
changeset 459 01f6664bf8c5
parent 457 67d8b07bac22
child 462 f7dada0a8952
equal deleted inserted replaced
458:587884880be6 459:01f6664bf8c5
   563 /************************/
   563 /************************/
   564 /* B 1.2.3.1 - Duration */
   564 /* B 1.2.3.1 - Duration */
   565 /************************/
   565 /************************/
   566 void *fill_candidate_datatypes_c::visit(duration_c *symbol) {
   566 void *fill_candidate_datatypes_c::visit(duration_c *symbol) {
   567 	/* TODO: check whether the literal follows the rules specified in section '2.2.3.1 Duration' of the standard! */
   567 	/* TODO: check whether the literal follows the rules specified in section '2.2.3.1 Duration' of the standard! */
   568 	symbol->candidate_datatypes.push_back(symbol->type_name);
   568 	
       
   569 	symbol->candidate_datatypes.push_back(&search_constant_type_c::time_type_name);
       
   570 // 	symbol->candidate_datatypes.push_back(symbol->type_name);
   569 	if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
   571 	if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
   570 	return NULL;
   572 	return NULL;
   571 }
   573 }
   572 
   574 
   573 /************************************/
   575 /************************************/
   798 /*| instruction_list il_instruction */
   800 /*| instruction_list il_instruction */
   799 // SYM_LIST(instruction_list_c)
   801 // SYM_LIST(instruction_list_c)
   800 // void *visit(instruction_list_c *symbol);
   802 // void *visit(instruction_list_c *symbol);
   801 
   803 
   802 
   804 
       
   805 
   803 /* | label ':' [il_incomplete_instruction] eol_list */
   806 /* | label ':' [il_incomplete_instruction] eol_list */
   804 // SYM_REF2(il_instruction_c, label, il_instruction)
   807 // SYM_REF2(il_instruction_c, label, il_instruction)
   805 // void *visit(instruction_list_c *symbol);
   808 // void *visit(instruction_list_c *symbol);
   806 void *fill_candidate_datatypes_c::visit(il_instruction_c *symbol) {
   809 void *fill_candidate_datatypes_c::visit(il_instruction_c *symbol) {
   807 	if (NULL == symbol->il_instruction) {
   810 	if (NULL == symbol->il_instruction) {
   808 		/* This empty/null il_instruction does not change the value of the current/default IL variable.
   811 		/* This empty/null il_instruction does not change the value of the current/default IL variable.
   809 		 * So it inherits the candidate_datatypes from it's previous IL instructions!
   812 		 * So it inherits the candidate_datatypes from it's previous IL instructions!
   810 		 */
   813 		 */
   811 		if (!symbol->prev_il_instruction.empty()) {
   814 		intersect_prev_candidate_datatype_lists(symbol);
   812 			copy_candidate_datatype_list(symbol->prev_il_instruction[0] /*from*/, symbol /*to*/);
       
   813 			for (unsigned int i = 1; i < symbol->prev_il_instruction.size(); i++) {
       
   814 				intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->prev_il_instruction[i] /*with*/);
       
   815 			}
       
   816 		}
       
   817 	} else {
   815 	} else {
   818 		if (symbol->prev_il_instruction.size() > 1) ERROR; /* This assertion is only valid for now. Remove it once flow_control_analysis_c is complete */
   816 // 		if (symbol->prev_il_instruction.size() > 1) ERROR; /* This assertion is only valid for now. Remove it once flow_control_analysis_c is complete */
       
   817 		il_instruction_c fake_prev_il_instruction = *symbol;
       
   818 		intersect_prev_candidate_datatype_lists(&fake_prev_il_instruction);
       
   819 
   819 		if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
   820 		if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
   820 		else                                          prev_il_instruction = symbol->prev_il_instruction[0];
   821 		else                                          prev_il_instruction = &fake_prev_il_instruction;
   821 		symbol->il_instruction->accept(*this);
   822 		symbol->il_instruction->accept(*this);
   822 		prev_il_instruction = NULL;
   823 		prev_il_instruction = NULL;
   823 
   824 
   824 		/* This object has (inherits) the same candidate datatypes as the il_instruction */
   825 		/* This object has (inherits) the same candidate datatypes as the il_instruction */
   825 		copy_candidate_datatype_list(symbol->il_instruction /*from*/, symbol /*to*/);	
   826 		copy_candidate_datatype_list(symbol->il_instruction /*from*/, symbol /*to*/);	
   853 	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
   854 	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
   854 	 * to the il_operand_list, and remove it after calling handle_function_call().
   855 	 * to the il_operand_list, and remove it after calling handle_function_call().
   855 	 *
   856 	 *
   856 	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
   857 	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
   857 	 * need to create a new object to hold the pointer to prev_il_instruction.
   858 	 * need to create a new object to hold the pointer to prev_il_instruction.
   858 	 * This change will also be undone later in print_datatypes_error_c.
       
   859 	 */
   859 	 */
   860 	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
   860 	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
   861 	if (NULL == symbol->il_operand_list)  ERROR;
   861 	if (NULL == symbol->il_operand_list)  ERROR;
   862 
   862 
   863 	symbol->il_operand_list->accept(*this);
   863 	symbol->il_operand_list->accept(*this);
  1020 
  1020 
  1021 
  1021 
  1022 
  1022 
  1023 // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
  1023 // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
  1024 void *fill_candidate_datatypes_c::visit(il_simple_instruction_c *symbol) {
  1024 void *fill_candidate_datatypes_c::visit(il_simple_instruction_c *symbol) {
  1025   if (symbol->prev_il_instruction.size() > 1) ERROR; /* This assertion is only valid for now. Remove it once flow_control_analysis_c is complete */
  1025   if (symbol->prev_il_instruction.size() > 1) ERROR; /* There should be no labeled insructions inside an IL expression! */
  1026   if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
  1026   if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
  1027   else                                          prev_il_instruction = symbol->prev_il_instruction[0];
  1027   else                                          prev_il_instruction = symbol->prev_il_instruction[0];
  1028   symbol->il_simple_instruction->accept(*this);
  1028   symbol->il_simple_instruction->accept(*this);
  1029   prev_il_instruction = NULL;
  1029   prev_il_instruction = NULL;
  1030 
  1030