diff options
Diffstat (limited to 'clang/lib/Tooling/Core/Diagnostic.cpp')
-rw-r--r-- | clang/lib/Tooling/Core/Diagnostic.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/Tooling/Core/Diagnostic.cpp b/clang/lib/Tooling/Core/Diagnostic.cpp index 235bd7fc1433..b0c4ea8c5608 100644 --- a/clang/lib/Tooling/Core/Diagnostic.cpp +++ b/clang/lib/Tooling/Core/Diagnostic.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "clang/Tooling/Core/Diagnostic.h" +#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/STLExtras.h" @@ -25,7 +26,7 @@ DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, SourceLocation Loc) : Message(Message), FileOffset(0) { assert(Loc.isValid() && Loc.isFileID()); - FilePath = Sources.getFilename(Loc); + FilePath = std::string(Sources.getFilename(Loc)); // Don't store offset in the scratch space. It doesn't tell anything to the // user. Moreover, it depends on the history of macro expansions and thus @@ -34,6 +35,16 @@ DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message, FileOffset = Sources.getFileOffset(Loc); } +FileByteRange::FileByteRange( + const SourceManager &Sources, CharSourceRange Range) + : FileOffset(0), Length(0) { + FilePath = std::string(Sources.getFilename(Range.getBegin())); + if (!FilePath.empty()) { + FileOffset = Sources.getFileOffset(Range.getBegin()); + Length = Sources.getFileOffset(Range.getEnd()) - FileOffset; + } +} + Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, Diagnostic::Level DiagLevel, StringRef BuildDirectory) : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel), @@ -42,9 +53,10 @@ Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, Diagnostic::Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message, const SmallVector<DiagnosticMessage, 1> &Notes, - Level DiagLevel, llvm::StringRef BuildDirectory) + Level DiagLevel, llvm::StringRef BuildDirectory, + const SmallVector<FileByteRange, 1> &Ranges) : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes), - DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {} + DiagLevel(DiagLevel), BuildDirectory(BuildDirectory), Ranges(Ranges) {} const llvm::StringMap<Replacements> *selectFirstFix(const Diagnostic& D) { if (!D.Message.Fix.empty()) |