stage3/fill_candidate_datatypes.cc
changeset 870 9c6c588fd708
parent 854 13d0b67de111
child 873 dea39ef02847
equal deleted inserted replaced
822:a7d9e0b8636b 870:9c6c588fd708
   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));
   625  */
   666  */
   626 void *fill_candidate_datatypes_c::handle_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
   667 void *fill_candidate_datatypes_c::handle_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
   627 	handle_binary_expression(widen_table, symbol, l_expr, r_expr);
   668 	handle_binary_expression(widen_table, symbol, l_expr, r_expr);
   628 	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
   669 	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
   629 		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) {
   670 		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) {
   630 			if ((l_expr->candidate_datatypes[i] == r_expr->candidate_datatypes[j]) && search_base_type_c::type_is_enumerated(l_expr->candidate_datatypes[i]))
   671 			if ((l_expr->candidate_datatypes[i] == r_expr->candidate_datatypes[j]) && get_datatype_info_c::is_enumerated(l_expr->candidate_datatypes[i]))
   631 				add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name);
   672 				add_datatype_to_candidate_list(symbol, &get_datatype_info_c::bool_type_name);
   632 		}
   673 		}
   633 	return NULL;
   674 	return NULL;
   634 }
   675 }
   635 
   676 
  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 
  1527  * | il_call_operator prev_declared_fb_name '(' ')'
  1592  * | il_call_operator prev_declared_fb_name '(' ')'
  1528  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
  1593  * | il_call_operator prev_declared_fb_name '(' eol_list ')'
  1529  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  1594  * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
  1530  * | 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 ')'
  1531  */
  1596  */
  1532 /* 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 */
  1533 // 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)
  1534 void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1599 void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
  1535 	/* We do not call
  1600 	symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
  1536 	 * 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;
  1537 	 * because we want to make sure it is a FB instance, and not some other data type...
       
  1538 	 */
       
  1539 	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(symbol->fb_name);
       
  1540 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
       
  1541 	if (NULL == fb_type_id) ERROR;
       
  1542 
       
  1543  	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
       
  1544 	if (function_block_type_symtable.end_value() == fb_decl) 
       
  1545 		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
       
  1546 		fb_decl = NULL;
       
  1547 
  1602 
  1548 	/* 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! */
  1549 	if (NULL == fb_decl) ERROR;
  1604 	if (NULL == fb_decl) ERROR;
  1550 
  1605 
  1551 	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);
  1638 
  1693 
  1639 /*******************/
  1694 /*******************/
  1640 /* B 2.2 Operators */
  1695 /* B 2.2 Operators */
  1641 /*******************/
  1696 /*******************/
  1642 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;
  1643 	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++) {
  1644 		add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1700 		add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1645 	}
  1701 	}
  1646 	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";
  1647 	return NULL;
  1703 	return NULL;
  1648 }
  1704 }
  1649 
  1705 
  1650 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;
  1651 	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++) {
  1652 		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]))
  1653 			add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1710 			add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
  1654 	}
  1711 	}
  1655 	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";
  1658 
  1715 
  1659 void *fill_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1716 void *fill_candidate_datatypes_c::visit(ST_operator_c *symbol) {
  1660 	symbol_c *prev_instruction_type, *operand_type;
  1717 	symbol_c *prev_instruction_type, *operand_type;
  1661 
  1718 
  1662 	if (NULL == prev_il_instruction) return NULL;
  1719 	if (NULL == prev_il_instruction) return NULL;
       
  1720 	if (NULL == il_operand)          return NULL;
  1663 	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++) {
  1664 		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++) {
  1665 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1723 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1666 			operand_type = il_operand->candidate_datatypes[j];
  1724 			operand_type = il_operand->candidate_datatypes[j];
  1667 			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))
  1674 
  1732 
  1675 void *fill_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1733 void *fill_candidate_datatypes_c::visit(STN_operator_c *symbol) {
  1676 	symbol_c *prev_instruction_type, *operand_type;
  1734 	symbol_c *prev_instruction_type, *operand_type;
  1677 
  1735 
  1678 	if (NULL == prev_il_instruction) return NULL;
  1736 	if (NULL == prev_il_instruction) return NULL;
       
  1737 	if (NULL == il_operand)          return NULL;
  1679 	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++) {
  1680 		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++) {
  1681 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1740 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
  1682 			operand_type = il_operand->candidate_datatypes[j];
  1741 			operand_type = il_operand->candidate_datatypes[j];
  1683 			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))
  1694 	 *       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.
  1695 	 *       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!
  1696 	 *       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!
  1697 	 */
  1756 	 */
  1698 	if (NULL == prev_il_instruction) return NULL;
  1757 	if (NULL == prev_il_instruction) return NULL;
       
  1758 	if (NULL == il_operand)          return NULL;
  1699 	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++) {
  1700 		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]))
  1701 			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]);
  1702 	}
  1762 	}
  1703 	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";
  1704 	return NULL;
  1764 	return NULL;
  1705 }
  1765 }
  1706 
  1766 
  1707 
  1767 
  1708 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);}
  1709   /* 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);}
  1710 	symbol_c *prev_instruction_type, *operand_type;
  1770 
  1711 
  1771 void *fill_candidate_datatypes_c::visit(  S1_operator_c *symbol) {return handle_implicit_il_fb_call(symbol,  "S1", symbol->called_fb_declaration);}
  1712 	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);}
  1713 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1714 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1715 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1716 			operand_type = il_operand->candidate_datatypes[j];
       
  1717 			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
       
  1718 			 * the prev_instruction_type MUST be BOOL compatible.
       
  1719 			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
       
  1720 			 */
       
  1721 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
       
  1722 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
       
  1723 		}
       
  1724 	}
       
  1725 	if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1726 	return NULL;
       
  1727 }
       
  1728 
       
  1729 
       
  1730 void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) {
       
  1731   /* TODO: what if this is a FB call ?? */
       
  1732 	symbol_c *prev_instruction_type, *operand_type;
       
  1733 
       
  1734 	if (NULL == prev_il_instruction) return NULL;
       
  1735 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1736 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1737 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1738 			operand_type = il_operand->candidate_datatypes[j];
       
  1739 			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
       
  1740 			 * the prev_instruction_type MUST be BOOL compatible.
       
  1741 			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
       
  1742 			 */
       
  1743 			if (get_datatype_info_c::is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
       
  1744 				add_datatype_to_candidate_list(symbol, prev_instruction_type);
       
  1745 		}
       
  1746 	}
       
  1747 	if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1748 	return NULL;
       
  1749 }
       
  1750 
       
  1751 
       
  1752 void *fill_candidate_datatypes_c::visit( S1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "S1", symbol->called_fb_declaration);}
       
  1753 void *fill_candidate_datatypes_c::visit( R1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "R1", symbol->called_fb_declaration);}
       
  1754 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);}
  1755 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);}
  1756 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);}
  1757 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);}
  1758 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);}
  1759 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);}
  1760 
  1779 
  1761 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);}
  1762 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);}
  1763 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);}
  1764 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);}
  1943 
  1962 
  1944 /*****************************************/
  1963 /*****************************************/
  1945 /* B 3.2.2 Subprogram Control Statements */
  1964 /* B 3.2.2 Subprogram Control Statements */
  1946 /*****************************************/
  1965 /*****************************************/
  1947 void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
  1966 void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
  1948 	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);
  1949 	/* 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;
  1950 	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! */
  1951 
       
  1952 	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
       
  1953 	if (function_block_type_symtable.end_value() == fb_decl) 
       
  1954 		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
       
  1955 		fb_decl = NULL;
       
  1956 
       
  1957 	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
       
  1958 	if (NULL == fb_decl) ERROR;
       
  1959 	
  1970 	
  1960 	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);
  1961 	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);
  1962 
  1973 
  1963 	/* 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