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

Method indexForUsedDeclaration

kdevplatform/language/duchain/topducontext.cpp:1151–1199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1149}
1150
1151int TopDUContext::indexForUsedDeclaration(Declaration* declaration, bool create)
1152{
1153 if (create) {
1154 ENSURE_CAN_WRITE
1155 } else {
1156 ENSURE_CAN_READ
1157 }
1158
1159 if (!declaration) {
1160 return std::numeric_limits<int>::max();
1161 }
1162
1163 if (declaration->topContext() == this && !declaration->inSymbolTable() &&
1164 !m_dynamicData->isTemporaryDeclarationIndex(declaration->ownIndex())) {
1165 uint index = declaration->ownIndex();
1166 Q_ASSERT(!(index & (1 << 31)));
1167 return ( int )(index | (1 << 31)); //We don't put context-local declarations into the list, that's a waste. We just use the mark them with the highest bit.
1168 }
1169
1170 // if the declaration can not be found from this top-context, we create a direct
1171 // reference by index, to ensure that the use can be resolved in
1172 // usedDeclarationForIndex
1173 bool useDirectId = !recursiveImportIndices().contains(declaration->topContext());
1174 DeclarationId id(declaration->id(useDirectId));
1175
1176 int index = -1;
1177
1178 uint size = d_func()->m_usedDeclarationIdsSize();
1179 const DeclarationId* ids = d_func()->m_usedDeclarationIds();
1180
1181 ///@todo Make m_usedDeclarationIds sorted, and find the decl. using binary search
1182 for (unsigned int a = 0; a < size; ++a)
1183 if (ids[a] == id) {
1184 index = a;
1185 break;
1186 }
1187
1188 if (index != -1)
1189 return index;
1190 if (!create)
1191 return std::numeric_limits<int>::max();
1192
1193 d_func_dynamic()->m_usedDeclarationIdsList().append(id);
1194
1195 if (declaration->topContext() != this)
1196 DUChain::uses()->addUse(id, this);
1197
1198 return d_func()->m_usedDeclarationIdsSize() - 1;
1199}
1200
1201QVector<RangeInRevision> allUses(TopDUContext* context, Declaration* declaration, bool noEmptyRanges)
1202{

Callers 9

hasUsesMethod · 0.80
allUsesFunction · 0.80
contextHasUseMethod · 0.80
contextCountUsesMethod · 0.80
newUseMethod · 0.80
ContextUsesWidgetMethod · 0.80
VisitorMethod · 0.80
newUseMethod · 0.80

Calls 8

topContextMethod · 0.45
inSymbolTableMethod · 0.45
ownIndexMethod · 0.45
containsMethod · 0.45
idMethod · 0.45
appendMethod · 0.45
addUseMethod · 0.45

Tested by

no test coverage detected