data: Parsing field usage in initialization list
This commit is contained in:
@@ -57,6 +57,11 @@ TokenLocation::LocationType TokenLocation::getType() const
|
||||
void TokenLocation::setType(LocationType type)
|
||||
{
|
||||
m_type = type;
|
||||
|
||||
if (m_other)
|
||||
{
|
||||
m_other->m_type = type;
|
||||
}
|
||||
}
|
||||
|
||||
TokenLocationLine* TokenLocation::getTokenLocationLine() const
|
||||
|
||||
@@ -201,8 +201,20 @@ bool ASTVisitor::VisitCXXConstructorDecl(clang::CXXConstructorDecl* declaration)
|
||||
{
|
||||
if ((*it)->getInit())
|
||||
{
|
||||
clang::CXXCtorInitializer* init = *it;
|
||||
|
||||
if (init->isMemberInitializer())
|
||||
{
|
||||
m_client->onFieldUsageParsed(
|
||||
// getParseLocation(init->getSourceRange()),
|
||||
getParseLocationForNamedDecl(init->getMember(), init->getMemberLocation()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
init->getMember()->getQualifiedNameAsString()
|
||||
);
|
||||
}
|
||||
|
||||
ASTBodyVisitor bodyVisitor(this, declaration);
|
||||
bodyVisitor.Visit((*it)->getInit());
|
||||
bodyVisitor.Visit(init->getInit());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -338,10 +350,10 @@ ParseLocation ASTVisitor::getParseLocation(const clang::SourceRange& sourceRange
|
||||
);
|
||||
}
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocationForNamedDecl(clang::NamedDecl* decl) const
|
||||
ParseLocation ASTVisitor::getParseLocationForNamedDecl(clang::NamedDecl* decl, const clang::SourceLocation& loc) const
|
||||
{
|
||||
const clang::SourceManager& sourceManager = m_context->getSourceManager();
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(decl->getLocation());
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(loc);
|
||||
|
||||
return ParseLocation(
|
||||
presumedBegin.getFilename(),
|
||||
@@ -352,6 +364,11 @@ ParseLocation ASTVisitor::getParseLocationForNamedDecl(clang::NamedDecl* decl) c
|
||||
);
|
||||
}
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocationForNamedDecl(clang::NamedDecl* decl) const
|
||||
{
|
||||
return getParseLocationForNamedDecl(decl, decl->getLocation());
|
||||
}
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocationOfFunctionBody(clang::FunctionDecl* decl) const
|
||||
{
|
||||
if (decl->hasBody() && decl->isThisDeclarationADefinition())
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
private:
|
||||
bool hasValidLocation(const clang::Decl* declaration) const;
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
ParseLocation getParseLocationForNamedDecl(clang::NamedDecl* decl, const clang::SourceLocation& loc) const;
|
||||
ParseLocation getParseLocationForNamedDecl(clang::NamedDecl* decl) const;
|
||||
ParseLocation getParseLocationOfFunctionBody(clang::FunctionDecl* decl) const;
|
||||
ParseLocation getParseLocationOfRecordBody(clang::CXXRecordDecl* decl) const;
|
||||
|
||||
@@ -755,6 +755,22 @@ public:
|
||||
TS_ASSERT_EQUALS(client->usages[1], "App::foo -> App::bar <6:3 6:11>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_usage_of_field_in_initialization_list()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"class App\n"
|
||||
"{\n"
|
||||
" App()\n"
|
||||
" : bar(42)\n"
|
||||
" {}\n"
|
||||
" int bar;\n"
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->usages.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->usages[0], "App::App -> App::bar <4:5 4:7>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_return_type_use_in_function()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
|
||||
Reference in New Issue
Block a user