Coverage Report

Created: 2020-02-15 09:57

/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
6.93M
  explicit OptionalDiagnostic(PartialDiagnostic *Diag = nullptr) : Diag(Diag) {}
33
34
3.12M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
3.12M
    if (Diag)
36
504k
      *Diag << v;
37
3.12M
    return *this;
38
3.12M
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::AccessKinds>(clang::AccessKinds const&)
Line
Count
Source
34
3.52k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
3.52k
    if (Diag)
36
1.42k
      *Diag << v;
37
3.52k
    return *this;
38
3.52k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<bool>(bool const&)
Line
Count
Source
34
319k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
319k
    if (Diag)
36
80.0k
      *Diag << v;
37
319k
    return *this;
38
319k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::QualType>(clang::QualType const&)
Line
Count
Source
34
18.6k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
18.6k
    if (Diag)
36
2.54k
      *Diag << v;
37
18.6k
    return *this;
38
18.6k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::VarDecl const*>(clang::VarDecl const* const&)
Line
Count
Source
34
2.65M
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
2.65M
    if (Diag)
36
386k
      *Diag << v;
37
2.65M
    return *this;
38
2.65M
  }
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
725
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
725
    if (Diag)
36
432
      *Diag << v;
37
725
    return *this;
38
725
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<int>(int const&)
Line
Count
Source
34
14.2k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
14.2k
    if (Diag)
36
1.68k
      *Diag << v;
37
14.2k
    return *this;
38
14.2k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::NamedDecl const*>(clang::NamedDecl const* const&)
Line
Count
Source
34
11
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
11
    if (Diag)
36
11
      *Diag << v;
37
11
    return *this;
38
11
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl*>(clang::FieldDecl* const&)
Line
Count
Source
34
4
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
4
    if (Diag)
36
4
      *Diag << v;
37
4
    return *this;
38
4
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::FieldDecl const*>(clang::FieldDecl const* const&)
Line
Count
Source
34
388
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
388
    if (Diag)
36
386
      *Diag << v;
37
388
    return *this;
38
388
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CheckSubobjectKind>(clang::CheckSubobjectKind const&)
Line
Count
Source
34
300
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
300
    if (Diag)
36
28
      *Diag << v;
37
300
    return *this;
38
300
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<unsigned int>(unsigned int const&)
Line
Count
Source
34
275
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
275
    if (Diag)
36
117
      *Diag << v;
37
275
    return *this;
38
275
  }
ExprConstant.cpp:clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<(anonymous namespace)::DynAlloc::Kind>((anonymous namespace)::DynAlloc::Kind const&)
Line
Count
Source
34
34
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
34
    if (Diag)
36
34
      *Diag << v;
37
34
    return *this;
38
34
  }
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 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
  }
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
100k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
100k
    if (Diag)
36
24.2k
      *Diag << v;
37
100k
    return *this;
38
100k
  }
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
182
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
182
    if (Diag)
36
16
      *Diag << v;
37
182
    return *this;
38
182
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::SourceRange>(clang::SourceRange const&)
Line
Count
Source
34
23
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
23
    if (Diag)
36
19
      *Diag << v;
37
23
    return *this;
38
23
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::ValueDecl const*>(clang::ValueDecl const* const&)
Line
Count
Source
34
10.7k
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
10.7k
    if (Diag)
36
7.26k
      *Diag << v;
37
10.7k
    return *this;
38
10.7k
  }
clang::OptionalDiagnostic& clang::OptionalDiagnostic::operator<<<clang::CXXConstructorDecl const*>(clang::CXXConstructorDecl const* const&)
Line
Count
Source
34
137
  template <typename T> OptionalDiagnostic &operator<<(const T &v) {
35
137
    if (Diag)
36
12
      *Diag << v;
37
137
    return *this;
38
137
  }
39
40
677
  OptionalDiagnostic &operator<<(const llvm::APSInt &I) {
41
677
    if (Diag) {
42
146
      SmallVector<char, 32> Buffer;
43
146
      I.toString(Buffer);
44
146
      *Diag << StringRef(Buffer.data(), Buffer.size());
45
146
    }
46
677
    return *this;
47
677
  }
48
49
8
  OptionalDiagnostic &operator<<(const llvm::APFloat &F) {
50
8
    if (Diag) {
51
7
      // FIXME: Force the precision of the source value down so we don't
52
7
      // print digits which are usually useless (we don't really care here if
53
7
      // we truncate a digit by accident in edge cases).  Ideally,
54
7
      // APFloat::toString would automatically print the shortest
55
7
      // representation which rounds to the correct value, but it's a bit
56
7
      // 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
8
    return *this;
64
8
  }
65
66
18
  OptionalDiagnostic &operator<<(const APFixedPoint &FX) {
67
18
    if (Diag) {
68
6
      SmallVector<char, 32> Buffer;
69
6
      FX.toString(Buffer);
70
6
      *Diag << StringRef(Buffer.data(), Buffer.size());
71
6
    }
72
18
    return *this;
73
18
  }
74
};
75
76
} // namespace clang
77
78
#endif