diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-07 20:44:15 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-12-07 20:44:15 +0000 |
commit | b3c16bad2096aca843807b35012ac82c405c907c (patch) | |
tree | ee141bb12c55751a893f9c7302c34c969cdb0b8e /clang/tools/libclang/IndexingContext.cpp | |
parent | 520028802c12f6a7af3eda8a2aba1dc3805f57c6 (diff) | |
download | bcm5719-llvm-b3c16bad2096aca843807b35012ac82c405c907c.tar.gz bcm5719-llvm-b3c16bad2096aca843807b35012ac82c405c907c.zip |
[libclang] Fix indexing of C++ bases in a C++ class.
llvm-svn: 146068
Diffstat (limited to 'clang/tools/libclang/IndexingContext.cpp')
-rw-r--r-- | clang/tools/libclang/IndexingContext.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/clang/tools/libclang/IndexingContext.cpp b/clang/tools/libclang/IndexingContext.cpp index bb00acfea37..0ec8619bed2 100644 --- a/clang/tools/libclang/IndexingContext.cpp +++ b/clang/tools/libclang/IndexingContext.cpp @@ -100,15 +100,23 @@ IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D, const CXXBaseSpecifier &Base = *I; BaseEntities.push_back(EntityInfo()); const NamedDecl *BaseD = 0; - if (const RecordType *RT = Base.getType()->getAs<RecordType>()) - BaseD = RT->getDecl(); - else if (const TypedefType *TDT = Base.getType()->getAs<TypedefType>()) + QualType T = Base.getType(); + SourceLocation Loc = getBaseLoc(Base); + + if (const TypedefType *TDT = T->getAs<TypedefType>()) { BaseD = TDT->getDecl(); + } else if (const TemplateSpecializationType * + TST = T->getAs<TemplateSpecializationType>()) { + BaseD = TST->getTemplateName().getAsTemplateDecl(); + } else if (const RecordType *RT = T->getAs<RecordType>()) { + BaseD = RT->getDecl(); + } + if (BaseD) IdxCtx.getEntityInfo(BaseD, BaseEntities.back(), SA); CXIdxBaseClassInfo BaseInfo = { 0, MakeCursorCXXBaseSpecifier(&Base, IdxCtx.CXTU), - IdxCtx.getIndexLoc(Base.getSourceRange().getBegin()) }; + IdxCtx.getIndexLoc(Loc) }; BaseInfos.push_back(BaseInfo); } @@ -121,6 +129,29 @@ IndexingContext::CXXBasesListInfo::CXXBasesListInfo(const CXXRecordDecl *D, CXBases.push_back(&BaseInfos[i]); } +SourceLocation IndexingContext::CXXBasesListInfo::getBaseLoc( + const CXXBaseSpecifier &Base) const { + SourceLocation Loc = Base.getSourceRange().getBegin(); + TypeLoc TL; + if (Base.getTypeSourceInfo()) + TL = Base.getTypeSourceInfo()->getTypeLoc(); + if (TL.isNull()) + return Loc; + + if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL)) + TL = QL->getUnqualifiedLoc(); + + if (const ElaboratedTypeLoc *EL = dyn_cast<ElaboratedTypeLoc>(&TL)) + return EL->getNamedTypeLoc().getBeginLoc(); + if (const DependentNameTypeLoc *DL = dyn_cast<DependentNameTypeLoc>(&TL)) + return DL->getNameLoc(); + if (const DependentTemplateSpecializationTypeLoc * + DTL = dyn_cast<DependentTemplateSpecializationTypeLoc>(&TL)) + return DTL->getNameLoc(); + + return Loc; +} + const char *IndexingContext::StrAdapter::toCStr(StringRef Str) { if (Str.empty()) return ""; |