LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
Variable.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_VARIABLE_H
16#define LIEF_DWARF_VARIABLE_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/DWARF/Type.hpp"
24
25namespace LIEF {
26namespace dwarf {
27class Scope;
28
29namespace details {
30class Variable;
31class VariableIt;
32}
33
37 public:
39 public:
40 using iterator_category = std::bidirectional_iterator_tag;
41 using value_type = std::unique_ptr<Variable>;
42 using difference_type = std::ptrdiff_t;
43 using pointer = Variable*;
44 using reference = std::unique_ptr<Variable>&;
45 using implementation = details::VariableIt;
46
48 // Inspired from LLVM's iterator_facade_base
49 friend class Iterator;
50 public:
51 pointer operator->() const { return R.get(); }
52
53 private:
54 value_type R;
55
56 template <typename RefT>
57 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
58 };
59
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::VariableIt> impl);
64
65 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
66 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
67 return !(LHS == RHS);
68 }
69
72
74 Iterator tmp = *static_cast<Iterator*>(this);
75 --*static_cast<Iterator *>(this);
76 return tmp;
77 }
78
80 Iterator tmp = *static_cast<Iterator*>(this);
81 ++*static_cast<Iterator *>(this);
82 return tmp;
83 }
84
85 std::unique_ptr<Variable> operator*() const;
86
88 return static_cast<const Iterator*>(this)->operator*();
89 }
90
91 private:
92 std::unique_ptr<details::VariableIt> impl_;
93 };
94
95 Variable(std::unique_ptr<details::Variable> impl);
96
98 std::string name() const;
99
104 std::string linkage_name() const;
105
115
121
123 bool is_constexpr() const;
124
127
129 std::unique_ptr<Type> type() const;
130
132 std::unique_ptr<Scope> scope() const;
133
135 private:
136 std::unique_ptr<details::Variable> impl_;
137};
138
139}
140}
141#endif
pointer operator->() const
Definition Variable.hpp:51
Definition Variable.hpp:38
Iterator operator++(int)
Definition Variable.hpp:79
Iterator operator--(int)
Definition Variable.hpp:73
std::ptrdiff_t difference_type
Definition Variable.hpp:42
details::VariableIt implementation
Definition Variable.hpp:45
PointerProxy operator->() const
Definition Variable.hpp:87
std::bidirectional_iterator_tag iterator_category
Definition Variable.hpp:40
std::unique_ptr< Variable > operator*() const
std::unique_ptr< Variable > value_type
Definition Variable.hpp:41
Iterator(Iterator &&) noexcept
std::unique_ptr< Variable > & reference
Definition Variable.hpp:44
This class represents a DWARF variable which can be owned by a dwarf::Function or a dwarf::Compilatio...
Definition Variable.hpp:36
std::string linkage_name() const
The name of the variable which is used for linking (DW_AT_linkage_name).
Variable(std::unique_ptr< details::Variable > impl)
bool is_constexpr() const
Whether it's a constexpr variable.
std::unique_ptr< Type > type() const
Return the type of this variable.
debug_location_t debug_location() const
The original source location where the variable is defined.
std::unique_ptr< Scope > scope() const
Return the scope in which this variable is defined.
std::string name() const
Name of the variable (usually demangled)
result< int64_t > address() const
Address of the variable.
result< uint64_t > size() const
Return the size of the variable (or a lief_errors if it can't be resolved).
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:74
This structure holds a debug location (source filename & line)
Definition debug_loc.hpp:23
#define LIEF_API
Definition visibility.h:41