Bash++
Bash++ compiler internal documentation
EntityMap.h
Go to the documentation of this file.
1
7#pragma once
8#include <optional>
9#include <memory>
10#include "IntervalTree.h"
11
12
13// Forward decl.
14namespace bpp {
15class bpp_entity;
16}
17
28 uint32_t line;
29 uint32_t column;
30
31 operator uint64_t() const {
32 // Encode line and column into a single uint64_t
33 // The first 32 bits represent the line number,
34 // and the last 32 bits represent the column number.
35 // This permits perfect sorting of file positions
36 return (static_cast<uint64_t>(line) << 32) | column;
37 }
38
39 FilePosition(uint32_t line, uint32_t column)
40 : line(line), column(column) {}
41};
42
55class EntityMap {
56 private:
58 public:
59
63 void insert(FilePosition start, FilePosition end, const std::shared_ptr<bpp::bpp_entity>& entity) {
64 tree.insert(start, end, entity);
65 }
66
67 std::shared_ptr<bpp::bpp_entity> find(FilePosition point) {
68 return tree.find_innermost_overlap(point);
69 }
70
74 std::shared_ptr<bpp::bpp_entity> find(uint32_t line, uint32_t column) {
75 return find(FilePosition(line, column));
76 }
77};
A map of file positions to Bash++ container entities.
Definition EntityMap.h:55
void insert(FilePosition start, FilePosition end, const std::shared_ptr< bpp::bpp_entity > &entity)
Add an entity to the entity map.
Definition EntityMap.h:63
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:74
FlatIntervalTree< std::shared_ptr< bpp::bpp_entity > > tree
Definition EntityMap.h:57
std::shared_ptr< bpp::bpp_entity > find(FilePosition point)
Definition EntityMap.h:67
A specialized implementation of an Interval Tree optimized for Bash++'s particular use case.
Definition IntervalTree.h:39
void insert(uint64_t low, uint64_t high, T payload)
Definition IntervalTree.h:64
T find_innermost_overlap(uint64_t point)
Find the innermost interval that overlaps a given point.
Definition IntervalTree.h:79
Definition bash_case.cpp:9
Represents a position in a source file by line and column.
Definition EntityMap.h:27
uint32_t line
Definition EntityMap.h:28
FilePosition(uint32_t line, uint32_t column)
Definition EntityMap.h:39
uint32_t column
Definition EntityMap.h:29