clang  5.0.0
Diagnostic.cpp
Go to the documentation of this file.
1 //===--- Diagnostic.cpp - Framework for clang diagnostics tools ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Implements classes to support/store diagnostics refactoring.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 
17 namespace clang {
18 namespace tooling {
19 
20 DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message)
21  : Message(Message), FileOffset(0) {}
22 
23 DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message,
24  const SourceManager &Sources,
25  SourceLocation Loc)
26  : Message(Message) {
27  assert(Loc.isValid() && Loc.isFileID());
28  FilePath = Sources.getFilename(Loc);
29  FileOffset = Sources.getFileOffset(Loc);
30 }
31 
32 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
33  Diagnostic::Level DiagLevel, StringRef BuildDirectory)
34  : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel),
35  BuildDirectory(BuildDirectory) {}
36 
37 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
38  const DiagnosticMessage &Message,
39  const llvm::StringMap<Replacements> &Fix,
41  Level DiagLevel, llvm::StringRef BuildDirectory)
42  : DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes),
43  DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
44 
45 } // end namespace tooling
46 } // end namespace clang
DiagnosticMessage(llvm::StringRef Message="")
Definition: Diagnostic.cpp:20
Defines the SourceManager interface.
bool isFileID() const
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
This class handles loading and caching of source files into memory.