| 8553 | } |
| 8554 | |
| 8555 | size_t ValueType::getSizeOf( const Settings& settings, Accuracy accuracy, SizeOf sizeOf, int maxRecursion) const |
| 8556 | { |
| 8557 | if (maxRecursion > settings.vfOptions.maxSizeOfRecursion) { |
| 8558 | // TODO: add bailout message |
| 8559 | return 0; |
| 8560 | } |
| 8561 | const auto& platform = settings.platform; |
| 8562 | if (sizeOf == SizeOf::Pointer && (pointer || reference != Reference::None)) |
| 8563 | return platform.sizeof_pointer; |
| 8564 | if (type == ValueType::Type::BOOL || type == ValueType::Type::CHAR) |
| 8565 | return 1; |
| 8566 | if (type == ValueType::Type::SHORT) |
| 8567 | return platform.sizeof_short; |
| 8568 | if (type == ValueType::Type::WCHAR_T) |
| 8569 | return platform.sizeof_wchar_t; |
| 8570 | if (type == ValueType::Type::INT) |
| 8571 | return platform.sizeof_int; |
| 8572 | if (type == ValueType::Type::LONG) |
| 8573 | return platform.sizeof_long; |
| 8574 | if (type == ValueType::Type::LONGLONG) |
| 8575 | return platform.sizeof_long_long; |
| 8576 | if (type == ValueType::Type::FLOAT) |
| 8577 | return platform.sizeof_float; |
| 8578 | if (type == ValueType::Type::DOUBLE) |
| 8579 | return platform.sizeof_double; |
| 8580 | if (type == ValueType::Type::LONGDOUBLE) |
| 8581 | return platform.sizeof_long_double; |
| 8582 | if (type == ValueType::Type::CONTAINER) |
| 8583 | return 3 * platform.sizeof_pointer; // Just guess |
| 8584 | if (type == ValueType::Type::RECORD && typeScope) { |
| 8585 | size_t currentBitCount = 0; |
| 8586 | size_t currentBitfieldAlloc = 0; |
| 8587 | auto accHelper = [&](size_t total, const ValueType& vt2, size_t dim, MathLib::bigint nBits) -> size_t { |
| 8588 | const size_t charBit = settings.platform.char_bit; |
| 8589 | size_t n = vt2.getSizeOf(settings, accuracy, SizeOf::Pointer, ++maxRecursion); |
| 8590 | size_t a = getAlignOf(vt2, settings, accuracy, SizeOf::Pointer); |
| 8591 | if (n == 0 || a == 0) |
| 8592 | return accuracy == Accuracy::ExactOrZero ? 0 : total; |
| 8593 | if (nBits == 0) { |
| 8594 | if (currentBitfieldAlloc == 0) { |
| 8595 | nBits = n * charBit; |
| 8596 | } else { |
| 8597 | nBits = (currentBitfieldAlloc * charBit) - currentBitCount; |
| 8598 | } |
| 8599 | } |
| 8600 | if (nBits > 0) { |
| 8601 | size_t ret = total; |
| 8602 | if (currentBitfieldAlloc == 0) { |
| 8603 | currentBitfieldAlloc = n; |
| 8604 | currentBitCount = 0; |
| 8605 | } else if (currentBitCount + nBits > charBit * currentBitfieldAlloc) { |
| 8606 | ret += currentBitfieldAlloc; |
| 8607 | currentBitfieldAlloc = n; |
| 8608 | currentBitCount = 0; |
| 8609 | } |
| 8610 | while (nBits > charBit * currentBitfieldAlloc) { |
| 8611 | ret += currentBitfieldAlloc; |
| 8612 | nBits -= charBit * currentBitfieldAlloc; |
no test coverage detected