@@ -130,6 +130,16 @@ static void Main(string[] args)
130130 functionsJson = JObject . Load ( jr ) ;
131131 }
132132
133+ JObject variantsJson = null ;
134+ if ( File . Exists ( Path . Combine ( AppContext . BaseDirectory , "variants.json" ) ) )
135+ {
136+ using ( StreamReader fs = File . OpenText ( Path . Combine ( AppContext . BaseDirectory , "variants.json" ) ) )
137+ using ( JsonTextReader jr = new JsonTextReader ( fs ) )
138+ {
139+ variantsJson = JObject . Load ( jr ) ;
140+ }
141+ }
142+
133143 EnumDefinition [ ] enums = typesJson [ "enums" ] . Select ( jt =>
134144 {
135145 JProperty jp = ( JProperty ) jt ;
@@ -195,11 +205,20 @@ static void Main(string[] args)
195205
196206 List < TypeReference > parameters = new List < TypeReference > ( ) ;
197207
208+ // find any variants that can be applied to the parameters of this method based on the method name
209+ JToken variants = variantsJson ? . Children ( ) . Where ( variant => ( ( JProperty ) variant ) . Name == cimguiname ) . FirstOrDefault ( ) ?? null ;
210+
198211 foreach ( JToken p in val [ "argsT" ] )
199212 {
200213 string pType = p [ "type" ] . ToString ( ) ;
201214 string pName = p [ "name" ] . ToString ( ) ;
202- parameters . Add ( new TypeReference ( pName , pType , enums ) ) ;
215+
216+ // if there are possible variants for this method then try to match them based on the parameter name and expected type
217+ var matchingVariant = variants ? . Values ( ) . Where ( v => v [ "name" ] . ToString ( ) == pName && v [ "type" ] . ToString ( ) == pType ) . FirstOrDefault ( ) ?? null ;
218+ // if there was a match to this name and type then apply those variants to this parameter
219+ string [ ] pVariants = matchingVariant ? [ "variants" ] . Values ( ) . Select ( variant => variant . ToString ( ) ) . ToArray ( ) ?? null ;
220+
221+ parameters . Add ( new TypeReference ( pName , pType , enums , pVariants ) ) ;
203222 }
204223
205224 Dictionary < string , string > defaultValues = new Dictionary < string , string > ( ) ;
@@ -231,7 +250,7 @@ static void Main(string[] args)
231250 isDestructor ) ;
232251 } ) . Where ( od => od != null ) . ToArray ( ) ;
233252
234- return new FunctionDefinition ( name , overloads ) ;
253+ return new FunctionDefinition ( name , overloads , enums ) ;
235254 } ) . OrderBy ( fd => fd . Name ) . ToArray ( ) ;
236255
237256 foreach ( EnumDefinition ed in enums )
@@ -1049,11 +1068,18 @@ class TypeReference
10491068 public string TemplateType { get ; }
10501069 public int ArraySize { get ; }
10511070 public bool IsFunctionPointer { get ; }
1071+ public string [ ] TypeVariants { get ; }
10521072
10531073 public TypeReference ( string name , string type , EnumDefinition [ ] enums )
1054- : this ( name , type , null , enums ) { }
1074+ : this ( name , type , null , enums , null ) { }
1075+
1076+ public TypeReference ( string name , string type , EnumDefinition [ ] enums , string [ ] typeVariants )
1077+ : this ( name , type , null , enums , typeVariants ) { }
10551078
10561079 public TypeReference ( string name , string type , string templateType , EnumDefinition [ ] enums )
1080+ : this ( name , type , templateType , enums , null ) { }
1081+
1082+ public TypeReference ( string name , string type , string templateType , EnumDefinition [ ] enums , string [ ] typeVariants )
10571083 {
10581084 Name = name ;
10591085 Type = type . Replace ( "const" , string . Empty ) . Trim ( ) ;
@@ -1082,6 +1108,8 @@ public TypeReference(string name, string type, string templateType, EnumDefiniti
10821108 }
10831109
10841110 IsFunctionPointer = Type . IndexOf ( '(' ) != - 1 ;
1111+
1112+ TypeVariants = typeVariants ;
10851113 }
10861114
10871115 private int ParseSizeString ( string sizePart , EnumDefinition [ ] enums )
@@ -1117,17 +1145,76 @@ private int ParseSizeString(string sizePart, EnumDefinition[] enums)
11171145
11181146 return ret ;
11191147 }
1148+
1149+ public TypeReference WithVariant ( int variantIndex , EnumDefinition [ ] enums )
1150+ {
1151+ if ( variantIndex == 0 ) return this ;
1152+ else return new TypeReference ( Name , TypeVariants [ variantIndex - 1 ] , TemplateType , enums ) ;
1153+ }
11201154 }
11211155
11221156 class FunctionDefinition
11231157 {
11241158 public string Name { get ; }
11251159 public OverloadDefinition [ ] Overloads { get ; }
11261160
1127- public FunctionDefinition ( string name , OverloadDefinition [ ] overloads )
1161+ public FunctionDefinition ( string name , OverloadDefinition [ ] overloads , EnumDefinition [ ] enums )
11281162 {
11291163 Name = name ;
1130- Overloads = overloads ;
1164+ Overloads = ExpandOverloadVariants ( overloads , enums ) ;
1165+ }
1166+
1167+ private OverloadDefinition [ ] ExpandOverloadVariants ( OverloadDefinition [ ] overloads , EnumDefinition [ ] enums )
1168+ {
1169+ List < OverloadDefinition > newDefinitions = new List < OverloadDefinition > ( ) ;
1170+
1171+ foreach ( OverloadDefinition overload in overloads )
1172+ {
1173+ bool hasVariants = false ;
1174+ int [ ] variantCounts = new int [ overload . Parameters . Length ] ;
1175+
1176+ for ( int i = 0 ; i < overload . Parameters . Length ; i ++ )
1177+ {
1178+ if ( overload . Parameters [ i ] . TypeVariants != null )
1179+ {
1180+ hasVariants = true ;
1181+ variantCounts [ i ] = overload . Parameters [ i ] . TypeVariants . Length + 1 ;
1182+ }
1183+ else
1184+ {
1185+ variantCounts [ i ] = 1 ;
1186+ }
1187+ }
1188+
1189+ if ( hasVariants )
1190+ {
1191+ int totalVariants = variantCounts [ 0 ] ;
1192+ for ( int i = 1 ; i < variantCounts . Length ; i ++ ) totalVariants *= variantCounts [ i ] ;
1193+
1194+ for ( int i = 0 ; i < totalVariants ; i ++ )
1195+ {
1196+ TypeReference [ ] parameters = new TypeReference [ overload . Parameters . Length ] ;
1197+ int div = 1 ;
1198+
1199+ for ( int j = 0 ; j < parameters . Length ; j ++ )
1200+ {
1201+ int k = ( i / div ) % variantCounts [ j ] ;
1202+
1203+ parameters [ j ] = overload . Parameters [ j ] . WithVariant ( k , enums ) ;
1204+
1205+ if ( j > 0 ) div *= variantCounts [ j ] ;
1206+ }
1207+
1208+ newDefinitions . Add ( overload . WithParameters ( parameters ) ) ;
1209+ }
1210+ }
1211+ else
1212+ {
1213+ newDefinitions . Add ( overload ) ;
1214+ }
1215+ }
1216+
1217+ return newDefinitions . ToArray ( ) ;
11311218 }
11321219 }
11331220
@@ -1166,6 +1253,11 @@ public OverloadDefinition(
11661253 IsConstructor = isConstructor ;
11671254 IsDestructor = isDestructor ;
11681255 }
1256+
1257+ public OverloadDefinition WithParameters ( TypeReference [ ] parameters )
1258+ {
1259+ return new OverloadDefinition ( ExportedName , FriendlyName , parameters , DefaultValues , ReturnType , StructName , Comment , IsConstructor , IsDestructor ) ;
1260+ }
11691261 }
11701262
11711263 class MarshalledParameter
0 commit comments