clang 8.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
14 #include "clang/Tooling/Core/Diagnostic.h"
15 #include "clang/Basic/SourceManager.h"
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), FileOffset(0) {
27 assert(Loc.isValid() && Loc.isFileID());
28 FilePath = Sources.getFilename(Loc);
29
30 // Don't store offset in the scratch space. It doesn't tell anything to the
31 // user. Moreover, it depends on the history of macro expansions and thus
32 // prevents deduplication of warnings in headers.
33 if (!FilePath.empty())
34 FileOffset = Sources.getFileOffset(Loc);
35 }
36
37 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
38 Diagnostic::Level DiagLevel, StringRef BuildDirectory)
39 : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel),
40 BuildDirectory(BuildDirectory) {}
41
42 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
43 const DiagnosticMessage &Message,
44 const llvm::StringMap<Replacements> &Fix,
45 const SmallVector<DiagnosticMessage, 1> &Notes,
46 Level DiagLevel, llvm::StringRef BuildDirectory)
47 : DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes),
48 DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
49
50 } // end namespace tooling
51 } // end namespace clang
clang::tooling::DiagnosticMessage::DiagnosticMessage
DiagnosticMessage(llvm::StringRef Message="")
Definition: Diagnostic.cpp:20
SourceManager.h
Defines the SourceManager interface.
clang::tooling::Diagnostic::DiagLevel
Level DiagLevel
Diagnostic level. Can indicate either an error or a warning.
Definition: Diagnostic.h:79
clang::tooling::DiagnosticMessage::Message
std::string Message
Definition: Diagnostic.h:43
clang::tooling::DiagnosticMessage::FilePath
std::string FilePath
Definition: Diagnostic.h:44
Diagnostic.h
clang::tooling::Diagnostic::BuildDirectory
std::string BuildDirectory
A build directory of the diagnostic source file.
Definition: Diagnostic.h:88
clang::SourceLocation::isFileID
bool isFileID() const
Definition: SourceLocation.h:100
clang::tooling::Diagnostic::DiagnosticName
std::string DiagnosticName
Name identifying the Diagnostic.
Definition: Diagnostic.h:67
clang::tooling::Diagnostic::Level
Level
Definition: Diagnostic.h:51
clang::tooling::DiagnosticMessage::FileOffset
unsigned FileOffset
Definition: Diagnostic.h:45
clang::tooling::Diagnostic::Notes
SmallVector< DiagnosticMessage, 1 > Notes
Potential notes about the diagnostic.
Definition: Diagnostic.h:76
clang::SourceManager::getFileOffset
unsigned getFileOffset(SourceLocation SpellingLoc) const
Returns the offset from the start of the file that the specified SourceLocation represents.
Definition: SourceManager.h:1250
clang::tooling::DiagnosticMessage
Represents the diagnostic message with the error message associated and the information on the locati...
Definition: Diagnostic.h:32
clang::SourceManager::getFilename
StringRef getFilename(SourceLocation SpellingLoc) const
Return the filename of the file containing a SourceLocation.
Definition: SourceManager.h:1059
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:88
clang::tooling::Diagnostic::Diagnostic
Diagnostic()=default
llvm::SmallVector
Definition: LLVM.h:36
clang::tooling::Diagnostic::Message
DiagnosticMessage Message
Message associated to the diagnostic.
Definition: Diagnostic.h:70
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:108
clang::tooling::Diagnostic::Fix
llvm::StringMap< Replacements > Fix
Fixes to apply, grouped by file path.
Definition: Diagnostic.h:73
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582