LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
PDB/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PDB_TYPE_H
16#define LIEF_PDB_TYPE_H
17#include <cstdint>
18#include <memory>
19#include <string>
20
21#include "LIEF/visibility.h"
22#include "LIEF/optional.hpp"
23#include "LIEF/DebugDeclOpt.hpp"
24
25namespace LIEF {
26namespace pdb {
27
28namespace details {
29class Type;
30class TypeIt;
31}
32
34class LIEF_API Type {
35 public:
37 public:
38 using iterator_category = std::forward_iterator_tag;
39 using value_type = std::unique_ptr<Type>;
40 using difference_type = std::ptrdiff_t;
41 using pointer = Type*;
42 using reference = Type&;
43 using implementation = details::TypeIt;
44
45 class LIEF_API PointerProxy {
46 // Inspired from LLVM's iterator_facade_base
47 friend class Iterator;
48 public:
49 pointer operator->() const { return R.get(); }
50
51 private:
52 value_type R;
53
54 template <typename RefT>
55 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
56 };
57
59 Iterator(Iterator&&) noexcept;
60 Iterator(std::unique_ptr<details::TypeIt> impl);
62
63 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
64
65 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
66 return !(LHS == RHS);
67 }
68
70
72 Iterator tmp = *static_cast<Iterator*>(this);
73 ++*static_cast<Iterator *>(this);
74 return tmp;
75 }
76
77 std::unique_ptr<Type> operator*() const;
78
80 return static_cast<const Iterator*>(this)->operator*();
81 }
82
83 private:
84 std::unique_ptr<details::TypeIt> impl_;
85 };
86
87 enum class KIND {
88 UNKNOWN = 0,
89 CLASS,
90 POINTER,
91 SIMPLE,
92 ENUM,
93 FUNCTION,
94 MODIFIER,
95 BITFIELD,
96 ARRAY,
97 UNION,
98 STRUCTURE,
99 INTERFACE,
100 };
101
102 KIND kind() const;
103
107
110
112 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
113
114 template<class T>
115 const T* as() const {
116 if (T::classof(this)) {
117 return static_cast<const T*>(this);
118 }
119 return nullptr;
120 }
121
122 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
123
124 virtual ~Type();
125
126 protected:
127 Type(std::unique_ptr<details::Type> impl);
128 std::unique_ptr<details::Type> impl_;
129};
130
131}
132}
133#endif
134
Definition optional.hpp:23
Definition PDB/Type.hpp:45
pointer operator->() const
Definition PDB/Type.hpp:49
friend class Iterator
Definition PDB/Type.hpp:47
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
PointerProxy operator->() const
Definition PDB/Type.hpp:79
Type * pointer
Definition PDB/Type.hpp:41
std::unique_ptr< Type > value_type
Definition PDB/Type.hpp:39
Type & reference
Definition PDB/Type.hpp:42
std::forward_iterator_tag iterator_category
Definition PDB/Type.hpp:38
std::unique_ptr< Type > operator*() const
details::TypeIt implementation
Definition PDB/Type.hpp:43
std::ptrdiff_t difference_type
Definition PDB/Type.hpp:40
Iterator operator++(int)
Definition PDB/Type.hpp:71
const T * as() const
Definition PDB/Type.hpp:115
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this type.
KIND
Definition PDB/Type.hpp:87
virtual ~Type()
static std::unique_ptr< Type > create(std::unique_ptr< details::Type > impl)
optional< uint64_t > size() const
Size of the type. This size should match the value of sizeof(...) applied to this type.
optional< std::string > name() const
Type's name (if present).
KIND kind() const
Definition BuildMetadata.hpp:26
Definition BuildMetadata.hpp:24
LIEF namespace.
Definition Abstract/Binary.hpp:40
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:25
#define LIEF_API
Definition visibility.h:41