@@ -120,20 +120,6 @@ struct AstTypeList
120120
121121using AstArgumentName = std::pair<AstName, Location>; // TODO: remove and replace when we get a common struct for this pair instead of AstName
122122
123- struct AstGenericType
124- {
125- AstName name;
126- Location location;
127- AstType* defaultValue = nullptr ;
128- };
129-
130- struct AstGenericTypePack
131- {
132- AstName name;
133- Location location;
134- AstTypePack* defaultValue = nullptr ;
135- };
136-
137123extern int gAstRttiIndex ;
138124
139125template <typename T>
@@ -253,6 +239,32 @@ class AstStat : public AstNode
253239 bool hasSemicolon;
254240};
255241
242+ class AstGenericType : public AstNode
243+ {
244+ public:
245+ LUAU_RTTI (AstGenericType)
246+
247+ explicit AstGenericType (const Location& location, AstName name, AstType* defaultValue = nullptr );
248+
249+ void visit (AstVisitor* visitor) override ;
250+
251+ AstName name;
252+ AstType* defaultValue = nullptr ;
253+ };
254+
255+ class AstGenericTypePack : public AstNode
256+ {
257+ public:
258+ LUAU_RTTI (AstGenericTypePack)
259+
260+ explicit AstGenericTypePack (const Location& location, AstName name, AstTypePack* defaultValue = nullptr );
261+
262+ void visit (AstVisitor* visitor) override ;
263+
264+ AstName name;
265+ AstTypePack* defaultValue = nullptr ;
266+ };
267+
256268class AstExprGroup : public AstExpr
257269{
258270public:
@@ -424,8 +436,8 @@ class AstExprFunction : public AstExpr
424436 AstExprFunction (
425437 const Location& location,
426438 const AstArray<AstAttr*>& attributes,
427- const AstArray<AstGenericType>& generics,
428- const AstArray<AstGenericTypePack>& genericPacks,
439+ const AstArray<AstGenericType* >& generics,
440+ const AstArray<AstGenericTypePack* >& genericPacks,
429441 AstLocal* self,
430442 const AstArray<AstLocal*>& args,
431443 bool vararg,
@@ -443,8 +455,8 @@ class AstExprFunction : public AstExpr
443455 bool hasNativeAttribute () const ;
444456
445457 AstArray<AstAttr*> attributes;
446- AstArray<AstGenericType> generics;
447- AstArray<AstGenericTypePack> genericPacks;
458+ AstArray<AstGenericType* > generics;
459+ AstArray<AstGenericTypePack* > genericPacks;
448460 AstLocal* self;
449461 AstArray<AstLocal*> args;
450462 std::optional<AstTypeList> returnAnnotation;
@@ -857,8 +869,8 @@ class AstStatTypeAlias : public AstStat
857869 const Location& location,
858870 const AstName& name,
859871 const Location& nameLocation,
860- const AstArray<AstGenericType>& generics,
861- const AstArray<AstGenericTypePack>& genericPacks,
872+ const AstArray<AstGenericType* >& generics,
873+ const AstArray<AstGenericTypePack* >& genericPacks,
862874 AstType* type,
863875 bool exported
864876 );
@@ -867,8 +879,8 @@ class AstStatTypeAlias : public AstStat
867879
868880 AstName name;
869881 Location nameLocation;
870- AstArray<AstGenericType> generics;
871- AstArray<AstGenericTypePack> genericPacks;
882+ AstArray<AstGenericType* > generics;
883+ AstArray<AstGenericTypePack* > genericPacks;
872884 AstType* type;
873885 bool exported;
874886};
@@ -911,8 +923,8 @@ class AstStatDeclareFunction : public AstStat
911923 const Location& location,
912924 const AstName& name,
913925 const Location& nameLocation,
914- const AstArray<AstGenericType>& generics,
915- const AstArray<AstGenericTypePack>& genericPacks,
926+ const AstArray<AstGenericType* >& generics,
927+ const AstArray<AstGenericTypePack* >& genericPacks,
916928 const AstTypeList& params,
917929 const AstArray<AstArgumentName>& paramNames,
918930 bool vararg,
@@ -925,8 +937,8 @@ class AstStatDeclareFunction : public AstStat
925937 const AstArray<AstAttr*>& attributes,
926938 const AstName& name,
927939 const Location& nameLocation,
928- const AstArray<AstGenericType>& generics,
929- const AstArray<AstGenericTypePack>& genericPacks,
940+ const AstArray<AstGenericType* >& generics,
941+ const AstArray<AstGenericTypePack* >& genericPacks,
930942 const AstTypeList& params,
931943 const AstArray<AstArgumentName>& paramNames,
932944 bool vararg,
@@ -942,8 +954,8 @@ class AstStatDeclareFunction : public AstStat
942954 AstArray<AstAttr*> attributes;
943955 AstName name;
944956 Location nameLocation;
945- AstArray<AstGenericType> generics;
946- AstArray<AstGenericTypePack> genericPacks;
957+ AstArray<AstGenericType* > generics;
958+ AstArray<AstGenericTypePack* > genericPacks;
947959 AstTypeList params;
948960 AstArray<AstArgumentName> paramNames;
949961 bool vararg = false ;
@@ -1074,8 +1086,8 @@ class AstTypeFunction : public AstType
10741086
10751087 AstTypeFunction (
10761088 const Location& location,
1077- const AstArray<AstGenericType>& generics,
1078- const AstArray<AstGenericTypePack>& genericPacks,
1089+ const AstArray<AstGenericType* >& generics,
1090+ const AstArray<AstGenericTypePack* >& genericPacks,
10791091 const AstTypeList& argTypes,
10801092 const AstArray<std::optional<AstArgumentName>>& argNames,
10811093 const AstTypeList& returnTypes
@@ -1084,8 +1096,8 @@ class AstTypeFunction : public AstType
10841096 AstTypeFunction (
10851097 const Location& location,
10861098 const AstArray<AstAttr*>& attributes,
1087- const AstArray<AstGenericType>& generics,
1088- const AstArray<AstGenericTypePack>& genericPacks,
1099+ const AstArray<AstGenericType* >& generics,
1100+ const AstArray<AstGenericTypePack* >& genericPacks,
10891101 const AstTypeList& argTypes,
10901102 const AstArray<std::optional<AstArgumentName>>& argNames,
10911103 const AstTypeList& returnTypes
@@ -1096,8 +1108,8 @@ class AstTypeFunction : public AstType
10961108 bool isCheckedFunction () const ;
10971109
10981110 AstArray<AstAttr*> attributes;
1099- AstArray<AstGenericType> generics;
1100- AstArray<AstGenericTypePack> genericPacks;
1111+ AstArray<AstGenericType* > generics;
1112+ AstArray<AstGenericTypePack* > genericPacks;
11011113 AstTypeList argTypes;
11021114 AstArray<std::optional<AstArgumentName>> argNames;
11031115 AstTypeList returnTypes;
@@ -1276,6 +1288,16 @@ class AstVisitor
12761288 return visit (static_cast <AstNode*>(node));
12771289 }
12781290
1291+ virtual bool visit (class AstGenericType * node)
1292+ {
1293+ return visit (static_cast <AstNode*>(node));
1294+ }
1295+
1296+ virtual bool visit (class AstGenericTypePack * node)
1297+ {
1298+ return visit (static_cast <AstNode*>(node));
1299+ }
1300+
12791301 virtual bool visit (class AstExpr * node)
12801302 {
12811303 return visit (static_cast <AstNode*>(node));
0 commit comments