stage3/fill_candidate_datatypes.cc
changeset 417 d48f53715f77
child 418 2ac41d2cba91
equal deleted inserted replaced
416:0c2ef191b22a 417:d48f53715f77
       
     1 /*
       
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
       
     3  *
       
     4  *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
       
     5  *  Copyright (C) 2012       Manuele Conti (manuele.conti@sirius-es.it)
       
     6  *  Copyright (C) 2012       Matteo Facchinetti (matteo.facchinetti@sirius-es.it)
       
     7  *
       
     8  *  This program is free software: you can redistribute it and/or modify
       
     9  *  it under the terms of the GNU General Public License as published by
       
    10  *  the Free Software Foundation, either version 3 of the License, or
       
    11  *  (at your option) any later version.
       
    12  *
       
    13  *  This program is distributed in the hope that it will be useful,
       
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16  *  GNU General Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License
       
    19  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    20  *
       
    21  *
       
    22  * This code is made available on the understanding that it will not be
       
    23  * used in safety-critical situations without a full and competent review.
       
    24  */
       
    25 
       
    26 /*
       
    27  * An IEC 61131-3 compiler.
       
    28  *
       
    29  * Based on the
       
    30  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    31  *
       
    32  */
       
    33 
       
    34 
       
    35 /*
       
    36  *  Fill candidate list of data types for all symbols
       
    37  */
       
    38 
       
    39 #include "fill_candidate_datatypes.hh"
       
    40 #include "datatype_functions.hh"
       
    41 #include <typeinfo>
       
    42 #include <list>
       
    43 #include <string>
       
    44 #include <string.h>
       
    45 #include <strings.h>
       
    46 
       
    47 /* set to 1 to see debug info during execution */
       
    48 static int debug = 0;
       
    49 
       
    50 fill_candidate_datatypes_c::fill_candidate_datatypes_c(symbol_c *ignore) {
       
    51 
       
    52 }
       
    53 
       
    54 fill_candidate_datatypes_c::~fill_candidate_datatypes_c(void) {
       
    55 }
       
    56 
       
    57 symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]) {
       
    58 	int k;
       
    59 	/* find a widening table entry compatible */
       
    60 	for (k = 0; NULL != widen_table[k].left;  k++)
       
    61 		if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right)))
       
    62 			return widen_table[k].result;
       
    63 	return NULL;
       
    64 }
       
    65 
       
    66 void fill_candidate_datatypes_c::match_nonformal_call(symbol_c *f_call, symbol_c *f_decl, int *error_count) {
       
    67 	symbol_c *call_param_value,  *param_type;
       
    68 	identifier_c *param_name;
       
    69 	function_param_iterator_c       fp_iterator(f_decl);
       
    70 	function_call_param_iterator_c fcp_iterator(f_call);
       
    71 	int extensible_parameter_highest_index = -1;
       
    72 	unsigned int i;
       
    73 
       
    74 	/* reset error counter */
       
    75 	if (error_count != NULL) *error_count = 0;
       
    76 	/* Iterating through the non-formal parameters of the function call */
       
    77 	while((call_param_value = fcp_iterator.next_nf()) != NULL) {
       
    78 		/* Obtaining the type of the value being passed in the function call */
       
    79 		std::vector <symbol_c *>&call_param_types = call_param_value->candidate_datatypes;
       
    80 		/* Iterate to the next parameter of the function being called.
       
    81 		 * Get the name of that parameter, and ignore if EN or ENO.
       
    82 		 */
       
    83 		do {
       
    84 			param_name = fp_iterator.next();
       
    85 			/* If there is no other parameter declared, then we are passing too many parameters... */
       
    86 			if(param_name == NULL) {
       
    87 				(*error_count)++;
       
    88 				return;
       
    89 			}
       
    90 		} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
       
    91 
       
    92 		/* Get the parameter type */
       
    93 		param_type = base_type(fp_iterator.param_type());
       
    94 		for(i = 0; i < call_param_types.size(); i++) {
       
    95 			/* If the declared parameter and the parameter from the function call do not have the same type */
       
    96 			if(is_type_equal(param_type, call_param_types[i])) {
       
    97 				break;
       
    98 			}
       
    99 		}
       
   100 		if (i >= call_param_types.size()) (*error_count)++;
       
   101 	}
       
   102 }
       
   103 
       
   104 void fill_candidate_datatypes_c::match_formal_call(symbol_c *f_call, symbol_c *f_decl, int *error_count) {
       
   105 	symbol_c *call_param_value, *call_param_name, *param_type;
       
   106 	symbol_c *verify_duplicate_param;
       
   107 	identifier_c *param_name;
       
   108 	function_param_iterator_c       fp_iterator(f_decl);
       
   109 	function_call_param_iterator_c fcp_iterator(f_call);
       
   110 	int extensible_parameter_highest_index = -1;
       
   111 	identifier_c *extensible_parameter_name;
       
   112 	unsigned int i;
       
   113 
       
   114 	/* reset error counter */
       
   115 	if (error_count != NULL) *error_count = 0;
       
   116 
       
   117 	/* Iterating through the formal parameters of the function call */
       
   118 	while((call_param_name = fcp_iterator.next_f()) != NULL) {
       
   119 
       
   120 		/* Obtaining the value being passed in the function call */
       
   121 		call_param_value = fcp_iterator.get_current_value();
       
   122 		/* the following should never occur. If it does, then we have a bug in our code... */
       
   123 		if (NULL == call_param_value) ERROR;
       
   124 
       
   125 		/* Checking if there are duplicated parameter values */
       
   126 		verify_duplicate_param = fcp_iterator.search_f(call_param_name);
       
   127 		if(verify_duplicate_param != call_param_value)
       
   128 			(*error_count)++;
       
   129 
       
   130 		/* Obtaining the type of the value being passed in the function call */
       
   131 		std::vector <symbol_c *>&call_param_types = call_param_value->candidate_datatypes;
       
   132 
       
   133 
       
   134 		/* Find the corresponding parameter in function declaration */
       
   135 		param_name = fp_iterator.search(call_param_name);
       
   136 		if(param_name == NULL) {
       
   137 			(*error_count)++;
       
   138 		} else {
       
   139 			/* Get the parameter type */
       
   140 			param_type = base_type(fp_iterator.param_type());
       
   141 			for (i = 0; i < call_param_types.size(); i++) {
       
   142 				/* If the declared parameter and the parameter from the function call have the same type */
       
   143 				if(is_type_equal(param_type, call_param_types[i]))
       
   144 					break;
       
   145 			}
       
   146 			if (i >= call_param_types.size()) (*error_count)++;
       
   147 		}
       
   148 	}
       
   149 
       
   150 }
       
   151 
       
   152 /* a helper function... */
       
   153 symbol_c *fill_candidate_datatypes_c::base_type(symbol_c *symbol) {
       
   154 	/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used
       
   155 	 *       in the code.
       
   156 	 */
       
   157 	if (symbol == NULL) return NULL;
       
   158 	return (symbol_c *)symbol->accept(search_base_type);
       
   159 }
       
   160 
       
   161 /*********************/
       
   162 /* B 1.2 - Constants */
       
   163 /*********************/
       
   164 /******************************/
       
   165 /* B 1.2.1 - Numeric Literals */
       
   166 /******************************/
       
   167 void *fill_candidate_datatypes_c::visit(real_c *symbol) {
       
   168 	int calc_size;
       
   169 
       
   170 	calc_size = sizeoftype(symbol);
       
   171 	if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name))
       
   172 		symbol->candidate_datatypes.push_back(&search_constant_type_c::real_type_name);
       
   173 	if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name))
       
   174 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lreal_type_name);
       
   175 	if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
       
   176 	return NULL;
       
   177 }
       
   178 
       
   179 void *fill_candidate_datatypes_c::visit(integer_c *symbol) {
       
   180 	int calc_size;
       
   181 
       
   182 	calc_size = sizeoftype(symbol);
       
   183 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
       
   184 	        symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   185 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
       
   186 		symbol->candidate_datatypes.push_back(&search_constant_type_c::byte_type_name);
       
   187 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
       
   188 		symbol->candidate_datatypes.push_back(&search_constant_type_c::word_type_name);
       
   189 	if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name))
       
   190 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dword_type_name);
       
   191 	if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name))
       
   192 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lword_type_name);
       
   193 
       
   194 	if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name))
       
   195 		symbol->candidate_datatypes.push_back(&search_constant_type_c::sint_type_name);
       
   196 	if (calc_size < sizeoftype(&search_constant_type_c::int_type_name))
       
   197 		symbol->candidate_datatypes.push_back(&search_constant_type_c::int_type_name);
       
   198 	if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name))
       
   199 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dint_type_name);
       
   200 	if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name))
       
   201 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lint_type_name);
       
   202 	if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name))
       
   203 		symbol->candidate_datatypes.push_back(&search_constant_type_c::usint_type_name);
       
   204 	if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name))
       
   205 		symbol->candidate_datatypes.push_back(&search_constant_type_c::uint_type_name);
       
   206 	if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name))
       
   207 		symbol->candidate_datatypes.push_back(&search_constant_type_c::udint_type_name);
       
   208 	if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name))
       
   209 		symbol->candidate_datatypes.push_back(&search_constant_type_c::ulint_type_name);
       
   210 	if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl;
       
   211 	return NULL;
       
   212 }
       
   213 
       
   214 void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {
       
   215 	if (sizeoftype(symbol) <= sizeoftype(&search_constant_type_c::real_type_name))
       
   216 		symbol->candidate_datatypes.push_back(&search_constant_type_c::real_type_name);
       
   217 	symbol->candidate_datatypes.push_back(&search_constant_type_c::lreal_type_name);
       
   218 	if (debug) std::cout << "neg ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
       
   219 	return NULL;
       
   220 }
       
   221 
       
   222 void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) {
       
   223 	int calc_size;
       
   224 
       
   225 	calc_size = sizeoftype(symbol);
       
   226 	if (calc_size <= sizeoftype(&search_constant_type_c::int_type_name))
       
   227 		symbol->candidate_datatypes.push_back(&search_constant_type_c::int_type_name);
       
   228 	if (calc_size <= sizeoftype(&search_constant_type_c::sint_type_name))
       
   229 		symbol->candidate_datatypes.push_back(&search_constant_type_c::sint_type_name);
       
   230 	if (calc_size <= sizeoftype(&search_constant_type_c::dint_type_name))
       
   231 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dint_type_name);
       
   232 	if (calc_size <= sizeoftype(&search_constant_type_c::lint_type_name))
       
   233 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lint_type_name);
       
   234 	if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl;
       
   235 	return NULL;
       
   236 }
       
   237 
       
   238 void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) {
       
   239 	int calc_size;
       
   240 
       
   241 	calc_size = sizeoftype(symbol);
       
   242 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
       
   243 	        symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   244 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
       
   245 		symbol->candidate_datatypes.push_back(&search_constant_type_c::byte_type_name);
       
   246 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
       
   247 		symbol->candidate_datatypes.push_back(&search_constant_type_c::word_type_name);
       
   248 	if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name))
       
   249 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dword_type_name);
       
   250 	if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name))
       
   251 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lword_type_name);
       
   252 	
       
   253 	if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name))
       
   254 		symbol->candidate_datatypes.push_back(&search_constant_type_c::sint_type_name);
       
   255 	if (calc_size < sizeoftype(&search_constant_type_c::int_type_name))
       
   256 		symbol->candidate_datatypes.push_back(&search_constant_type_c::int_type_name);
       
   257 	if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name))
       
   258 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dint_type_name);
       
   259 	if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name))
       
   260 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lint_type_name);
       
   261 	if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name))
       
   262 		symbol->candidate_datatypes.push_back(&search_constant_type_c::usint_type_name);
       
   263 	if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name))
       
   264 		symbol->candidate_datatypes.push_back(&search_constant_type_c::uint_type_name);
       
   265 	if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name))
       
   266 		symbol->candidate_datatypes.push_back(&search_constant_type_c::udint_type_name);
       
   267 	if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name))
       
   268 		symbol->candidate_datatypes.push_back(&search_constant_type_c::ulint_type_name);
       
   269 	if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl;
       
   270 	return NULL;
       
   271 }
       
   272 
       
   273 void *fill_candidate_datatypes_c::visit(octal_integer_c *symbol) {
       
   274 	int calc_size;
       
   275 
       
   276 	calc_size = sizeoftype(symbol);
       
   277 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
       
   278 	        symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   279 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
       
   280 		symbol->candidate_datatypes.push_back(&search_constant_type_c::byte_type_name);
       
   281 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
       
   282 		symbol->candidate_datatypes.push_back(&search_constant_type_c::word_type_name);
       
   283 	if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name))
       
   284 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dword_type_name);
       
   285 	if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name))
       
   286 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lword_type_name);
       
   287 
       
   288 	if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name))
       
   289 		symbol->candidate_datatypes.push_back(&search_constant_type_c::sint_type_name);
       
   290 	if (calc_size < sizeoftype(&search_constant_type_c::int_type_name))
       
   291 		symbol->candidate_datatypes.push_back(&search_constant_type_c::int_type_name);
       
   292 	if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name))
       
   293 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dint_type_name);
       
   294 	if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name))
       
   295 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lint_type_name);
       
   296 	if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name))
       
   297 		symbol->candidate_datatypes.push_back(&search_constant_type_c::usint_type_name);
       
   298 	if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name))
       
   299 		symbol->candidate_datatypes.push_back(&search_constant_type_c::uint_type_name);
       
   300 	if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name))
       
   301 		symbol->candidate_datatypes.push_back(&search_constant_type_c::udint_type_name);
       
   302 	if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name))
       
   303 		symbol->candidate_datatypes.push_back(&search_constant_type_c::ulint_type_name);
       
   304 	if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl;
       
   305 	return NULL;
       
   306 }
       
   307 
       
   308 void *fill_candidate_datatypes_c::visit(hex_integer_c *symbol) {
       
   309 	int calc_size;
       
   310 
       
   311 	calc_size = sizeoftype(symbol);
       
   312 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
       
   313 	        symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   314 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
       
   315 		symbol->candidate_datatypes.push_back(&search_constant_type_c::byte_type_name);
       
   316 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
       
   317 		symbol->candidate_datatypes.push_back(&search_constant_type_c::word_type_name);
       
   318 	if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name))
       
   319 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dword_type_name);
       
   320 	if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name))
       
   321 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lword_type_name);
       
   322 
       
   323 	if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name))
       
   324 		symbol->candidate_datatypes.push_back(&search_constant_type_c::sint_type_name);
       
   325 	if (calc_size < sizeoftype(&search_constant_type_c::int_type_name))
       
   326 		symbol->candidate_datatypes.push_back(&search_constant_type_c::int_type_name);
       
   327 	if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name))
       
   328 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dint_type_name);
       
   329 	if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name))
       
   330 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lint_type_name);
       
   331 	if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name))
       
   332 		symbol->candidate_datatypes.push_back(&search_constant_type_c::usint_type_name);
       
   333 	if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name))
       
   334 		symbol->candidate_datatypes.push_back(&search_constant_type_c::uint_type_name);
       
   335 	if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name))
       
   336 		symbol->candidate_datatypes.push_back(&search_constant_type_c::udint_type_name);
       
   337 	if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name))
       
   338 		symbol->candidate_datatypes.push_back(&search_constant_type_c::ulint_type_name);
       
   339 	if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl;
       
   340 	return NULL;
       
   341 }
       
   342 
       
   343 void *fill_candidate_datatypes_c::visit(integer_literal_c *symbol) {
       
   344 	symbol->candidate_datatypes.push_back(symbol->type);
       
   345 	if (debug) std::cout << "INT_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
       
   346 	return NULL;
       
   347 }
       
   348 
       
   349 void *fill_candidate_datatypes_c::visit(real_literal_c *symbol) {
       
   350 	symbol->candidate_datatypes.push_back(symbol->type);
       
   351 	if (debug) std::cout << "REAL_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
       
   352 	return NULL;
       
   353 }
       
   354 
       
   355 void *fill_candidate_datatypes_c::visit(bit_string_literal_c *symbol) {
       
   356 	symbol->candidate_datatypes.push_back(symbol->type);
       
   357 	return NULL;
       
   358 }
       
   359 
       
   360 void *fill_candidate_datatypes_c::visit(boolean_literal_c *symbol) {
       
   361 	symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   362 	return NULL;
       
   363 }
       
   364 
       
   365 void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) {
       
   366 	symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   367 	return NULL;
       
   368 }
       
   369 
       
   370 void *fill_candidate_datatypes_c::visit(boolean_false_c *symbol) {
       
   371 	symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   372 	return NULL;
       
   373 }
       
   374 
       
   375 /*******************************/
       
   376 /* B.1.2.2   Character Strings */
       
   377 /*******************************/
       
   378 void *fill_candidate_datatypes_c::visit(double_byte_character_string_c *symbol) {
       
   379 	symbol->candidate_datatypes.push_back(&search_constant_type_c::wstring_type_name);
       
   380 	return NULL;
       
   381 }
       
   382 
       
   383 void *fill_candidate_datatypes_c::visit(single_byte_character_string_c *symbol) {
       
   384 	symbol->candidate_datatypes.push_back(&search_constant_type_c::string_type_name);
       
   385 	return NULL;
       
   386 }
       
   387 
       
   388 /***************************/
       
   389 /* B 1.2.3 - Time Literals */
       
   390 /***************************/
       
   391 /************************/
       
   392 /* B 1.2.3.1 - Duration */
       
   393 /************************/
       
   394 void *fill_candidate_datatypes_c::visit(duration_c *symbol) {
       
   395 	symbol->candidate_datatypes.push_back(symbol->type_name);
       
   396 	if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
       
   397 	return NULL;
       
   398 }
       
   399 
       
   400 /************************************/
       
   401 /* B 1.2.3.2 - Time of day and Date */
       
   402 /************************************/
       
   403 void *fill_candidate_datatypes_c::visit(time_of_day_c *symbol) {
       
   404 	symbol->candidate_datatypes.push_back(symbol->type_name);
       
   405 	return NULL;
       
   406 }
       
   407 
       
   408 void *fill_candidate_datatypes_c::visit(date_c *symbol) {
       
   409 	symbol->candidate_datatypes.push_back(symbol->type_name);
       
   410 	return NULL;
       
   411 }
       
   412 
       
   413 void *fill_candidate_datatypes_c::visit(date_and_time_c *symbol) {
       
   414 	symbol->candidate_datatypes.push_back(symbol->type_name);
       
   415 	return NULL;
       
   416 }
       
   417 
       
   418 /**********************/
       
   419 /* B 1.3 - Data types */
       
   420 /**********************/
       
   421 /********************************/
       
   422 /* B 1.3.3 - Derived data types */
       
   423 /********************************/
       
   424 /*  signed_integer DOTDOT signed_integer */
       
   425 // SYM_REF2(subrange_c, lower_limit, upper_limit)
       
   426 void *fill_candidate_datatypes_c::visit(subrange_c *symbol) {
       
   427 	symbol->lower_limit->accept(*this);
       
   428 	symbol->upper_limit->accept(*this);
       
   429 	
       
   430 	for (unsigned int u = 0; u < symbol->upper_limit->candidate_datatypes.size(); u++) {
       
   431 		for(unsigned int l = 0; l < symbol->lower_limit->candidate_datatypes.size(); l++) {
       
   432 			if (is_type_equal(symbol->upper_limit->candidate_datatypes[u], symbol->lower_limit->candidate_datatypes[l]))
       
   433 				symbol->candidate_datatypes.push_back(symbol->lower_limit->candidate_datatypes[l]);
       
   434 		}
       
   435 	}
       
   436 	return NULL;
       
   437 }
       
   438 
       
   439 
       
   440 void *fill_candidate_datatypes_c::visit(data_type_declaration_c *symbol) {
       
   441 	// TODO !!!
       
   442 	/* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
       
   443 	return NULL;
       
   444 }
       
   445 
       
   446 void *fill_candidate_datatypes_c::visit(enumerated_value_c *symbol) {
       
   447 	symbol_c *enumerated_type;
       
   448 
       
   449 	if (NULL != symbol->type)
       
   450 		enumerated_type = symbol->type;
       
   451 	else {
       
   452 		enumerated_type = enumerated_value_symtable.find_value(symbol->value);
       
   453 		if (enumerated_type == enumerated_value_symtable.end_value())
       
   454 			enumerated_type = NULL;
       
   455 	}
       
   456 	enumerated_type = base_type(enumerated_type);
       
   457 	if (NULL != enumerated_type)
       
   458 		symbol->candidate_datatypes.push_back(enumerated_type);
       
   459 
       
   460 	if (debug) std::cout << "ENUMERATE [" << symbol->candidate_datatypes.size() << "]\n";
       
   461 	return NULL;
       
   462 }
       
   463 
       
   464 
       
   465 /*********************/
       
   466 /* B 1.4 - Variables */
       
   467 /*********************/
       
   468 void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
       
   469 	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
       
   470 	if (NULL != result)
       
   471 		symbol->candidate_datatypes.push_back(result);
       
   472 	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
       
   473 	return NULL;
       
   474 }
       
   475 
       
   476 /********************************************/
       
   477 /* B 1.4.1 - Directly Represented Variables */
       
   478 /********************************************/
       
   479 void *fill_candidate_datatypes_c::visit(direct_variable_c *symbol) {
       
   480 	/* Comment added by mario:
       
   481 	 * The following code is safe, actually, as the lexical parser guarantees the correct IEC61131-3 syntax was used.
       
   482 	 */
       
   483 	/* However, we should probably add an assertion in case we later change the lexical parser! */
       
   484 	/* if (symbol->value == NULL) ERROR;
       
   485 	 * if (symbol->value[0] == '\0') ERROR;
       
   486 	 * if (symbol->value[1] == '\0') ERROR;
       
   487 	 */
       
   488 	switch (symbol->value[2]) {
       
   489 	case 'X': // bit - 1 bit
       
   490 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   491 		break;
       
   492 
       
   493 	case 'B': // byte - 8 bits
       
   494 		symbol->candidate_datatypes.push_back(&search_constant_type_c::byte_type_name);
       
   495 		break;
       
   496 
       
   497 	case 'W': // word - 16 bits
       
   498 		symbol->candidate_datatypes.push_back(&search_constant_type_c::word_type_name);
       
   499 		break;
       
   500 
       
   501 	case 'D': // double word - 32 bits
       
   502 		symbol->candidate_datatypes.push_back(&search_constant_type_c::dword_type_name);
       
   503 		break;
       
   504 
       
   505 	case 'L': // long word - 64 bits
       
   506 		symbol->candidate_datatypes.push_back(&search_constant_type_c::lword_type_name);
       
   507 		break;
       
   508 
       
   509 	default:  // if none of the above, then the empty string was used <=> boolean
       
   510 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
   511 		break;
       
   512 	}
       
   513 	return NULL;
       
   514 }
       
   515 
       
   516 /*************************************/
       
   517 /* B 1.4.2 - Multi-element variables */
       
   518 /*************************************/
       
   519 /*  subscripted_variable '[' subscript_list ']' */
       
   520 // SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
       
   521 void *fill_candidate_datatypes_c::visit(array_variable_c *symbol) {
       
   522 	/* get the declaration of the data type __stored__ in the array... */
       
   523 	/* if we were to want the data type of the array itself, then we should call_param_name
       
   524 	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_variable)
       
   525 	 */
       
   526 	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
       
   527 	if (NULL != result) symbol->candidate_datatypes.push_back(result);
       
   528 	
       
   529 	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
       
   530 if (debug) std::cout << "ARRAY_VAR XXX\n";		
       
   531 	symbol->subscript_list->accept(*this);
       
   532 if (debug) std::cout << "ARRAY_VAR YYY\n";		
       
   533 
       
   534 	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
       
   535 	return NULL;
       
   536 }
       
   537 
       
   538 
       
   539 /* subscript_list ',' subscript */
       
   540 // SYM_LIST(subscript_list_c)
       
   541 /* NOTE: we inherit from iterator visitor, so we do not need to implement this method... */
       
   542 #if 0
       
   543 void *fill_candidate_datatypes_c::visit(subscript_list_c *symbol) {
       
   544 }
       
   545 #endif
       
   546 
       
   547 
       
   548 /*  record_variable '.' field_selector */
       
   549 /*  WARNING: input and/or output variables of function blocks
       
   550  *           may be accessed as fields of a structured variable!
       
   551  *           Code handling a structured_variable_c must take
       
   552  *           this into account!
       
   553  */
       
   554 // SYM_REF2(structured_variable_c, record_variable, field_selector)
       
   555 /* NOTE: We do not need to recursively determine the data types of each field_selector, as the search_varfb_instance_type
       
   556  * will do that for us. So we determine the candidate datatypes only for the full structured_variable.
       
   557  */
       
   558 void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
       
   559 	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
       
   560 	if (NULL != result) symbol->candidate_datatypes.push_back(result);
       
   561 	return NULL;
       
   562 }
       
   563 
       
   564 /************************************/
       
   565 /* B 1.5 Program organization units */
       
   566 /************************************/
       
   567 /*********************/
       
   568 /* B 1.5.1 Functions */
       
   569 /*********************/
       
   570 void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) {
       
   571 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
       
   572 	symbol->var_declarations_list->accept(*this);
       
   573 	if (debug) printf("Filling candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
       
   574 	il_parenthesis_level = 0;
       
   575 	prev_il_instruction = NULL;
       
   576 	symbol->function_body->accept(*this);
       
   577 	prev_il_instruction = NULL;
       
   578 	delete search_varfb_instance_type;
       
   579 	search_varfb_instance_type = NULL;
       
   580 	return NULL;
       
   581 }
       
   582 
       
   583 /***************************/
       
   584 /* B 1.5.2 Function blocks */
       
   585 /***************************/
       
   586 void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
       
   587 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
       
   588 	symbol->var_declarations->accept(*this);
       
   589 	if (debug) printf("Filling candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
       
   590 	il_parenthesis_level = 0;
       
   591 	prev_il_instruction = NULL;
       
   592 	symbol->fblock_body->accept(*this);
       
   593 	prev_il_instruction = NULL;
       
   594 	delete search_varfb_instance_type;
       
   595 	search_varfb_instance_type = NULL;
       
   596 	return NULL;
       
   597 }
       
   598 
       
   599 /**********************/
       
   600 /* B 1.5.3 - Programs */
       
   601 /**********************/
       
   602 void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) {
       
   603 	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
       
   604 	symbol->var_declarations->accept(*this);
       
   605 	if (debug) printf("Filling candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
       
   606 	il_parenthesis_level = 0;
       
   607 	prev_il_instruction = NULL;
       
   608 	symbol->function_block_body->accept(*this);
       
   609 	prev_il_instruction = NULL;
       
   610 	delete search_varfb_instance_type;
       
   611 	search_varfb_instance_type = NULL;
       
   612 	return NULL;
       
   613 }
       
   614 
       
   615 
       
   616 
       
   617 /********************************/
       
   618 /* B 1.7 Configuration elements */
       
   619 /********************************/
       
   620 void *fill_candidate_datatypes_c::visit(configuration_declaration_c *symbol) {
       
   621 #if 0
       
   622 	// TODO !!!
       
   623 	/* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
       
   624 #endif
       
   625 	return NULL;
       
   626 }
       
   627 
       
   628 /****************************************/
       
   629 /* B.2 - Language IL (Instruction List) */
       
   630 /****************************************/
       
   631 /***********************************/
       
   632 /* B 2.1 Instructions and Operands */
       
   633 /***********************************/
       
   634 // void *visit(instruction_list_c *symbol);
       
   635 void *fill_candidate_datatypes_c::visit(il_simple_operation_c *symbol) {
       
   636 	/* determine the data type of the operand */
       
   637 	if (NULL != symbol->il_operand) {
       
   638 		symbol->il_operand->accept(*this);
       
   639 	}
       
   640 	/* recursive call to fill the candidate data types list */
       
   641 	il_operand = symbol->il_operand;
       
   642 	symbol->il_simple_operator->accept(*this);
       
   643 	il_operand = NULL;
       
   644 	return NULL;
       
   645 }
       
   646 
       
   647 void *fill_candidate_datatypes_c::visit(il_function_call_c *symbol) {
       
   648 }
       
   649 
       
   650 /* MJS: Manuele, could you please not delete the following 2 lines of comments. They help me understand where this class is used
       
   651  *     and when it is created by bison - syntax parse, and how it can show up in the abstract syntax tree.
       
   652  *
       
   653  *       Actually, it could be helpful if we could have all the similar comments already present in visit_expression_type_c
       
   654  *       in the 3 new classes fill/narrow/print candidate datatype 
       
   655  */
       
   656 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
       
   657 // SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
       
   658 void *fill_candidate_datatypes_c::visit(il_expression_c *symbol) {
       
   659   if (NULL != symbol->il_operand)
       
   660     symbol->il_operand->accept(*this);
       
   661   
       
   662   il_parenthesis_level++;
       
   663 
       
   664   /* Note that prev_il_instruction will actually be used to get the current value store in the il_default_variable */
       
   665   /* If a symbol->il_operand is provided, then that will be the result before executing the simple_instr_list.
       
   666    * If this symbol is NULL, then the current result is also NULL, which is correct for what we want to do!
       
   667    */
       
   668   symbol_c *prev_il_instruction_backup = prev_il_instruction;
       
   669   prev_il_instruction = symbol->il_operand;
       
   670   
       
   671   if(symbol->simple_instr_list != NULL) {
       
   672     symbol->simple_instr_list->accept(*this);
       
   673   }
       
   674 
       
   675   il_parenthesis_level--;
       
   676   if (il_parenthesis_level < 0) ERROR;
       
   677 
       
   678   /* Now check the if the data type semantics of operation are correct,  */
       
   679   il_operand = prev_il_instruction;
       
   680   prev_il_instruction = prev_il_instruction_backup;
       
   681   symbol->il_expr_operator->accept(*this);
       
   682   il_operand = NULL;
       
   683   return NULL;
       
   684 }
       
   685 
       
   686 void *fill_candidate_datatypes_c::visit(il_jump_operation_c *symbol) {
       
   687   /* recursive call to fill the candidate data types list */
       
   688   il_operand = NULL;
       
   689   symbol->il_jump_operator->accept(*this);
       
   690   il_operand = NULL;
       
   691   return NULL;
       
   692 }
       
   693 
       
   694 void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
       
   695 }
       
   696 
       
   697 void *fill_candidate_datatypes_c::visit(il_formal_funct_call_c *symbol) {
       
   698 
       
   699 }
       
   700 
       
   701 /*
       
   702     void *visit(il_operand_list_c *symbol);
       
   703     void *visit(simple_instr_list_c *symbol);
       
   704     void *visit(il_param_list_c *symbol);
       
   705     void *visit(il_param_assignment_c *symbol);
       
   706     void *visit(il_param_out_assignment_c *symbol);
       
   707 */
       
   708 
       
   709 /*******************/
       
   710 /* B 2.2 Operators */
       
   711 /*******************/
       
   712 void *fill_candidate_datatypes_c::visit(LD_operator_c *symbol) {
       
   713 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
       
   714 		symbol->candidate_datatypes.push_back(il_operand->candidate_datatypes[i]);
       
   715 	}
       
   716 	if (debug) std::cout << "LD [" <<  il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   717 	prev_il_instruction = symbol;
       
   718 	return NULL;
       
   719 }
       
   720 
       
   721 void *fill_candidate_datatypes_c::visit(LDN_operator_c *symbol) {
       
   722 	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
       
   723 		if      (is_ANY_BIT_compatible(il_operand->candidate_datatypes[i]))
       
   724 			symbol->candidate_datatypes.push_back(il_operand->candidate_datatypes[i]);
       
   725 	}
       
   726 	if (debug) std::cout << "LDN [" << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   727 	prev_il_instruction = symbol;
       
   728 	return NULL;
       
   729 }
       
   730 
       
   731 void *fill_candidate_datatypes_c::visit(ST_operator_c *symbol) {
       
   732 	symbol_c *prev_instruction_type, *operand_type;
       
   733 
       
   734 	if (NULL == prev_il_instruction) return NULL;
       
   735 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   736 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   737 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   738 			operand_type = il_operand->candidate_datatypes[j];
       
   739 			if (is_type_equal(prev_instruction_type,operand_type))
       
   740 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   741 		}
       
   742 	}
       
   743 	if (debug) std::cout << "ST [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   744 	prev_il_instruction = symbol;
       
   745 	return NULL;
       
   746 }
       
   747 
       
   748 void *fill_candidate_datatypes_c::visit(STN_operator_c *symbol) {
       
   749 	symbol_c *prev_instruction_type, *operand_type;
       
   750 
       
   751 	if (NULL == prev_il_instruction) return NULL;
       
   752 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   753 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   754 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   755 			operand_type = il_operand->candidate_datatypes[j];
       
   756 			if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BIT_compatible(il_operand->candidate_datatypes[i]))
       
   757 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   758 		}
       
   759 	}
       
   760 	if (debug) std::cout << "STN [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   761 	prev_il_instruction = symbol;
       
   762 	return NULL;
       
   763 }
       
   764 
       
   765 void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
       
   766 	prev_il_instruction = symbol;
       
   767 	return NULL;
       
   768 }
       
   769 
       
   770 void *fill_candidate_datatypes_c::visit(S_operator_c *symbol) {
       
   771 	symbol_c *prev_instruction_type, *operand_type;
       
   772 
       
   773 	if (NULL == prev_il_instruction) return NULL;
       
   774 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   775 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   776 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   777 			operand_type = il_operand->candidate_datatypes[j];
       
   778 			if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(il_operand->candidate_datatypes[i]))
       
   779 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   780 		}
       
   781 	}
       
   782 	if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   783 	prev_il_instruction = symbol;
       
   784 	return NULL;
       
   785 }
       
   786 
       
   787 void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) {
       
   788 	symbol_c *prev_instruction_type, *operand_type;
       
   789 
       
   790 	if (NULL == prev_il_instruction) return NULL;
       
   791 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   792 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   793 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   794 			operand_type = il_operand->candidate_datatypes[j];
       
   795 			if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(il_operand->candidate_datatypes[i]))
       
   796 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   797 		}
       
   798 	}
       
   799 	if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   800 	prev_il_instruction = symbol;
       
   801 	return NULL;
       
   802 }
       
   803 
       
   804 void *fill_candidate_datatypes_c::visit(S1_operator_c *symbol) {
       
   805 	symbol_c *prev_instruction_type, *operand_type;
       
   806 
       
   807 	if (NULL == prev_il_instruction) return NULL;
       
   808 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   809 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   810 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   811 			operand_type = il_operand->candidate_datatypes[j];
       
   812 			if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(il_operand->candidate_datatypes[i]))
       
   813 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   814 		}
       
   815 	}
       
   816 	if (debug) std::cout << "S1 [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   817 	prev_il_instruction = symbol;
       
   818 	return NULL;
       
   819 }
       
   820 
       
   821 void *fill_candidate_datatypes_c::visit(R1_operator_c *symbol) {
       
   822 	symbol_c *prev_instruction_type, *operand_type;
       
   823 
       
   824 	if (NULL == prev_il_instruction) return NULL;
       
   825 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   826 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   827 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   828 			operand_type = il_operand->candidate_datatypes[j];
       
   829 			if (is_type_equal(prev_instruction_type,operand_type) && is_ANY_BOOL_compatible(il_operand->candidate_datatypes[i]))
       
   830 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   831 		}
       
   832 	}
       
   833 	if (debug) std::cout << "R1 [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
   834 	prev_il_instruction = symbol;
       
   835 	return NULL;
       
   836 }
       
   837 
       
   838 void *fill_candidate_datatypes_c::visit(CLK_operator_c *symbol) {
       
   839 	/* MANU:
       
   840 	 * How it works? I(MANU) don't know this function
       
   841 	 */
       
   842 	prev_il_instruction = symbol;
       
   843 	return NULL;
       
   844 }
       
   845 
       
   846 void *fill_candidate_datatypes_c::visit(CU_operator_c *symbol) {
       
   847 	/* MANU:
       
   848 	 * How it works? I(MANU) don't know this function
       
   849 	 */
       
   850 	prev_il_instruction = symbol;
       
   851 	return NULL;
       
   852 }
       
   853 
       
   854 void *fill_candidate_datatypes_c::visit(CD_operator_c *symbol) {
       
   855 	/* MANU:
       
   856 	 * How it works? I(MANU) don't know this function
       
   857 	 */
       
   858 
       
   859 	prev_il_instruction = symbol;
       
   860 	return NULL;
       
   861 }
       
   862 
       
   863 void *fill_candidate_datatypes_c::visit(PV_operator_c *symbol) {
       
   864 	/* MANU:
       
   865 	 * How it works? I(MANU) don't know this function
       
   866 	 */
       
   867 
       
   868 	prev_il_instruction = symbol;
       
   869 	return NULL;
       
   870 }
       
   871 
       
   872 void *fill_candidate_datatypes_c::visit(IN_operator_c *symbol) {
       
   873 	/* MANU:
       
   874 	 * How it works? I(MANU) don't know this function
       
   875 	 */
       
   876 
       
   877 	prev_il_instruction = symbol;
       
   878 	return NULL;
       
   879 }
       
   880 
       
   881 void *fill_candidate_datatypes_c::visit(PT_operator_c *symbol) {
       
   882 	/* MANU:
       
   883 	 * How it works? I(MANU) don't know this function
       
   884 	 */
       
   885 
       
   886 	prev_il_instruction = symbol;
       
   887 	return NULL;
       
   888 }
       
   889 
       
   890 void *fill_candidate_datatypes_c::visit(AND_operator_c *symbol) {
       
   891 	symbol_c *prev_instruction_type, *operand_type;
       
   892 
       
   893 	if (NULL == prev_il_instruction) return NULL;
       
   894 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   895 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   896 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   897 			operand_type = il_operand->candidate_datatypes[j];
       
   898 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   899 					is_ANY_BIT_compatible(operand_type))
       
   900 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   901 		}
       
   902 	}
       
   903 	prev_il_instruction = symbol;
       
   904 	return NULL;
       
   905 }
       
   906 
       
   907 void *fill_candidate_datatypes_c::visit(OR_operator_c *symbol) {
       
   908 	symbol_c *prev_instruction_type, *operand_type;
       
   909 
       
   910 	if (NULL == prev_il_instruction) return NULL;
       
   911 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   912 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   913 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   914 			operand_type = il_operand->candidate_datatypes[j];
       
   915 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   916 					is_ANY_BIT_compatible(operand_type))
       
   917 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   918 		}
       
   919 	}
       
   920 	prev_il_instruction = symbol;
       
   921 	return NULL;
       
   922 }
       
   923 
       
   924 void *fill_candidate_datatypes_c::visit(XOR_operator_c *symbol) {
       
   925 	symbol_c *prev_instruction_type, *operand_type;
       
   926 
       
   927 	if (NULL == prev_il_instruction) return NULL;
       
   928 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   929 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   930 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   931 			operand_type = il_operand->candidate_datatypes[j];
       
   932 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   933 					is_ANY_BIT_compatible(operand_type))
       
   934 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   935 		}
       
   936 	}
       
   937 	prev_il_instruction = symbol;
       
   938 	return NULL;
       
   939 }
       
   940 
       
   941 void *fill_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {
       
   942 	symbol_c *prev_instruction_type, *operand_type;
       
   943 
       
   944 	if (NULL == prev_il_instruction) return NULL;
       
   945 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   946 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   947 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   948 			operand_type = il_operand->candidate_datatypes[j];
       
   949 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   950 					is_ANY_BIT_compatible(operand_type))
       
   951 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   952 		}
       
   953 	}
       
   954 	prev_il_instruction = symbol;
       
   955 	return NULL;
       
   956 }
       
   957 
       
   958 void *fill_candidate_datatypes_c::visit(ORN_operator_c *symbol) {
       
   959 	symbol_c *prev_instruction_type, *operand_type;
       
   960 
       
   961 	if (NULL == prev_il_instruction) return NULL;
       
   962 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   963 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   964 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   965 			operand_type = il_operand->candidate_datatypes[j];
       
   966 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   967 					is_ANY_BIT_compatible(operand_type))
       
   968 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   969 		}
       
   970 	}
       
   971 	prev_il_instruction = symbol;
       
   972 	return NULL;
       
   973 }
       
   974 
       
   975 void *fill_candidate_datatypes_c::visit(XORN_operator_c *symbol) {
       
   976 	symbol_c *prev_instruction_type, *operand_type;
       
   977 
       
   978 	if (NULL == prev_il_instruction) return NULL;
       
   979 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   980 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   981 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   982 			operand_type = il_operand->candidate_datatypes[j];
       
   983 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
   984 					is_ANY_BIT_compatible(operand_type))
       
   985 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
   986 		}
       
   987 	}
       
   988 	prev_il_instruction = symbol;
       
   989 	return NULL;
       
   990 }
       
   991 
       
   992 void *fill_candidate_datatypes_c::visit(ADD_operator_c *symbol) {
       
   993 	symbol_c *prev_instruction_type, *operand_type;
       
   994 
       
   995 	if (NULL == prev_il_instruction) return NULL;
       
   996 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
   997 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
   998 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
   999 			operand_type = il_operand->candidate_datatypes[j];
       
  1000 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
  1001 					is_ANY_NUM_compatible(prev_instruction_type))
       
  1002 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
  1003 			else {
       
  1004 				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_ADD_table);
       
  1005 				if (result)
       
  1006 					symbol->candidate_datatypes.push_back(result);
       
  1007 
       
  1008 			}
       
  1009 		}
       
  1010 	}
       
  1011 	if (debug) std::cout <<  "ADD [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1012 	prev_il_instruction = symbol;
       
  1013 	return NULL;
       
  1014 }
       
  1015 
       
  1016 void *fill_candidate_datatypes_c::visit(SUB_operator_c *symbol) {
       
  1017 	symbol_c *prev_instruction_type, *operand_type;
       
  1018 
       
  1019 	if (NULL == prev_il_instruction) return NULL;
       
  1020 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1021 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1022 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1023 			operand_type = il_operand->candidate_datatypes[j];
       
  1024 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
  1025 					is_ANY_NUM_compatible(prev_instruction_type))
       
  1026 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
  1027 			else {
       
  1028 				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_SUB_table);
       
  1029 				if (result)
       
  1030 					symbol->candidate_datatypes.push_back(result);
       
  1031 			}
       
  1032 		}
       
  1033 	}
       
  1034 	if (debug) std::cout <<  "SUB [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1035 	prev_il_instruction = symbol;
       
  1036 	return NULL;
       
  1037 }
       
  1038 
       
  1039 void *fill_candidate_datatypes_c::visit(MUL_operator_c *symbol) {
       
  1040 	symbol_c *prev_instruction_type, *operand_type;
       
  1041 
       
  1042 	if (NULL == prev_il_instruction) return NULL;
       
  1043 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1044 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1045 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1046 			operand_type = il_operand->candidate_datatypes[j];
       
  1047 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
  1048 					is_ANY_NUM_compatible(prev_instruction_type))
       
  1049 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
  1050 			else {
       
  1051 				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_MUL_table);
       
  1052 				if (result)
       
  1053 					symbol->candidate_datatypes.push_back(result);
       
  1054 			}
       
  1055 		}
       
  1056 	}
       
  1057 	if (debug) std::cout <<  "MUL [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1058 	prev_il_instruction = symbol;
       
  1059 	return NULL;
       
  1060 }
       
  1061 
       
  1062 void *fill_candidate_datatypes_c::visit(DIV_operator_c *symbol) {
       
  1063 	symbol_c *prev_instruction_type, *operand_type;
       
  1064 
       
  1065 	if (NULL == prev_il_instruction) return NULL;
       
  1066 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1067 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1068 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1069 			operand_type = il_operand->candidate_datatypes[j];
       
  1070 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
  1071 					is_ANY_NUM_compatible(prev_instruction_type))
       
  1072 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
  1073 			else {
       
  1074 				symbol_c *result = widening_conversion(prev_instruction_type, operand_type, widen_DIV_table);
       
  1075 				if (result)
       
  1076 					symbol->candidate_datatypes.push_back(result);
       
  1077 			}
       
  1078 		}
       
  1079 	}
       
  1080 	if (debug) std::cout <<  "DIV [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1081 	prev_il_instruction = symbol;
       
  1082 	return NULL;
       
  1083 }
       
  1084 
       
  1085 void *fill_candidate_datatypes_c::visit(MOD_operator_c *symbol) {
       
  1086 	symbol_c *prev_instruction_type, *operand_type;
       
  1087 
       
  1088 	if (NULL == prev_il_instruction) return NULL;
       
  1089 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1090 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1091 			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
       
  1092 			operand_type = il_operand->candidate_datatypes[j];
       
  1093 			if (is_type_equal(prev_instruction_type, operand_type) &&
       
  1094 					is_ANY_INT_compatible(prev_instruction_type))
       
  1095 				symbol->candidate_datatypes.push_back(prev_instruction_type);
       
  1096 		}
       
  1097 	}
       
  1098 	if (debug) std::cout <<  "MOD [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1099 	prev_il_instruction = symbol;
       
  1100 	return NULL;
       
  1101 }
       
  1102 
       
  1103 void *fill_candidate_datatypes_c::visit(GT_operator_c *symbol) {
       
  1104 	bool found = false;
       
  1105 
       
  1106 	if (NULL == prev_il_instruction) return NULL;
       
  1107 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1108 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1109 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1110 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1111 				found = true;
       
  1112 				break;
       
  1113 			}
       
  1114 		}
       
  1115 	}
       
  1116 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1117 	prev_il_instruction = symbol;
       
  1118 	return NULL;
       
  1119 }
       
  1120 
       
  1121 void *fill_candidate_datatypes_c::visit(GE_operator_c *symbol) {
       
  1122 	bool found = false;
       
  1123 
       
  1124 	if (NULL == prev_il_instruction) return NULL;
       
  1125 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1126 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1127 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1128 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1129 				found = true;
       
  1130 				break;
       
  1131 			}
       
  1132 		}
       
  1133 	}
       
  1134 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1135 	prev_il_instruction = symbol;
       
  1136 	return NULL;
       
  1137 }
       
  1138 
       
  1139 void *fill_candidate_datatypes_c::visit(EQ_operator_c *symbol) {
       
  1140 	bool found = false;
       
  1141 
       
  1142 	if (NULL == prev_il_instruction) return NULL;
       
  1143 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1144 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1145 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1146 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1147 				found = true;
       
  1148 				break;
       
  1149 			}
       
  1150 		}
       
  1151 	}
       
  1152 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1153 	prev_il_instruction = symbol;
       
  1154 	return NULL;
       
  1155 }
       
  1156 
       
  1157 void *fill_candidate_datatypes_c::visit(LT_operator_c *symbol) {
       
  1158 	bool found = false;
       
  1159 
       
  1160 	if (NULL == prev_il_instruction) return NULL;
       
  1161 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1162 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1163 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1164 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1165 				found = true;
       
  1166 				break;
       
  1167 			}
       
  1168 		}
       
  1169 	}
       
  1170 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1171 	prev_il_instruction = symbol;
       
  1172 	return NULL;
       
  1173 }
       
  1174 
       
  1175 void *fill_candidate_datatypes_c::visit(LE_operator_c *symbol) {
       
  1176 	bool found = false;
       
  1177 
       
  1178 	if (NULL == prev_il_instruction) return NULL;
       
  1179 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1180 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1181 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1182 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1183 				found = true;
       
  1184 				break;
       
  1185 			}
       
  1186 		}
       
  1187 	}
       
  1188 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1189 	prev_il_instruction = symbol;
       
  1190 	return NULL;
       
  1191 }
       
  1192 
       
  1193 void *fill_candidate_datatypes_c::visit(NE_operator_c *symbol) {
       
  1194 	bool found = false;
       
  1195 
       
  1196 	if (NULL == prev_il_instruction) return NULL;
       
  1197 	for(unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1198 		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
       
  1199 			if (is_type_equal(prev_il_instruction->candidate_datatypes[i], il_operand->candidate_datatypes[j])
       
  1200 					&& is_ANY_ELEMENTARY_compatible(prev_il_instruction->candidate_datatypes[i])) {
       
  1201 				found = true;
       
  1202 				break;
       
  1203 			}
       
  1204 		}
       
  1205 	}
       
  1206 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1207 	prev_il_instruction = symbol;
       
  1208 	return NULL;
       
  1209 }
       
  1210 
       
  1211 void *fill_candidate_datatypes_c::visit(CAL_operator_c *symbol) {
       
  1212 	if (NULL == prev_il_instruction) return NULL;
       
  1213 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1214 	        /* does not need to be bool type !! */
       
  1215 		symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1216 	}
       
  1217 	if (debug) std::cout <<  "CAL [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1218 	prev_il_instruction = symbol;
       
  1219 	return NULL;
       
  1220 }
       
  1221 
       
  1222 void *fill_candidate_datatypes_c::visit(CALC_operator_c *symbol) {
       
  1223 	if (NULL == prev_il_instruction) return NULL;
       
  1224 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1225 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1226 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1227 	}
       
  1228 	if (debug) std::cout <<  "CALC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1229 	prev_il_instruction = symbol;
       
  1230 	return NULL;
       
  1231 }
       
  1232 
       
  1233 void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {
       
  1234 	if (NULL == prev_il_instruction) return NULL;
       
  1235 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1236 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1237 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1238 	}
       
  1239 	if (debug) std::cout <<  "CALCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1240 	prev_il_instruction = symbol;
       
  1241 	return NULL;
       
  1242 }
       
  1243 
       
  1244 void *fill_candidate_datatypes_c::visit(RET_operator_c *symbol) {
       
  1245 	if (NULL == prev_il_instruction) return NULL;
       
  1246 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1247 	        /* does not need to be bool type !! */
       
  1248 		symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1249 	}
       
  1250 	if (debug) std::cout <<  "RET [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1251 	prev_il_instruction = symbol;
       
  1252 	return NULL;
       
  1253 }
       
  1254 
       
  1255 void *fill_candidate_datatypes_c::visit(RETC_operator_c *symbol) {
       
  1256 	if (NULL == prev_il_instruction) return NULL;
       
  1257 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1258 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1259 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1260 	}
       
  1261 	if (debug) std::cout <<  "RETC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1262 	prev_il_instruction = symbol;
       
  1263 	return NULL;
       
  1264 }
       
  1265 
       
  1266 void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {
       
  1267 	if (NULL == prev_il_instruction) return NULL;
       
  1268 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1269 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1270 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1271 	}
       
  1272 	if (debug) std::cout <<  "RETCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1273 	prev_il_instruction = symbol;
       
  1274 	return NULL;
       
  1275 }
       
  1276 
       
  1277 void *fill_candidate_datatypes_c::visit(JMP_operator_c *symbol) {
       
  1278 	if (NULL == prev_il_instruction) return NULL;
       
  1279 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1280 	        /* does not need to be bool type !! */
       
  1281 		symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1282 	}
       
  1283 	if (debug) std::cout <<  "JMP [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1284 	prev_il_instruction = symbol;
       
  1285 	return NULL;
       
  1286 }
       
  1287 
       
  1288 void *fill_candidate_datatypes_c::visit(JMPC_operator_c *symbol) {
       
  1289 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1290 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1291 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1292 	}
       
  1293 	if (debug) std::cout <<  "JMPC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1294 	prev_il_instruction = symbol;
       
  1295 	return NULL;
       
  1296 }
       
  1297 
       
  1298 void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {
       
  1299 	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
       
  1300 		if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c))
       
  1301 			symbol->candidate_datatypes.push_back(prev_il_instruction->candidate_datatypes[i]);
       
  1302 	}
       
  1303 	if (debug) std::cout <<  "JMPCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1304 	prev_il_instruction = symbol;
       
  1305 	return NULL;
       
  1306 }
       
  1307 /* Symbol class handled together with function call checks */
       
  1308 // void *visit(il_assign_operator_c *symbol, variable_name);
       
  1309 /* Symbol class handled together with function call checks */
       
  1310 // void *visit(il_assign_operator_c *symbol, option, variable_name);
       
  1311 
       
  1312 /***************************************/
       
  1313 /* B.3 - Language ST (Structured Text) */
       
  1314 /***************************************/
       
  1315 /***********************/
       
  1316 /* B 3.1 - Expressions */
       
  1317 /***********************/
       
  1318 
       
  1319 void *fill_candidate_datatypes_c::visit(or_expression_c *symbol) {
       
  1320 	symbol->l_exp->accept(*this);
       
  1321 	symbol->r_exp->accept(*this);
       
  1322 	for (unsigned  int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1323 		for (unsigned  int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1324 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1325 					&& is_ANY_BIT_compatible(symbol->l_exp->candidate_datatypes[i]))
       
  1326 				symbol->candidate_datatypes.push_back(symbol->l_exp->candidate_datatypes[i]);
       
  1327 		}
       
  1328 	}
       
  1329 	return NULL;
       
  1330 }
       
  1331 
       
  1332 
       
  1333 void *fill_candidate_datatypes_c::visit(xor_expression_c *symbol) {
       
  1334 	symbol->l_exp->accept(*this);
       
  1335 	symbol->r_exp->accept(*this);
       
  1336 
       
  1337 	for (unsigned  int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1338 		for (unsigned  int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1339 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1340 					&& is_ANY_BIT_compatible(symbol->l_exp->candidate_datatypes[i]))
       
  1341 				symbol->candidate_datatypes.push_back(symbol->l_exp->candidate_datatypes[i]);
       
  1342 		}
       
  1343 	}
       
  1344 	return NULL;
       
  1345 }
       
  1346 
       
  1347 
       
  1348 void *fill_candidate_datatypes_c::visit(and_expression_c *symbol) {
       
  1349 	symbol->l_exp->accept(*this);
       
  1350 	symbol->r_exp->accept(*this);
       
  1351 
       
  1352 	for (unsigned  int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1353 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1354 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1355 					&& is_ANY_BIT_compatible(symbol->l_exp->candidate_datatypes[i]))
       
  1356 				symbol->candidate_datatypes.push_back(symbol->l_exp->candidate_datatypes[i]);
       
  1357 		}
       
  1358 	}
       
  1359 	return NULL;
       
  1360 }
       
  1361 
       
  1362 
       
  1363 void *fill_candidate_datatypes_c::visit(equ_expression_c *symbol) {
       
  1364 	symbol->l_exp->accept(*this);
       
  1365 	symbol->r_exp->accept(*this);
       
  1366 	bool found = false;
       
  1367 
       
  1368 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1369 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1370 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1371 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1372 				found = true;
       
  1373 				break;
       
  1374 			}
       
  1375 		}
       
  1376 	}
       
  1377 	if (found) symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1378 	return NULL;
       
  1379 }
       
  1380 
       
  1381 
       
  1382 void *fill_candidate_datatypes_c::visit(notequ_expression_c *symbol)  {
       
  1383 	symbol->l_exp->accept(*this);
       
  1384 	symbol->r_exp->accept(*this);
       
  1385 	bool found = false;
       
  1386 
       
  1387 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1388 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1389 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1390 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1391 				found = true;
       
  1392 				break;
       
  1393 			}
       
  1394 		}
       
  1395 	}
       
  1396 	if (found)
       
  1397 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1398 	return NULL;
       
  1399 }
       
  1400 
       
  1401 
       
  1402 void *fill_candidate_datatypes_c::visit(lt_expression_c *symbol) {
       
  1403 	symbol->l_exp->accept(*this);
       
  1404 	symbol->r_exp->accept(*this);
       
  1405 	bool found = false;
       
  1406 
       
  1407 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1408 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1409 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1410 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1411 				found = true;
       
  1412 				break;
       
  1413 			}
       
  1414 		}
       
  1415 	}
       
  1416 	if (found)
       
  1417 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1418 	return NULL;
       
  1419 }
       
  1420 
       
  1421 
       
  1422 void *fill_candidate_datatypes_c::visit(gt_expression_c *symbol) {
       
  1423 	symbol->l_exp->accept(*this);
       
  1424 	symbol->r_exp->accept(*this);
       
  1425 	bool found = false;
       
  1426 
       
  1427 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1428 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1429 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1430 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1431 				found = true;
       
  1432 				break;
       
  1433 			}
       
  1434 		}
       
  1435 	}
       
  1436 	if (found)
       
  1437 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1438 	return NULL;
       
  1439 }
       
  1440 
       
  1441 void *fill_candidate_datatypes_c::visit(le_expression_c *symbol) {
       
  1442 	symbol->l_exp->accept(*this);
       
  1443 	symbol->r_exp->accept(*this);
       
  1444 	bool found = false;
       
  1445 
       
  1446 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1447 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1448 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1449 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1450 				found = true;
       
  1451 				break;
       
  1452 			}
       
  1453 		}
       
  1454 	}
       
  1455 	if (found)
       
  1456 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1457 	return NULL;
       
  1458 }
       
  1459 
       
  1460 void *fill_candidate_datatypes_c::visit(ge_expression_c *symbol) {
       
  1461 	symbol->l_exp->accept(*this);
       
  1462 	symbol->r_exp->accept(*this);
       
  1463 	bool found = false;
       
  1464 
       
  1465 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1466 		for (unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1467 			if (is_type_equal(symbol->l_exp->candidate_datatypes[i], symbol->r_exp->candidate_datatypes[j])
       
  1468 					&& is_ANY_ELEMENTARY_compatible(symbol->l_exp->candidate_datatypes[i])) {
       
  1469 				found = true;
       
  1470 				break;
       
  1471 			}
       
  1472 		}
       
  1473 	}
       
  1474 	if (found)
       
  1475 		symbol->candidate_datatypes.push_back(&search_constant_type_c::bool_type_name);
       
  1476 	return NULL;
       
  1477 }
       
  1478 
       
  1479 void *fill_candidate_datatypes_c::visit(add_expression_c *symbol) {
       
  1480 	/* The following code is correct when handling the addition of 2 symbolic_variables
       
  1481 	 * In this case, adding two variables (e.g. USINT_var1 + USINT_var2) will always yield
       
  1482 	 * the same data type, even if the result of the adition could not fit inside the same
       
  1483 	 * data type (due to overflowing)
       
  1484 	 *
       
  1485 	 * However, when adding two literals (e.g. USINT#42 + USINT#3)
       
  1486 	 * we should be able to detect overflows of the result, and therefore not consider
       
  1487 	 * that the result may be of type USINT.
       
  1488 	 * Currently we do not yet detect these overflows, and allow handling the sum of two USINTs
       
  1489 	 * as always resulting in an USINT, even in the following expression
       
  1490 	 * (USINT#65535 + USINT#2).
       
  1491 	 *
       
  1492 	 * In the future we can add some code to reduce
       
  1493 	 * all the expressions that are based on literals into the resulting literal
       
  1494 	 * value (maybe some visitor class that will run before or after data type
       
  1495 	 * checking). Since this class will have to be very careful to make sure it implements the same mathematical
       
  1496 	 * details (e.g. how to round and truncate numbers) as defined in IEC 61131-3, we will leave this to the future.
       
  1497 	 * Also, the question will arise if we should also replace calls to standard
       
  1498 	 * functions if the input parameters are all literals (e.g. ADD(42, 42)). This
       
  1499 	 * means this class will be more difficult than it appears at first.
       
  1500 	 */
       
  1501 	symbol_c *left_type, *right_type;
       
  1502 
       
  1503 	symbol->l_exp->accept(*this);
       
  1504 	symbol->r_exp->accept(*this);
       
  1505 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1506 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1507 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1508 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1509 			if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
       
  1510 				symbol->candidate_datatypes.push_back(left_type);
       
  1511 			else {
       
  1512 				symbol_c *result = widening_conversion(left_type, right_type, widen_ADD_table);
       
  1513 				if (result)
       
  1514 					symbol->candidate_datatypes.push_back(result);
       
  1515 			}
       
  1516 		}
       
  1517 	}
       
  1518 	if (debug) std::cout <<  "+ [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1519 	return NULL;
       
  1520 }
       
  1521 
       
  1522 
       
  1523 void *fill_candidate_datatypes_c::visit(sub_expression_c *symbol) {
       
  1524 	symbol_c *left_type, *right_type;
       
  1525 
       
  1526 	symbol->l_exp->accept(*this);
       
  1527 	symbol->r_exp->accept(*this);
       
  1528 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1529 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1530 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1531 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1532 			if (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
       
  1533 				symbol->candidate_datatypes.push_back(left_type);
       
  1534 			else {
       
  1535 				symbol_c *result = widening_conversion(left_type, right_type, widen_SUB_table);
       
  1536 				if (result)
       
  1537 					symbol->candidate_datatypes.push_back(result);
       
  1538 			}
       
  1539 		}
       
  1540 	}
       
  1541 	if (debug) std::cout <<  "- [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1542 	return NULL;
       
  1543 }
       
  1544 
       
  1545 
       
  1546 void *fill_candidate_datatypes_c::visit(mul_expression_c *symbol) {
       
  1547 	symbol_c *left_type, *right_type;
       
  1548 
       
  1549 	symbol->l_exp->accept(*this);
       
  1550 	symbol->r_exp->accept(*this);
       
  1551 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1552 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1553 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1554 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1555 			if      (is_type_equal(left_type, right_type) && is_ANY_NUM_compatible(left_type))
       
  1556 				symbol->candidate_datatypes.push_back(left_type);
       
  1557 			else {
       
  1558 				symbol_c *result = widening_conversion(left_type, right_type, widen_MUL_table);
       
  1559 				if (result)
       
  1560 					symbol->candidate_datatypes.push_back(result);
       
  1561 			}
       
  1562 
       
  1563 		}
       
  1564 	}
       
  1565 	if (debug) std::cout << "* [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1566 
       
  1567 	return NULL;
       
  1568 }
       
  1569 
       
  1570 void *fill_candidate_datatypes_c::visit(div_expression_c *symbol) {
       
  1571 	symbol_c *left_type, *right_type;
       
  1572 
       
  1573 	symbol->l_exp->accept(*this);
       
  1574 	symbol->r_exp->accept(*this);
       
  1575 	for(unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1576 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1577 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1578 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1579 			if      (is_type_equal(left_type, right_type) && is_ANY_NUM_type(left_type))
       
  1580 				symbol->candidate_datatypes.push_back(left_type);
       
  1581 			else {
       
  1582 				symbol_c *result = widening_conversion(left_type, right_type, widen_DIV_table);
       
  1583 				if (result)
       
  1584 					symbol->candidate_datatypes.push_back(result);
       
  1585 			}
       
  1586 
       
  1587 		}
       
  1588 	}
       
  1589 	if (debug) std::cout << "/ [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1590 	return NULL;
       
  1591 }
       
  1592 
       
  1593 
       
  1594 void *fill_candidate_datatypes_c::visit(mod_expression_c *symbol) {
       
  1595 	symbol_c *left_type, *right_type;
       
  1596 
       
  1597 	symbol->l_exp->accept(*this);
       
  1598 	symbol->r_exp->accept(*this);
       
  1599 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1600 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1601 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1602 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1603 			if (is_type_equal(left_type, right_type) && is_ANY_INT_compatible(left_type))
       
  1604 				symbol->candidate_datatypes.push_back(left_type);
       
  1605 		}
       
  1606 	}
       
  1607 	if (debug) std::cout << "mod [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1608 	return NULL;
       
  1609 }
       
  1610 
       
  1611 
       
  1612 void *fill_candidate_datatypes_c::visit(power_expression_c *symbol) {
       
  1613 	symbol_c *left_type, *right_type;
       
  1614 	bool check_ok;
       
  1615 
       
  1616 	symbol->l_exp->accept(*this);
       
  1617 	symbol->r_exp->accept(*this);
       
  1618 	check_ok = false;
       
  1619 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1620 		left_type = symbol->l_exp->candidate_datatypes[i];
       
  1621 		if (is_ANY_REAL_compatible(left_type)) {
       
  1622 			check_ok = true;
       
  1623 			break;
       
  1624 		}
       
  1625 	}
       
  1626 	if (! check_ok) return NULL;
       
  1627 	check_ok = false;
       
  1628 	for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1629 		right_type = symbol->r_exp->candidate_datatypes[j];
       
  1630 		if (is_ANY_NUM_compatible(right_type)) {
       
  1631 			check_ok = true;
       
  1632 			break;
       
  1633 		}
       
  1634 	}
       
  1635 	if (! check_ok) return NULL;
       
  1636 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1637 		symbol->candidate_datatypes.push_back(symbol->l_exp->candidate_datatypes[i]);
       
  1638 	}
       
  1639 	if (debug) std::cout << "** [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1640 	return NULL;
       
  1641 }
       
  1642 
       
  1643 
       
  1644 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) {
       
  1645 	symbol->exp->accept(*this);
       
  1646 	for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) {
       
  1647 		if (is_ANY_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i]))
       
  1648 			symbol->candidate_datatypes.push_back(symbol->exp->candidate_datatypes[i]);
       
  1649 	}
       
  1650 	if (debug) std::cout << "neg [" << symbol->exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1651 	return NULL;
       
  1652 }
       
  1653 
       
  1654 
       
  1655 void *fill_candidate_datatypes_c::visit(not_expression_c *symbol) {
       
  1656 	symbol->exp->accept(*this);
       
  1657 	for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) {
       
  1658 		if      (is_ANY_BIT_compatible(symbol->exp->candidate_datatypes[i]))
       
  1659 			symbol->candidate_datatypes.push_back(symbol->exp->candidate_datatypes[i]);
       
  1660 	}
       
  1661 	if (debug) std::cout << "not [" << symbol->exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1662 	return NULL;
       
  1663 }
       
  1664 
       
  1665 
       
  1666 void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {
       
  1667 	function_declaration_c *f_decl;
       
  1668 	list_c *parameter_list;
       
  1669 	list_c *parameter_candidate_datatypes;
       
  1670 	symbol_c *parameter_type;
       
  1671 	int error_count;
       
  1672 	function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
       
  1673 	function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
       
  1674 
       
  1675 	if (NULL != symbol->formal_param_list)
       
  1676 		parameter_list = (list_c *)symbol->formal_param_list;
       
  1677 	else if (NULL != symbol->nonformal_param_list)
       
  1678 		parameter_list = (list_c *)symbol->nonformal_param_list;
       
  1679 	else ERROR;
       
  1680 	if (debug) std::cout << "function()\n";
       
  1681 	parameter_list->accept(*this);
       
  1682 	for(; lower != upper; lower++) {
       
  1683 		f_decl = function_symtable.get_value(lower);
       
  1684 		error_count = 0;
       
  1685 		/* Check if function declaration in symbol_table is compatible with parameters */
       
  1686 		if (NULL != symbol->nonformal_param_list)
       
  1687 			/* nonformal parameter function call */
       
  1688 			match_nonformal_call(symbol, f_decl, &error_count);
       
  1689 		else
       
  1690 			/* formal parameter function call */
       
  1691 			match_formal_call (symbol, f_decl, &error_count);
       
  1692 		if (0 == error_count) {
       
  1693 			/* Add basetype matching function only if not present */
       
  1694 			unsigned int k;
       
  1695 			parameter_type = base_type(f_decl->type_name);
       
  1696 			for(k = 0; k < symbol->candidate_datatypes.size(); k++) {
       
  1697 				if (is_type_equal(parameter_type, symbol->candidate_datatypes[k]))
       
  1698 					break;
       
  1699 			}
       
  1700 			if (k >= symbol->candidate_datatypes.size())
       
  1701 				symbol->candidate_datatypes.push_back(parameter_type);
       
  1702 		}
       
  1703 	}
       
  1704 	if (debug) std::cout << "end_function() [" << symbol->candidate_datatypes.size() << "] result.\n";
       
  1705 	return NULL;
       
  1706 }
       
  1707 
       
  1708 /********************/
       
  1709 /* B 3.2 Statements */
       
  1710 /********************/
       
  1711 // SYM_LIST(statement_list_c)
       
  1712 /* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
       
  1713  * We do not need to do anything here...
       
  1714  */
       
  1715 // void *fill_candidate_datatypes_c::visit(statement_list_c *symbol)
       
  1716 
       
  1717 
       
  1718 /*********************************/
       
  1719 /* B 3.2.1 Assignment Statements */
       
  1720 /*********************************/
       
  1721 void *fill_candidate_datatypes_c::visit(assignment_statement_c *symbol) {
       
  1722 	symbol_c *left_type, *right_type;
       
  1723 
       
  1724 	symbol->l_exp->accept(*this);
       
  1725 	symbol->r_exp->accept(*this);
       
  1726 	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
       
  1727 		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
       
  1728 			left_type = symbol->l_exp->candidate_datatypes[i];
       
  1729 			right_type = symbol->r_exp->candidate_datatypes[j];
       
  1730 			if (is_type_equal(left_type, right_type))
       
  1731 				symbol->candidate_datatypes.push_back(left_type);
       
  1732 		}
       
  1733 	}
       
  1734 	if (debug) std::cout << ":= [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
       
  1735 	return NULL;
       
  1736 }
       
  1737 
       
  1738 
       
  1739 
       
  1740 /********************************/
       
  1741 /* B 3.2.3 Selection Statements */
       
  1742 /********************************/
       
  1743 void *fill_candidate_datatypes_c::visit(if_statement_c *symbol) {
       
  1744 	/* MANU:
       
  1745 	 * IF statement accept only BOOL type. We intersect with BOOL type to validate current if condition
       
  1746 	 * Example:
       
  1747 	 * IF 1 THEN 		---> 	 ok
       
  1748 	 * IF 5 THEN 		---> not ok
       
  1749 	 * IF 1 OR 1 THEN	--->     ok
       
  1750 	 * IF 1 OR 5 THEN   ---> not ok
       
  1751 	 * IF SHL() THEN	---> 	 ok if shl return BOOL
       
  1752 	 * IF INT_TO_REAL() ---> not ok
       
  1753 	 */
       
  1754 	symbol->expression->accept(*this);
       
  1755 	if (NULL != symbol->statement_list)
       
  1756 		symbol->statement_list->accept(*this);
       
  1757 	if (NULL != symbol->elseif_statement_list)
       
  1758 		symbol->elseif_statement_list->accept(*this);
       
  1759 	if (NULL != symbol->else_statement_list)
       
  1760 		symbol->else_statement_list->accept(*this);
       
  1761 	return NULL;
       
  1762 }
       
  1763 
       
  1764 
       
  1765 void *fill_candidate_datatypes_c::visit(elseif_statement_c *symbol) {
       
  1766 	symbol->expression->accept(*this);
       
  1767 	if (NULL != symbol->statement_list)
       
  1768 		symbol->statement_list->accept(*this);
       
  1769 	return NULL;
       
  1770 }
       
  1771 
       
  1772 /* CASE expression OF case_element_list ELSE statement_list END_CASE */
       
  1773 // SYM_REF3(case_statement_c, expression, case_element_list, statement_list)
       
  1774 void *fill_candidate_datatypes_c::visit(case_statement_c *symbol) {
       
  1775 	symbol->expression->accept(*this);
       
  1776 	if (NULL != symbol->case_element_list)
       
  1777 		symbol->case_element_list->accept(*this);
       
  1778 	if (NULL != symbol->statement_list)
       
  1779 		symbol->statement_list->accept(*this);
       
  1780 	return NULL;
       
  1781 }
       
  1782 
       
  1783 
       
  1784 /* helper symbol for case_statement */
       
  1785 // SYM_LIST(case_element_list_c)
       
  1786 /* NOTE: visitor method for case_element_list_c is not required since we inherit from iterator_visitor_c */
       
  1787 
       
  1788 /*  case_list ':' statement_list */
       
  1789 // SYM_REF2(case_element_c, case_list, statement_list)
       
  1790 /* NOTE: visitor method for case_element_c is not required since we inherit from iterator_visitor_c */
       
  1791 
       
  1792 // SYM_LIST(case_list_c)
       
  1793 /* NOTE: visitor method for case_list_c is not required since we inherit from iterator_visitor_c */
       
  1794 
       
  1795 /********************************/
       
  1796 /* B 3.2.4 Iteration Statements */
       
  1797 /********************************/
       
  1798 
       
  1799 void *fill_candidate_datatypes_c::visit(for_statement_c *symbol) {
       
  1800 	symbol->control_variable->accept(*this);
       
  1801 	symbol->beg_expression->accept(*this);
       
  1802 	symbol->end_expression->accept(*this);
       
  1803 	if (NULL != symbol->by_expression)
       
  1804 		symbol->by_expression->accept(*this);
       
  1805 	if (NULL != symbol->statement_list)
       
  1806 		symbol->statement_list->accept(*this);
       
  1807 	return NULL;
       
  1808 }
       
  1809 
       
  1810 
       
  1811 void *fill_candidate_datatypes_c::visit(while_statement_c *symbol) {
       
  1812 	symbol->expression->accept(*this);
       
  1813 	if (NULL != symbol->statement_list)
       
  1814 		symbol->statement_list->accept(*this);
       
  1815 	return NULL;
       
  1816 }
       
  1817 
       
  1818 
       
  1819 void *fill_candidate_datatypes_c::visit(repeat_statement_c *symbol) {
       
  1820 	symbol->expression->accept(*this);
       
  1821 	if (NULL != symbol->statement_list)
       
  1822 		symbol->statement_list->accept(*this);
       
  1823 	return NULL;
       
  1824 }
       
  1825 
       
  1826 
       
  1827 
       
  1828 
       
  1829 
       
  1830