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
19#include "LIEF/visibility.h"
20#include "LIEF/iterators.hpp"
21#include "LIEF/optional.hpp"
22#include "LIEF/range.hpp"
23
24#include <memory>
25#include <string>
26#include <cstdint>
27
28namespace LIEF {
29namespace dwarf {
30
31namespace details {
32class LexicalBlock;
33class LexicalBlockIt;
34}
35
38 public:
39 class Iterator final
40 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
41 LexicalBlock, std::ptrdiff_t,
42 const LexicalBlock*, const LexicalBlock&> {
43 public:
44 using implementation = details::LexicalBlockIt;
45 using iterator_facade_base::operator++;
46 using iterator_facade_base::operator--;
47
49
50 LIEF_API Iterator(std::unique_ptr<details::LexicalBlockIt> impl);
51
54
56 LIEF_API Iterator& operator=(Iterator&&) noexcept;
57
59
60 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
61 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
62 return !(LHS == RHS);
63 }
64
65 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
67
68 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
70
72
73 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74 LIEF_API const LexicalBlock* operator->() const LIEF_LIFETIMEBOUND;
75
78 LIEF_API std::unique_ptr<LexicalBlock> yield();
79
80 private:
81 void load() const;
82
83 std::unique_ptr<details::LexicalBlockIt> impl_;
84 mutable std::unique_ptr<LexicalBlock> cached_;
85 };
86
88
89 LexicalBlock(std::unique_ptr<details::LexicalBlock> impl);
90 LexicalBlock() = delete;
91 LexicalBlock& operator=(const LexicalBlock&) = delete;
92 LexicalBlock(const LexicalBlock&) = delete;
93
96 std::string name() const;
97
100 std::string description() const;
101
104
106 optional<uint64_t> addr() const;
107
110 uint64_t size() const;
111
113 optional<uint64_t> low_pc() const;
114
116 optional<uint64_t> high_pc() const;
117
122 std::vector<range_t> ranges() const;
123
125
126 LIEF_LOCAL static std::unique_ptr<LexicalBlock>
127 create(std::unique_ptr<details::LexicalBlock> impl);
128
129 protected:
130 std::unique_ptr<details::LexicalBlock> impl_;
131};
132
133}
134}
135#endif
Definition LexicalBlock.hpp:42
details::LexicalBlockIt implementation
Definition LexicalBlock.hpp:44
const LexicalBlock & operator*() const
std::unique_ptr< LexicalBlock > yield()
Transfer ownership of the lexical block at the current position to the caller. Returns nullptr if the...
Iterator & operator=(const Iterator &)
Iterator(Iterator &&) noexcept
Iterator(std::unique_ptr< details::LexicalBlockIt > impl)
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:87
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.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:729
Definition iterators.hpp:601
Definition optional.hpp:23
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DWARF/CompilationUnit.hpp:32
Namespace for the DWARF debug format.
Definition DWARF/CompilationUnit.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:41
Definition range.hpp:23
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46