LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
DWARF/types/ClassLike.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_STRUCTURE_H
16#define LIEF_DWARF_TYPE_STRUCTURE_H
17
19#include "LIEF/DWARF/Type.hpp"
21#include "LIEF/visibility.h"
22
23#include <string_view>
24
25namespace LIEF::dwarf::types {
26
27namespace details {
28class Member;
29}
30
33class LIEF_API ClassLike : public Type {
34 public:
35 template<typename... Args,
36 typename = std::enable_if_t<std::is_constructible_v<Type, Args&&...>>>
37 ClassLike(Args&&... args) :
38 Type(std::forward<Args>(args)...) {}
39
42 public:
43 Member(std::unique_ptr<details::Member> impl);
44 Member(Member&& other) noexcept;
45 Member& operator=(Member&& other) noexcept;
46
47 Member(const Member&) = delete;
48 Member& operator=(const Member&) = delete;
49
51 std::string_view name() const LIEF_LIFETIMEBOUND;
52
56 result<uint64_t> offset() const;
57
73 result<uint64_t> bit_offset() const;
74
77 result<uint64_t> bit_size() const;
78
80 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
81
82 bool is_external() const;
83
84 bool is_declaration() const;
85
87
88 private:
89 std::unique_ptr<details::Member> impl_;
90 };
91
92 ClassLike(const ClassLike&) = delete;
93 ClassLike& operator=(const ClassLike&) = delete;
94
95 ClassLike(ClassLike&&) noexcept = default;
96 ClassLike& operator=(ClassLike&&) noexcept = default;
97
99
100 static bool classof(const Type* type) {
101 const auto kind = type->kind();
104 }
105
107 std::vector<Member> members() const LIEF_LIFETIMEBOUND;
108
110 std::unique_ptr<Member> find_member(uint64_t offset) const LIEF_LIFETIMEBOUND;
111
114
115 ~ClassLike() override;
116};
117
120 public:
121 template<typename... Args,
122 typename =
123 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
124 Structure(Args&&... args) :
125 ClassLike(std::forward<Args>(args)...) {}
126
127 Structure(const Structure&) = delete;
128 Structure& operator=(const Structure&) = delete;
129
130 Structure(Structure&&) noexcept = default;
131 Structure& operator=(Structure&&) noexcept = default;
132
133 static bool classof(const Type* type) {
134 return type->kind() == Type::KIND::STRUCT;
135 }
136
137 ~Structure() override;
138};
139
141class LIEF_API Class : public ClassLike {
142 public:
143 template<typename... Args,
144 typename =
145 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
146 Class(Args&&... args) :
147 ClassLike(std::forward<Args>(args)...) {}
148
149 Class(const Class&) = delete;
150 Class& operator=(const Class&) = delete;
151
152 Class(Class&&) noexcept = default;
153 Class& operator=(Class&&) noexcept = default;
154
155 static bool classof(const Type* type) {
156 return type->kind() == Type::KIND::CLASS;
157 }
158
159 ~Class() override;
160};
161
163class LIEF_API Union : public ClassLike {
164 public:
165 template<typename... Args,
166 typename =
167 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
168 Union(Args&&... args) :
169 ClassLike(std::forward<Args>(args)...) {}
170
171 Union(const Union&) = delete;
172 Union& operator=(const Union&) = delete;
173
174 Union(Union&&) noexcept = default;
175 Union& operator=(Union&&) noexcept = default;
176
177 static bool classof(const Type* type) {
178 return type->kind() == Type::KIND::UNION;
179 }
180
181 ~Union() override;
182};
183
185class LIEF_API Packed : public ClassLike {
186 public:
187 template<typename... Args,
188 typename =
189 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
190 Packed(Args&&... args) :
191 ClassLike(std::forward<Args>(args)...) {}
192
193 Packed(const Packed&) = delete;
194 Packed& operator=(const Packed&) = delete;
195
196 Packed(Packed&&) noexcept = default;
197 Packed& operator=(Packed&&) noexcept = default;
198
199 static bool classof(const Type* type) {
200 return type->kind() == Type::KIND::PACKED;
201 }
202
203 ~Packed() override;
204};
205
206}
207
208
209#endif
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_T...
Definition DWARF/Function.hpp:46
Definition DWARF/Type.hpp:72
KIND kind() const
@ PACKED
Definition DWARF/Type.hpp:144
@ STRUCT
Definition DWARF/Type.hpp:136
@ CLASS
Definition DWARF/Type.hpp:133
@ UNION
Definition DWARF/Type.hpp:137
Type(std::unique_ptr< details::Type > impl)
This represents a class/struct/union attribute.
Definition DWARF/types/ClassLike.hpp:41
std::string_view name() const
Name of the member.
result< uint64_t > bit_size() const
If the current member is a bit-field, this function returns its size in bits.
Member(std::unique_ptr< details::Member > impl)
std::unique_ptr< Type > type() const
Type of the current member.
Member & operator=(Member &&other) noexcept
Member(Member &&other) noexcept
result< uint64_t > offset() const
Offset of the current member in the struct/union/class.
result< uint64_t > bit_offset() const
Offset of the current member in bits in the struct/union/class.
Member & operator=(const Member &)=delete
iterator_range< Function::Iterator > functions_it
Definition DWARF/types/ClassLike.hpp:98
functions_it functions() const
Iterator over the functions defined by the class-like.
std::vector< Member > members() const
Return the list of all the attributes defined in this class-like type.
std::unique_ptr< Member > find_member(uint64_t offset) const
Try to find the attribute at the given offset.
ClassLike(Args &&... args)
Definition DWARF/types/ClassLike.hpp:37
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:100
Class(Args &&... args)
Definition DWARF/types/ClassLike.hpp:146
Class & operator=(const Class &)=delete
Class(Class &&) noexcept=default
Class(const Class &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:155
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:199
Packed & operator=(const Packed &)=delete
Packed(Packed &&) noexcept=default
Packed(Args &&... args)
Definition DWARF/types/ClassLike.hpp:190
Packed(const Packed &)=delete
Structure(Args &&... args)
Definition DWARF/types/ClassLike.hpp:124
Structure(Structure &&) noexcept=default
Structure(const Structure &)=delete
Structure & operator=(const Structure &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:133
Union(Union &&) noexcept=default
Union(const Union &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:177
Union & operator=(const Union &)=delete
Union(Args &&... args)
Definition DWARF/types/ClassLike.hpp:168
Definition iterators.hpp:595
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:79
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/types/ClassLike.hpp:27
Definition DWARF/types/Array.hpp:23
#define LIEF_API
Definition visibility.h:45