LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
LexicalBlock.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 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_LEXICAL_BLOCK_H
16#define LIEF_DWARF_LEXICAL_BLOCK_H
17
18#include "LIEF/visibility.h"
19#include "LIEF/iterators.hpp"
20#include "LIEF/optional.hpp"
21#include "LIEF/range.hpp"
22
23#include <memory>
24#include <string>
25#include <cstdint>
26
27namespace LIEF {
28namespace dwarf {
29
30namespace details {
31class LexicalBlock;
32class LexicalBlockIt;
33}
34
37 public:
39 public:
40 using iterator_category = std::bidirectional_iterator_tag;
41 using value_type = std::unique_ptr<LexicalBlock>;
42 using difference_type = std::ptrdiff_t;
44 using reference = std::unique_ptr<LexicalBlock>&;
45 using implementation = details::LexicalBlockIt;
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
61 Iterator(Iterator&&) noexcept;
62 Iterator(std::unique_ptr<details::LexicalBlockIt> 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<LexicalBlock> operator*() const;
86
88 return static_cast<const Iterator*>(this)->operator*();
89 }
90
91 private:
92 std::unique_ptr<details::LexicalBlockIt> impl_;
93 };
94
96
97 LexicalBlock(std::unique_ptr<details::LexicalBlock> impl);
98 LexicalBlock() = delete;
100 LexicalBlock(const LexicalBlock&) = delete;
101
104 std::string name() const;
105
108 std::string description() const;
109
112
115
118 uint64_t size() const;
119
122
125
130 std::vector<range_t> ranges() const;
131
133
134 LIEF_LOCAL static
135 std::unique_ptr<LexicalBlock> create(std::unique_ptr<details::LexicalBlock> impl);
136
137 protected:
138 std::unique_ptr<details::LexicalBlock> impl_;
139};
140
141}
142}
143#endif
friend class Iterator
Definition LexicalBlock.hpp:49
pointer operator->() const
Definition LexicalBlock.hpp:51
details::LexicalBlockIt implementation
Definition LexicalBlock.hpp:45
std::unique_ptr< LexicalBlock > value_type
Definition LexicalBlock.hpp:41
std::unique_ptr< LexicalBlock > operator*() const
PointerProxy operator->() const
Definition LexicalBlock.hpp:87
LexicalBlock * pointer
Definition LexicalBlock.hpp:43
Iterator operator++(int)
Definition LexicalBlock.hpp:79
std::unique_ptr< LexicalBlock > & reference
Definition LexicalBlock.hpp:44
std::ptrdiff_t difference_type
Definition LexicalBlock.hpp:42
Iterator(Iterator &&) noexcept
Iterator operator--(int)
Definition LexicalBlock.hpp:73
std::bidirectional_iterator_tag iterator_category
Definition LexicalBlock.hpp:40
LexicalBlock(std::unique_ptr< details::LexicalBlock > impl)
optional< uint64_t > addr() const
Return the start address of this block.
std::vector< range_t > ranges() const
Return a list of address ranges owned by this block.
optional< uint64_t > high_pc() const
Return the highest virtual address owned by this block.
sub_blocks_it sub_blocks() const
Return an iterator over the sub-LexicalBlock owned by this block.
uint64_t size() const
Return the size of this block as the difference of the highest address and the lowest address.
iterator_range< Iterator > sub_blocks_it
Definition LexicalBlock.hpp:95
LexicalBlock & operator=(const LexicalBlock &)=delete
LexicalBlock(const LexicalBlock &)=delete
optional< uint64_t > low_pc() const
Return the lowest virtual address owned by this block.
static std::unique_ptr< LexicalBlock > create(std::unique_ptr< details::LexicalBlock > impl)
std::string description() const
Return the description associated with this lexical block or an empty string.
std::string name() const
Return the name associated with this lexical block or an empty string.
Definition iterators.hpp:486
Definition optional.hpp:23
Definition DWARF/CompilationUnit.hpp:30
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:28
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42