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
27 uint32_t line;
28 uint32_t column;
29
30 operator uint64_t() const {
31 // Encode line and column into a single uint64_t
32 // The first 32 bits represent the line number,
33 // and the last 32 bits represent the column number.
34 // This permits perfect sorting of file positions
35 return (static_cast<uint64_t>(line) << 32) | column;
36 }
37
38 FilePosition(uint32_t line, uint32_t column)
39 : line(line), column(column) {}
40};
41
54class EntityMap {
55 private:
57 public:
58
62 void insert(FilePosition start, FilePosition end, const std::shared_ptr<bpp::bpp_entity>& entity) {
63 tree.insert(start, end, entity);
64 }
65
66 std::shared_ptr<bpp::bpp_entity> find(FilePosition point) {
67 return tree.find_innermost_overlap(point);
68 }
69
73 std::shared_ptr<bpp::bpp_entity> find(uint32_t line, uint32_t column) {
74 return find(FilePosition(line, column));
75 }
76};
A map of file positions to Bash++ container entities.
Definition EntityMap.h:54
void insert(FilePosition start, FilePosition end, const std::shared_ptr< bpp::bpp_entity > &entity)
Add an entity to the entity map.
Definition EntityMap.h:62
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:73
FlatIntervalTree< std::shared_ptr< bpp::bpp_entity > > tree
Definition EntityMap.h:56
std::shared_ptr< bpp::bpp_entity > find(FilePosition point)
Definition EntityMap.h:66
A specialized implementation of an Interval Tree optimized for Bash++'s particular use case.
Definition IntervalTree.h:38
void insert(uint64_t low, uint64_t high, T payload)
Definition IntervalTree.h:63
T find_innermost_overlap(uint64_t point)
Find the innermost interval that overlaps a given point.
Definition IntervalTree.h:78
Definition bash_case.cpp:8
Represents a position in a source file by line and column.
Definition EntityMap.h:26
uint32_t line
Definition EntityMap.h:27
FilePosition(uint32_t line, uint32_t column)
Definition EntityMap.h:38
uint32_t column
Definition EntityMap.h:28