Bash++
Bash++ compiler internal documentation
EntityMap.h
Go to the documentation of this file.
1
6#pragma once
7#include <optional>
8#include <memory>
9#include "IntervalTree.h"
10
11
12// Forward decl.
13namespace bpp {
14class bpp_entity;
15}
16
18 uint32_t line;
19 uint32_t column;
20
21 operator uint64_t() const {
22 // Encode line and column into a single uint64_t
23 // The first 32 bits represent the line number,
24 // and the last 32 bits represent the column number.
25 // This permits perfect sorting of file positions
26 return (static_cast<uint64_t>(line) << 32) | column;
27 }
28
29 FilePosition(uint32_t line, uint32_t column)
30 : line(line), column(column) {}
31};
32
33class EntityMap {
34 private:
36 public:
37
41 void insert(FilePosition start, FilePosition end, const std::shared_ptr<bpp::bpp_entity>& entity) {
42 tree.insert(start, end, entity);
43 }
44
45 std::shared_ptr<bpp::bpp_entity> find(FilePosition point) {
46 return tree.find_innermost_overlap(point);
47 }
48
52 std::shared_ptr<bpp::bpp_entity> find(uint32_t line, uint32_t column) {
53 return find(FilePosition(line, column));
54 }
55};
Definition EntityMap.h:33
void insert(FilePosition start, FilePosition end, const std::shared_ptr< bpp::bpp_entity > &entity)
Add an entity to the entity map.
Definition EntityMap.h:41
IntervalTree< std::shared_ptr< bpp::bpp_entity > > tree
Definition EntityMap.h:35
std::shared_ptr< bpp::bpp_entity > find(uint32_t line, uint32_t column)
Find the active code entity at a specific line and column.
Definition EntityMap.h:52
std::shared_ptr< bpp::bpp_entity > find(FilePosition point)
Definition EntityMap.h:45
A specialized implementation of an Interval Tree for Bash++'s particular use case.
Definition IntervalTree.h:91
T find_innermost_overlap(uint64_t point)
Find the innermost interval that contains the given point.
Definition IntervalTree.h:190
void insert(uint64_t low, uint64_t high, T payload)
Definition IntervalTree.h:159
Definition bash_case.cpp:8
Definition EntityMap.h:17
uint32_t line
Definition EntityMap.h:18
FilePosition(uint32_t line, uint32_t column)
Definition EntityMap.h:29
uint32_t column
Definition EntityMap.h:19