Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Tooling/Core/Diagnostic.cpp
Line
Count
Source (jump to first uncovered line)
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
#include "llvm/ADT/STLExtras.h"
16
17
namespace clang {
18
namespace tooling {
19
20
DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message)
21
13
    : Message(Message), FileOffset(0) {}
22
23
DiagnosticMessage::DiagnosticMessage(llvm::StringRef Message,
24
                                     const SourceManager &Sources,
25
                                     SourceLocation Loc)
26
0
    : Message(Message), FileOffset(0) {
27
0
  assert(Loc.isValid() && Loc.isFileID());
28
0
  FilePath = std::string(Sources.getFilename(Loc));
29
0
30
0
  // Don't store offset in the scratch space. It doesn't tell anything to the
31
0
  // user. Moreover, it depends on the history of macro expansions and thus
32
0
  // prevents deduplication of warnings in headers.
33
0
  if (!FilePath.empty())
34
0
    FileOffset = Sources.getFileOffset(Loc);
35
0
}
36
37
Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
38
                       Diagnostic::Level DiagLevel, StringRef BuildDirectory)
39
    : DiagnosticName(DiagnosticName), DiagLevel(DiagLevel),
40
0
      BuildDirectory(BuildDirectory) {}
41
42
Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
43
                       const DiagnosticMessage &Message,
44
                       const SmallVector<DiagnosticMessage, 1> &Notes,
45
                       Level DiagLevel, llvm::StringRef BuildDirectory)
46
    : DiagnosticName(DiagnosticName), Message(Message), Notes(Notes),
47
6
      DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}
48
49
0
const llvm::StringMap<Replacements> *selectFirstFix(const Diagnostic& D) {
50
0
   if (!D.Message.Fix.empty())
51
0
    return &D.Message.Fix;
52
0
  auto Iter = llvm::find_if(D.Notes, [](const tooling::DiagnosticMessage &D) {
53
0
    return !D.Fix.empty();
54
0
  });
55
0
  if (Iter != D.Notes.end())
56
0
    return &Iter->Fix;
57
0
  return nullptr;
58
0
}
59
60
} // end namespace tooling
61
} // end namespace clang