Clang Project

clang_source_code/lib/Tooling/Core/Diagnostic.cpp
1//===--- Diagnostic.cpp - Framework for clang diagnostics tools ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9//  Implements classes to support/store diagnostics refactoring.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Tooling/Core/Diagnostic.h"
14#include "clang/Basic/SourceManager.h"
15
16namespace clang {
17namespace tooling {
18
19DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message)
20    : Message(Message), FileOffset(0) {}
21
22DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message,
23                                     const SourceManager &Sources,
24                                     SourceLocation Loc)
25    : Message(Message), FileOffset(0) {
26  assert(Loc.isValid() && Loc.isFileID());
27  FilePath = Sources.getFilename(Loc);
28
29  // Don't store offset in the scratch space. It doesn't tell anything to the
30  // user. Moreover, it depends on the history of macro expansions and thus
31  // prevents deduplication of warnings in headers.
32  if (!FilePath.empty())
33    FileOffset = Sources.getFileOffset(Loc);
34}
35
36Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
37                       Diagnostic::Level DiagLevelStringRef BuildDirectory)
38    : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel),
39      BuildDirectory(BuildDirectory) {}
40
41Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
42                       const DiagnosticMessage &Message,
43                       const llvm::StringMap<Replacements> &Fix,
44                       const SmallVector<DiagnosticMessage1> &Notes,
45                       Level DiagLevelllvm::StringRef BuildDirectory)
46    : DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes),
47      DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
48
49// end namespace tooling
50// end namespace clang
51