@@ -120,20 +120,6 @@ struct AstTypeList
120
120
121
121
using AstArgumentName = std::pair<AstName, Location>; // TODO: remove and replace when we get a common struct for this pair instead of AstName
122
122
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
-
137
123
extern int gAstRttiIndex ;
138
124
139
125
template <typename T>
@@ -253,6 +239,32 @@ class AstStat : public AstNode
253
239
bool hasSemicolon;
254
240
};
255
241
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
+
256
268
class AstExprGroup : public AstExpr
257
269
{
258
270
public:
@@ -424,8 +436,8 @@ class AstExprFunction : public AstExpr
424
436
AstExprFunction (
425
437
const Location& location,
426
438
const AstArray<AstAttr*>& attributes,
427
- const AstArray<AstGenericType>& generics,
428
- const AstArray<AstGenericTypePack>& genericPacks,
439
+ const AstArray<AstGenericType* >& generics,
440
+ const AstArray<AstGenericTypePack* >& genericPacks,
429
441
AstLocal* self,
430
442
const AstArray<AstLocal*>& args,
431
443
bool vararg,
@@ -443,8 +455,8 @@ class AstExprFunction : public AstExpr
443
455
bool hasNativeAttribute () const ;
444
456
445
457
AstArray<AstAttr*> attributes;
446
- AstArray<AstGenericType> generics;
447
- AstArray<AstGenericTypePack> genericPacks;
458
+ AstArray<AstGenericType* > generics;
459
+ AstArray<AstGenericTypePack* > genericPacks;
448
460
AstLocal* self;
449
461
AstArray<AstLocal*> args;
450
462
std::optional<AstTypeList> returnAnnotation;
@@ -857,8 +869,8 @@ class AstStatTypeAlias : public AstStat
857
869
const Location& location,
858
870
const AstName& name,
859
871
const Location& nameLocation,
860
- const AstArray<AstGenericType>& generics,
861
- const AstArray<AstGenericTypePack>& genericPacks,
872
+ const AstArray<AstGenericType* >& generics,
873
+ const AstArray<AstGenericTypePack* >& genericPacks,
862
874
AstType* type,
863
875
bool exported
864
876
);
@@ -867,8 +879,8 @@ class AstStatTypeAlias : public AstStat
867
879
868
880
AstName name;
869
881
Location nameLocation;
870
- AstArray<AstGenericType> generics;
871
- AstArray<AstGenericTypePack> genericPacks;
882
+ AstArray<AstGenericType* > generics;
883
+ AstArray<AstGenericTypePack* > genericPacks;
872
884
AstType* type;
873
885
bool exported;
874
886
};
@@ -911,8 +923,8 @@ class AstStatDeclareFunction : public AstStat
911
923
const Location& location,
912
924
const AstName& name,
913
925
const Location& nameLocation,
914
- const AstArray<AstGenericType>& generics,
915
- const AstArray<AstGenericTypePack>& genericPacks,
926
+ const AstArray<AstGenericType* >& generics,
927
+ const AstArray<AstGenericTypePack* >& genericPacks,
916
928
const AstTypeList& params,
917
929
const AstArray<AstArgumentName>& paramNames,
918
930
bool vararg,
@@ -925,8 +937,8 @@ class AstStatDeclareFunction : public AstStat
925
937
const AstArray<AstAttr*>& attributes,
926
938
const AstName& name,
927
939
const Location& nameLocation,
928
- const AstArray<AstGenericType>& generics,
929
- const AstArray<AstGenericTypePack>& genericPacks,
940
+ const AstArray<AstGenericType* >& generics,
941
+ const AstArray<AstGenericTypePack* >& genericPacks,
930
942
const AstTypeList& params,
931
943
const AstArray<AstArgumentName>& paramNames,
932
944
bool vararg,
@@ -942,8 +954,8 @@ class AstStatDeclareFunction : public AstStat
942
954
AstArray<AstAttr*> attributes;
943
955
AstName name;
944
956
Location nameLocation;
945
- AstArray<AstGenericType> generics;
946
- AstArray<AstGenericTypePack> genericPacks;
957
+ AstArray<AstGenericType* > generics;
958
+ AstArray<AstGenericTypePack* > genericPacks;
947
959
AstTypeList params;
948
960
AstArray<AstArgumentName> paramNames;
949
961
bool vararg = false ;
@@ -1074,8 +1086,8 @@ class AstTypeFunction : public AstType
1074
1086
1075
1087
AstTypeFunction (
1076
1088
const Location& location,
1077
- const AstArray<AstGenericType>& generics,
1078
- const AstArray<AstGenericTypePack>& genericPacks,
1089
+ const AstArray<AstGenericType* >& generics,
1090
+ const AstArray<AstGenericTypePack* >& genericPacks,
1079
1091
const AstTypeList& argTypes,
1080
1092
const AstArray<std::optional<AstArgumentName>>& argNames,
1081
1093
const AstTypeList& returnTypes
@@ -1084,8 +1096,8 @@ class AstTypeFunction : public AstType
1084
1096
AstTypeFunction (
1085
1097
const Location& location,
1086
1098
const AstArray<AstAttr*>& attributes,
1087
- const AstArray<AstGenericType>& generics,
1088
- const AstArray<AstGenericTypePack>& genericPacks,
1099
+ const AstArray<AstGenericType* >& generics,
1100
+ const AstArray<AstGenericTypePack* >& genericPacks,
1089
1101
const AstTypeList& argTypes,
1090
1102
const AstArray<std::optional<AstArgumentName>>& argNames,
1091
1103
const AstTypeList& returnTypes
@@ -1096,8 +1108,8 @@ class AstTypeFunction : public AstType
1096
1108
bool isCheckedFunction () const ;
1097
1109
1098
1110
AstArray<AstAttr*> attributes;
1099
- AstArray<AstGenericType> generics;
1100
- AstArray<AstGenericTypePack> genericPacks;
1111
+ AstArray<AstGenericType* > generics;
1112
+ AstArray<AstGenericTypePack* > genericPacks;
1101
1113
AstTypeList argTypes;
1102
1114
AstArray<std::optional<AstArgumentName>> argNames;
1103
1115
AstTypeList returnTypes;
@@ -1276,6 +1288,16 @@ class AstVisitor
1276
1288
return visit (static_cast <AstNode*>(node));
1277
1289
}
1278
1290
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
+
1279
1301
virtual bool visit (class AstExpr * node)
1280
1302
{
1281
1303
return visit (static_cast <AstNode*>(node));
0 commit comments