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
49 public:
51 return R.get();
52 }
53
54 private:
55 value_type R;
56
57 template<typename RefT>
58 PointerProxy(RefT&& R) :
59 R(std::forward<RefT>(R)) {
60 } // NOLINT(bugprone-forwarding-reference-overload)
61 };
62
64 Iterator(Iterator&&) noexcept;
65 Iterator(std::unique_ptr<details::TypeIt> impl);
67
68 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
69
70 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
71 return !(LHS == RHS);
72 }
73
75
77 Iterator tmp = *static_cast<Iterator*>(this);
78 ++*static_cast<Iterator*>(this);
79 return tmp;
80 }
81
82 std::unique_ptr<Type> operator*() const;
83
85 return static_cast<const Iterator*>(this)->operator*();
86 }
87
88 private:
89 std::unique_ptr<details::TypeIt> impl_;
90 };
91
92 enum class KIND {
93 UNKNOWN = 0,
94 CLASS,
95 POINTER,
96 SIMPLE,
97 ENUM,
98 FUNCTION,
99 MODIFIER,
100 BITFIELD,
101 ARRAY,
102 UNION,
103 STRUCTURE,
104 INTERFACE,
105 };
106
107 KIND kind() const;
108
112
115
117 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
118
119 template<class T>
120 const T* as() const {
121 if (T::classof(this)) {
122 return static_cast<const T*>(this);
123 }
124 return nullptr;
125 }
126
127 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
128
129 virtual ~Type();
130
131 protected:
132 Type(std::unique_ptr<details::Type> impl);
133 std::unique_ptr<details::Type> impl_;
134};
135
136}
137}
138#endif
Definition optional.hpp:23
Definition PDB/Type.hpp:45
pointer operator->() const
Definition PDB/Type.hpp:50
friend class Iterator
Definition PDB/Type.hpp:47
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
PointerProxy operator->() const
Definition PDB/Type.hpp:84
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:76
const T * as() const
Definition PDB/Type.hpp:120
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this type.
KIND
Definition PDB/Type.hpp:92
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
Definition string.h:155
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:25
#define LIEF_API
Definition visibility.h:43