| 288 | } |
| 289 | |
| 290 | void Declaration::setContext(DUContext* context, bool anonymous) |
| 291 | { |
| 292 | Q_ASSERT(!context || context->topContext()); |
| 293 | |
| 294 | DUCHAIN_D_DYNAMIC(Declaration); |
| 295 | |
| 296 | if (context == m_context && anonymous == d->m_anonymousInContext) { |
| 297 | // skip costly operations below when the same context is set |
| 298 | // this happens often when updating a TopDUContext from the cache |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | setInSymbolTable(false); |
| 303 | |
| 304 | //We don't need to clear, because it's not allowed to move from one top-context into another |
| 305 | // clearOwnIndex(); |
| 306 | |
| 307 | if (m_context && context) { |
| 308 | Q_ASSERT(m_context->topContext() == context->topContext()); |
| 309 | } |
| 310 | |
| 311 | if (m_context) { |
| 312 | if (!d->m_anonymousInContext) { |
| 313 | m_context->m_dynamicData->removeDeclaration(this); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (context) |
| 318 | m_topContext = context->topContext(); |
| 319 | else |
| 320 | m_topContext = nullptr; |
| 321 | |
| 322 | d->m_anonymousInContext = anonymous; |
| 323 | m_context = context; |
| 324 | |
| 325 | if (context) { |
| 326 | if (!m_indexInTopContext) |
| 327 | allocateOwnIndex(); |
| 328 | |
| 329 | if (!d->m_anonymousInContext) { |
| 330 | context->m_dynamicData->addDeclaration(this); |
| 331 | } |
| 332 | |
| 333 | if (context->inSymbolTable() && !anonymous) |
| 334 | setInSymbolTable(true); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void Declaration::clearOwnIndex() |
| 339 | { |
no test coverage detected