Coverage Report

Created: 2022-07-16 07:03

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/AST/OptionalDiagnostic.h
Line
Count
Source
1
//===- OptionalDiagnostic.h - An optional diagnostic ------------*- C++ -*-===//
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
/// \file
10
/// Implements a partial diagnostic which may not be emitted.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_OPTIONALDIAGNOSTIC_H
15
#define LLVM_CLANG_AST_OPTIONALDIAGNOSTIC_H
16
17
#include "clang/AST/APValue.h"
18
#include "clang/Basic/PartialDiagnostic.h"
19
#include "llvm/ADT/APFloat.h"
20
#include "llvm/ADT/APSInt.h"
21
#include "llvm/ADT/SmallVector.h"
22
#include "llvm/ADT/StringRef.h"
23
24
namespace clang {
25
26
/// A partial diagnostic which we might know in advance that we are not going
27
/// to emit.
28
class OptionalDiagnostic {
29
  PartialDiagnostic *Diag;
30
31
public:
32
11.2M
  explicit OptionalDiagnostic(PartialDiagnostic *Diag = nullptr) : Diag(Diag) {}
33
34
5.58M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
5.58M
    if (Diag)
36
1.02M
      *Diag << v;
37
5.58M
    return *this;
38
5.58M
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::AccessKinds>(clang::AccessKinds const&)
Line
Count
Source
34
4.31k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
4.31k
    if (Diag)
36
1.88k
      *Diag << v;
37
4.31k
    return *this;
38
4.31k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<bool>(bool const&)
Line
Count
Source
34
383k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
383k
    if (Diag)
36
187k
      *Diag << v;
37
383k
    return *this;
38
383k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::QualType>(clang::QualType const&)
Line
Count
Source
34
447k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
447k
    if (Diag)
36
50.6k
      *Diag << v;
37
447k
    return *this;
38
447k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::VarDecl const*>(clang::VarDecl const* const&)
Line
Count
Source
34
4.61M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
4.61M
    if (Diag)
36
709k
      *Diag << v;
37
4.61M
    return *this;
38
4.61M
  }
Unexecuted instantiation: clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<char [31]>(char const (&) [31])
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
34
3.13k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
3.13k
    if (Diag)
36
1.54k
      *Diag << v;
37
3.13k
    return *this;
38
3.13k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<int>(int const&)
Line
Count
Source
34
23.3k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
23.3k
    if (Diag)
36
6.50k
      *Diag << v;
37
23.3k
    return *this;
38
23.3k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::NamedDecl const*>(clang::NamedDecl const* const&)
Line
Count
Source
34
24
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
24
    if (Diag)
36
21
      *Diag << v;
37
24
    return *this;
38
24
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl*>(clang::FieldDecl* const&)
Line
Count
Source
34
13
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
13
    if (Diag)
36
13
      *Diag << v;
37
13
    return *this;
38
13
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl const*>(clang::FieldDecl const* const&)
Line
Count
Source
34
699
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
699
    if (Diag)
36
508
      *Diag << v;
37
699
    return *this;
38
699
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CheckSubobjectKind>(clang::CheckSubobjectKind const&)
Line
Count
Source
34
630
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
630
    if (Diag)
36
183
      *Diag << v;
37
630
    return *this;
38
630
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<unsigned int>(unsigned int const&)
Line
Count
Source
34
457
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
457
    if (Diag)
36
211
      *Diag << v;
37
457
    return *this;
38
457
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXRecordDecl const*>(clang::CXXRecordDecl const* const&)
Line
Count
Source
34
10
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
10
    if (Diag)
36
10
      *Diag << v;
37
10
    return *this;
38
10
  }
ExprConstant.cpp:clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<(anonymous namespace)::DynAlloc::Kind>((anonymous namespace)::DynAlloc::Kind const&)
Line
Count
Source
34
38
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
38
    if (Diag)
36
34
      *Diag << v;
37
38
    return *this;
