11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4- using System . Net . Mime ;
5- using System . Reflection . Metadata ;
64using System . Text ;
7- using System . Threading . Tasks ;
85using CppAst ;
96
107namespace WebGPUGen
@@ -40,7 +37,7 @@ public static string ConvertToCSharpType(CppType type, bool isPointer = false)
4037
4138 if ( type is CppQualifiedType qualifiedType )
4239 {
43- return GetCsTypeName ( qualifiedType . ElementType , isPointer ) ;
40+ return ConvertToCSharpType ( qualifiedType . ElementType , isPointer ) ;
4441 }
4542
4643 if ( type is CppEnum enumType )
@@ -77,13 +74,13 @@ public static string ConvertToCSharpType(CppType type, bool isPointer = false)
7774
7875 if ( type is CppArrayType arrayType )
7976 {
80- return GetCsTypeName ( arrayType . ElementType , isPointer ) ;
77+ return ConvertToCSharpType ( arrayType . ElementType , isPointer ) ;
8178 }
8279
8380 return string . Empty ;
8481 }
8582
86- public static object GetParametersSignature ( CppFunction command , bool useTypes = true )
83+ public static string GetParametersSignature ( CppFunction command , bool useTypes = true )
8784 {
8885 StringBuilder signature = new StringBuilder ( ) ;
8986 foreach ( var parameter in command . Parameters )
@@ -168,79 +165,11 @@ private static string GetCsTypeName(CppPointerType pointerType)
168165 {
169166 return GetCsTypeName ( primitiveType , true ) ;
170167 }
171- else if ( qualifiedType . ElementType is CppClass @classType )
172- {
173- return GetCsTypeName ( @classType , true ) ;
174- }
175- else if ( qualifiedType . ElementType is CppPointerType subPointerType )
176- {
177- return GetCsTypeName ( subPointerType , true ) + "*" ;
178- }
179- else if ( qualifiedType . ElementType is CppTypedef typedef )
180- {
181- return GetCsTypeName ( typedef , true ) ;
182- }
183- else if ( qualifiedType . ElementType is CppEnum @enum )
184- {
185- return GetCsTypeName ( @enum , true ) ;
186- }
187168
188- return GetCsTypeName ( qualifiedType . ElementType , true ) ;
169+ return ConvertToCSharpType ( qualifiedType . ElementType , true ) ;
189170 }
190171
191- return GetCsTypeName ( pointerType . ElementType , true ) ;
192- }
193-
194- private static string GetCsTypeName ( CppType type , bool isPointer = false )
195- {
196- if ( type is CppPrimitiveType primitiveType )
197- {
198- return GetCsTypeName ( primitiveType , isPointer ) ;
199- }
200-
201- if ( type is CppQualifiedType qualifiedType )
202- {
203- return GetCsTypeName ( qualifiedType . ElementType , isPointer ) ;
204- }
205-
206- if ( type is CppEnum enumType )
207- {
208- var enumCsName = GetCsCleanName ( enumType . Name ) ;
209- if ( isPointer )
210- return enumCsName + "*" ;
211-
212- return enumCsName ;
213- }
214-
215- if ( type is CppTypedef typedef )
216- {
217- var typeDefCsName = GetCsCleanName ( typedef . Name ) ;
218- if ( isPointer )
219- return typeDefCsName + "*" ;
220-
221- return typeDefCsName ;
222- }
223-
224- if ( type is CppClass @class )
225- {
226- var className = GetCsCleanName ( @class . Name ) ;
227- if ( isPointer )
228- return className + "*" ;
229-
230- return className ;
231- }
232-
233- if ( type is CppPointerType pointerType )
234- {
235- return GetCsTypeName ( pointerType ) ;
236- }
237-
238- if ( type is CppArrayType arrayType )
239- {
240- return GetCsTypeName ( arrayType . ElementType , isPointer ) ;
241- }
242-
243- return string . Empty ;
172+ return ConvertToCSharpType ( pointerType . ElementType , true ) ;
244173 }
245174
246175 private static string GetCsCleanName ( string name )
@@ -258,7 +187,7 @@ private static string GetCsCleanName(string name)
258187
259188 if ( name . Contains ( "Flags" ) )
260189 {
261- return name . Remove ( name . Count ( ) - 5 ) ;
190+ return name . Remove ( name . Length - 5 ) ;
262191 }
263192
264193 return name ;
@@ -274,7 +203,7 @@ public static string GetConstantType(string value)
274203 else if ( value . EndsWith ( "F" , StringComparison . OrdinalIgnoreCase ) )
275204 constType = "float" ;
276205 else if ( uint . TryParse ( value , out _ ) || value . StartsWith ( "0x" ) )
277- constType = "float " ;
206+ constType = "uint " ;
278207 return constType ;
279208 }
280209
0 commit comments