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:
38 class Iterator final
39 : public iterator_facade_base<Iterator, std::bidirectional_iterator_tag,
40 LexicalBlock, std::ptrdiff_t,
41 const LexicalBlock*, const LexicalBlock&> {
42 public:
43 using implementation = details::LexicalBlockIt;
44 using iterator_facade_base::operator++;
45 using iterator_facade_base::operator--;
46
48
49 LIEF_API Iterator(std::unique_ptr<details::LexicalBlockIt> impl);
50
53
55 LIEF_API Iterator& operator=(Iterator&&) noexcept;
56
58
59 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
60 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
61 return !(LHS == RHS);
62 }
63
64 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
66
67 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
69
71
72 // NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
74
77 LIEF_API std::unique_ptr<LexicalBlock> yield();
78
79 private:
80 void load() const;
81
82 std::unique_ptr<details::LexicalBlockIt> impl_;
83 mutable std::unique_ptr<LexicalBlock> cached_;
84 };
85
87
88 LexicalBlock(std::unique_ptr<details::LexicalBlock> impl);
89 LexicalBlock() = delete;
91 LexicalBlock(const LexicalBlock&) = delete;
92
95 std::string name() const;
96
99 std::string description() const;
100
103
106
109 uint64_t size() const;
110
113
116
121 std::vector<range_t> ranges() const;
122
124
125 LIEF_LOCAL static std::unique_ptr<LexicalBlock>
126 create(std::unique_ptr<details::LexicalBlock> impl);
127
128 protected:
129 std::unique_ptr<details::LexicalBlock> impl_;
130};
131
132}
133}
134#endif
details::LexicalBlockIt implementation
Definition LexicalBlock.hpp:43
const LexicalBlock * operator->() const
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:86
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.
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
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