MCPcopy Create free account
hub / github.com/KDE/kdevelop / saveDUChainItem

Function saveDUChainItem

kdevplatform/language/duchain/topducontextdynamicdata.cpp:44–93  ·  view source on GitHub ↗

* 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. *

Source from the content-addressed store, hash-verified

42 * we unmap the data and a shared pointer outlives that.
43 */
44void 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
95uint indexForParentContext(DUContext* context)
96{

Callers 2

storeDataMethod · 0.85
storeMethod · 0.85

Calls 10

d_funcMethod · 0.80
QByteArrayClass · 0.70
nameMethod · 0.45
dynamicSizeMethod · 0.45
sizeMethod · 0.45
backMethod · 0.45
appendMethod · 0.45
dataMethod · 0.45
copyMethod · 0.45
setDataMethod · 0.45

Tested by

no test coverage detected