SymbolDatabase: Better type lookup in methods
This commit is contained in:
parent
f021094f75
commit
bb227613bb
|
@ -3921,7 +3921,9 @@ const Type* SymbolDatabase::findVariableType(const Scope *start, const Token *ty
|
||||||
if (scope1) {
|
if (scope1) {
|
||||||
scope = scope1;
|
scope = scope1;
|
||||||
break;
|
break;
|
||||||
} else
|
} else if (scope->type == Scope::eFunction && scope->functionOf)
|
||||||
|
scope = scope->functionOf;
|
||||||
|
else
|
||||||
scope = scope->nestedIn;
|
scope = scope->nestedIn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,9 @@ private:
|
||||||
TEST_CASE(isVariableDeclarationRValueRef);
|
TEST_CASE(isVariableDeclarationRValueRef);
|
||||||
TEST_CASE(isVariableStlType);
|
TEST_CASE(isVariableStlType);
|
||||||
|
|
||||||
|
TEST_CASE(findVariableType1);
|
||||||
|
TEST_CASE(findVariableType2);
|
||||||
|
|
||||||
TEST_CASE(rangeBasedFor);
|
TEST_CASE(rangeBasedFor);
|
||||||
|
|
||||||
TEST_CASE(arrayMemberVar1);
|
TEST_CASE(arrayMemberVar1);
|
||||||
|
@ -773,6 +776,53 @@ private:
|
||||||
ASSERT(var.tokens()->tokAt(2)->scope() != 0);
|
ASSERT(var.tokens()->tokAt(2)->scope() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void findVariableType1() {
|
||||||
|
GET_SYMBOL_DB("class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" struct B {};\n"
|
||||||
|
" void f();\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct A::B b;\n"
|
||||||
|
" b.x = 1;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT(db != nullptr);
|
||||||
|
if (!db)
|
||||||
|
return;
|
||||||
|
const Variable* bvar = db->getVariableFromVarId(1);
|
||||||
|
ASSERT_EQUALS("b", bvar->name());
|
||||||
|
ASSERT(bvar->type() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void findVariableType2() {
|
||||||
|
GET_SYMBOL_DB("class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" class B {\n"
|
||||||
|
" public:\n"
|
||||||
|
" struct C {\n"
|
||||||
|
" int x;\n"
|
||||||
|
" int y;\n"
|
||||||
|
" };\n"
|
||||||
|
" };\n"
|
||||||
|
"\n"
|
||||||
|
" void f();\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"void A::f()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct B::C c;\n"
|
||||||
|
" c.x = 1;\n"
|
||||||
|
"}");
|
||||||
|
ASSERT(db != nullptr);
|
||||||
|
if (!db)
|
||||||
|
return;
|
||||||
|
const Variable* cvar = db->getVariableFromVarId(3);
|
||||||
|
ASSERT_EQUALS("c", cvar->name());
|
||||||
|
ASSERT(cvar->type() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void rangeBasedFor() {
|
void rangeBasedFor() {
|
||||||
GET_SYMBOL_DB("void reset() {\n"
|
GET_SYMBOL_DB("void reset() {\n"
|
||||||
" for(auto& e : array)\n"
|
" for(auto& e : array)\n"
|
||||||
|
|
Loading…
Reference in New Issue