| 8522 | } |
| 8523 | |
| 8524 | static 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 | |
| 8555 | size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion) const |
| 8556 | { |