aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Frontend/ASTUnit.h
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-26 08:01:41 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-09-26 08:01:41 +0000
commitee0f84fc84ed7de7975e102668d8e53a778f7a8c (patch)
tree8b93a515c07f1806207d85a1517c45b4d3aed9cd /include/clang/Frontend/ASTUnit.h
parent7e7b503211f1c0ae1537da4657c9ed34f69b3506 (diff)
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140519 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Frontend/ASTUnit.h')
-rw-r--r--include/clang/Frontend/ASTUnit.h38
1 files changed, 34 insertions, 4 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index 86f9b0670e..074b4174be 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -175,6 +175,7 @@ private:
/// \brief The file in which the precompiled preamble is stored.
std::string PreambleFile;
+public:
class PreambleData {
const FileEntry *File;
std::vector<char> Buffer;
@@ -203,10 +204,21 @@ private:
return NumLines;
}
+ SourceRange getSourceRange(const SourceManager &SM) const {
+ SourceLocation FileLoc = SM.getLocForStartOfFile(SM.getPreambleFileID());
+ return SourceRange(FileLoc, FileLoc.getLocWithOffset(size()-1));
+ }
+
private:
void countLines() const;
};
+ const PreambleData &getPreambleData() const {
+ return Preamble;
+ }
+
+private:
+
/// \brief The contents of the preamble that has been precompiled to
/// \c PreambleFile.
PreambleData Preamble;
@@ -514,11 +526,29 @@ public:
unsigned Line, unsigned Col) const;
/// \brief Get the source location for the given file:offset pair.
- ///
- /// The difference with SourceManager::getLocation is that this method checks
- /// whether the requested location points inside the precompiled preamble
- /// in which case the returned source location will be a "loaded" one.
SourceLocation getLocation(const FileEntry *File, unsigned Offset) const;
+
+ /// \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 mapLocationFromPreamble(SourceLocation 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 mapLocationToPreamble(SourceLocation Loc);
+
+ /// \brief \see mapLocationFromPreamble.
+ SourceRange mapRangeFromPreamble(SourceRange R) {
+ return SourceRange(mapLocationFromPreamble(R.getBegin()),
+ mapLocationFromPreamble(R.getEnd()));
+ }
+
+ /// \brief \see mapLocationToPreamble.
+ SourceRange mapRangeToPreamble(SourceRange R) {
+ return SourceRange(mapLocationToPreamble(R.getBegin()),
+ mapLocationToPreamble(R.getEnd()));
+ }
// Retrieve the diagnostics associated with this AST
typedef const StoredDiagnostic *stored_diag_iterator;