Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Utility/Cloneable.h
Line
Count
Source
1
//===-- Cloneable.h ---------------------------------------------*- 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
#ifndef LLDB_UTILITY_CLONEABLE_H
10
#define LLDB_UTILITY_CLONEABLE_H
11
12
#include <memory>
13
#include <type_traits>
14
15
namespace lldb_private {
16
17
/// \class Cloneable Cloneable.h "lldb/Utility/Cloneable.h"
18
/// A class that implements CRTP-based "virtual constructor" idiom.
19
///
20
/// Example:
21
/// @code
22
/// class Base {
23
///   using TopmostBase = Base;
24
/// public:
25
///   virtual std::shared_ptr<Base> Clone() const = 0;
26
/// };
27
/// @endcode
28
///
29
/// To define a class derived from the Base with overridden Clone:
30
/// @code
31
/// class Intermediate : public Cloneable<Intermediate, Base> {};
32
/// @endcode
33
///
34
/// To define a class at the next level of inheritance with overridden Clone:
35
/// @code
36
/// class Derived : public Cloneable<Derived, Intermediate> {};
37
/// @endcode
38
39
template <typename Derived, typename Base>
40
class Cloneable : public Base {
41
public:
42
  using Base::Base;
43
44
498k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
498k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
498k
                  "Derived class must be derived from this.");
49
50
498k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
498k
  }
lldb_private::Cloneable<lldb_private::OptionValueArray, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
12.0k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
12.0k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
12.0k
                  "Derived class must be derived from this.");
49
50
12.0k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
12.0k
  }
lldb_private::Cloneable<lldb_private::OptionValueUInt64, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
42.6k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
42.6k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
42.6k
                  "Derived class must be derived from this.");
49
50
42.6k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
42.6k
  }
lldb_private::Cloneable<lldb_private::OptionValueString, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.06k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.06k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.06k
                  "Derived class must be derived from this.");
49
50
9.06k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.06k
  }
lldb_private::Cloneable<lldb_private::OptionValueDictionary, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.04k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.04k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.04k
                  "Derived class must be derived from this.");
49
50
9.04k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.04k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueProperties, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<lldb_private::OptionValueFileSpecList, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
27.1k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
27.1k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
27.1k
                  "Derived class must be derived from this.");
49
50
27.1k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
27.1k
  }
Unexecuted instantiation: lldb_private::Cloneable<ProcessExperimentalOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
lldb_private::Cloneable<ProcessOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
Line
Count
Source
44
3.02k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
3.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
3.02k
                  "Derived class must be derived from this.");
49
50
3.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
3.02k
  }
Unexecuted instantiation: lldb_private::Cloneable<TargetExperimentalOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
lldb_private::Cloneable<TargetOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
Line
Count
Source
44
9.04k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.04k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.04k
                  "Derived class must be derived from this.");
49
50
9.04k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.04k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueFormat, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<lldb_private::OptionValueSInt64, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
27.1k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
27.1k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
27.1k
                  "Derived class must be derived from this.");
49
50
27.1k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
27.1k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueArch, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<lldb_private::OptionValueArgs, lldb_private::OptionValueArray>::Clone() const
Line
Count
Source
44
9.04k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.04k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.04k
                  "Derived class must be derived from this.");
49
50
9.04k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.04k
  }
lldb_private::Cloneable<lldb_private::OptionValueBoolean, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
214k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
214k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
214k
                  "Derived class must be derived from this.");
49
50
214k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
214k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueChar, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<lldb_private::OptionValueLanguage, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.04k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.04k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.04k
                  "Derived class must be derived from this.");
49
50
9.04k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.04k
  }
lldb_private::Cloneable<lldb_private::OptionValuePathMappings, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.04k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
9.04k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.04k
                  "Derived class must be derived from this.");
49
50
9.04k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.04k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueRegex, lldb_private::OptionValue>::Clone() const
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueUUID, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<ThreadOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
Line
Count
Source
44
3.41k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
3.41k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
3.41k
                  "Derived class must be derived from this.");
49
50
3.41k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
3.41k
  }
lldb_private::Cloneable<lldb_private::OptionValueFileSpec, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
39.1k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
39.1k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
39.1k
                  "Derived class must be derived from this.");
49
50
39.1k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
39.1k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueFormatEntity, lldb_private::OptionValue>::Clone() const
lldb_private::Cloneable<lldb_private::OptionValueEnumeration, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
75.3k
  std::shared_ptr<typename Base::TopmostBase> Clone() const override {
45
    // std::is_base_of requires derived type to be complete, that's why class
46
    // scope static_assert cannot be used.
47
75.3k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
75.3k
                  "Derived class must be derived from this.");
49
50
75.3k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
75.3k
  }
Unexecuted instantiation: lldb_private::Cloneable<lldb_private::OptionValueFileColonLine, lldb_private::OptionValue>::Clone() const
52
};
53
54
} // namespace lldb_private
55
56
#endif // LLDB_UTILITY_CLONEABLE_H