diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-18 00:26:46 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-18 00:26:46 +0000 |
commit | 1cff795e5118f71d0529a4800a8af67ea400c0ba (patch) | |
tree | 67a5499fecc7cfff9fc7777893935d01a999db24 /clang/tools/libclang/IndexingContext.cpp | |
parent | 316651ab2196c985b5f86f58fddc7587fcb1901a (diff) | |
download | bcm5719-llvm-1cff795e5118f71d0529a4800a8af67ea400c0ba.tar.gz bcm5719-llvm-1cff795e5118f71d0529a4800a8af67ea400c0ba.zip |
[libclang] Indexing API: make sure we don't pass declarations/references without USR or location.
llvm-svn: 144941
Diffstat (limited to 'clang/tools/libclang/IndexingContext.cpp')
-rw-r--r-- | clang/tools/libclang/IndexingContext.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/clang/tools/libclang/IndexingContext.cpp b/clang/tools/libclang/IndexingContext.cpp index 890336e3ac0..f63fd3f103f 100644 --- a/clang/tools/libclang/IndexingContext.cpp +++ b/clang/tools/libclang/IndexingContext.cpp @@ -105,11 +105,14 @@ void IndexingContext::handleDiagnostic(CXDiagnostic CXDiag) { void IndexingContext::handleDecl(const NamedDecl *D, SourceLocation Loc, CXCursor Cursor, DeclInfo &DInfo) { - if (!CB.indexDeclaration) + if (!CB.indexDeclaration || !D) return; StrAdapter SA(*this); getEntityInfo(D, DInfo.CXEntInfo, SA); + if (!DInfo.CXEntInfo.USR || Loc.isInvalid()) + return; + DInfo.entityInfo = &DInfo.CXEntInfo; DInfo.cursor = Cursor; DInfo.loc = getIndexLoc(Loc); @@ -307,6 +310,14 @@ void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, D = getEntityDecl(D); + StrAdapter SA(*this); + CXIdxEntityInfo RefEntity, ParentEntity; + getEntityInfo(D, RefEntity, SA); + if (!RefEntity.USR) + return; + + getEntityInfo(Parent, ParentEntity, SA); + if (onlyOneRefPerFile()) { SourceManager &SM = Ctx->getSourceManager(); SourceLocation FileLoc = SM.getFileLoc(Loc); @@ -326,14 +337,9 @@ void IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, return; // already in map. } - StrAdapter SA(*this); CXCursor Cursor = E ? MakeCXCursor(const_cast<Expr*>(E), const_cast<Decl*>(cast<Decl>(DC)), CXTU) : getRefCursor(D, Loc); - - CXIdxEntityInfo RefEntity, ParentEntity; - getEntityInfo(D, RefEntity, SA); - getEntityInfo(Parent, ParentEntity, SA); CXIdxEntityRefInfo Info = { Cursor, getIndexLoc(Loc), &RefEntity, @@ -543,7 +549,7 @@ void IndexingContext::getEntityInfo(const NamedDecl *D, unsigned Begin = SA.getCurSize(); bool Ignore = getDeclCursorUSR(D, SA.getBuffer()); if (Ignore) { - EntityInfo.USR = ""; + EntityInfo.USR = 0; } else { EntityInfo.USR = SA.getCStr(Begin); } |