aboutsummaryrefslogtreecommitdiff
path: root/include/clang
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang')
-rw-r--r--include/clang/Basic/SourceManager.h24
-rw-r--r--include/clang/Frontend/ASTUnit.h49
2 files changed, 63 insertions, 10 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h
index 09aadcebba..46fdbe5066 100644
--- a/include/clang/Basic/SourceManager.h
+++ b/include/clang/Basic/SourceManager.h
@@ -559,6 +559,9 @@ class SourceManager : public llvm::RefCountedBase<SourceManager> {
/// MainFileID - The file ID for the main source file of the translation unit.
FileID MainFileID;
+ /// \brief The file ID for the precompiled preamble there is one.
+ FileID PreambleFileID;
+
// Statistics for -print-stats.
mutable unsigned NumLinearScans, NumBinaryProbes;
@@ -610,13 +613,15 @@ public:
return MainFileID;
}
- /// \brief Set the file ID for the precompiled preamble, which is also the
- /// main file.
- void SetPreambleFileID(FileID Preamble) {
- assert(MainFileID.isInvalid() && "MainFileID already set!");
- MainFileID = Preamble;
+ /// \brief Set the file ID for the precompiled preamble.
+ void setPreambleFileID(FileID Preamble) {
+ assert(PreambleFileID.isInvalid() && "PreambleFileID already set!");
+ PreambleFileID = Preamble;
}
+ /// \brief Get the file ID for the precompiled preamble if there is one.
+ FileID getPreambleFileID() const { return PreambleFileID; }
+
//===--------------------------------------------------------------------===//
// Methods to create new FileID's and macro expansions.
//===--------------------------------------------------------------------===//
@@ -1117,11 +1122,12 @@ public:
/// If the source file is included multiple times, the source location will
/// be based upon the first inclusion.
SourceLocation translateFileLineCol(const FileEntry *SourceFile,
- unsigned Line, unsigned Col);
+ unsigned Line, unsigned Col) const;
/// \brief Get the source location in \arg FID for the given line:col.
/// Returns null location if \arg FID is not a file SLocEntry.
- SourceLocation translateLineCol(FileID FID, unsigned Line, unsigned Col);
+ SourceLocation translateLineCol(FileID FID,
+ unsigned Line, unsigned Col) const;
/// \brief If \arg Loc points inside a function macro argument, the returned
/// location will be the macro location in which the argument was expanded.
@@ -1132,7 +1138,7 @@ public:
/// ^
/// Passing a file location pointing at 'foo', will yield a macro location
/// where 'foo' was expanded into.
- SourceLocation getMacroArgExpandedLocation(SourceLocation Loc);
+ SourceLocation getMacroArgExpandedLocation(SourceLocation Loc) const;
/// \brief Determines the order of 2 source locations in the translation unit.
///
@@ -1309,7 +1315,7 @@ private:
std::pair<FileID, unsigned>
getDecomposedSpellingLocSlowCase(const SrcMgr::SLocEntry *E,
unsigned Offset) const;
- void computeMacroArgsCache(SrcMgr::ContentCache *Content, FileID FID);
+ void computeMacroArgsCache(SrcMgr::ContentCache *Content, FileID FID) const;
friend class ASTReader;
friend class ASTWriter;
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h
index e2fa5574fe..4a8475bb6c 100644
--- a/include/clang/Frontend/ASTUnit.h
+++ b/include/clang/Frontend/ASTUnit.h
@@ -196,9 +196,41 @@ private:
/// \brief The file in which the precompiled preamble is stored.
std::string PreambleFile;
+ class PreambleData {
+ const FileEntry *File;
+ std::vector<char> Buffer;
+ mutable unsigned NumLines;
+
+ public:
+ PreambleData() : File(0), NumLines(0) { }
+
+ void assign(const FileEntry *F, const char *begin, const char *end) {
+ File = F;
+ Buffer.assign(begin, end);
+ NumLines = 0;
+ }
+
+ void clear() { Buffer.clear(); File = 0; NumLines = 0; }
+
+ size_t size() const { return Buffer.size(); }
+ bool empty() const { return Buffer.empty(); }
+
+ const char *getBufferStart() const { return &Buffer[0]; }
+
+ unsigned getNumLines() const {
+ if (NumLines)
+ return NumLines;
+ countLines();
+ return NumLines;
+ }
+
+ private:
+ void countLines() const;
+ };
+
/// \brief The contents of the preamble that has been precompiled to
/// \c PreambleFile.
- std::vector<char> Preamble;
+ PreambleData Preamble;
/// \brief Whether the preamble ends at the start of a new line.
///
@@ -515,6 +547,21 @@ public:
PreprocessedEntitiesByFileMap &getPreprocessedEntitiesByFile() {
return PreprocessedEntitiesByFile;
}
+
+ /// \brief Get the source location for the given file:line:col triplet.
+ ///
+ /// 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 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;
// Retrieve the diagnostics associated with this AST
typedef const StoredDiagnostic *stored_diag_iterator;