# HG changeset patch # User Mario de Sousa # Date 1331378501 0 # Node ID d26759a2274a22840e1b61ace798f23e59faac40 # Parent da650a87662db725f291ef252e679b73144202fe Clean up code, and add support for 'safe' version of literals. diff -r da650a87662d -r d26759a2274a stage3/datatype_functions.hh --- a/stage3/datatype_functions.hh Sat Mar 10 11:21:04 2012 +0000 +++ b/stage3/datatype_functions.hh Sat Mar 10 11:21:41 2012 +0000 @@ -30,10 +30,6 @@ -#define is_type(type_name_symbol, type_name_class) ((type_name_symbol == NULL) ? false : (typeid(*type_name_symbol) == typeid(type_name_class))) -#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol) - - typedef struct { diff -r da650a87662d -r d26759a2274a stage3/fill_candidate_datatypes.cc --- a/stage3/fill_candidate_datatypes.cc Sat Mar 10 11:21:04 2012 +0000 +++ b/stage3/fill_candidate_datatypes.cc Sat Mar 10 11:21:41 2012 +0000 @@ -76,7 +76,11 @@ } - +bool fill_candidate_datatypes_c::add_2datatypes_to_candidate_list(symbol_c *symbol, symbol_c *datatype1, symbol_c *datatype2) { + add_datatype_to_candidate_list(symbol, datatype1); + add_datatype_to_candidate_list(symbol, datatype2); + return true; +} /* returns true if compatible function/FB invocation, otherwise returns false */ @@ -322,183 +326,127 @@ /******************************/ /* B 1.2.1 - Numeric Literals */ /******************************/ +#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol) + +void *fill_candidate_datatypes_c::handle_any_integer(symbol_c *symbol) { + int calc_size; + + calc_size = sizeoftype(symbol); + if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::byte_type_name, &search_constant_type_c::safebyte_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::word_type_name, &search_constant_type_c::safeword_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dword_type_name, &search_constant_type_c::safedword_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lword_type_name, &search_constant_type_c::safelword_type_name); + + if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name); + if (calc_size < sizeoftype(&search_constant_type_c::int_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name); + if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name, &search_constant_type_c::safedint_type_name); + if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name, &search_constant_type_c::safelint_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::usint_type_name, &search_constant_type_c::safeusint_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::uint_type_name, &search_constant_type_c::safeuint_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::udint_type_name, &search_constant_type_c::safeudint_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name, &search_constant_type_c::safeulint_type_name); + return NULL; +} + + + + void *fill_candidate_datatypes_c::visit(real_c *symbol) { int calc_size; calc_size = sizeoftype(symbol); if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::real_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name, &search_constant_type_c::safereal_type_name); if (calc_size <= sizeoftype(&search_constant_type_c::lreal_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name); if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl; return NULL; } + + void *fill_candidate_datatypes_c::visit(integer_c *symbol) { + handle_any_integer(symbol); + if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; + return NULL; +} + + +void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) { int calc_size; calc_size = sizeoftype(symbol); - if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); - - if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::int_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::usint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::uint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::udint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name); - if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; - return NULL; -} - -void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) { - if (sizeoftype(symbol) <= sizeoftype(&search_constant_type_c::real_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::real_type_name); - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::real_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name, &search_constant_type_c::safereal_type_name); + if (calc_size <= sizeoftype(&search_constant_type_c::lreal_type_name)) + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name); if (debug) std::cout << "neg ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl; return NULL; } + void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) { int calc_size; calc_size = sizeoftype(symbol); if (calc_size <= sizeoftype(&search_constant_type_c::int_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name); if (calc_size <= sizeoftype(&search_constant_type_c::sint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name); if (calc_size <= sizeoftype(&search_constant_type_c::dint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name, &search_constant_type_c::safedint_type_name); if (calc_size <= sizeoftype(&search_constant_type_c::lint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name, &search_constant_type_c::safelint_type_name); if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl; return NULL; } + void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) { - int calc_size; - - calc_size = sizeoftype(symbol); - if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); - - if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::int_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::usint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::uint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::udint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name); + handle_any_integer(symbol); if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; return NULL; } + + void *fill_candidate_datatypes_c::visit(octal_integer_c *symbol) { - int calc_size; - - calc_size = sizeoftype(symbol); - if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); - - if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::int_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::usint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::uint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::udint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name); + handle_any_integer(symbol); if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; return NULL; } + + void *fill_candidate_datatypes_c::visit(hex_integer_c *symbol) { - int calc_size; - - calc_size = sizeoftype(symbol); - if (calc_size <= sizeoftype(&search_constant_type_c::bool_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::byte_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::word_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::dword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::lword_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); - - if (calc_size < sizeoftype(&search_constant_type_c::sint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::int_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::dint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name); - if (calc_size < sizeoftype(&search_constant_type_c::lint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::usint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::usint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::uint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::uint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::udint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::udint_type_name); - if (calc_size <= sizeoftype(&search_constant_type_c::ulint_type_name)) - add_datatype_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name); + handle_any_integer(symbol); if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl; return NULL; } + // SYM_REF2(integer_literal_c, type, value) +/* + * integer_literal: + * integer_type_name '#' signed_integer + * | integer_type_name '#' binary_integer + * | integer_type_name '#' octal_integer + * | integer_type_name '#' hex_integer + */ void *fill_candidate_datatypes_c::visit(integer_literal_c *symbol) { symbol->value->accept(*this); if (search_in_candidate_datatype_list(symbol->type, symbol->value->candidate_datatypes) >= 0) @@ -532,21 +480,18 @@ else { /* Then only a literal TRUE or FALSE was given! */ /* In this case, symbol->type will be NULL! */ - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - add_datatype_to_candidate_list(symbol, &search_constant_type_c::safebool_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name); } return NULL; } void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) { - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - add_datatype_to_candidate_list(symbol, &search_constant_type_c::safebool_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name); return NULL; } void *fill_candidate_datatypes_c::visit(boolean_false_c *symbol) { - add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name); - add_datatype_to_candidate_list(symbol, &search_constant_type_c::safebool_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name); return NULL; } @@ -554,12 +499,12 @@ /* B.1.2.2 Character Strings */ /*******************************/ void *fill_candidate_datatypes_c::visit(double_byte_character_string_c *symbol) { - add_datatype_to_candidate_list(symbol, &search_constant_type_c::wstring_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::wstring_type_name, &search_constant_type_c::safewstring_type_name); return NULL; } void *fill_candidate_datatypes_c::visit(single_byte_character_string_c *symbol) { - add_datatype_to_candidate_list(symbol, &search_constant_type_c::string_type_name); + add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::string_type_name, &search_constant_type_c::safestring_type_name); return NULL; } @@ -572,9 +517,7 @@ void *fill_candidate_datatypes_c::visit(duration_c *symbol) { /* TODO: check whether the literal follows the rules specified in section '2.2.3.1 Duration' of the standard! */ - /* Either of the following two lines is correct. Each of them will have advantages and drawbacks during compiler debugging. Use whichever suits you best... */ - add_datatype_to_candidate_list(symbol, &search_constant_type_c::time_type_name); -// symbol->candidate_datatypes.push_back(symbol->type_name); + add_datatype_to_candidate_list(symbol, symbol->type_name); if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n"; return NULL; } @@ -1537,7 +1480,7 @@ void *fill_candidate_datatypes_c::visit(CALC_operator_c *symbol) { if (NULL == prev_il_instruction) return NULL; for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "CALC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1547,7 +1490,7 @@ void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) { if (NULL == prev_il_instruction) return NULL; for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "CALCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1567,7 +1510,7 @@ void *fill_candidate_datatypes_c::visit(RETC_operator_c *symbol) { if (NULL == prev_il_instruction) return NULL; for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "RETC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1577,7 +1520,7 @@ void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) { if (NULL == prev_il_instruction) return NULL; for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "RETCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1596,7 +1539,7 @@ void *fill_candidate_datatypes_c::visit(JMPC_operator_c *symbol) { for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "JMPC [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; @@ -1605,7 +1548,7 @@ void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) { for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) { - if (is_type(prev_il_instruction->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(prev_il_instruction->candidate_datatypes[i])) add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]); } if (debug) std::cout << "JMPCN [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; diff -r da650a87662d -r d26759a2274a stage3/fill_candidate_datatypes.hh --- a/stage3/fill_candidate_datatypes.hh Sat Mar 10 11:21:04 2012 +0000 +++ b/stage3/fill_candidate_datatypes.hh Sat Mar 10 11:21:41 2012 +0000 @@ -93,7 +93,8 @@ /* add a data type to a candidate data type list, while guaranteeing no duplicate entries! */ /* Returns true if it really did add the datatype to the list, or false if it was already present in the list! */ - bool add_datatype_to_candidate_list(symbol_c *symbol, symbol_c *datatype); + bool add_datatype_to_candidate_list (symbol_c *symbol, symbol_c *datatype); + bool add_2datatypes_to_candidate_list(symbol_c *symbol, symbol_c *datatype1, symbol_c *datatype2); public: @@ -107,6 +108,8 @@ /******************************/ /* B 1.2.1 - Numeric Literals */ /******************************/ + void *handle_any_integer(symbol_c *symbol); + void *visit(real_c *symbol); void *visit(integer_c *symbol); void *visit(neg_real_c *symbol); diff -r da650a87662d -r d26759a2274a stage3/narrow_candidate_datatypes.cc --- a/stage3/narrow_candidate_datatypes.cc Sat Mar 10 11:21:04 2012 +0000 +++ b/stage3/narrow_candidate_datatypes.cc Sat Mar 10 11:21:41 2012 +0000 @@ -889,7 +889,7 @@ /* if the next IL instructions needs us to provide a datatype other than a bool, * then we have an internal compiler error - most likely in fill_candidate_datatypes_c */ - if ((NULL != symbol->datatype) && (!is_type(symbol->datatype, bool_type_name_c))) ERROR; + if ((NULL != symbol->datatype) && (!is_ANY_BOOL_compatible(symbol->datatype))) ERROR; if (symbol->candidate_datatypes.size() > 1) ERROR; /* NOTE: If there is no IL instruction following this CALC, CALCN, JMPC, JMPC, ..., instruction, @@ -898,7 +898,7 @@ */ if (symbol->candidate_datatypes.size() == 0) symbol->datatype = NULL; else symbol->datatype = symbol->candidate_datatypes[0]; /* i.e. a bool_type_name_c! */ - if ((NULL != symbol->datatype) && (!is_type(symbol->datatype, bool_type_name_c))) ERROR; + if ((NULL != symbol->datatype) && (!is_ANY_BOOL_compatible(symbol->datatype))) ERROR; /* set the required datatype of the previous IL instruction, i.e. a bool_type_name_c! */ set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); @@ -1400,7 +1400,7 @@ void *narrow_candidate_datatypes_c::visit(if_statement_c *symbol) { for(unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) { - if (is_type(symbol->expression->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(symbol->expression->candidate_datatypes[i])) symbol->expression->datatype = symbol->expression->candidate_datatypes[i]; } symbol->expression->accept(*this); @@ -1416,7 +1416,7 @@ void *narrow_candidate_datatypes_c::visit(elseif_statement_c *symbol) { for (unsigned int i = 0; i < symbol->expression->candidate_datatypes.size(); i++) { - if (is_type(symbol->expression->candidate_datatypes[i], bool_type_name_c)) + if (is_ANY_BOOL_compatible(symbol->expression->candidate_datatypes[i])) symbol->expression->datatype = symbol->expression->candidate_datatypes[i]; } symbol->expression->accept(*this);