Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/Analysis/src/RecursionCounter.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
3
#include "Luau/RecursionCounter.h"
4
#include "Luau/Error.h"
5
6
namespace Luau
7
{
8
9
RecursionLimitException::RecursionLimitException(const std::string& system)
10
: InternalCompilerError("Internal recursion counter limit exceeded in " + system)
11
{
12
}
13
14
RecursionCounter::RecursionCounter(int* count)
15
: count(count)
16
{
17
++(*count);
18
}
19
20
RecursionCounter::~RecursionCounter()
21
{
22
LUAU_ASSERT(*count > 0);
23
--(*count);
24
}
25
26
RecursionLimiter::RecursionLimiter(const std::string& system, int* count, int limit)
27
: RecursionCounter(count)
28
{
29
if (!nativeStackGuard.isOk())
30
{
31
throw InternalCompilerError("Stack overflow in " + system);
32
}
33
34
if (limit > 0 && *count > limit)
35
{
36
throw RecursionLimitException(system);
37
}
38
}
39
40
NonExceptionalRecursionLimiter::NonExceptionalRecursionLimiter(int* count)
41
: RecursionCounter(count)
42
{
43
}
44
45
bool NonExceptionalRecursionLimiter::isOk(int limit) const
46
{
47
return nativeStackGuard.isOk() && !(limit > 0 && *count > limit);
48
}
49
50
} // namespace Luau
51
52