LIEF: Library to Instrument Executable Formats Version 0.16.0
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}
33class LIEF_API Variable {
37 public:
38 class LIEF_API Iterator {
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
47 class LIEF_API PointerProxy {
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
60 Iterator(const Iterator&);
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::VariableIt> impl);
63 ~Iterator();
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
70 Iterator& operator++();
71 Iterator& operator--();
72
73 Iterator operator--(int) {
74 Iterator tmp = *static_cast<Iterator*>(this);
75 --*static_cast<Iterator *>(this);
76 return tmp;
77 }
78
79 Iterator operator++(int) {
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
87 PointerProxy operator->() const {
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 std::string name() const;
99 std::string linkage_name() const;
105 result<int64_t> address() const;
115 result<uint64_t> size() const;
121 bool is_constexpr() const;
124 debug_location_t debug_location() const;
127 std::unique_ptr<Type> type() const;
130 std::unique_ptr<Scope> scope() const;
133
135 private:
136 std::unique_ptr<details::Variable> impl_;
137};
138
139}
140}
141#endif
This class materializes a scope in which Function, Variable, Type, ... can be defined.
Definition Scope.hpp:32
pointer operator->() const
Definition Variable.hpp:51
Iterator operator++(int)
Definition Variable.hpp:79
Iterator operator--(int)
Definition Variable.hpp:73
PointerProxy operator->() const
Definition Variable.hpp:87
std::unique_ptr< Variable > operator*() const
Iterator(Iterator &&) noexcept
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).
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41