cppcheck-suppress functionConst - has side effects
| 1838 | |
| 1839 | // cppcheck-suppress functionConst - has side effects |
| 1840 | void SymbolDatabase::setArrayDimensionsUsingValueFlow() |
| 1841 | { |
| 1842 | // set all unknown array dimensions |
| 1843 | for (const Variable *var : mVariableList) { |
| 1844 | // check each array variable |
| 1845 | if (!var || !var->isArray()) |
| 1846 | continue; |
| 1847 | // check each array dimension |
| 1848 | for (const Dimension &const_dimension : var->dimensions()) { |
| 1849 | auto &dimension = const_cast<Dimension &>(const_dimension); |
| 1850 | if (dimension.num != 0 || !dimension.tok) |
| 1851 | continue; |
| 1852 | |
| 1853 | if (Token::Match(dimension.tok->previous(), "[<,]")) { |
| 1854 | if (dimension.known) |
| 1855 | continue; |
| 1856 | |
| 1857 | // In template arguments, there might not be AST |
| 1858 | // Determine size by using the "raw tokens" |
| 1859 | TokenList tokenList(mSettings, dimension.tok->isCpp() ? Standards::Language::CPP : Standards::Language::C); |
| 1860 | tokenList.addtoken(";", 0, 0, 0, false); |
| 1861 | bool fail = false; |
| 1862 | for (const Token *tok = dimension.tok; tok && !Token::Match(tok, "[,>]"); tok = tok->next()) { |
| 1863 | if (!tok->isName()) |
| 1864 | tokenList.addtoken(tok->str(), 0, 0, 0, false); |
| 1865 | |
| 1866 | else if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::INT)) |
| 1867 | tokenList.addtoken(MathLib::toString(v->intvalue), 0, 0, 0, false); |
| 1868 | |
| 1869 | else { |
| 1870 | fail = true; |
| 1871 | break; |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | if (fail) |
| 1876 | continue; |
| 1877 | |
| 1878 | tokenList.addtoken(";", 0, 0, 0, false); |
| 1879 | |
| 1880 | for (Token *tok = tokenList.front(); tok;) { |
| 1881 | if (TemplateSimplifier::simplifyNumericCalculations(tok, false)) |
| 1882 | tok = tokenList.front(); |
| 1883 | else |
| 1884 | tok = tok->next(); |
| 1885 | } |
| 1886 | |
| 1887 | if (Token::Match(tokenList.front(), "; %num% ;")) { |
| 1888 | dimension.known = true; |
| 1889 | dimension.num = MathLib::toBigNumber(tokenList.front()->tokAt(1)); |
| 1890 | } |
| 1891 | |
| 1892 | continue; |
| 1893 | } |
| 1894 | |
| 1895 | // Normal array [..dimension..] |
| 1896 | dimension.known = false; |
| 1897 |
no test coverage detected