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

Function getAlignOf

lib/symboldatabase.cpp:8524–8553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8522}
8523
8524static size_t getAlignOf(const ValueType& vt, const Settings& settings, ValueType::Accuracy accuracy, ValueType::SizeOf sizeOf, int maxRecursion = 0)
8525{
8526 if (maxRecursion > settings.vfOptions.maxAlignOfRecursion) {
8527 // TODO: add bailout message
8528 return 0;
8529 }
8530 if ((vt.pointer && sizeOf == ValueType::SizeOf::Pointer) || vt.reference != Reference::None || vt.isPrimitive()) {
8531 auto align = vt.getSizeOf(settings, accuracy, ValueType::SizeOf::Pointer);
8532 return align == 0 ? 0 : bitCeil(align);
8533 }
8534 if (vt.type == ValueType::Type::RECORD && vt.typeScope) {
8535 auto accHelper = [&](size_t max, const ValueType& vt2, size_t /*dim*/, MathLib::bigint /*bits*/) {
8536 size_t a = getAlignOf(vt2, settings, accuracy, ValueType::SizeOf::Pointer, ++maxRecursion);
8537 return std::max(max, a);
8538 };
8539 Result result = accumulateStructMembers(vt.typeScope, accHelper, accuracy);
8540 size_t total = result.total;
8541 if (const Type* dt = vt.typeScope->definedType) {
8542 total = std::accumulate(dt->derivedFrom.begin(), dt->derivedFrom.end(), total, [&](size_t v, const Type::BaseInfo& bi) {
8543 if (bi.type && bi.type->classScope)
8544 v += accumulateStructMembers(bi.type->classScope, accHelper, accuracy).total;
8545 return v;
8546 });
8547 }
8548 return result.success ? std::max<size_t>(1, total) : total;
8549 }
8550 if (vt.type == ValueType::Type::CONTAINER)
8551 return settings.platform.sizeof_pointer; // Just guess
8552 return 0;
8553}
8554
8555size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion) const
8556{

Callers 1

getSizeOfMethod · 0.85

Calls 5

bitCeilFunction · 0.85
accumulateStructMembersFunction · 0.85
getSizeOfMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected