| 1746 | } |
| 1747 | |
| 1748 | void Token::printValueFlow(const std::vector<std::string>& files, bool xml, std::ostream &out) const |
| 1749 | { |
| 1750 | std::string outs; |
| 1751 | |
| 1752 | // cppcheck-suppress shadowFunction |
| 1753 | int fileIndex = -1; |
| 1754 | int line = 0; |
| 1755 | if (xml) |
| 1756 | outs += " <valueflow>\n"; |
| 1757 | else |
| 1758 | outs += "\n\n##Value flow\n"; |
| 1759 | for (const Token *tok = this; tok; tok = tok->next()) { |
| 1760 | // cppcheck-suppress shadowFunction - TODO: fix this |
| 1761 | const auto* const values = tok->mImpl->mValues; |
| 1762 | if (!values) |
| 1763 | continue; |
| 1764 | if (values->empty()) // Values might be removed by removeContradictions |
| 1765 | continue; |
| 1766 | if (xml) { |
| 1767 | outs += " <values id=\""; |
| 1768 | outs += id_string(values); |
| 1769 | outs += "\">"; |
| 1770 | outs += '\n'; |
| 1771 | } |
| 1772 | else { |
| 1773 | if (fileIndex != tok->fileIndex()) { |
| 1774 | outs += "File "; |
| 1775 | outs += files[tok->fileIndex()]; |
| 1776 | outs += '\n'; |
| 1777 | line = 0; |
| 1778 | } |
| 1779 | if (line != tok->linenr()) { |
| 1780 | outs += "Line "; |
| 1781 | outs += std::to_string(tok->linenr()); |
| 1782 | outs += '\n'; |
| 1783 | } |
| 1784 | } |
| 1785 | fileIndex = tok->fileIndex(); |
| 1786 | line = tok->linenr(); |
| 1787 | if (!xml) { |
| 1788 | ValueFlow::Value::ValueKind valueKind = values->front().valueKind; |
| 1789 | const bool same = std::all_of(values->begin(), values->end(), [&](const ValueFlow::Value& value) { |
| 1790 | return value.valueKind == valueKind; |
| 1791 | }); |
| 1792 | outs += " "; |
| 1793 | outs += tok->str(); |
| 1794 | outs += " "; |
| 1795 | if (same) { |
| 1796 | switch (valueKind) { |
| 1797 | case ValueFlow::Value::ValueKind::Impossible: |
| 1798 | case ValueFlow::Value::ValueKind::Known: |
| 1799 | outs += "always "; |
| 1800 | break; |
| 1801 | case ValueFlow::Value::ValueKind::Inconclusive: |
| 1802 | outs += "inconclusive "; |
| 1803 | break; |
| 1804 | case ValueFlow::Value::ValueKind::Possible: |
| 1805 | outs += "possible "; |