LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
DWARF/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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
25namespace LIEF {
26namespace dwarf {
27class Scope;
28
29namespace details {
30class Type;
31class TypeIt;
32}
33
64class LIEF_API Type {
65 public:
67 public:
68 using iterator_category = std::bidirectional_iterator_tag;
69 using value_type = std::unique_ptr<Type>;
70 using difference_type = std::ptrdiff_t;
71 using pointer = Type*;
72 using reference = std::unique_ptr<Type>&;
73 using implementation = details::TypeIt;
74
75 class LIEF_API PointerProxy {
76 // Inspired from LLVM's iterator_facade_base
77 friend class Iterator;
78 public:
79 pointer operator->() const { return R.get(); }
80
81 private:
82 value_type R;
83
84 template <typename RefT>
85 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
86 };
87
89 Iterator(Iterator&&) noexcept;
90 Iterator(std::unique_ptr<details::TypeIt> impl);
92
93 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
94 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
95 return !(LHS == RHS);
96 }
97
100
102 Iterator tmp = *static_cast<Iterator*>(this);
103 --*static_cast<Iterator *>(this);
104 return tmp;
105 }
106
108 Iterator tmp = *static_cast<Iterator*>(this);
109 ++*static_cast<Iterator *>(this);
110 return tmp;
111 }
112
113 std::unique_ptr<Type> operator*() const;
114
116 return static_cast<const Iterator*>(this)->operator*();
117 }
118
119 private:
120 std::unique_ptr<details::TypeIt> impl_;
121 };
122
123 virtual ~Type();
124
156
157 KIND kind() const;
158
160 bool is_unspecified() const {
161 return kind() == KIND::UNSPECIFIED;
162 }
163
167
172
175
177 std::unique_ptr<Scope> scope() const;
178
179 template<class T>
180 const T* as() const {
181 if (T::classof(this)) {
182 return static_cast<const T*>(this);
183 }
184 return nullptr;
185 }
186
187 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
188
189 protected:
190 Type(std::unique_ptr<details::Type> impl);
191 Type(details::Type& impl);
192
194};
195
196}
197}
198#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:75
pointer operator->() const
Definition DWARF/Type.hpp:79
friend class Iterator
Definition DWARF/Type.hpp:77
std::unique_ptr< Type > value_type
Definition DWARF/Type.hpp:69
PointerProxy operator->() const
Definition DWARF/Type.hpp:115
Iterator operator--(int)
Definition DWARF/Type.hpp:101
Iterator operator++(int)
Definition DWARF/Type.hpp:107
Type * pointer
Definition DWARF/Type.hpp:71
std::bidirectional_iterator_tag iterator_category
Definition DWARF/Type.hpp:68
Iterator(const Iterator &)
std::unique_ptr< Type > & reference
Definition DWARF/Type.hpp:72
Iterator(Iterator &&) noexcept
std::ptrdiff_t difference_type
Definition DWARF/Type.hpp:70
std::unique_ptr< Type > operator*() const
details::TypeIt implementation
Definition DWARF/Type.hpp:73
const T * as() const
Definition DWARF/Type.hpp:180
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type.
Definition DWARF/Type.hpp:160
KIND kind() const
KIND
Definition DWARF/Type.hpp:125
@ SHARED
Definition DWARF/Type.hpp:147
@ TEMPLATE_ALIAS
Definition DWARF/Type.hpp:149
@ DYNAMIC
Definition DWARF/Type.hpp:151
@ UNSPECIFIED
Definition DWARF/Type.hpp:127
@ INTERFACE
Definition DWARF/Type.hpp:146
@ SUBROUTINE
Definition DWARF/Type.hpp:139
@ COARRAY
Definition DWARF/Type.hpp:150
@ STRING
Definition DWARF/Type.hpp:138
@ IMMUTABLE
Definition DWARF/Type.hpp:153
@ POINTER_MEMBER
Definition DWARF/Type.hpp:140
@ UNKNOWN
Definition DWARF/Type.hpp:126
@ THROWN
Definition DWARF/Type.hpp:143
@ CONST_KIND
Definition DWARF/Type.hpp:129
@ REF
Definition DWARF/Type.hpp:136
@ PACKED
Definition DWARF/Type.hpp:141
@ ENUM
Definition DWARF/Type.hpp:154
@ VOLATILE
Definition DWARF/Type.hpp:144
@ TYPEDEF
Definition DWARF/Type.hpp:135
@ FILE
Definition DWARF/Type.hpp:142
@ POINTER
Definition DWARF/Type.hpp:132
@ STRUCT
Definition DWARF/Type.hpp:133
@ CLASS
Definition DWARF/Type.hpp:130
@ ARRAY
Definition DWARF/Type.hpp:131
@ SET_TYPE
Definition DWARF/Type.hpp:137
@ BASE
Definition DWARF/Type.hpp:128
@ UNION
Definition DWARF/Type.hpp:134
@ ATOMIC
Definition DWARF/Type.hpp:152
@ RESTRICT
Definition DWARF/Type.hpp:145
@ RVALREF
Definition DWARF/Type.hpp:148
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.
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.
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:41