| 1149 | } |
| 1150 | |
| 1151 | int 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 | |
| 1201 | QVector<RangeInRevision> allUses(TopDUContext* context, Declaration* declaration, bool noEmptyRanges) |
| 1202 | { |
no test coverage detected