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
24namespace LIEF::dwarf::types {
25
26namespace details {
27class Member;
28}
29
32class LIEF_API ClassLike : public Type {
33 public:
34 template<typename... Args,
35 typename = std::enable_if_t<std::is_constructible_v<Type, Args&&...>>>
36 ClassLike(Args&&... args) :
37 Type(std::forward<Args>(args)...) {}
38
41 public:
42 Member(std::unique_ptr<details::Member> impl);
43 Member(Member&& other) noexcept;
44 Member& operator=(Member&& other) noexcept;
45
46 Member(const Member&) = delete;
47 Member& operator=(const Member&) = delete;
48
50 std::string name() const;
51
56
73
77
79 std::unique_ptr<Type> type() const LIEF_LIFETIMEBOUND;
80
81 bool is_external() const;
82
83 bool is_declaration() const;
84
86
87 private:
88 std::unique_ptr<details::Member> impl_;
89 };
90
91 ClassLike(const ClassLike&) = delete;
92 ClassLike& operator=(const ClassLike&) = delete;
93
94 ClassLike(ClassLike&&) noexcept = default;
95 ClassLike& operator=(ClassLike&&) noexcept = default;
96
98
99 static bool classof(const Type* type) {
100 const auto kind = type->kind();
103 }
104
106 std::vector<Member> members() const LIEF_LIFETIMEBOUND;
107
109 std::unique_ptr<Member> find_member(uint64_t offset) const LIEF_LIFETIMEBOUND;
110
113
114 ~ClassLike() override;
115};
116
119 public:
120 template<typename... Args,
121 typename =
122 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
123 Structure(Args&&... args) :
124 ClassLike(std::forward<Args>(args)...) {}
125
126 Structure(const Structure&) = delete;
127 Structure& operator=(const Structure&) = delete;
128
129 Structure(Structure&&) noexcept = default;
130 Structure& operator=(Structure&&) noexcept = default;
131
132 static bool classof(const Type* type) {
133 return type->kind() == Type::KIND::STRUCT;
134 }
135
136 ~Structure() override;
137};
138
140class LIEF_API Class : public ClassLike {
141 public:
142 template<typename... Args,
143 typename =
144 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
145 Class(Args&&... args) :
146 ClassLike(std::forward<Args>(args)...) {}
147
148 Class(const Class&) = delete;
149 Class& operator=(const Class&) = delete;
150
151 Class(Class&&) noexcept = default;
152 Class& operator=(Class&&) noexcept = default;
153
154 static bool classof(const Type* type) {
155 return type->kind() == Type::KIND::CLASS;
156 }
157
158 ~Class() override;
159};
160
162class LIEF_API Union : public ClassLike {
163 public:
164 template<typename... Args,
165 typename =
166 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
167 Union(Args&&... args) :
168 ClassLike(std::forward<Args>(args)...) {}
169
170 Union(const Union&) = delete;
171 Union& operator=(const Union&) = delete;
172
173 Union(Union&&) noexcept = default;
174 Union& operator=(Union&&) noexcept = default;
175
176 static bool classof(const Type* type) {
177 return type->kind() == Type::KIND::UNION;
178 }
179
180 ~Union() override;
181};
182
184class LIEF_API Packed : public ClassLike {
185 public:
186 template<typename... Args,
187 typename =
188 std::enable_if_t<std::is_constructible_v<ClassLike, Args&&...>>>
189 Packed(Args&&... args) :
190 ClassLike(std::forward<Args>(args)...) {}
191
192 Packed(const Packed&) = delete;
193 Packed& operator=(const Packed&) = delete;
194
195 Packed(Packed&&) noexcept = default;
196 Packed& operator=(Packed&&) noexcept = default;
197
198 static bool classof(const Type* type) {
199 return type->kind() == Type::KIND::PACKED;
200 }
201
202 ~Packed() override;
203};
204
205}
206
207
208#endif
This class represents a DWARF function which can be associated with either: DW_TAG_subprogram or DW_T...
Definition DWARF/Function.hpp:45
Definition DWARF/Type.hpp:71
KIND kind() const
@ PACKED
Definition DWARF/Type.hpp:143
@ STRUCT
Definition DWARF/Type.hpp:135
@ CLASS
Definition DWARF/Type.hpp:132
@ UNION
Definition DWARF/Type.hpp:136
Type(std::unique_ptr< details::Type > impl)
This represents a class/struct/union attribute.
Definition DWARF/types/ClassLike.hpp:40
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
std::string name() const
Name of the member.
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:97
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:36
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:99
Class(Args &&... args)
Definition DWARF/types/ClassLike.hpp:145
Class & operator=(const Class &)=delete
Class(Class &&) noexcept=default
Class(const Class &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:154
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:198
Packed & operator=(const Packed &)=delete
Packed(Packed &&) noexcept=default
Packed(Args &&... args)
Definition DWARF/types/ClassLike.hpp:189
Packed(const Packed &)=delete
Structure(Args &&... args)
Definition DWARF/types/ClassLike.hpp:123
Structure(Structure &&) noexcept=default
Structure(const Structure &)=delete
Structure & operator=(const Structure &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:132
Union(Union &&) noexcept=default
Union(const Union &)=delete
static bool classof(const Type *type)
Definition DWARF/types/ClassLike.hpp:176
Union & operator=(const Union &)=delete
Union(Args &&... args)
Definition DWARF/types/ClassLike.hpp:167
Definition iterators.hpp:591
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:26
Definition DWARF/types/Array.hpp:23
#define LIEF_API
Definition visibility.h:45