diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-26 08:01:41 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-09-26 08:01:41 +0000 |
| commit | 4cdfcae75d7d9eddef079ceff7e6f53a35a89948 (patch) | |
| tree | a593c66584b28fa9d4272118966b92bfde395559 /clang/lib/Frontend | |
| parent | 8f7180b11e024406e50ed53e27c95af461e6ec4d (diff) | |
| download | bcm5719-llvm-4cdfcae75d7d9eddef079ceff7e6f53a35a89948.tar.gz bcm5719-llvm-4cdfcae75d7d9eddef079ceff7e6f53a35a89948.zip | |
Don't map a file:line:col triplet that is inside the preamble range to
a "loaded" location of the precompiled preamble.
Instead, handle specially locations of preprocessed entities:
-When looking up for preprocessed entities, map main file locations inside the
preamble range to a preamble loaded location.
-When getting the source range of a preprocessing cursor, map preamble loaded
locations back to main file locations.
Fixes rdar://10175093 & http://llvm.org/PR10999
llvm-svn: 140519
Diffstat (limited to 'clang/lib/Frontend')
| -rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 4cc936a2b68..4e8226d6511 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2342,27 +2342,59 @@ void ASTUnit::TranslateStoredDiagnostics( 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); - + SourceLocation 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); - + SourceLocation FileLoc = SM.translateFileLineCol(File, 1, 1); return SM.getMacroArgExpandedLocation(FileLoc.getLocWithOffset(Offset)); } +/// \brief If \arg Loc is a loaded location from the preamble, returns +/// the corresponding local location of the main file, otherwise it returns +/// \arg Loc. +SourceLocation ASTUnit::mapLocationFromPreamble(SourceLocation Loc) { + FileID PreambleID; + if (SourceMgr) + PreambleID = SourceMgr->getPreambleFileID(); + + if (Loc.isInvalid() || Preamble.empty() || PreambleID.isInvalid()) + return Loc; + + unsigned Offs; + if (SourceMgr->isInFileID(Loc, PreambleID, &Offs) && Offs < Preamble.size()) { + SourceLocation FileLoc + = SourceMgr->getLocForStartOfFile(SourceMgr->getMainFileID()); + return FileLoc.getLocWithOffset(Offs); + } + + return Loc; +} + +/// \brief If \arg Loc is a local location of the main file but inside the +/// preamble chunk, returns the corresponding loaded location from the +/// preamble, otherwise it returns \arg Loc. +SourceLocation ASTUnit::mapLocationToPreamble(SourceLocation Loc) { + FileID PreambleID; + if (SourceMgr) + PreambleID = SourceMgr->getPreambleFileID(); + + if (Loc.isInvalid() || Preamble.empty() || PreambleID.isInvalid()) + return Loc; + + unsigned Offs; + if (SourceMgr->isInFileID(Loc, SourceMgr->getMainFileID(), &Offs) && + Offs < Preamble.size()) { + SourceLocation FileLoc = SourceMgr->getLocForStartOfFile(PreambleID); + return FileLoc.getLocWithOffset(Offs); + } + + return Loc; +} + void ASTUnit::PreambleData::countLines() const { NumLines = 0; if (empty()) |

