diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-19 20:40:35 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-19 20:40:35 +0000 |
commit | 7c06d8666b3f81051787159d2d5c7ff84270ae10 (patch) | |
tree | ada454a1a3f1276706bc219f9d78810fcc2ddb8d /clang/lib/Frontend/ASTUnit.cpp | |
parent | 532c5196b016847ee4fcdb06bb6b1cbee774f3be (diff) | |
download | bcm5719-llvm-7c06d8666b3f81051787159d2d5c7ff84270ae10.tar.gz bcm5719-llvm-7c06d8666b3f81051787159d2d5c7ff84270ae10.zip |
[libclang] When getting a source location from a file:line:col triplet
check whether the requested location points inside the precompiled preamble,
in which case the returned source location will be a "loaded" one.
llvm-svn: 140060
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 6f9b4378141..53e0412750e 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1200,7 +1200,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( if (Preamble.size() == NewPreamble.second.first && PreambleEndsAtStartOfLine == NewPreamble.second.second && NewPreamble.first->getBufferSize() < PreambleReservedSize-2 && - memcmp(&Preamble[0], NewPreamble.first->getBufferStart(), + memcmp(Preamble.getBufferStart(), NewPreamble.first->getBufferStart(), NewPreamble.second.first) == 0) { // The preamble has not changed. We may be able to re-use the precompiled // preamble. @@ -1332,7 +1332,9 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble( // Save the preamble text for later; we'll need to compare against it for // subsequent reparses. - Preamble.assign(NewPreamble.first->getBufferStart(), + StringRef MainFilename = PreambleInvocation->getFrontendOpts().Inputs[0].second; + Preamble.assign(FileMgr->getFile(MainFilename), + NewPreamble.first->getBufferStart(), NewPreamble.first->getBufferStart() + NewPreamble.second.first); PreambleEndsAtStartOfLine = NewPreamble.second.second; @@ -2396,3 +2398,41 @@ void ASTUnit::TranslateStoredDiagnostics( } Result.swap(Out); } + +SourceLocation ASTUnit::getLocation(const FileEntry *File, + unsigned Line, unsigned Col) const { + const SourceManager &SM = getSourceManager(); + SourceLocation Loc; + if (!Preamble.empty() && Line <= Preamble.getNumLines()) + Loc = SM.translateLineCol(SM.getPreambleFileID(), Line, Col); + else + Loc = SM.translateFileLineCol(File, Line, Col); + + return SM.getMacroArgExpandedLocation(Loc); +} + +SourceLocation ASTUnit::getLocation(const FileEntry *File, + unsigned Offset) const { + const SourceManager &SM = getSourceManager(); + SourceLocation FileLoc; + if (!Preamble.empty() && Offset < Preamble.size()) + FileLoc = SM.getLocForStartOfFile(SM.getPreambleFileID()); + else + FileLoc = SM.translateFileLineCol(File, 1, 1); + + return SM.getMacroArgExpandedLocation(FileLoc.getLocWithOffset(Offset)); +} + +void ASTUnit::PreambleData::countLines() const { + NumLines = 0; + if (empty()) + return; + + for (std::vector<char>::const_iterator + I = Buffer.begin(), E = Buffer.end(); I != E; ++I) { + if (*I == '\n') + ++NumLines; + } + if (Buffer.back() != '\n') + ++NumLines; +} |