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
21#include "LIEF/iterators.hpp"
22#include "LIEF/visibility.h"
23#include "LIEF/errors.hpp"
24#include "LIEF/debug_loc.hpp"
25#include "LIEF/canbe_unique.hpp"
26#include "LIEF/DebugDeclOpt.hpp"
27
28namespace LIEF {
29namespace dwarf {
30class Scope;
31
32namespace details {
33class Type;
34class TypeIt;
35}
36
68 public:
69 class Iterator final
70 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Type,
71 std::ptrdiff_t, const Type*, const Type&> {
72 public:
73 using implementation = details::TypeIt;
74 using iterator_facade_base::operator++;
75 using iterator_facade_base::operator--;
76
78
79 LIEF_API Iterator(std::unique_ptr<details::TypeIt> impl);
80
83
85 LIEF_API Iterator& operator=(Iterator&&) noexcept;
86
88
89 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
90 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
91 return !(LHS == RHS);
92 }
93
94 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
96
97 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
99
101
102 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
103 LIEF_API const Type* operator->() const LIEF_LIFETIMEBOUND;
104
107 LIEF_API std::unique_ptr<Type> yield();
108
109 private:
110 void load() const;
111
112 std::unique_ptr<details::TypeIt> impl_;
113 mutable std::unique_ptr<Type> cached_;
114 };
115
116 LIEF_LOCAL Type(std::unique_ptr<details::Type> impl);
118
119 Type(const Type&) = delete;
120 Type& operator=(const Type&) = delete;
121
122 Type(Type&&) noexcept;
123 Type& operator=(Type&&) noexcept;
124
125 virtual ~Type();
126
127 enum class KIND {
128 UNKNOWN = 0,
129 UNSPECIFIED,
130 BASE,
131 CONST_KIND,
132 CLASS,
133 ARRAY,
134 POINTER,
135 STRUCT,
136 UNION,
137 TYPEDEF,
138 REF,
139 SET_TYPE,
140 STRING,
141 SUBROUTINE,
142 POINTER_MEMBER,
143 PACKED,
144 FILE,
145 THROWN,
146 VOLATILE,
147 RESTRICT,
148 INTERFACE,
149 SHARED,
150 RVALREF,
151 TEMPLATE_ALIAS,
152 COARRAY,
153 DYNAMIC,
154 ATOMIC,
155 IMMUTABLE,
156 ENUM,
157 };
158
159 KIND kind() const;
160
162 bool is_unspecified() const {
163 return kind() == KIND::UNSPECIFIED;
164 }
165
169
174
177
179 std::unique_ptr<Scope> scope() const;
180
182 std::string to_decl(const DeclOpt& opt = DeclOpt()) const;
183
184 template<class T>
185 const T* as() const {
186 if (T::classof(this)) {
187 return static_cast<const T*>(this);
188 }
189 return nullptr;
190 }
191
192 static std::unique_ptr<Type>
193 create(std::unique_ptr<details::Type> impl LIEF_LIFETIMEBOUND);
194
195 protected:
197};
198
199}
200}
201#endif
Configuration options for generated code from debug info.
Definition DebugDeclOpt.hpp:36
Definition canbe_unique.hpp:22
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:33
Iterator(std::unique_ptr< details::TypeIt > impl)
Iterator(const Iterator &)
Iterator(Iterator &&) noexcept
std::unique_ptr< Type > yield()
Transfer ownership of the type at the current position to the caller. Returns nullptr if the iterator...
Iterator & operator=(const Iterator &)
const Type & operator*() const
details::TypeIt implementation
Definition DWARF/Type.hpp:73
const T * as() const
Definition DWARF/Type.hpp:185
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type.
Definition DWARF/Type.hpp:162
KIND kind() const
KIND
Definition DWARF/Type.hpp:127
@ UNSPECIFIED
Definition DWARF/Type.hpp:129
Type(std::unique_ptr< details::Type > impl)
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.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:78
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:32
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
This structure holds a debug location (source filename & line).
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46