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 public:
80 pointer operator->() const { return R.get(); }
81
82 private:
83 value_type R;
84
85 template <typename RefT>
86 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
87 };
88
90 Iterator(Iterator&&) noexcept;
91 Iterator(std::unique_ptr<details::TypeIt> impl);
93
94 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
95 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
96 return !(LHS == RHS);
97 }
98
101
103 Iterator tmp = *static_cast<Iterator*>(this);
104 --*static_cast<Iterator *>(this);
105 return tmp;
106 }
107
109 Iterator tmp = *static_cast<Iterator*>(this);
110 ++*static_cast<Iterator *>(this);
111 return tmp;
112 }
113
114 std::unique_ptr<Type> operator*() const;
115
117 return static_cast<const Iterator*>(this)->operator*();
118 }
119
120 private:
121 std::unique_ptr<details::TypeIt> impl_;
122 };
123
124 virtual ~Type();
125
126 enum class KIND {
127 UNKNOWN = 0,
128 UNSPECIFIED,
129 BASE,
130 CONST_KIND,
131 CLASS,
132 ARRAY,
133 POINTER,
134 STRUCT,
135 UNION,
136 TYPEDEF,
137 REF,
138 SET_TYPE,
139 STRING,
140 SUBROUTINE,
141 POINTER_MEMBER,
142 PACKED,
143 FILE,
144 THROWN,
145 VOLATILE,
146 RESTRICT,
147 INTERFACE,
148 SHARED,
149 RVALREF,
150 TEMPLATE_ALIAS,
151 COARRAY,
152 DYNAMIC,
153 ATOMIC,
154 IMMUTABLE,
155 ENUM,
156 };
157
158 KIND kind() const;
159
161 bool is_unspecified() const {
162 return kind() == KIND::UNSPECIFIED;
163 }
164
168
173
176
178 std::unique_ptr<Scope> scope() const;
179
181 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
182
183 template<class T>
184 const T* as() const {
185 if (T::classof(this)) {
186 return static_cast<const T*>(this);
187 }
188 return nullptr;
189 }
190
191 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
192
193 protected:
194 Type(std::unique_ptr<details::Type> impl);
195 Type(details::Type& impl);
196
198};
199
200}
201}
202#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:80
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:116
Iterator operator--(int)
Definition DWARF/Type.hpp:102
Iterator operator++(int)
Definition DWARF/Type.hpp:108
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:184
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type.
Definition DWARF/Type.hpp:161
KIND kind() const
KIND
Definition DWARF/Type.hpp:126
@ UNSPECIFIED
Definition DWARF/Type.hpp:128
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:75
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:41