mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Fix + json encoder
This commit is contained in:
parent
50847e134f
commit
e399794562
3 changed files with 26 additions and 21 deletions
|
@ -776,7 +776,10 @@ struct AstJsonEncoder : public AstVisitor
|
||||||
writeNode(node, "AstTypeReference", [&]() {
|
writeNode(node, "AstTypeReference", [&]() {
|
||||||
if (node->prefix)
|
if (node->prefix)
|
||||||
PROP(prefix);
|
PROP(prefix);
|
||||||
|
if (node->prefixLocation)
|
||||||
|
write("prefixLocation", *node->prefixLocation);
|
||||||
PROP(name);
|
PROP(name);
|
||||||
|
PROP(nameLocation);
|
||||||
PROP(parameters);
|
PROP(parameters);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,15 +94,15 @@ public:
|
||||||
switch (ptv.type)
|
switch (ptv.type)
|
||||||
{
|
{
|
||||||
case PrimitiveType::NilType:
|
case PrimitiveType::NilType:
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("nil"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("nil"), std::nullopt, Location());
|
||||||
case PrimitiveType::Boolean:
|
case PrimitiveType::Boolean:
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("boolean"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("boolean"), std::nullopt, Location());
|
||||||
case PrimitiveType::Number:
|
case PrimitiveType::Number:
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("number"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("number"), std::nullopt, Location());
|
||||||
case PrimitiveType::String:
|
case PrimitiveType::String:
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("string"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("string"), std::nullopt, Location());
|
||||||
case PrimitiveType::Thread:
|
case PrimitiveType::Thread:
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("thread"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("thread"), std::nullopt, Location());
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -110,12 +110,12 @@ public:
|
||||||
|
|
||||||
AstType* operator()(const BlockedType& btv)
|
AstType* operator()(const BlockedType& btv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("*blocked*"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("*blocked*"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
|
|
||||||
AstType* operator()(const PendingExpansionType& petv)
|
AstType* operator()(const PendingExpansionType& petv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("*pending-expansion*"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("*pending-expansion*"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
|
|
||||||
AstType* operator()(const SingletonType& stv)
|
AstType* operator()(const SingletonType& stv)
|
||||||
|
@ -135,7 +135,7 @@ public:
|
||||||
|
|
||||||
AstType* operator()(const AnyType&)
|
AstType* operator()(const AnyType&)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("any"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("any"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const TableType& ttv)
|
AstType* operator()(const TableType& ttv)
|
||||||
{
|
{
|
||||||
|
@ -157,15 +157,16 @@ public:
|
||||||
parameters.data[i] = {{}, rehydrate(ttv.instantiatedTypePackParams[i])};
|
parameters.data[i] = {{}, rehydrate(ttv.instantiatedTypePackParams[i])};
|
||||||
}
|
}
|
||||||
|
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName(ttv.name->c_str()), parameters.size != 0, parameters);
|
return allocator->alloc<AstTypeReference>(
|
||||||
|
Location(), std::nullopt, AstName(ttv.name->c_str()), std::nullopt, Location(), parameters.size != 0, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSeen(&ttv))
|
if (hasSeen(&ttv))
|
||||||
{
|
{
|
||||||
if (ttv.name)
|
if (ttv.name)
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName(ttv.name->c_str()));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName(ttv.name->c_str()), std::nullopt, Location());
|
||||||
else
|
else
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Cycle>"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Cycle>"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
|
|
||||||
AstArray<AstTableProp> props;
|
AstArray<AstTableProp> props;
|
||||||
|
@ -208,7 +209,7 @@ public:
|
||||||
char* name = allocateString(*allocator, ctv.name);
|
char* name = allocateString(*allocator, ctv.name);
|
||||||
|
|
||||||
if (!options.expandClassProps || hasSeen(&ctv) || count > 1)
|
if (!options.expandClassProps || hasSeen(&ctv) || count > 1)
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{name});
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{name}, std::nullopt, Location());
|
||||||
|
|
||||||
AstArray<AstTableProp> props;
|
AstArray<AstTableProp> props;
|
||||||
props.size = ctv.props.size();
|
props.size = ctv.props.size();
|
||||||
|
@ -233,7 +234,7 @@ public:
|
||||||
RecursionCounter counter(&count);
|
RecursionCounter counter(&count);
|
||||||
|
|
||||||
if (hasSeen(&ftv))
|
if (hasSeen(&ftv))
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Cycle>"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Cycle>"), std::nullopt, Location());
|
||||||
|
|
||||||
AstArray<AstGenericType> generics;
|
AstArray<AstGenericType> generics;
|
||||||
generics.size = ftv.generics.size();
|
generics.size = ftv.generics.size();
|
||||||
|
@ -304,11 +305,12 @@ public:
|
||||||
}
|
}
|
||||||
AstType* operator()(const Unifiable::Error&)
|
AstType* operator()(const Unifiable::Error&)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("Unifiable<Error>"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("Unifiable<Error>"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const GenericType& gtv)
|
AstType* operator()(const GenericType& gtv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName(getName(allocator, syntheticNames, gtv)));
|
return allocator->alloc<AstTypeReference>(
|
||||||
|
Location(), std::nullopt, AstName(getName(allocator, syntheticNames, gtv)), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const Unifiable::Bound<TypeId>& bound)
|
AstType* operator()(const Unifiable::Bound<TypeId>& bound)
|
||||||
{
|
{
|
||||||
|
@ -316,7 +318,7 @@ public:
|
||||||
}
|
}
|
||||||
AstType* operator()(const FreeType& ftv)
|
AstType* operator()(const FreeType& ftv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("free"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("free"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const UnionType& uv)
|
AstType* operator()(const UnionType& uv)
|
||||||
{
|
{
|
||||||
|
@ -342,15 +344,15 @@ public:
|
||||||
}
|
}
|
||||||
AstType* operator()(const LazyType& ltv)
|
AstType* operator()(const LazyType& ltv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Lazy?>"));
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName("<Lazy?>"), std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const UnknownType& ttv)
|
AstType* operator()(const UnknownType& ttv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{"unknown"});
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{"unknown"}, std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const NeverType& ttv)
|
AstType* operator()(const NeverType& ttv)
|
||||||
{
|
{
|
||||||
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{"never"});
|
return allocator->alloc<AstTypeReference>(Location(), std::nullopt, AstName{"never"}, std::nullopt, Location());
|
||||||
}
|
}
|
||||||
AstType* operator()(const NegationType& ntv)
|
AstType* operator()(const NegationType& ntv)
|
||||||
{
|
{
|
||||||
|
|
|
@ -848,10 +848,10 @@ public:
|
||||||
|
|
||||||
bool hasParameterList;
|
bool hasParameterList;
|
||||||
std::optional<AstName> prefix;
|
std::optional<AstName> prefix;
|
||||||
AstName name;
|
|
||||||
AstArray<AstTypeOrPack> parameters;
|
|
||||||
std::optional<Location> prefixLocation;
|
std::optional<Location> prefixLocation;
|
||||||
|
AstName name;
|
||||||
Location nameLocation;
|
Location nameLocation;
|
||||||
|
AstArray<AstTypeOrPack> parameters;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AstTableProp
|
struct AstTableProp
|
||||||
|
|
Loading…
Add table
Reference in a new issue