| 1583 | } |
| 1584 | |
| 1585 | static void setValues(const Tokenizer &tokenizer, const SymbolDatabase *symbolDatabase) |
| 1586 | { |
| 1587 | const Settings & settings = tokenizer.getSettings(); |
| 1588 | |
| 1589 | for (const Scope& scope : symbolDatabase->scopeList) { |
| 1590 | if (!scope.definedType) |
| 1591 | continue; |
| 1592 | |
| 1593 | MathLib::bigint typeSize = 0; |
| 1594 | for (const Variable &var: scope.varlist) { |
| 1595 | const MathLib::bigint mul = std::accumulate(var.dimensions().cbegin(), var.dimensions().cend(), MathLib::bigint(1), [](MathLib::bigint v, const Dimension& dim) { |
| 1596 | return v * dim.num; |
| 1597 | }); |
| 1598 | if (var.valueType()) |
| 1599 | typeSize += mul * var.valueType()->getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); |
| 1600 | } |
| 1601 | scope.definedType->sizeOf = typeSize; |
| 1602 | } |
| 1603 | |
| 1604 | for (auto *tok = const_cast<Token*>(tokenizer.tokens()); tok; tok = tok->next()) { |
| 1605 | if (Token::simpleMatch(tok, "sizeof (")) { |
| 1606 | ValueType vt = ValueType::parseDecl(tok->tokAt(2), settings); |
| 1607 | const size_t sz = vt.getSizeOf(settings, ValueType::Accuracy::ExactOrZero, ValueType::SizeOf::Pointer); |
| 1608 | if (sz == 0) |
| 1609 | continue; |
| 1610 | long long mul = 1; |
| 1611 | for (const Token *arrtok = tok->linkAt(1)->previous(); arrtok; arrtok = arrtok->previous()) { |
| 1612 | const std::string &a = arrtok->str(); |
| 1613 | if (a.size() > 2 && a[0] == '[' && a.back() == ']') |
| 1614 | mul *= strToInt<long long>(a.substr(1)); |
| 1615 | else |
| 1616 | break; |
| 1617 | } |
| 1618 | ValueFlow::Value v(mul * sz); |
| 1619 | v.setKnown(); |
| 1620 | tok->next()->addValue(v); |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f) |
| 1626 | { |