Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Ast/src/Location.cpp
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#include "Luau/Location.h"
3
4
namespace Luau
5
{
6
7
void Position::shift(const Position& start, const Position& oldEnd, const Position& newEnd)
8
{
9
if (*this >= start)
10
{
11
if (this->line > oldEnd.line)
12
this->line += (newEnd.line - oldEnd.line);
13
else
14
{
15
this->line = newEnd.line;
16
this->column += (newEnd.column - oldEnd.column);
17
}
18
}
19
}
20
21
bool Location::encloses(const Location& l) const
22
{
23
return begin <= l.begin && end >= l.end;
24
}
25
26
bool Location::overlaps(const Location& l) const
27
{
28
return (begin <= l.begin && end >= l.begin) || (begin <= l.end && end >= l.end) || (begin >= l.begin && end <= l.end);
29
}
30
31
bool Location::contains(const Position& p) const
32
{
33
return begin <= p && p < end;
34
}
35
36
bool Location::containsClosed(const Position& p) const
37
{
38
return begin <= p && p <= end;
39
}
40
41
void Location::extend(const Location& other)
42
{
43
if (other.begin < begin)
44
begin = other.begin;
45
if (other.end > end)
46
end = other.end;
47
}
48
49
void Location::shift(const Position& start, const Position& oldEnd, const Position& newEnd)
50
{
51
begin.shift(start, oldEnd, newEnd);
52
end.shift(start, oldEnd, newEnd);
53
}
54
55
} // namespace Luau
56
57