stage3/fill_candidate_datatypes.cc
changeset 849 1f8885ae539a
parent 837 e0184feaebd2
child 854 13d0b67de111
equal deleted inserted replaced
823:c95f42f28b69 849:1f8885ae539a
   553 /* handle implicit FB call in IL.
   553 /* handle implicit FB call in IL.
   554  * e.g.  CLK ton_var
   554  * e.g.  CLK ton_var
   555  *        CU counter_var
   555  *        CU counter_var
   556  */
   556  */
   557 void *fill_candidate_datatypes_c::handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
   557 void *fill_candidate_datatypes_c::handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
   558 	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(il_operand);
   558 	symbol_c *fb_decl = (NULL == il_operand)? NULL : search_varfb_instance_type->get_basetype_decl(il_operand);
   559   	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
   559 	if (! get_datatype_info_c::is_function_block(fb_decl)) fb_decl = NULL;
   560 	if (NULL == fb_type_id) ERROR;
   560 
   561 
   561 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
   562 	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
   562 	/* However, when calling using the 'S' and 'R' operators, this error is not caught by stage 2, as these operators have two possible semantics */
   563 	if (function_block_type_symtable.end_value() == fb_decl)
   563 	// if (NULL == fb_type_id) ERROR;
   564 		/* The il_operand is not the name of a FB instance. Most probably it is the name of a variable of some other type.
   564 
   565 		 * this is a semantic error.
       
   566 		 */
       
   567 		fb_decl = NULL;
       
   568 	
       
   569 	/* The narrow_candidate_datatypes_c does not rely on this called_fb_declaration pointer being == NULL to conclude that
   565 	/* The narrow_candidate_datatypes_c does not rely on this called_fb_declaration pointer being == NULL to conclude that
   570 	 * we have a datatype incompatibility error, so we set it to fb_decl to allow the print_datatype_error_c to print out
   566 	 * we have a datatype incompatibility error, so we set it to fb_decl to allow the print_datatype_error_c to print out
   571 	 * more informative error messages!
   567 	 * more informative error messages!
   572 	 */
   568 	 */
   573 	called_fb_declaration = fb_decl;
   569 	called_fb_declaration = fb_decl;
   592 }
   588 }
   593 
   589 
   594 
   590 
   595 
   591 
   596 
   592 
       
   593 
       
   594 /* handle the S and R IL operators... */
       
   595 /* operator_str should be set to either "S" or "R" */
       
   596 void *fill_candidate_datatypes_c::handle_S_and_R_operator(symbol_c *symbol, const char *operator_str, symbol_c *&called_fb_declaration) {
       
   597 	/* NOTE: this operator has two possible semantic meanings:
       
   598 	 *          - Set/Reset the BOOL operand variable to true
       
   599 	 *          - call the FB specified by the operand.
       
   600 	 *       Which of the two semantics will have to be determined by the datatype of the operand!
       
   601 	 */
       
   602 	symbol_c *prev_instruction_type, *operand_type;
       
   603 
       
   604 	if (NULL == prev_il_instruction) return NULL;
       
   605 	if (NULL == il_operand)          return NULL;
       
   606 
       
   607 	/* Try the Set/Reset semantics */
       
   608 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   609 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   610 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   611 			operand_type = il_operand->candidate_datatypes[j];
       
   612 			/* IEC61131-3, Table 52, Note (e) states that the datatype of the operand must be BOOL!
       
   613 			 * IEC61131-3, Table 52, line 3 states that this operator should "Set operand to 1 if current result is Boolean 1"
       
   614 			 *     which implies that the prev_instruction_type MUST also be BOOL compatible.
       
   615 			 */
       
   616 			if (get_datatype_info_c::is_BOOL_compatible(prev_instruction_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
       
   617 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
       
   618 		}
       
   619 	}
       
   620 
       
   621 	/* if the appropriate semantics is not a Set/Reset of a boolean variable, the we try for the FB invocation! */
       
   622 	if (symbol->candidate_datatypes.size() == 0) {
       
   623 		handle_implicit_il_fb_call(symbol,  operator_str, called_fb_declaration);
       
   624 		/* If it is also not a valid FB call, make sure the candidate_datatypes is empty (handle_implicit_il_fb_call may leave it non-empty!!) */
       
   625 		/* From here on out, all later code will consider the symbol->called_fb_declaration being NULL as an indication that this operator must use the
       
   626 		 * Set/Reset semantics, so we must also guarantee that the remainder of the state of this symbol is compatible with that assumption!
       
   627 		 */
       
   628 		if (NULL == called_fb_declaration)
       
   629 			symbol->candidate_datatypes.clear();
       
   630 	}
       
   631 
       
   632 	if (debug) std::cout << operator_str << " [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   633 	return NULL;
       
   634 }
       
   635 
       
   636 
       
   637 
   597 /* handle a binary IL operator, like ADD, SUB, etc... */
   638 /* handle a binary IL operator, like ADD, SUB, etc... */
   598 void *fill_candidate_datatypes_c::handle_binary_operator(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
   639 void *fill_candidate_datatypes_c::handle_binary_operator(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
   599 	if (NULL == l_expr) /* if no prev_il_instruction */
   640 	if (NULL == l_expr) return NULL; /* if no prev_il_instruction */
   600 		return NULL; 
   641 	if (NULL == r_expr) return NULL; /* if no IL operand!! */
   601 
   642 
   602 	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
   643 	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
   603 		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++)
   644 		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++)
   604 			/* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */
   645 			/* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */
   605 			add_datatype_to_candidate_list(symbol, widening_conversion(l_expr->candidate_datatypes[i], r_expr->candidate_datatypes[j], widen_table));
   646 			add_datatype_to_candidate_list(symbol, widening_conversion(l_expr->candidate_datatypes[i], r_expr->candidate_datatypes[j], widen_table));
  1110 void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) {
  1151 void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) {
  1111 	/* get the declaration of the data type __stored__ in the array... */
  1152 	/* get the declaration of the data type __stored__ in the array... */
  1112 	/* if we were to want the data type of the array itself, then we should call_param_name
  1153 	/* if we were to want the data type of the array itself, then we should call_param_name
  1113 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1154 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
  1114 	 */
  1155 	 */
  1115 	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
  1156 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));   /* will only add if non NULL */
  1116 	if (NULL != result) add_datatype_to_candidate_list(symbol, result);
       
  1117 	
  1157 	
  1118 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1158 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
  1119 	symbol->subscript_list->accept(*this);
  1159 	symbol->subscript_list->accept(*this);
       
  1160 
       
  1161 	/* recursively call the subscripted_variable. We need to do this since the array variable may be stored inside a structured
       
  1162 	 * variable (i.e. if it is an element inside a struct), in which case we want to recursively visit every element of the struct,
       
  1163 	 * as it may contain more arrays whose subscripts must also be visited!
       
  1164 	 * e.g.   structvar.a1[v1+2].b1.c1[v2+3].d1
       
  1165 	 *        TYPE
       
  1166 	 *           d_s: STRUCT d1: int; d2: int;
       
  1167 	 *           d_a: ARRAY [1..3] OF d_s;  
       
  1168 	 *           c_s: STRUCT c1: d_a; c2: d_a;
       
  1169 	 *           b_s: STRUCT b1: c_s; b2: c_s;
       
  1170 	 *           b_a: ARRAY [1..3] OF b_s;  
       
  1171 	 *           a_s: STRUCT a1: b_a; a2: b_a;
       
  1172 	 *        END_TYPE 
       
  1173 	 *        VAR
       
  1174 	 *          structvar: a_s;
       
  1175 	 *        END_VAR
       
  1176 	 */
       
  1177 	symbol->subscripted_variable->accept(*this);
  1120 
  1178 
  1121 	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
  1179 	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
  1122 	return NULL;
  1180 	return NULL;
  1123 }
  1181 }
  1124 
  1182 
  1134  *           may be accessed as fields of a structured variable!
  1192  *           may be accessed as fields of a structured variable!
  1135  *           Code handling a structured_variable_c must take
  1193  *           Code handling a structured_variable_c must take
  1136  *           this into account!
  1194  *           this into account!
  1137  */
  1195  */
  1138 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1196 // SYM_REF2(structured_variable_c, record_variable, field_selector)
  1139 /* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
       
  1140  * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
  1141  */
       
  1142 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
  1197 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
       
  1198 	/* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
       
  1199 	 * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
  1200 	 */
  1143 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
  1201 	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
       
  1202 	/* However, we do need to visit each record type recursively!
       
  1203 	 * Remember that a structured variable may be stored inside an array (e.g. arrayvar[33].elem1)
       
  1204 	 * The array subscripts may contain a complex expression (e.g. arrayvar[ varx + 33].elem1) whose datatype must be correctly determined!
       
  1205 	 * The expression, may even contain a function call to an overloaded function!
       
  1206 	 *      (e.g.  arrayvar[ varx + TRUNC(realvar)].elem1)
       
  1207 	 */
       
  1208 	symbol->record_variable->accept(*this);
  1144 	return NULL;
  1209 	return NULL;
  1145 }
  1210 }
  1146 
  1211 
  1147 
  1212 
  1148 
  1213 
  1321 
  1386 
  1322 	local_enumerated_value_symtable.reset();
  1387 	local_enumerated_value_symtable.reset();
  1323 	return NULL;
  1388 	return NULL;
  1324 }
  1389 }
  1325 
  1390 
  1326 
  1391 /********************************************/
       
  1392 /* B 1.6 Sequential function chart elements */
       
  1393 /********************************************/
       
  1394 
       
  1395 void *fill_candidate_datatypes_c::visit(transition_condition_c *symbol) {
       
  1396 	symbol_c *condition_type;
       
  1397 
       
  1398 	if (symbol->transition_condition_il != NULL) {
       
  1399 		symbol->transition_condition_il->accept(*this);
       
  1400 		for (unsigned int i = 0; i < symbol->transition_condition_il->candidate_datatypes.size(); i++) {
       
  1401 			condition_type = symbol->transition_condition_il->candidate_datatypes[i];
       
  1402 			if (get_datatype_info_c::is_BOOL_compatible(condition_type))
       
  1403 				add_datatype_to_candidate_list(symbol, condition_type);
       
  1404 		}
       
  1405 	}
       
  1406 	if (symbol->transition_condition_st != NULL) {
       
  1407 		symbol->transition_condition_st->accept(*this);
       
  1408 		for (unsigned int i = 0; i < symbol->transition_condition_st->candidate_datatypes.size(); i++) {
       
  1409 			condition_type = symbol->transition_condition_st->candidate_datatypes[i];
       
  1410 			if (get_datatype_info_c::is_BOOL_compatible(condition_type))
       
  1411 				add_datatype_to_candidate_list(symbol, condition_type);
       
  1412 		}
       
  1413 	}
       
  1414 	return NULL;
       
  1415 }
  1327 
  1416 
  1328 /********************************/
  1417 /********************************/
  1329 /* B 1.7 Configuration elements */
  1418 /* B 1.7 Configuration elements */
  1330 /********************************/
  1419 /********************************/
  1331 void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) {
  1420 void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) {
  1503  * | il_call_operator prev_declared_fb_name '(' ')'
  1592  * | il_call_operator prev_declared_fb_name '(' ')'
  1504  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
  1593  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
  1505  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  1594  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  1506  * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  1595  * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
  1507  */
  1596  */
  1508 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
  1597 /* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 */
  1509 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
  1598 // SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
  1510 void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1599 void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1511 	/* We do not call
  1600 	symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
  1512 	 * fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
  1601 	if (! get_datatype_info_c::is_function_block(fb_decl)) fb_decl = NULL;
  1513 	 * because we want to make sure it is a FB instance, and not some other data type...
       
  1514 	 */
       
  1515 	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(symbol->fb_name);
       
  1516 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
       
  1517 	if (NULL == fb_type_id) ERROR;
       
  1518 
       
  1519  	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
       
  1520 	if (function_block_type_symtable.end_value() == fb_decl) 
       
  1521 		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
       
  1522 		fb_decl = NULL;
       
  1523 
  1602 
  1524 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1603 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1525 	if (NULL == fb_decl) ERROR;
  1604 	if (NULL == fb_decl) ERROR;
  1526 
  1605 
  1527 	if (symbol->  il_param_list != NULL) symbol->il_param_list->accept(*this);
  1606 	if (symbol->  il_param_list != NULL) symbol->il_param_list->accept(*this);
  1614 
  1693 
  1615 /*******************/
  1694 /*******************/
  1616 /* B 2.2 Operators */
  1695 /* B 2.2 Operators */
  1617 /*******************/
  1696 /*******************/
  1618 void *fill_candidate_datatypes_c::visit(LD_operator_c *symbol) {
  1697 void *fill_candidate_datatypes_c::visit(LD_operator_c *symbol) {
       
  1698 	if (NULL == il_operand)          return NULL;
  1619 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
  1699 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
  1620 		add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1700 		add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1621 	}
  1701 	}
  1622 	if (debug) std::cout << "LD [" <<  il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1702 	if (debug) std::cout << "LD [" <<  il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1623 	return NULL;
  1703 	return NULL;
  1624 }
  1704 }
  1625 
  1705 
  1626 void *fill_candidate_datatypes_c::visit(LDN_operator_c *symbol) {
  1706 void *fill_candidate_datatypes_c::visit(LDN_operator_c *symbol) {
       
  1707 	if (NULL == il_operand)          return NULL;
  1627 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
  1708 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
  1628 		if      (get_datatype_info_c::is_ANY_BIT_compatible(il_operand->candidate_datatypes[i]))
  1709 		if      (get_datatype_info_c::is_ANY_BIT_compatible(il_operand->candidate_datatypes[i]))
  1629 			add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1710 			add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1630 	}
  1711 	}
  1631 	if (debug) std::cout << "LDN [" << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1712 	if (debug) std::cout << "LDN [" << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1634 
  1715 
  1635 void *fill_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1716 void *fill_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1636 	symbol_c *prev_instruction_type, *operand_type;
  1717 	symbol_c *prev_instruction_type, *operand_type;
  1637 
  1718 
  1638 	if (NULL == prev_il_instruction) return NULL;
  1719 	if (NULL == prev_il_instruction) return NULL;
       
  1720 	if (NULL == il_operand)          return NULL;
  1639 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1721 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1640 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
  1722 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
  1641 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1723 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1642 			operand_type = il_operand->candidate_datatypes[j];
  1724 			operand_type = il_operand->candidate_datatypes[j];
  1643 			if (get_datatype_info_c::is_type_equal(prev_instruction_type, operand_type))
  1725 			if (get_datatype_info_c::is_type_equal(prev_instruction_type, operand_type))
  1650 
  1732 
  1651 void *fill_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1733 void *fill_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1652 	symbol_c *prev_instruction_type, *operand_type;
  1734 	symbol_c *prev_instruction_type, *operand_type;
  1653 
  1735 
  1654 	if (NULL == prev_il_instruction) return NULL;
  1736 	if (NULL == prev_il_instruction) return NULL;
       
  1737 	if (NULL == il_operand)          return NULL;
  1655 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1738 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1656 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
  1739 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
  1657 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1740 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1658 			operand_type = il_operand->candidate_datatypes[j];
  1741 			operand_type = il_operand->candidate_datatypes[j];
  1659 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_ANY_BIT_compatible(operand_type))
  1742 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_ANY_BIT_compatible(operand_type))
  1670 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
  1753 	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
  1671 	 *       We therefore consider it an error if an il_operand is specified!
  1754 	 *       We therefore consider it an error if an il_operand is specified!
  1672 	 *       We do not need to generate an error message. This error will be caught somewhere else!
  1755 	 *       We do not need to generate an error message. This error will be caught somewhere else!
  1673 	 */
  1756 	 */
  1674 	if (NULL == prev_il_instruction) return NULL;
  1757 	if (NULL == prev_il_instruction) return NULL;
       
  1758 	if (NULL == il_operand)          return NULL;
  1675 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1759 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
  1676 		if (get_datatype_info_c::is_ANY_BIT_compatible(prev_il_instruction->candidate_datatypes[i]))
  1760 		if (get_datatype_info_c::is_ANY_BIT_compatible(prev_il_instruction->candidate_datatypes[i]))
  1677 			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
  1761 			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
  1678 	}
  1762 	}
  1679 	if (debug) std::cout <<  "NOT_operator [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1763 	if (debug) std::cout <<  "NOT_operator [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
  1680 	return NULL;
  1764 	return NULL;
  1681 }
  1765 }
  1682 
  1766 
  1683 
  1767 
  1684 void *fill_candidate_datatypes_c::visit(S_operator_c *symbol) {
  1768 void *fill_candidate_datatypes_c::visit(   S_operator_c *symbol) {return handle_S_and_R_operator   (symbol,   "S", symbol->called_fb_declaration);}
  1685   /* TODO: what if this is a FB call ?? */
  1769 void *fill_candidate_datatypes_c::visit(   R_operator_c *symbol) {return handle_S_and_R_operator   (symbol,   "R", symbol->called_fb_declaration);}
  1686 	symbol_c *prev_instruction_type, *operand_type;
  1770 
  1687 
  1771 void *fill_candidate_datatypes_c::visit(  S1_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "S1", symbol->called_fb_declaration);}
  1688 	if (NULL == prev_il_instruction) return NULL;
  1772 void *fill_candidate_datatypes_c::visit(  R1_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "R1", symbol->called_fb_declaration);}
  1689 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1690 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1691 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1692 			operand_type = il_operand->candidate_datatypes[j];
       
  1693 			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
       
  1694 			 * the prev_instruction_type MUST be BOOL compatible.
       
  1695 			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
       
  1696 			 */
       
  1697 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
       
  1698 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
       
  1699 		}
       
  1700 	}
       
  1701 	if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1702 	return NULL;
       
  1703 }
       
  1704 
       
  1705 
       
  1706 void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) {
       
  1707   /* TODO: what if this is a FB call ?? */
       
  1708 	symbol_c *prev_instruction_type, *operand_type;
       
  1709 
       
  1710 	if (NULL == prev_il_instruction) return NULL;
       
  1711 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1712 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1713 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1714 			operand_type = il_operand->candidate_datatypes[j];
       
  1715 			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
       
  1716 			 * the prev_instruction_type MUST be BOOL compatible.
       
  1717 			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
       
  1718 			 */
       
  1719 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
       
  1720 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
       
  1721 		}
       
  1722 	}
       
  1723 	if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1724 	return NULL;
       
  1725 }
       
  1726 
       
  1727 
       
  1728 void *fill_candidate_datatypes_c::visit( S1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "S1", symbol->called_fb_declaration);}
       
  1729 void *fill_candidate_datatypes_c::visit( R1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "R1", symbol->called_fb_declaration);}
       
  1730 void *fill_candidate_datatypes_c::visit( CLK_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
  1773 void *fill_candidate_datatypes_c::visit( CLK_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
  1731 void *fill_candidate_datatypes_c::visit( CU_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "CU", symbol->called_fb_declaration);}
  1774 void *fill_candidate_datatypes_c::visit(  CU_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "CU", symbol->called_fb_declaration);}
  1732 void *fill_candidate_datatypes_c::visit( CD_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "CD", symbol->called_fb_declaration);}
  1775 void *fill_candidate_datatypes_c::visit(  CD_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "CD", symbol->called_fb_declaration);}
  1733 void *fill_candidate_datatypes_c::visit( PV_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "PV", symbol->called_fb_declaration);}
  1776 void *fill_candidate_datatypes_c::visit(  PV_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "PV", symbol->called_fb_declaration);}
  1734 void *fill_candidate_datatypes_c::visit( IN_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "IN", symbol->called_fb_declaration);}
  1777 void *fill_candidate_datatypes_c::visit(  IN_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "IN", symbol->called_fb_declaration);}
  1735 void *fill_candidate_datatypes_c::visit( PT_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "PT", symbol->called_fb_declaration);}
  1778 void *fill_candidate_datatypes_c::visit(  PT_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "PT", symbol->called_fb_declaration);}
  1736 
  1779 
  1737 void *fill_candidate_datatypes_c::visit( AND_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
  1780 void *fill_candidate_datatypes_c::visit( AND_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
  1738 void *fill_candidate_datatypes_c::visit(  OR_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);}
  1781 void *fill_candidate_datatypes_c::visit(  OR_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);}
  1739 void *fill_candidate_datatypes_c::visit( XOR_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);}
  1782 void *fill_candidate_datatypes_c::visit( XOR_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);}
  1740 void *fill_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
  1783 void *fill_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
  1919 
  1962 
  1920 /*****************************************/
  1963 /*****************************************/
  1921 /* B 3.2.2 Subprogram Control Statements */
  1964 /* B 3.2.2 Subprogram Control Statements */
  1922 /*****************************************/
  1965 /*****************************************/
  1923 void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
  1966 void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
  1924 	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(symbol->fb_name);
  1967 	symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
  1925 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1968 	if (! get_datatype_info_c::is_function_block(fb_decl )) fb_decl = NULL;
  1926 	if (NULL == fb_type_id) ERROR;
  1969 	if (NULL == fb_decl) ERROR; /* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
  1927 
       
  1928 	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
       
  1929 	if (function_block_type_symtable.end_value() == fb_decl) 
       
  1930 		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
       
  1931 		fb_decl = NULL;
       
  1932 
       
  1933 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
       
  1934 	if (NULL == fb_decl) ERROR;
       
  1935 	
  1970 	
  1936 	if (symbol->   formal_param_list != NULL) symbol->formal_param_list->accept(*this);
  1971 	if (symbol->   formal_param_list != NULL) symbol->formal_param_list->accept(*this);
  1937 	if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this);
  1972 	if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this);
  1938 
  1973 
  1939 	/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that
  1974 	/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that