LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
DWARF/Type.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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
48 public:
50 public:
51 using iterator_category = std::bidirectional_iterator_tag;
52 using value_type = std::unique_ptr<Type>;
53 using difference_type = std::ptrdiff_t;
54 using pointer = Type*;
55 using reference = std::unique_ptr<Type>&;
56 using implementation = details::TypeIt;
57
59 // Inspired from LLVM's iterator_facade_base
60 friend class Iterator;
61 public:
62 pointer operator->() const { return R.get(); }
63
64 private:
65 value_type R;
66
67 template <typename RefT>
68 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
69 };
70
72 Iterator(Iterator&&) noexcept;
73 Iterator(std::unique_ptr<details::TypeIt> impl);
75
76 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
77 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
78 return !(LHS == RHS);
79 }
80
83
85 Iterator tmp = *static_cast<Iterator*>(this);
86 --*static_cast<Iterator *>(this);
87 return tmp;
88 }
89
91 Iterator tmp = *static_cast<Iterator*>(this);
92 ++*static_cast<Iterator *>(this);
93 return tmp;
94 }
95
96 std::unique_ptr<Type> operator*() const;
97
99 return static_cast<const Iterator*>(this)->operator*();
100 }
101
102 private:
103 std::unique_ptr<details::TypeIt> impl_;
104 };
105
106 virtual ~Type();
107
108 enum class KIND {
109 UNKNOWN = 0,
110 UNSPECIFIED,
111 BASE,
112 CONST_KIND,
113 CLASS,
114 ARRAY,
115 POINTER,
116 STRUCT,
117 UNION,
118 };
119
120 KIND kind() const;
121
123 bool is_unspecified() const {
124 return kind() == KIND::UNSPECIFIED;
125 }
126
129
134
137
139 std::unique_ptr<Scope> scope() const;
140
141 template<class T>
142 const T* as() const {
143 if (T::classof(this)) {
144 return static_cast<const T*>(this);
145 }
146 return nullptr;
147 }
148
149 static std::unique_ptr<Type> create(std::unique_ptr<details::Type> impl);
150
151 protected:
152 Type(std::unique_ptr<details::Type> impl);
153 Type(details::Type& impl);
154
156};
157
158}
159}
160#endif
Definition canbe_unique.hpp:22
Definition DWARF/Type.hpp:58
pointer operator->() const
Definition DWARF/Type.hpp:62
Definition DWARF/Type.hpp:49
std::unique_ptr< Type > value_type
Definition DWARF/Type.hpp:52
PointerProxy operator->() const
Definition DWARF/Type.hpp:98
Iterator operator--(int)
Definition DWARF/Type.hpp:84
Iterator operator++(int)
Definition DWARF/Type.hpp:90
std::bidirectional_iterator_tag iterator_category
Definition DWARF/Type.hpp:51
Iterator(const Iterator &)
std::unique_ptr< Type > & reference
Definition DWARF/Type.hpp:55
Iterator(Iterator &&) noexcept
std::ptrdiff_t difference_type
Definition DWARF/Type.hpp:53
std::unique_ptr< Type > operator*() const
details::TypeIt implementation
Definition DWARF/Type.hpp:56
This class represents a DWARF Type which includes:
Definition DWARF/Type.hpp:47
const T * as() const
Definition DWARF/Type.hpp:142
bool is_unspecified() const
Whether this type is a DW_TAG_unspecified_type
Definition DWARF/Type.hpp:123
KIND kind() const
KIND
Definition DWARF/Type.hpp:108
result< std::string > name() const
Return the type's name (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.
LIEF namespace.
Definition Abstract/Binary.hpp:32
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