@@ -1875,17 +1875,29 @@ void SymbolDatabase::removeSymbolsForTokens(const std::unordered_set<const Token
18751875
18761876 // the scopes, functions, variables, types and enumerators declared by those tokens
18771877 std::unordered_set<const Scope*> removedScopes;
1878+ std::unordered_set<const Variable*> removedVariables;
1879+ std::unordered_set<const Enumerator*> removedEnumerators;
18781880 for (const Scope& scope : scopeList) {
18791881 if ((scope.classDef && removedTokens.count (scope.classDef ) != 0 ) ||
1880- (scope.bodyStart && removedTokens.count (scope.bodyStart ) != 0 ))
1882+ (scope.bodyStart && removedTokens.count (scope.bodyStart ) != 0 )) {
18811883 removedScopes.insert (&scope);
1884+ std::transform (scope.varlist .cbegin (), scope.varlist .cend (), std::inserter (removedVariables, removedVariables.end ()), [](const Variable& var) {
1885+ return &var;
1886+ });
1887+ std::transform (scope.enumeratorList .cbegin (), scope.enumeratorList .cend (), std::inserter (removedEnumerators, removedEnumerators.end ()), [](const Enumerator& enumerator) {
1888+ return &enumerator;
1889+ });
1890+ }
18821891 }
18831892 std::unordered_set<const Function*> removedFunctions;
18841893 for (Scope& scope : scopeList) {
18851894 for (Function& function : scope.functionList ) {
1886- if (function.tokenDef && removedTokens.count (function.tokenDef ) != 0 )
1895+ if (function.tokenDef && removedTokens.count (function.tokenDef ) != 0 ) {
18871896 removedFunctions.insert (&function);
1888- else if (function.token && removedTokens.count (function.token ) != 0 ) {
1897+ std::transform (function.argumentList .cbegin (), function.argumentList .cend (), std::inserter (removedVariables, removedVariables.end ()), [](const Variable& arg) {
1898+ return &arg;
1899+ });
1900+ } else if (function.token && removedTokens.count (function.token ) != 0 ) {
18891901 // only the function definition is removed - the declaration remains
18901902 function.token = nullptr ;
18911903 function.arg = function.argDef ;
@@ -1894,28 +1906,11 @@ void SymbolDatabase::removeSymbolsForTokens(const std::unordered_set<const Token
18941906 }
18951907 }
18961908 }
1897- std::unordered_set<const Variable*> removedVariables;
1898- for (const Scope* scope : removedScopes) {
1899- std::transform (scope->varlist .cbegin (), scope->varlist .cend (), std::inserter (removedVariables, removedVariables.end ()), [](const Variable& var) {
1900- return &var;
1901- });
1902- }
1903- for (const Function* function : removedFunctions) {
1904- std::transform (function->argumentList .cbegin (), function->argumentList .cend (), std::inserter (removedVariables, removedVariables.end ()), [](const Variable& arg) {
1905- return &arg;
1906- });
1907- }
19081909 std::unordered_set<const Type*> removedTypes;
19091910 for (const Type& type : typeList) {
19101911 if (type.classDef && removedTokens.count (type.classDef ) != 0 )
19111912 removedTypes.insert (&type);
19121913 }
1913- std::unordered_set<const Enumerator*> removedEnumerators;
1914- for (const Scope* scope : removedScopes) {
1915- std::transform (scope->enumeratorList .cbegin (), scope->enumeratorList .cend (), std::inserter (removedEnumerators, removedEnumerators.end ()), [](const Enumerator& enumerator) {
1916- return &enumerator;
1917- });
1918- }
19191914
19201915 // clear the references from the surviving tokens
19211916 for (Token* tok = mTokenizer .list .front (); tok; tok = tok->next ()) {
@@ -2004,7 +1999,11 @@ void SymbolDatabase::addSymbolsForNewTokenRanges(const std::vector<std::pair<Tok
20041999 const Scope* enclosing = anchor ? anchor->scope () : &scopeList.front ();
20052000 if (!enclosing)
20062001 continue ;
2007- if (anchor && anchor == enclosing->bodyEnd )
2002+ // an anchor that closes the enclosing scope means the new tokens are in its parent.
2003+ // a namespace can consist of multiple blocks and bodyStart/bodyEnd only track the
2004+ // latest block - so for namespaces any closing brace with the namespace scope closes it.
2005+ if (anchor && anchor->str () == " }" &&
2006+ (anchor == enclosing->bodyEnd || enclosing->type == ScopeType::eNamespace))
20082007 enclosing = enclosing->nestedIn ? enclosing->nestedIn : &scopeList.front ();
20092008 findAllScopes (range.first , range.second ->next (), const_cast <Scope*>(enclosing));
20102009 }
0 commit comments