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 - 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_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
51 public:
53 return R.get();
54 }
55
56 private:
57 value_type R;
58
59 template<typename RefT>
60 PointerProxy(RefT&& R) :
61 R(std::forward<RefT>(R)) {
62 } // NOLINT(bugprone-forwarding-reference-overload)
63 };
64
66 Iterator(Iterator&&) noexcept;
67 Iterator(std::unique_ptr<details::LexicalBlockIt> impl);
69
70 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
71 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
72 return !(LHS == RHS);
73 }
74
77
79 Iterator tmp = *static_cast<Iterator*>(this);
80 --*static_cast<Iterator*>(this);
81 return tmp;
82 }
83
85 Iterator tmp = *static_cast<Iterator*>(this);
86 ++*static_cast<Iterator*>(this);
87 return tmp;
88 }
89
90 std::unique_ptr<LexicalBlock> operator*() const;
91
93 return static_cast<const Iterator*>(this)->operator*();
94 }
95
96 private:
97 std::unique_ptr<details::LexicalBlockIt> impl_;
98 };
99
101
102 LexicalBlock(std::unique_ptr<details::LexicalBlock> impl);
103 LexicalBlock() = delete;
105 LexicalBlock(const LexicalBlock&) = delete;
106
109 std::string name() const;
110
113 std::string description() const;
114
117
120
123 uint64_t size() const;
124
127
130
135 std::vector<range_t> ranges() const;
136
138
139 LIEF_LOCAL static std::unique_ptr<LexicalBlock>
140 create(std::unique_ptr<details::LexicalBlock> impl);
141
142 protected:
143 std::unique_ptr<details::LexicalBlock> impl_;
144};
145
146}
147}
148#endif
friend class Iterator
Definition LexicalBlock.hpp:49
pointer operator->() const
Definition LexicalBlock.hpp:52
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:92
LexicalBlock * pointer
Definition LexicalBlock.hpp:43
Iterator operator++(int)
Definition LexicalBlock.hpp:84
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:78
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:100
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:599
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:45
#define LIEF_LOCAL
Definition visibility.h:46