476 void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {return handle_any_real(symbol);} |
476 void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {return handle_any_real(symbol);} |
477 |
477 |
478 |
478 |
479 |
479 |
480 void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) { |
480 void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) { |
|
481 /* Please read the comment in neg_expression_c method, as it also applies here */ |
481 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name); |
482 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name); |
482 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name); |
483 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name); |
483 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name, &search_constant_type_c::safedint_type_name); |
484 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name, &search_constant_type_c::safedint_type_name); |
484 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name, &search_constant_type_c::safelint_type_name); |
485 add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name, &search_constant_type_c::safelint_type_name); |
485 remove_incompatible_datatypes(symbol); |
486 remove_incompatible_datatypes(symbol); |
1369 * possible datatypes for the 'negation' operation is also |
1370 * possible datatypes for the 'negation' operation is also |
1370 * the same as those for the SUB expression/operation, namely ANY_MAGNITUDE. |
1371 * the same as those for the SUB expression/operation, namely ANY_MAGNITUDE. |
1371 * |
1372 * |
1372 * However, this would then mean that the following ST code would be |
1373 * However, this would then mean that the following ST code would be |
1373 * syntactically and semantically correct: |
1374 * syntactically and semantically correct: |
|
1375 * VAR uint_var : UINT END_VAR; |
1374 * uint_var := - (uint_var); |
1376 * uint_var := - (uint_var); |
1375 * |
1377 * |
1376 * According to the standard, the above code should result in a |
1378 * Assuming uint_var is not 0, the standard states that the above code should result in a |
1377 * runtime error, when we try to apply a negative value to the |
1379 * runtime error since the operation will result in an overflow. Since the above operation |
1378 * UINT typed variable 'uint_var'. |
1380 * is only valid when uint_var=0, it would probably make more sense for the programmer to |
|
1381 * use if (uint_var=0) ..., so we will simply assume that the above statement simply |
|
1382 * does not make sense in any situation (whether or not uint_var is 0), and therefore |
|
1383 * we will not allow it. |
|
1384 * (Notice that doing so does not ago against the standard, as the standard does not |
|
1385 * explicitly define the semantics of the NEG operator, nor the data types it may accept |
|
1386 * as input. We are simply assuming that the NEG operator may not be applied to unsigned |
|
1387 * ANY_NUM data types!). |
1379 * |
1388 * |
1380 * It is much easier for the compiler to detect this at compile time, |
1389 * It is much easier for the compiler to detect this at compile time, |
1381 * and it is probably safer to the resulting code too. |
1390 * and it is probably safer to the resulting code too. |
1382 * |
1391 * |
1383 * To detect these tyes of errors at compile time, the easisest solution |
1392 * To detect these tyes of errors at compile time, the easisest solution |
1384 * is to only allow ANY_NUM datatytpes that are signed. |
1393 * is to only allow ANY_NUM datatytpes that are signed. |
1385 * So, that is what we do here! |
1394 * So, that is what we do here! |
|
1395 * |
|
1396 * NOTE: The above argument also applies to the neg_integer_c method! |
1386 */ |
1397 */ |
1387 symbol->exp->accept(*this); |
1398 symbol->exp->accept(*this); |
1388 for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
1399 for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
1389 if (is_ANY_signed_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i])) |
1400 if (is_ANY_signed_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i])) |
1390 add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]); |
1401 add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]); |