38
38
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXMethodDecl const*>(clang::CXXMethodDecl const* const&)
Line
Count
Source
34
11
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
11
    if (Diag)
36
8
      *Diag << v;
37
11
    return *this;
38
11
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXRecordDecl*>(clang::CXXRecordDecl* const&)
Line
Count
Source
34
17
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
17
    if (Diag)
36
17
      *Diag << v;
37
17
    return *this;
38
17
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FunctionDecl const*>(clang::FunctionDecl const* const&)
Line
Count
Source
34
69.1k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
69.1k
    if (Diag)
36
32.9k
      *Diag << v;
37
69.1k
    return *this;
38
69.1k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::RecordDecl const*>(clang::RecordDecl const* const&)
Line
Count
Source
34
8
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
8
    if (Diag)
36
8
      *Diag << v;
37
8
    return *this;
38
8
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::AccessSpecifier>(clang::AccessSpecifier const&)
Line
Count
Source
34
8
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
8
    if (Diag)
36
8
      *Diag << v;
37
8
    return *this;
38
8
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FunctionDecl*>(clang::FunctionDecl* const&)
Line
Count
Source
34
224
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
224
    if (Diag)
36
11
      *Diag << v;
37
224
    return *this;
38
224
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::SourceRange>(clang::SourceRange const&)
Line
Count
Source
34
40
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
40
    if (Diag)
36
32
      *Diag << v;
37
40
    return *this;
38
40
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXConstructorDecl const*>(clang::CXXConstructorDecl const* const&)
Line
Count
Source
34
1.50k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
1.50k
    if (Diag)
36
1.28k
      *Diag << v;
37
1.50k
    return *this;
38
1.50k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<llvm::StringRef>(llvm::StringRef const&)
Line
Count
Source
34
41
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
41
    if (Diag)
36
41
      *Diag << v;
37
41
    return *this;
38
41
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::ValueDecl const*>(clang::ValueDecl const* const&)
Line
Count
Source
34
36.8k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
36.8k
    if (Diag)
36
31.9k
      *Diag << v;
37
36.8k
    return *this;
38
36.8k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FixItHint>(clang::FixItHint const&)
Line
Count
Source
34
36
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
36
    if (Diag)
36
34
      *Diag << v;
37
36
    return *this;
38
36
  }
39
40
1.18k
  OptionalDiagnostic &operator<<(const llvm::APSInt &I) {
41
1.18k
    if (Diag) {
42
295
      SmallVector<char, 32> Buffer;
43
295
      I.toString(Buffer);
44
295
      *Diag << StringRef(Buffer.data(), Buffer.size());
45
295
    }
46
1.18k
    return *this;
47
1.18k
  }
48
49
28
  OptionalDiagnostic &operator<<(const llvm::APFloat &F) {
50
28
    if (Diag) {
51
      // FIXME: Force the precision of the source value down so we don't
52
      // print digits which are usually useless (we don't really care here if
53
      // we truncate a digit by accident in edge cases).  Ideally,
54
      // APFloat::toString would automatically print the shortest
55
      // representation which rounds to the correct value, but it's a bit
56
      // tricky to implement. Could use std::to_chars.
57
17
      unsigned precision = llvm::APFloat::semanticsPrecision(F.getSemantics());
58
17
      precision = (precision * 59 + 195) / 196;
59
17
      SmallVector<char, 32> Buffer;
60
17
      F.toString(Buffer, precision);
61
17
      *Diag << StringRef(Buffer.data(), Buffer.size());
62
17
    }
63
28
    return *this;
64
28
  }
65
66
58
  OptionalDiagnostic &operator<<(const llvm::APFixedPoint &FX) {
67
58
    if (Diag) {
68
8
      SmallVector<char, 32> Buffer;
69
8
      FX.toString(Buffer);
70
8
      *Diag << StringRef(Buffer.data(), Buffer.size());
71
8
    }
72
58
    return *this;
73
58
  }
74
};
75
76
} // namespace clang
77
78
#endif