1664 return NULL; |
1664 return NULL; |
1665 } |
1665 } |
1666 |
1666 |
1667 |
1667 |
1668 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) { |
1668 void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) { |
|
1669 /* NOTE: The standard defines the syntax for this 'negation' operation, but |
|
1670 * does not define the its semantics. |
|
1671 * |
|
1672 * We could be tempted to consider that the semantics of the |
|
1673 * 'negation' operation are similar/identical to the semantics of the |
|
1674 * SUB expression/operation. This would include assuming that the |
|
1675 * possible datatypes for the 'negation' operation is also |
|
1676 * the same as those for the SUB expression/operation, namely ANY_MAGNITUDE. |
|
1677 * |
|
1678 * However, this would then mean that the following ST code would be |
|
1679 * syntactically and semantically correct: |
|
1680 * uint_var := - (uint_var); |
|
1681 * |
|
1682 * According to the standard, the above code should result in a |
|
1683 * runtime error, when we try to apply a negative value to the |
|
1684 * UINT typed variable 'uint_var'. |
|
1685 * |
|
1686 * It is much easier for the compiler to detect this at compile time, |
|
1687 * and it is probably safer to the resulting code too. |
|
1688 * |
|
1689 * To detect these tyes of errors at compile time, the easisest solution |
|
1690 * is to only allow ANY_NUM datatytpes that are signed. |
|
1691 * So, that is what we do here! |
|
1692 */ |
1669 symbol->exp->accept(*this); |
1693 symbol->exp->accept(*this); |
1670 for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
1694 for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) { |
1671 if (is_ANY_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i])) |
1695 if (is_ANY_signed_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i])) |
1672 symbol->candidate_datatypes.push_back(symbol->exp->candidate_datatypes[i]); |
1696 symbol->candidate_datatypes.push_back(symbol->exp->candidate_datatypes[i]); |
1673 } |
1697 } |
1674 if (debug) std::cout << "neg [" << symbol->exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
1698 if (debug) std::cout << "neg [" << symbol->exp->candidate_datatypes.size() << "] ==> " << symbol->candidate_datatypes.size() << " result.\n"; |
1675 return NULL; |
1699 return NULL; |
1676 } |
1700 } |