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

Function accumulateStructMembers

lib/symboldatabase.cpp:8481–8507  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8479
8480template<class F>
8481static Result accumulateStructMembers(const Scope* scope, F f, ValueType::Accuracy accuracy)
8482{
8483 size_t total = 0;
8484 std::set<const Scope*> anonScopes;
8485 for (const Variable& var : scope->varlist) {
8486 if (var.isStatic())
8487 continue;
8488 const MathLib::bigint bits = var.nameToken() ? var.nameToken()->bits() : -1;
8489 if (const ValueType* vt = var.valueType()) {
8490 if (vt->type == ValueType::Type::RECORD && vt->typeScope == scope)
8491 return {0, false};
8492 const MathLib::bigint dim = std::accumulate(var.dimensions().cbegin(), var.dimensions().cend(), MathLib::bigint(1), [](MathLib::bigint i1, const Dimension& dim) {
8493 return i1 * dim.num;
8494 });
8495 if (var.nameToken()->scope() != scope && var.nameToken()->scope()->definedType) { // anonymous union
8496 const auto ret = anonScopes.insert(var.nameToken()->scope());
8497 if (ret.second)
8498 total = f(total, *vt, dim, bits);
8499 }
8500 else
8501 total = f(total, *vt, dim, bits);
8502 }
8503 if (accuracy == ValueType::Accuracy::ExactOrZero && total == 0 && bits == -1)
8504 return {0, false};
8505 }
8506 return {total, true};
8507}
8508
8509
8510static size_t bitCeil(size_t x)

Callers 2

getAlignOfFunction · 0.85
getSizeOfMethod · 0.85

Calls 3

scopeMethod · 0.80
fFunction · 0.50
nameTokenMethod · 0.45

Tested by

no test coverage detected