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/iterators.hpp"
21#include "LIEF/visibility.h"
22#include "LIEF/errors.hpp"
23#include "LIEF/debug_loc.hpp"
24#include "LIEF/canbe_unique.hpp"
25#include "LIEF/DebugDeclOpt.hpp"
26
27namespace LIEF {
28namespace dwarf {
29class Scope;
30
31namespace details {
32class Type;
33class TypeIt;
34}
35
67 public:
68 class Iterator final
69 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag, Type,
70 std::ptrdiff_t, const Type*, const Type&> {
71 public:
72 using implementation = details::TypeIt;
73 using iterator_facade_base::operator++;
74 using iterator_facade_base::operator--;
75
77
78 LIEF_API Iterator(std::unique_ptr<details::TypeIt> impl);
79
82
84 LIEF_API Iterator& operator=(Iterator&&) noexcept;
85
87
88 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
89 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
90 return !(LHS == RHS);
91 }
92
93 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
95
96 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
98
99 LIEF_API const Type& operator*() const;
100
101 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
102 LIEF_API const Type* operator->() const;
103
106 LIEF_API std::unique_ptr<Type> yield();
107
108 private:
109 void load() const;
110
111 std::unique_ptr<details::TypeIt> impl_;
112 mutable std::unique_ptr<Type> cached_;
113 };
114
115 LIEF_LOCAL Type(std::unique_ptr<details::Type> impl);
116 LIEF_LOCAL Type(details::Type& impl);
117
118 Type(const Type&) = delete;
119 Type& operator=(const Type&) = delete;
120
121 Type(Type&&) noexcept;
122 Type& operator=(Type&&) noexcept;
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:
195};
196
197}
198}
199#endif
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 &)
const Type * operator->() const
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:72
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
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).
Type & operator=(const Type &)=delete
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.
Type(details::Type &impl)
Type(Type &&) noexcept
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)
Type(const Type &)=delete
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: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
#define LIEF_LOCAL
Definition visibility.h:46