stage3/fill_candidate_datatypes.cc
changeset 488 c833f83aac8c
parent 487 1619b2fe03e1
child 489 2c874cccbb44
equal deleted inserted replaced
487:1619b2fe03e1 488:c833f83aac8c
   360 /* B 1.2.1 - Numeric Literals */
   360 /* B 1.2.1 - Numeric Literals */
   361 /******************************/
   361 /******************************/
   362 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
   362 #define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
   363 
   363 
   364 void *fill_candidate_datatypes_c::handle_any_integer(symbol_c *symbol) {
   364 void *fill_candidate_datatypes_c::handle_any_integer(symbol_c *symbol) {
   365 	int calc_size;
   365 	int calc_size = sizeoftype(symbol);
   366 
   366 
   367 	calc_size = sizeoftype(symbol);
       
   368 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
   367 	if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name))
   369 	        add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
   368 	        add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
   370 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
   369 	if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name))
   371 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::byte_type_name, &search_constant_type_c::safebyte_type_name);
   370 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::byte_type_name, &search_constant_type_c::safebyte_type_name);
   372 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
   371 	if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name))
   397 	return NULL;
   396 	return NULL;
   398 }
   397 }
   399 
   398 
   400 
   399 
   401 
   400 
   402 
   401 void *fill_candidate_datatypes_c::handle_any_real(symbol_c *symbol) {
   403 void *fill_candidate_datatypes_c::visit(real_c *symbol) {
   402 	int calc_size = sizeoftype(symbol);
   404 	int calc_size;
   403 
   405 
       
   406 	calc_size = sizeoftype(symbol);
       
   407 	if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name))
   404 	if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name))
   408 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name,  &search_constant_type_c::safereal_type_name);
   405 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name,  &search_constant_type_c::safereal_type_name);
   409 	if (calc_size <= sizeoftype(&search_constant_type_c::lreal_type_name))
   406 	if (calc_size <= sizeoftype(&search_constant_type_c::lreal_type_name))
   410 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name);
   407 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name);
   411 	if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
   408 	if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
   412 	return NULL;
   409 	return NULL;
   413 }
   410 }
   414 
   411 
   415 
   412 
   416 void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {
   413 
   417 	int calc_size;
   414 void *fill_candidate_datatypes_c::handle_any_literal(symbol_c *symbol, symbol_c *symbol_value, symbol_c *symbol_type) {
   418 
   415 	symbol_value->accept(*this);
   419 	calc_size = sizeoftype(symbol);
   416 	if (search_in_candidate_datatype_list(symbol_type, symbol_value->candidate_datatypes) >= 0)
   420 	if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name))
   417 		add_datatype_to_candidate_list(symbol, symbol_type);
   421 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name, &search_constant_type_c::safereal_type_name);
   418 	if (debug) std::cout << "XXX_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
   422 	if (calc_size <= sizeoftype(&search_constant_type_c::lreal_type_name))
   419 	return NULL;
   423 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name);
   420 }
   424 	if (debug) std::cout << "neg ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
   421 
   425 	return NULL;
   422 
   426 }
   423 
       
   424 void *fill_candidate_datatypes_c::visit(    real_c *symbol) {return handle_any_real(symbol);}
       
   425 void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {return handle_any_real(symbol);}
       
   426 
   427 
   427 
   428 
   428 
   429 void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) {
   429 void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) {
   430 	int calc_size;
   430 	int calc_size = sizeoftype(symbol);
   431 
   431 
   432 	calc_size = sizeoftype(symbol);
       
   433 	if (calc_size <= sizeoftype(&search_constant_type_c::int_type_name))
   432 	if (calc_size <= sizeoftype(&search_constant_type_c::int_type_name))
   434 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name);
   433 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name);
   435 	if (calc_size <= sizeoftype(&search_constant_type_c::sint_type_name))
   434 	if (calc_size <= sizeoftype(&search_constant_type_c::sint_type_name))
   436 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name);
   435 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name);
   437 	if (calc_size <= sizeoftype(&search_constant_type_c::dint_type_name))
   436 	if (calc_size <= sizeoftype(&search_constant_type_c::dint_type_name))
   441 	if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl;
   440 	if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl;
   442 	return NULL;
   441 	return NULL;
   443 }
   442 }
   444 
   443 
   445 
   444 
       
   445 
   446 void *fill_candidate_datatypes_c::visit(integer_c        *symbol) {return handle_any_integer(symbol);}
   446 void *fill_candidate_datatypes_c::visit(integer_c        *symbol) {return handle_any_integer(symbol);}
   447 void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) {return handle_any_integer(symbol);}
   447 void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) {return handle_any_integer(symbol);}
   448 void *fill_candidate_datatypes_c::visit(octal_integer_c  *symbol) {return handle_any_integer(symbol);}
   448 void *fill_candidate_datatypes_c::visit(octal_integer_c  *symbol) {return handle_any_integer(symbol);}
   449 void *fill_candidate_datatypes_c::visit(hex_integer_c    *symbol) {return handle_any_integer(symbol);}
   449 void *fill_candidate_datatypes_c::visit(hex_integer_c    *symbol) {return handle_any_integer(symbol);}
       
   450 
   450 
   451 
   451 
   452 
   452 // SYM_REF2(integer_literal_c, type, value)
   453 // SYM_REF2(integer_literal_c, type, value)
   453 /*
   454 /*
   454  * integer_literal:
   455  * integer_literal:
   455  *   integer_type_name '#' signed_integer
   456  *   integer_type_name '#' signed_integer
   456  * | integer_type_name '#' binary_integer
   457  * | integer_type_name '#' binary_integer
   457  * | integer_type_name '#' octal_integer
   458  * | integer_type_name '#' octal_integer
   458  * | integer_type_name '#' hex_integer
   459  * | integer_type_name '#' hex_integer
   459  */
   460  */
   460 void *fill_candidate_datatypes_c::visit(integer_literal_c *symbol) {
   461 void *fill_candidate_datatypes_c::visit(   integer_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
       
   462 void *fill_candidate_datatypes_c::visit(      real_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
       
   463 void *fill_candidate_datatypes_c::visit(bit_string_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
       
   464 
       
   465 void *fill_candidate_datatypes_c::visit(   boolean_literal_c *symbol) {
       
   466 	if (NULL != symbol->type) return handle_any_literal(symbol, symbol->value, symbol->type);
       
   467 
   461 	symbol->value->accept(*this);
   468 	symbol->value->accept(*this);
   462 	if (search_in_candidate_datatype_list(symbol->type, symbol->value->candidate_datatypes) >= 0)
   469 	symbol->candidate_datatypes = symbol->value->candidate_datatypes;
   463 		add_datatype_to_candidate_list(symbol, symbol->type);
   470 	return NULL;
   464 	if (debug) std::cout << "INT_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
   471 }
   465 	return NULL;
   472 
   466 }
       
   467 
       
   468 void *fill_candidate_datatypes_c::visit(real_literal_c *symbol) {
       
   469 	symbol->value->accept(*this);
       
   470 	if (search_in_candidate_datatype_list(symbol->type, symbol->value->candidate_datatypes) >= 0)
       
   471 		add_datatype_to_candidate_list(symbol, symbol->type);
       
   472 	if (debug) std::cout << "REAL_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
       
   473 	return NULL;
       
   474 }
       
   475 
       
   476 void *fill_candidate_datatypes_c::visit(bit_string_literal_c *symbol) {
       
   477 	symbol->value->accept(*this);
       
   478 	if (search_in_candidate_datatype_list(symbol->type, symbol->value->candidate_datatypes) >= 0)
       
   479 		add_datatype_to_candidate_list(symbol, symbol->type);
       
   480 	return NULL;
       
   481 }
       
   482 
       
   483 void *fill_candidate_datatypes_c::visit(boolean_literal_c *symbol) {
       
   484  	symbol->value->accept(*this);
       
   485  	if (search_in_candidate_datatype_list(symbol->type, symbol->value->candidate_datatypes) >= 0)
       
   486 		/* if an explicit datat type has been provided (e.g. SAFEBOOL#true), check whether
       
   487 		 * the possible datatypes of the value is consistent with the desired type.
       
   488 		 */
       
   489 		add_datatype_to_candidate_list(symbol, symbol->type);
       
   490 	else {
       
   491 		/* Then only a literal TRUE or FALSE was given! */
       
   492 		/* In this case, symbol->type will be NULL!     */
       
   493 		add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
       
   494 	}
       
   495 	return NULL;
       
   496 }
       
   497 
   473 
   498 void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) {
   474 void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) {
   499 	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
   475 	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
   500 	return NULL;
   476 	return NULL;
   501 }
   477 }