data: type alias indexing

* added recording of type aliases (note: template type alias does not work properly right now)
This commit is contained in:
malte_langkabel
2016-08-04 13:12:54 +02:00
parent b072972b50
commit 19d6ca3079
4 changed files with 62 additions and 7 deletions
+29 -7
View File
@@ -148,6 +148,14 @@ bool ASTVisitor::TraverseTypedefDecl(clang::TypedefDecl *d)
return base::TraverseTypedefDecl(d);
}
bool ASTVisitor::TraverseTypeAliasDecl(clang::TypeAliasDecl *d)
{
ScopedSwitcher<std::shared_ptr<ContextNameGenerator>> switcher(
m_contextNameGenerator, std::make_shared<ContextDeclNameGenerator>(d, m_declNameCache)
);
return base::TraverseTypeAliasDecl(d);
}
bool ASTVisitor::TraverseFieldDecl(clang::FieldDecl *d)
{
ScopedSwitcher<std::shared_ptr<ContextNameGenerator>> switcher(
@@ -878,12 +886,17 @@ bool ASTVisitor::VisitDecl(clang::Decl *d)
// Do nothing. The function will be recorded when it appears as a
// FunctionDecl.
} else if (llvm::isa<clang::ClassTemplateDecl>(d)) {
// Do nothing. The class will be recorded when it appears as a
// RecordDecl.
} else if (llvm::isa<clang::FieldDecl>(d)) {
// Do nothing. The class will be recorded when it appears as a
// RecordDecl.
} else if (llvm::isa<clang::TypeAliasTemplateDecl>(d)) {
// Do nothing. The type alias will be recorded when it appears as a
// TypeAliasDecl.
} else if (llvm::isa<clang::FieldDecl>(d)) {
RecordDeclRef(nd, loc, RT_Declaration, SYMBOL_FIELD);
} else if (llvm::isa<clang::TypedefDecl>(d)) {
RecordDeclRef(nd, loc, RT_Declaration, SYMBOL_TYPEDEF);
} else if (llvm::isa<clang::TypedefDecl>(d)) {
RecordDeclRef(nd, loc, RT_Declaration, SYMBOL_TYPEDEF);
} else if (llvm::isa<clang::TypeAliasDecl>(d)) {
RecordDeclRef(nd, loc, RT_Declaration, SYMBOL_TYPEDEF);
} else if (llvm::isa<clang::NamespaceDecl>(d)) {
RecordDeclRef(nd, loc, RT_Declaration, SYMBOL_NAMESPACE);
} else if (llvm::isa<clang::EnumConstantDecl>(d)) {
@@ -1169,12 +1182,21 @@ void ASTVisitor::RecordDeclRef(
switch (symbolType)
{
case SYMBOL_TYPEDEF:
if (clang::TypedefDecl* typedefDecl = clang::dyn_cast<clang::TypedefDecl>(d))
{
clang::AccessSpecifier accessSpecifier = clang::AccessSpecifier::AS_none;
if (clang::TypeAliasDecl* typeAliasDecl = clang::dyn_cast<clang::TypeAliasDecl>(d))
{
accessSpecifier = typeAliasDecl->getAccess();
}
else if (clang::TypedefDecl* typedefDecl = clang::dyn_cast<clang::TypedefDecl>(d))
{
accessSpecifier = typedefDecl->getAccess();
}
m_client->onTypedefParsed(
parseLocation,
declNameHierarchy,
convertAccessType(typedefDecl->getAccess()),
convertAccessType(accessSpecifier),
declIsImplicit);
}
break;
@@ -139,6 +139,7 @@ private:
bool TraverseLambdaExpr(clang::LambdaExpr* e);
bool TraverseFunctionDecl(clang::FunctionDecl* d);
bool TraverseTypedefDecl(clang::TypedefDecl *d);
bool TraverseTypeAliasDecl(clang::TypeAliasDecl *d);
bool TraverseFieldDecl(clang::FieldDecl *d);
bool TraverseVarDecl(clang::VarDecl *d);
bool TraverseClassTemplateDecl(clang::ClassTemplateDecl* d);
@@ -88,6 +88,14 @@ std::shared_ptr<NameElement> CxxDeclNameResolver::getDeclName()
{
const clang::NamedDecl* declaration = clang::dyn_cast<clang::NamedDecl>(m_declaration);
std::string declNameString = declaration->getNameAsString();
if (const clang::TypeAliasDecl* typeAliasDecl = clang::dyn_cast_or_null<clang::TypeAliasDecl>(declaration))
{
clang::TypeAliasTemplateDecl* templatedDeclaration = typeAliasDecl->getDescribedAliasTemplate();
if (templatedDeclaration)
{
return getDeclName(templatedDeclaration);
}
}
if (const clang::CXXRecordDecl* recordDecl = clang::dyn_cast_or_null<clang::CXXRecordDecl>(declaration))
{
clang::ClassTemplateDecl* templateClassDeclaration = recordDecl->getDescribedClassTemplate();
+24
View File
@@ -266,6 +266,19 @@ public:
TS_ASSERT_EQUALS(client->typedefs[0], "anonymous namespace (input.cc)::uint <3:23 3:26>");
}
void test_cxx_parser_finds_type_alias_in_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class Foo\n"
"{\n"
" using Bar = Foo;\n"
"};\n"
);
TS_ASSERT_EQUALS(client->typedefs.size(), 1);
TS_ASSERT_EQUALS(client->typedefs[0], "private Foo::Bar <3:8 3:10>");
}
void test_cxx_parser_finds_macro_define()
{
std::shared_ptr<TestParserClient> client = parseCode(
@@ -378,6 +391,17 @@ public:
TS_ASSERT_EQUALS(client->macros[0], "MAX <1:9 <1:9 1:11> 2:17>");
}
//void __test_cxx_parser_finds_type_template_parameter_type_of_template_type_alias()
//{
// std::shared_ptr<TestParserClient> client = parseCode(
// "template<class T>\n"
// "using MyType = int;\n"
// );
// TS_ASSERT_EQUALS(client->templateParameterTypes.size(), 1);
// TS_ASSERT_EQUALS(client->templateParameterTypes[0], "MyType<class T>::T <1:17 1:17>");
//}
void test_cxx_parser_finds_type_template_parameter_type_of_template_class()
{
std::shared_ptr<TestParserClient> client = parseCode(