Coverage Report

Created: 2020-09-22 08:39

/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
9.05M
  explicit OptionalDiagnostic(PartialDiagnostic *Diag = nullptr) : Diag(Diag) {}
33
34
4.71M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
4.71M
    if (Diag)
36
722k
      *Diag << v;
37
4.71M
    return *this;
38
4.71M
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::AccessKinds>(clang::AccessKinds const&)
Line
Count
Source
34
3.83k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
3.83k
    if (Diag)
36
1.40k
      *Diag << v;
37
3.83k
    return *this;
38
3.83k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<bool>(bool const&)
Line
Count
Source
34
371k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
371k
    if (Diag)
36
99.0k
      *Diag << v;
37
371k
    return *this;
38
371k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::QualType>(clang::QualType const&)
Line
Count
Source
34
552k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
552k
    if (Diag)
36
30.8k
      *Diag << v;
37
552k
    return *this;
38
552k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::VarDecl const*>(clang::VarDecl const* const&)
Line
Count
Source
34
3.63M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
3.63M
    if (Diag)
36
546k
      *Diag << v;
37
3.63M
    return *this;
38
3.63M
  }
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
1.56k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
1.56k
    if (Diag)
36
950
      *Diag << v;
37
1.56k
    return *this;
38
1.56k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<int>(int const&)
Line
Count
Source
34
16.0k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
16.0k
    if (Diag)
36
1.93k
      *Diag << v;
37
16.0k
    return *this;
38
16.0k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::NamedDecl const*>(clang::NamedDecl const* const&)
Line
Count
Source
34
12
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
12
    if (Diag)
36
11
      *Diag << v;
37
12
    return *this;
38
12
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl*>(clang::FieldDecl* const&)
Line
Count
Source
34
5
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
5
    if (Diag)
36
5
      *Diag << v;
37
5
    return *this;
38
5
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl const*>(clang::FieldDecl const* const&)
Line
Count
Source
34
547
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
547
    if (Diag)
36
388
      *Diag << v;
37
547
    return *this;
38
547
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CheckSubobjectKind>(clang::CheckSubobjectKind const&)
Line
Count
Source
34
326
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
326
    if (Diag)
36
33
      *Diag << v;
37
326
    return *this;
38
326
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<unsigned int>(unsigned int const&)
Line
Count
Source
34
307
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
307
    if (Diag)
36
120
      *Diag << v;
37
307
    return *this;
38
307
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXRecordDecl const*>(clang::CXXRecordDecl const* const&)
Line
Count
Source
34
7
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
7
    if (Diag)
36
7
      *Diag << v;
37
7
    return *this;
38
7
  }
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
4
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
4
    if (Diag)
36
3
      *Diag << v;
37
4
    return *this;
38
4
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXRecordDecl*>(clang::CXXRecordDecl* const&)
Line
Count
Source
34
7
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
7
    if (Diag)
36
7
      *Diag << v;
37
7
    return *this;
38
7
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FunctionDecl const*>(clang::FunctionDecl const* const&)
Line
Count
Source
34
122k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
122k
    if (Diag)
36
32.4k
      *Diag << v;
37
122k
    return *this;
38
122k
  }
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
178
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
178
    if (Diag)
36
10
      *Diag << v;
37
178
    return *this;
38
178
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::SourceRange>(clang::SourceRange const&)
Line
Count
Source
34
26
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
26
    if (Diag)
36
19
      *Diag << v;
37
26
    return *this;
38
26
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXConstructorDecl const*>(clang::CXXConstructorDecl const* const&)
Line
Count
Source
34
227
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
227
    if (Diag)
36
12
      *Diag << v;
37
227
    return *this;
38
227
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::ValueDecl const*>(clang::ValueDecl const* const&)
Line
Count
Source
34
12.6k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
12.6k
    if (Diag)
36
8.31k
      *Diag << v;
37
12.6k
    return *this;
38
12.6k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FixItHint>(clang::FixItHint const&)
Line
Count
Source
34
9
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
9
    if (Diag)
36
7
      *Diag << v;
37
9
    return *this;
38
9
  }
39
40
697
  OptionalDiagnostic &operator<<(const llvm::APSInt &I) {
41
697
    if (Diag) {
42
146
      SmallVector<char, 32> Buffer;
43
146
      I.toString(Buffer);
44
146
      *Diag << StringRef(Buffer.data(), Buffer.size());
45
146
    }
46
697
    return *this;
47
697
  }
48
49
12
  OptionalDiagnostic &operator<<(const llvm::APFloat &F) {
50
12
    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
7
      unsigned precision = llvm::APFloat::semanticsPrecision(F.getSemantics());
58
7
      precision = (precision * 59 + 195) / 196;
59
7
      SmallVector<char, 32> Buffer;
60
7
      F.toString(Buffer, precision);
61
7
      *Diag << StringRef(Buffer.data(), Buffer.size());
62
7
    }
63
12
    return *this;
64
12
  }
65
66
43
  OptionalDiagnostic &operator<<(const llvm::APFixedPoint &FX) {
67
43
    if (Diag) {
68
8
      SmallVector<char, 32> Buffer;
69
8
      FX.toString(Buffer);
70
8
      *Diag << StringRef(Buffer.data(), Buffer.size());
71
8
    }
72
43
    return *this;
73
43
  }
74
};
75
76
} // namespace clang
77
78
#endif