Add prefix and name location to AstTypeReference

This commit is contained in:
JohnnyMorganz 2023-04-14 17:48:13 +01:00
parent 7345891f6b
commit 50847e134f
3 changed files with 16 additions and 9 deletions

View file

@ -841,8 +841,8 @@ class AstTypeReference : public AstType
public: public:
LUAU_RTTI(AstTypeReference) LUAU_RTTI(AstTypeReference)
AstTypeReference(const Location& location, std::optional<AstName> prefix, AstName name, bool hasParameterList = false, AstTypeReference(const Location& location, std::optional<AstName> prefix, AstName name, std::optional<Location> prefixLocation,
const AstArray<AstTypeOrPack>& parameters = {}); const Location& nameLocation, bool hasParameterList = false, const AstArray<AstTypeOrPack>& parameters = {});
void visit(AstVisitor* visitor) override; void visit(AstVisitor* visitor) override;
@ -850,6 +850,8 @@ public:
std::optional<AstName> prefix; std::optional<AstName> prefix;
AstName name; AstName name;
AstArray<AstTypeOrPack> parameters; AstArray<AstTypeOrPack> parameters;
std::optional<Location> prefixLocation;
Location nameLocation;
}; };
struct AstTableProp struct AstTableProp

View file

@ -753,13 +753,15 @@ void AstStatError::visit(AstVisitor* visitor)
} }
} }
AstTypeReference::AstTypeReference( AstTypeReference::AstTypeReference(const Location& location, std::optional<AstName> prefix, AstName name, std::optional<Location> prefixLocation,
const Location& location, std::optional<AstName> prefix, AstName name, bool hasParameterList, const AstArray<AstTypeOrPack>& parameters) const Location& nameLocation, bool hasParameterList, const AstArray<AstTypeOrPack>& parameters)
: AstType(ClassIndex(), location) : AstType(ClassIndex(), location)
, hasParameterList(hasParameterList) , hasParameterList(hasParameterList)
, prefix(prefix) , prefix(prefix)
, name(name) , name(name)
, parameters(parameters) , parameters(parameters)
, prefixLocation(prefixLocation)
, nameLocation(nameLocation)
{ {
} }

View file

@ -1343,7 +1343,7 @@ AstType* Parser::parseTableType()
AstType* type = parseType(); AstType* type = parseType();
// array-like table type: {T} desugars into {[number]: T} // array-like table type: {T} desugars into {[number]: T}
AstType* index = allocator.alloc<AstTypeReference>(type->location, std::nullopt, nameNumber); AstType* index = allocator.alloc<AstTypeReference>(type->location, std::nullopt, nameNumber, std::nullopt, type->location);
indexer = allocator.alloc<AstTableIndexer>(AstTableIndexer{index, type, type->location}); indexer = allocator.alloc<AstTableIndexer>(AstTableIndexer{index, type, type->location});
break; break;
@ -1449,7 +1449,7 @@ AstType* Parser::parseFunctionTypeTail(const Lexeme& begin, AstArray<AstGenericT
{ {
report(Location(begin.location, lexer.previousLocation()), "Expected '->' after '()' when parsing function type; did you mean 'nil'?"); report(Location(begin.location, lexer.previousLocation()), "Expected '->' after '()' when parsing function type; did you mean 'nil'?");
return allocator.alloc<AstTypeReference>(begin.location, std::nullopt, nameNil); return allocator.alloc<AstTypeReference>(begin.location, std::nullopt, nameNil, std::nullopt, begin.location);
} }
else else
{ {
@ -1493,7 +1493,7 @@ AstType* Parser::parseTypeSuffix(AstType* type, const Location& begin)
{ {
Location loc = lexer.current().location; Location loc = lexer.current().location;
nextLexeme(); nextLexeme();
parts.push_back(allocator.alloc<AstTypeReference>(loc, std::nullopt, nameNil)); parts.push_back(allocator.alloc<AstTypeReference>(loc, std::nullopt, nameNil, std::nullopt, loc));
isUnion = true; isUnion = true;
} }
else if (c == '&') else if (c == '&')
@ -1577,7 +1577,7 @@ AstTypeOrPack Parser::parseSimpleType(bool allowPack)
if (lexer.current().type == Lexeme::ReservedNil) if (lexer.current().type == Lexeme::ReservedNil)
{ {
nextLexeme(); nextLexeme();
return {allocator.alloc<AstTypeReference>(start, std::nullopt, nameNil), {}}; return {allocator.alloc<AstTypeReference>(start, std::nullopt, nameNil, std::nullopt, start), {}};
} }
else if (lexer.current().type == Lexeme::ReservedTrue) else if (lexer.current().type == Lexeme::ReservedTrue)
{ {
@ -1613,6 +1613,7 @@ AstTypeOrPack Parser::parseSimpleType(bool allowPack)
else if (lexer.current().type == Lexeme::Name) else if (lexer.current().type == Lexeme::Name)
{ {
std::optional<AstName> prefix; std::optional<AstName> prefix;
std::optional<Location> prefixLocation;
Name name = parseName("type name"); Name name = parseName("type name");
if (lexer.current().type == '.') if (lexer.current().type == '.')
@ -1621,6 +1622,7 @@ AstTypeOrPack Parser::parseSimpleType(bool allowPack)
nextLexeme(); nextLexeme();
prefix = name.name; prefix = name.name;
prefixLocation = name.location;
name = parseIndexName("field name", pointPosition); name = parseIndexName("field name", pointPosition);
} }
else if (lexer.current().type == Lexeme::Dot3) else if (lexer.current().type == Lexeme::Dot3)
@ -1653,7 +1655,8 @@ AstTypeOrPack Parser::parseSimpleType(bool allowPack)
Location end = lexer.previousLocation(); Location end = lexer.previousLocation();
return {allocator.alloc<AstTypeReference>(Location(start, end), prefix, name.name, hasParameters, parameters), {}}; return {
allocator.alloc<AstTypeReference>(Location(start, end), prefix, name.name, prefixLocation, name.location, hasParameters, parameters), {}};
} }
else if (lexer.current().type == '{') else if (lexer.current().type == '{')
{ {