Coverage Report

Created: 2023-11-11 10:31

/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
548k
  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
548k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
548k
                  "Derived class must be derived from this.");
49
50
548k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
548k
  }
lldb_private::Cloneable<lldb_private::OptionValueArray, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
11.7k
  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
11.7k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
11.7k
                  "Derived class must be derived from this.");
49
50
11.7k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
11.7k
  }
lldb_private::Cloneable<lldb_private::OptionValueUInt64, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
79.5k
  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
79.5k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
79.5k
                  "Derived class must be derived from this.");
49
50
79.5k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
79.5k
  }
lldb_private::Cloneable<lldb_private::OptionValueString, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.05k
  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.05k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.05k
                  "Derived class must be derived from this.");
49
50
9.05k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.05k
  }
lldb_private::Cloneable<lldb_private::OptionValueDictionary, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.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
9.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.02k
                  "Derived class must be derived from this.");
49
50
9.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.02k
  }
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.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
27.0k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
27.0k
                  "Derived class must be derived from this.");
49
50
27.0k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
27.0k
  }
Unexecuted instantiation: lldb_private::Cloneable<ProcessExperimentalOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
lldb_private::Cloneable<ProcessOptionValueProperties, lldb_private::OptionValueProperties>::Clone() const
Line
Count
Source
44
2.69k
  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
2.69k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
2.69k
                  "Derived class must be derived from this.");
49
50
2.69k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
2.69k
  }
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.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
9.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.02k
                  "Derived class must be derived from this.");
49
50
9.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.02k
  }
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.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
27.0k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
27.0k
                  "Derived class must be derived from this.");
49
50
27.0k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
27.0k
  }
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.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
9.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.02k
                  "Derived class must be derived from this.");
49
50
9.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.02k
  }
lldb_private::Cloneable<lldb_private::OptionValueBoolean, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
212k
  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
212k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
212k
                  "Derived class must be derived from this.");
49
50
212k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
212k
  }
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.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
9.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.02k
                  "Derived class must be derived from this.");
49
50
9.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.02k
  }
lldb_private::Cloneable<lldb_private::OptionValuePathMappings, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
9.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
9.02k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
9.02k
                  "Derived class must be derived from this.");
49
50
9.02k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
9.02k
  }
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
2.88k
  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
2.88k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
2.88k
                  "Derived class must be derived from this.");
49
50
2.88k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
2.88k
  }
lldb_private::Cloneable<lldb_private::OptionValueFileSpec, lldb_private::OptionValue>::Clone() const
Line
Count
Source
44
47.8k
  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
47.8k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
47.8k
                  "Derived class must be derived from this.");
49
50
47.8k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
47.8k
  }
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
83.8k
  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
83.8k
    static_assert(std::is_base_of<Cloneable, Derived>::value,
48
83.8k
                  "Derived class must be derived from this.");
49
50
83.8k
    return std::make_shared<Derived>(static_cast<const Derived &>(*this));
51
83.8k
  }
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