diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-03 02:20:32 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-03 02:20:32 +0000 |
commit | e9681525649adf23f626641d5e0c2ec08b756927 (patch) | |
tree | 1afba30209580790d505120372fa61e337f328e8 /clang/lib/Frontend/ASTUnit.cpp | |
parent | cb373e3f31b945738d134c3d1cb93ee666996c03 (diff) | |
download | bcm5719-llvm-e9681525649adf23f626641d5e0c2ec08b756927.tar.gz bcm5719-llvm-e9681525649adf23f626641d5e0c2ec08b756927.zip |
[libclang] Add infrastructure to be able to only deserialize decls in a file region and
use it for clang_getCursor.
llvm-svn: 143605
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 0600203eae5..015e92dfcd7 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2518,6 +2518,42 @@ void ASTUnit::addFileLevelDecl(Decl *D) { Decls->insert(I, LocDecl); } +void ASTUnit::findFileRegionDecls(FileID File, unsigned Offset, unsigned Length, + SmallVectorImpl<Decl *> &Decls) { + if (File.isInvalid()) + return; + + if (SourceMgr->isLoadedFileID(File)) { + assert(Ctx->getExternalSource() && "No external source!"); + return Ctx->getExternalSource()->FindFileRegionDecls(File, Offset, Length, + Decls); + } + + FileDeclsTy::iterator I = FileDecls.find(File); + if (I == FileDecls.end()) + return; + + LocDeclsTy &LocDecls = *I->second; + if (LocDecls.empty()) + return; + + LocDeclsTy::iterator + BeginIt = std::lower_bound(LocDecls.begin(), LocDecls.end(), + std::make_pair(Offset, (Decl*)0), compLocDecl); + if (BeginIt != LocDecls.begin()) + --BeginIt; + + LocDeclsTy::iterator + EndIt = std::upper_bound(LocDecls.begin(), LocDecls.end(), + std::make_pair(Offset+Length, (Decl*)0), + compLocDecl); + if (EndIt != LocDecls.end()) + ++EndIt; + + for (LocDeclsTy::iterator DIt = BeginIt; DIt != EndIt; ++DIt) + Decls.push_back(DIt->second); +} + SourceLocation ASTUnit::getLocation(const FileEntry *File, unsigned Line, unsigned Col) const { const SourceManager &SM = getSourceManager(); |