49 bool contains(
unsigned line,
unsigned column)
const;
67 IntervalTree() =
default;
68 ~IntervalTree() =
default;
71 IntervalTree(
const IntervalTree &) =
delete;
72 IntervalTree &operator=(
const IntervalTree &) =
delete;
85 std::vector<AstViewNode *>
query(
unsigned line,
unsigned column)
const;
94 unsigned endLine,
unsigned endColumn)
const;
97 std::size_t
size()
const {
return intervals_.size(); }
107 std::vector<Interval> byBegin;
108 std::vector<Interval> byEndDescending;
109 std::unique_ptr<QueryNode> left;
110 std::unique_ptr<QueryNode> right;
113 std::vector<Interval> intervals_;
114 std::unique_ptr<QueryNode> queryRoot_;
115 bool finalized_ =
false;
117 static std::unique_ptr<QueryNode>
118 buildQueryTree(std::vector<Interval> intervals);
119 static void queryPoint(
const QueryNode *node, SourcePoint point,
120 std::vector<AstViewNode *> &results);
121 static SourcePoint beginPoint(
const Interval &interval);
122 static SourcePoint endPoint(
const Interval &interval);
123 static bool pointLess(SourcePoint lhs, SourcePoint rhs);
124 static bool startsAfter(
const Interval &interval, SourcePoint point);
125 static bool endsBefore(
const Interval &interval, SourcePoint point);
126 static bool intervalEndGreater(
const Interval &lhs,
const Interval &rhs);
128 unsigned getDepth(AstViewNode *node)
const;
135class SourceLocationIndex {
137 SourceLocationIndex() =
default;
138 ~SourceLocationIndex() =
default;
141 SourceLocationIndex(
const SourceLocationIndex &) =
delete;
142 SourceLocationIndex &operator=(
const SourceLocationIndex &) =
delete;
158 unsigned column)
const;
168 unsigned beginColumn,
170 unsigned endColumn)
const;
182 std::map<FileID, IntervalTree> trees_;
Centralized file registry with path-to-FileID mapping.
std::size_t FileID
Type-safe identifier for registered files. 0 is reserved for invalid.
Represents node in AST tree hierarchy.
AstViewNode * queryFirstContained(unsigned beginLine, unsigned beginColumn, unsigned endLine, unsigned endColumn) const
Find first interval fully contained within a range.
void finalize()
Sort intervals by start position (call once after all inserts).
std::size_t size() const
Get total number of intervals.
std::vector< AstViewNode * > query(unsigned line, unsigned column) const
Find all intervals containing a point.
void insert(Interval interval)
Add interval to collection (not sorted yet).
void finalize()
Finalize all interval trees (call after all nodes added).
void addNode(AstViewNode *node)
Add node to index.
std::size_t getFileCount() const
Get number of files in index.
std::vector< AstViewNode * > getNodesAt(FileID fileId, unsigned line, unsigned column) const
Query nodes at specific source position.
bool hasFile(FileID fileId) const
Check whether the current TU AST contains any indexed nodes for a file.
std::size_t getTotalIntervals() const
Get total number of intervals across all files.
AstViewNode * getFirstNodeContainedInRange(FileID fileId, unsigned beginLine, unsigned beginColumn, unsigned endLine, unsigned endColumn) const
Query first node fully contained within a range.
Represents an interval in source code with associated AST node.
bool operator<(const Interval &other) const
Compare intervals by start position for sorting.
bool contains(unsigned line, unsigned column) const
Check if interval contains a point.