Skip to content

Commit 7f00619

Browse files
committed
v0.20.2+luau722
1 parent 0ae4de2 commit 7f00619

82 files changed

Lines changed: 6338 additions & 2474 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.20.1+luau720"
3+
version = "0.20.2+luau722"
44
authors = ["Aleksandr Orlenko <zxteam@protonmail.com>"]
55
edition = "2024"
66
repository = "https://github.com/mlua-rs/luau-src-rs"

luau/Ast/include/Luau/Ast.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
22
#pragma once
33

4+
#include "Luau/Common.h"
45
#include "Luau/Location.h"
6+
#include "Luau/Variant.h"
57

68
#include <iterator>
79
#include <optional>
@@ -11,6 +13,8 @@
1113
#include <string.h>
1214
#include <stdint.h>
1315

16+
LUAU_FASTFLAG(DebugLuauUserDefinedClasses)
17+
1418
namespace Luau
1519
{
1620

@@ -1085,6 +1089,40 @@ struct AstDeclaredExternTypeProperty
10851089
AstTableAccess access = AstTableAccess::ReadWrite;
10861090
};
10871091

1092+
struct AstClassProperty
1093+
{
1094+
Location qualifierLocation;
1095+
AstName name;
1096+
Location nameLocation;
1097+
std::optional<Location> typeColonLocation = std::nullopt;
1098+
AstType* ty = nullptr;
1099+
};
1100+
1101+
struct AstClassMethod
1102+
{
1103+
std::optional<Location> qualifierLocation;
1104+
Location keywordLocation;
1105+
AstName functionName;
1106+
Location nameLocation;
1107+
AstExprFunction* function;
1108+
};
1109+
1110+
using AstClassMember = Variant<AstClassProperty, AstClassMethod>;
1111+
1112+
class AstStatClass : public AstStat
1113+
{
1114+
public:
1115+
LUAU_RTTI(AstStatClass)
1116+
1117+
AstLocal* name;
1118+
AstArray<AstClassMember> members;
1119+
bool exported;
1120+
1121+
AstStatClass(const Location& location, AstLocal* name, AstArray<AstClassMember> members, bool exported);
1122+
1123+
void visit(AstVisitor* visitor) override;
1124+
};
1125+
10881126
struct AstTableIndexer
10891127
{
10901128
AstType* indexType;
@@ -1580,6 +1618,11 @@ class AstVisitor
15801618
{
15811619
return visit(static_cast<AstStat*>(node));
15821620
}
1621+
virtual bool visit(class AstStatClass* node)
1622+
{
1623+
LUAU_ASSERT(FFlag::DebugLuauUserDefinedClasses);
1624+
return visit(static_cast<AstStat*>(node));
1625+
}
15831626
virtual bool visit(class AstStatDeclareExternType* node)
15841627
{
15851628
return visit(static_cast<AstStat*>(node));

luau/Ast/include/Luau/Cst.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ class CstNode
5151
const int classIndex;
5252
};
5353

54+
class CstExprGroup : public CstNode
55+
{
56+
public:
57+
LUAU_CST_RTTI(CstExprGroup)
58+
59+
explicit CstExprGroup(Position closePosition);
60+
61+
Position closePosition;
62+
};
63+
5464
class CstExprConstantNumber : public CstNode
5565
{
5666
public:
@@ -506,6 +516,16 @@ class CstTypeSingletonString : public CstNode
506516
unsigned int blockDepth;
507517
};
508518

519+
class CstTypeGroup : public CstNode
520+
{
521+
public:
522+
LUAU_CST_RTTI(CstTypeGroup)
523+
524+
CstTypeGroup(Position closePosition);
525+
526+
Position closePosition;
527+
};
528+
509529
class CstTypePackExplicit : public CstNode
510530
{
511531
public:

luau/Ast/include/Luau/Location.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
22
#pragma once
33

4+
#include <climits>
5+
46
namespace Luau
57
{
68

@@ -14,6 +16,11 @@ struct Position
1416
{
1517
}
1618

19+
static Position missing()
20+
{
21+
return {UINT_MAX, UINT_MAX};
22+
}
23+
1724
bool operator==(const Position& rhs) const
1825
{
1926
return this->column == rhs.column && this->line == rhs.line;
@@ -47,6 +54,11 @@ struct Position
4754
}
4855

4956
void shift(const Position& start, const Position& oldEnd, const Position& newEnd);
57+
58+
bool hasValue() const
59+
{
60+
return line != UINT_MAX || column != UINT_MAX;
61+
}
5062
};
5163

5264
struct Location

luau/Ast/include/Luau/Parser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Parser
146146
AstExpr* parseFunctionName(bool& hasself, AstName& debugname);
147147

148148
// function funcname funcbody
149-
LUAU_FORCEINLINE AstStat* parseFunctionStat(const AstArray<AstAttr*>& attributes = {nullptr, 0});
149+
LUAU_FORCEINLINE AstStatFunction* parseFunctionStat(const AstArray<AstAttr*>& attributes = {nullptr, 0});
150150

151151
std::optional<AstAttr::Type> validateAttribute(
152152
Location loc,
@@ -178,6 +178,8 @@ class Parser
178178
// type Name `=' Type
179179
AstStat* parseTypeAlias(const Location& start, bool exported, Position typeKeywordPosition);
180180

181+
AstStat* parseClassStat(const Location& start, bool exported);
182+
181183
// type function Name ... end
182184
AstStat* parseTypeFunction(const Location& start, bool exported, Position typeKeywordPosition);
183185

@@ -514,6 +516,7 @@ class Parser
514516

515517
DenseHashMap<AstName, AstLocal*> localMap;
516518
std::vector<AstLocal*> localStack;
519+
DenseHashSet<AstName> classesWithinModule{{}};
517520

518521
std::vector<ParseError> parseErrors;
519522

@@ -534,6 +537,7 @@ class Parser
534537
std::vector<AstType*> scratchType;
535538
std::vector<AstTypeOrPack> scratchTypeOrPack;
536539
std::vector<AstDeclaredExternTypeProperty> scratchDeclaredClassProps;
540+
std::vector<AstClassMember> scratchClassDeclarations;
537541
std::vector<AstExprTable::Item> scratchItem;
538542
std::vector<CstExprTable::Item> scratchCstItem;
539543
std::vector<AstArgumentName> scratchArgName;

luau/Ast/include/Luau/PrettyPrinter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ std::string prettyPrint(AstStatBlock& ast);
2727
std::string prettyPrintWithTypes(AstStatBlock& block);
2828
std::string prettyPrintWithTypes(AstStatBlock& block, const CstNodeMap& cstNodeMap);
2929

30-
// Only fails when parsing fails
31-
PrettyPrintResult prettyPrint(std::string_view source, ParseOptions options = ParseOptions{}, bool withTypes = false);
30+
// Only fails when parsing fails and we're not ignoring parse errors.
31+
PrettyPrintResult prettyPrint(std::string_view source, ParseOptions options = ParseOptions{}, bool withTypes = false, bool ignoreParseErrors = false);
3232

3333
} // namespace Luau

luau/Ast/src/Ast.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,40 @@ AstStatDeclareFunction::AstStatDeclareFunction(
978978
{
979979
}
980980

981+
AstStatClass::AstStatClass(const Location& location, AstLocal* name, AstArray<AstClassMember> members, bool exported)
982+
: AstStat(ClassIndex(), location)
983+
, name(name)
984+
, members(members)
985+
, exported(exported)
986+
{
987+
LUAU_ASSERT(FFlag::DebugLuauUserDefinedClasses);
988+
}
989+
990+
void AstStatClass::visit(AstVisitor* visitor)
991+
{
992+
LUAU_ASSERT(FFlag::DebugLuauUserDefinedClasses);
993+
if (visitor->visit(this))
994+
{
995+
for (const auto& member : members)
996+
{
997+
Luau::visit(
998+
overloaded{
999+
[&](const AstClassProperty& prop)
1000+
{
1001+
if (prop.ty)
1002+
prop.ty->visit(visitor);
1003+
},
1004+
[&](const AstClassMethod& method)
1005+
{
1006+
method.function->visit(visitor);
1007+
}
1008+
},
1009+
member
1010+
);
1011+
}
1012+
}
1013+
}
1014+
9811015
AstStatDeclareFunction::AstStatDeclareFunction(
9821016
const Location& location,
9831017
const AstArray<AstAttr*>& attributes,

luau/Ast/src/Cst.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
#include "Luau/Cst.h"
44
#include "Luau/Common.h"
55

6+
LUAU_FASTFLAG(LuauCstExprGroup)
7+
LUAU_FASTFLAG(LuauCstTypeGroup)
8+
69
namespace Luau
710
{
811

912
int gCstRttiIndex = 0;
1013

14+
CstExprGroup::CstExprGroup(Position closePosition)
15+
: CstNode(CstClassIndex())
16+
, closePosition(closePosition)
17+
{
18+
LUAU_ASSERT(FFlag::LuauCstExprGroup);
19+
}
20+
1121
CstExprConstantNumber::CstExprConstantNumber(const AstArray<char>& value)
1222
: CstNode(CstClassIndex())
1323
, value(value)
@@ -281,6 +291,13 @@ CstTypeSingletonString::CstTypeSingletonString(AstArray<char> sourceString, CstE
281291
LUAU_ASSERT(quoteStyle != CstExprConstantString::QuotedInterp);
282292
}
283293

294+
CstTypeGroup::CstTypeGroup(Position closePosition)
295+
: CstNode(CstClassIndex())
296+
, closePosition(closePosition)
297+
{
298+
LUAU_ASSERT(FFlag::LuauCstTypeGroup);
299+
}
300+
284301
CstTypePackExplicit::CstTypePackExplicit()
285302
: CstNode(CstClassIndex())
286303
, hasParentheses(false)

0 commit comments

Comments
 (0)