clang  6.0.0svn
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 
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 
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.
Level DiagLevel
Diagnostic level. Can indicate either an error or a warning.
Definition: Diagnostic.h:79
std::string BuildDirectory
A build directory of the diagnostic source file.
Definition: Diagnostic.h:88
std::string DiagnosticName
Name identifying the Diagnostic.
Definition: Diagnostic.h:67
SmallVector< DiagnosticMessage, 1 > Notes
Potential notes about the diagnostic.
Definition: Diagnostic.h:76
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Encodes a location in the source.
DiagnosticMessage Message
Message associated to the diagnostic.
Definition: Diagnostic.h:70
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
llvm::StringMap< Replacements > Fix
Fixes to apply, grouped by file path.
Definition: Diagnostic.h:73
This class handles loading and caching of source files into memory.