MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / setValues

Function setValues

lib/clangimport.cpp:1585–1623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1583}
1584
1585static 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
1625void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f)
1626{

Callers 3

parseClangAstDumpMethod · 0.85
simplifyTokens1Method · 0.85
checkClangMethod · 0.85

Calls 8

getSizeOfMethod · 0.80
nextMethod · 0.80
linkAtMethod · 0.80
addValueMethod · 0.80
simpleMatchFunction · 0.70
tokAtMethod · 0.45
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected