LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
DWARF/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_DWARF_TYPE_H
16#define LIEF_DWARF_TYPE_H
17
18#include <memory>
19
20#include "LIEF/visibility.h"
21#include "LIEF/errors.hpp"
22#include "LIEF/debug_loc.hpp"
23#include "LIEF/canbe_unique.hpp"
24#include "LIEF/DebugDeclOpt.hpp"
25
26namespace LIEF {
27namespace dwarf {
28class Scope;
29
30namespace details {
31class Type;
32class TypeIt;
33}
34
65class LIEF_API Type {
66 public:
68 public:
69 using iterator_category = std::bidirectional_iterator_tag;
70 using value_type = std::unique_ptr<Type>;
71 using difference_type = std::ptrdiff_t;
72 using pointer = Type*;
73 using reference = std::unique_ptr<Type>&;
74 using implementation = details::TypeIt;
75
76 class LIEF_API PointerProxy {
77 // Inspired from LLVM's iterator_facade_base
78 friend class Iterator;
79
80 public:
82 return R.get();
83 }
84
85 private:
86 value_type R;
87
88 template<typename RefT>
89 PointerProxy(RefT&& R) :
90 R(std::forward<RefT>(R)) {
91 } // NOLINT(bugprone-forwarding-reference-overload)
92 };
93
95 Iterator(Iterator&&) noexcept;
96 Iterator(std::unique_ptr<details::TypeIt> impl);
98
99 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
100 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
101 return !(LHS == RHS);
102 }
103
106
108 Iterator tmp = *static_cast<Iterator*>(this);
109 --*static_cast<Iterator*>(this);
110 return tmp;
111 }
112
114 Iterator tmp = *static_cast<Iterator*>(this);
115 ++*static_cast<Iterator*>(this);
116 return tmp;
117 }
118
119 std::unique_ptr<Type> operator*() const;
120
122 return static_cast<const Iterator*>(this)->operator*();
123 }
124
125 private:
126 std::unique_ptr<details::TypeIt> impl_;
127 };
128
129 virtual ~Type();
130
131 enum class KIND {
132 UNKNOWN = 0,
133 UNSPECIFIED,
134 BASE,
135 CONST_KIND,
136 CLASS,
137 ARRAY,
138 POINTER,
139 STRUCT,
140 UNION,
141 TYPEDEF,
142 REF,
143 SET_TYPE,
144 STRING,
145 SUBROUTINE,
146 POINTER_MEMBER,
147 PACKED,
148 FILE,
149 THROWN,
150 VOLATILE,
151 RESTRICT,
152 INTERFACE,
153 SHARED,
154 RVALREF,
155 TEMPLATE_ALIAS,
156 COARRAY,
157 DYNAMIC,
158 ATOMIC,
159 IMMUTABLE,
160 ENUM,
161 };
162
163 KIND kind() const;
164
166 bool is_unspecified() const {
167 return kind() == KIND::UNSPECIFIED;
168 }
169
173
178
181
183 std::unique_ptr<Scope> scope() const;
184
186 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
187
188 template<class T>
189 const T* as() const {
190 if (T::classof(this)) {
191 return static_cast<const T*>(this);
192 }
193 return nullptr;
194 }
195
196 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
197
198 protected:
199 Type(std::unique_ptr<details::Type> impl);
200 Type(details::Type& impl);
201
203};
204
205}
206}
207#endif
Definition canbe_unique.hpp:22
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:33
Definition DWARF/Type.hpp:76
pointer operator->() const
Definition DWARF/Type.hpp:81
friend class Iterator
Definition DWARF/Type.hpp:78
std::unique_ptr< Type > value_type
Definition DWARF/Type.hpp:70
PointerProxy operator->() const
Definition DWARF/Type.hpp:121
Iterator operator--(int)
Definition DWARF/Type.hpp:107
Iterator operator++(int)
Definition DWARF/Type.hpp:113
Type * pointer
Definition DWARF/Type.hpp:72
std::bidirectional_iterator_tag iterator_category
Definition DWARF/Type.hpp:69
Iterator(const Iterator &)
std::unique_ptr< Type > & reference
Definition DWARF/Type.hpp:73
Iterator(Iterator &&) noexcept
std::ptrdiff_t difference_type
Definition DWARF/Type.hpp:71
std::unique_ptr< Type > operator*() const
details::TypeIt implementation
Definition DWARF/Type.hpp:74
const T * as() const
Definition DWARF/Type.hpp:189
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type.
Definition DWARF/Type.hpp:166
KIND kind() const
KIND
Definition DWARF/Type.hpp:131
@ UNSPECIFIED
Definition DWARF/Type.hpp:133
result< std::string > name() const
Return the type's name using either DW_AT_name or DW_AT_picture_string (if any).
result< uint64_t > size() const
Return the size of the type or an error if it can't be computed.
std::string to_decl(const DeclOpt &opt=DeclOpt()) const
Generates a C/C++ definition for this type.
debug_location_t location() const
Return the debug location where this type is defined.
static std::unique_ptr< Type > create(std::unique_ptr< details::Type > impl)
std::unique_ptr< Scope > scope() const
Return the scope in which this type is defined.
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:25
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:45