SymbolDatabase: Look for types in anonymous scopes
This commit is contained in:
parent
b1bd6bb9ff
commit
5384802e16
|
@ -4352,11 +4352,24 @@ const Type* Scope::findType(const std::string & name) const
|
|||
{
|
||||
auto it = definedTypesMap.find(name);
|
||||
|
||||
if (definedTypesMap.end() == it) {
|
||||
return nullptr;
|
||||
} else {
|
||||
// Type was found
|
||||
if (definedTypesMap.end() != it)
|
||||
return (*it).second;
|
||||
|
||||
// is type defined in anonymous namespace..
|
||||
it = definedTypesMap.find("");
|
||||
if (it != definedTypesMap.end()) {
|
||||
for (const Scope *scope : nestedList) {
|
||||
if (scope->className.empty() && (scope->type == eNamespace || scope->isClassOrStructOrUnion())) {
|
||||
const Type *t = scope->findType(name);
|
||||
if (t)
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Type was not found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -149,6 +149,7 @@ private:
|
|||
|
||||
TEST_CASE(findVariableType1);
|
||||
TEST_CASE(findVariableType2);
|
||||
TEST_CASE(findVariableType3);
|
||||
|
||||
TEST_CASE(rangeBasedFor);
|
||||
|
||||
|
@ -826,6 +827,25 @@ private:
|
|||
ASSERT(cvar->type() != nullptr);
|
||||
}
|
||||
|
||||
void findVariableType3() {
|
||||
GET_SYMBOL_DB("namespace {\n"
|
||||
" struct A {\n"
|
||||
" int x;\n"
|
||||
" int y;\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" struct A a;\n"
|
||||
" a.x = 1;\n"
|
||||
"}");
|
||||
(void)db;
|
||||
const Variable* avar = Token::findsimplematch(tokenizer.tokens(), "a")->variable();
|
||||
ASSERT(avar);
|
||||
ASSERT(avar && avar->type() != nullptr);
|
||||
}
|
||||
|
||||
void rangeBasedFor() {
|
||||
GET_SYMBOL_DB("void reset() {\n"
|
||||
" for(auto& e : array)\n"
|
||||
|
|
Loading…
Reference in New Issue