* Serialize @p item into @p data and update @p totalDataOffset. * * If @p isSharedDataItem is true, then the item's internal data pointer is not updated * to point to the serialized data. Otherwise the dynamic data is deleted and the items * data will point to the constant serialized data. * * NOTE: The above is required to support serialization of shared-data such as from ProblemPointer. *
| 42 | * we unmap the data and a shared pointer outlives that. |
| 43 | */ |
| 44 | void saveDUChainItem(QVector<TopDUContextDynamicData::ArrayWithPosition>& data, DUChainBase& item, |
| 45 | uint& totalDataOffset, bool isSharedDataItem) |
| 46 | { |
| 47 | if (!item.d_func()->classId) { |
| 48 | //If this triggers, you have probably created an own DUChainBase based class, but haven't called setClassId(this) in the constructor. |
| 49 | qCritical() << "no class-id set for data attached to a declaration of type" << typeid(item).name(); |
| 50 | Q_ASSERT(0); |
| 51 | } |
| 52 | |
| 53 | int size = DUChainItemSystem::self().dynamicSize(*item.d_func()); |
| 54 | |
| 55 | if (data.back().array.size() - int( data.back().position ) < size) |
| 56 | //Create a new data item |
| 57 | data.append({QByteArray(size > 10000 ? size : 10000, 0), 0u}); |
| 58 | |
| 59 | uint pos = data.back().position; |
| 60 | data.back().position += size; |
| 61 | totalDataOffset += size; |
| 62 | |
| 63 | DUChainBaseData& target(*(reinterpret_cast<DUChainBaseData*>(data.back().array.data() + pos))); |
| 64 | |
| 65 | if (item.d_func()->isDynamic()) { |
| 66 | //Change from dynamic data to constant data |
| 67 | const DUChainReferenceCountingEnabler rcEnabler(data.back().array.data(), data.back().array.size()); |
| 68 | DUChainItemSystem::self().copy(*item.d_func(), target, true); |
| 69 | Q_ASSERT(!target.isDynamic()); |
| 70 | if (!isSharedDataItem) { |
| 71 | item.setData(&target); |
| 72 | } |
| 73 | } else { |
| 74 | //Just copy the data into another place, expensive copy constructors are not needed |
| 75 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 800) |
| 76 | #pragma GCC diagnostic push |
| 77 | #pragma GCC diagnostic ignored "-Wclass-memaccess" |
| 78 | #endif |
| 79 | memcpy(&target, item.d_func(), size); |
| 80 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 800) |
| 81 | #pragma GCC diagnostic pop |
| 82 | #endif |
| 83 | if (!isSharedDataItem) { |
| 84 | item.setData(&target, false); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (!isSharedDataItem) { |
| 89 | Q_ASSERT(item.d_func() == &target); |
| 90 | |
| 91 | Q_ASSERT(!item.d_func()->isDynamic()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | uint indexForParentContext(DUContext* context) |
| 96 | { |