From ea85ddbb6f51694237a31c3b1da163b69954d6da Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 16 Apr 2019 15:08:22 +0100 Subject: [PATCH] CodeWriter remove unused --- Generator/Argument.cs | 312 ----------------------------- Generator/CodeWriter/CodeWriter.cs | 14 -- Generator/CodeWriter/Utility.cs | 22 -- Generator/Generator.csproj | 1 - 4 files changed, 349 deletions(-) delete mode 100644 Generator/Argument.cs diff --git a/Generator/Argument.cs b/Generator/Argument.cs deleted file mode 100644 index 316c933..0000000 --- a/Generator/Argument.cs +++ /dev/null @@ -1,312 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Generator -{ - class Argument - { - public string Name; - public string NativeType; - public string ManagedType; - public CodeWriter.TypeDef TypeDef; - - public Argument( string Name, string ManagedType, Dictionary typeDefs ) - { - var cleantype = Cleanup.ConvertType( ManagedType ); - if ( cleantype != ManagedType ) - { - ManagedType = cleantype; - } - - this.Name = Name; - this.NativeType = ManagedType; - - Build( typeDefs ); - } - - private void Build( Dictionary typeDefs ) - { - var cleanNative = NativeType.Trim( '*', ' ' ).Replace( "class ", "" ).Replace( "const ", "" ); - - if ( typeDefs != null && typeDefs.ContainsKey( cleanNative ) ) - { - TypeDef = typeDefs[cleanNative]; - } - - ManagedType = ToManagedType( NativeType ); - - if ( ManagedType.EndsWith( "*" ) ) - { - ManagedType = ToManagedType( ManagedType.Trim( '*', ' ' ) ) + "*"; - } - } - - bool IsInputArray - { - get - { - if ( !NativeType.Contains( "const" ) ) return false; - if ( !NativeType.EndsWith( "*" ) ) return false; - - if ( NativeType.Contains( "const char" ) ) return false; - if ( NativeType.Contains( "const void" ) ) return false; - if ( NativeType.Contains( "SteamParamStringArray_t" ) ) return false; - - return true; - } - } - - bool IsStruct - { - get - { - return ManagedType.Contains( "_t" ); - } - } - - bool IsStructShouldBePassedAsRef - { - get - { - if ( ManagedType.Contains( "bool*" ) ) - return true; - - return ManagedType.EndsWith( "*" ) && ManagedType.Contains( "_t" ) && Name.StartsWith( "p" ) && !Name.StartsWith( "pvec" ); - } - } - - bool ShouldBePassedAsOut - { - get - { - - - return ManagedType.EndsWith( "*" ) && !ManagedType.Contains( "_t" ) && !ManagedType.Contains( "char" ) && !ManagedType.Contains( "bool" ); - } - } - - bool ShouldBeIntPtr - { - get - { - if ( IsInputArray ) - return false; - - if ( Name.Contains( "Flags" ) ) - return false; - - if ( ManagedType.Contains( "SteamUGCDetails_t" ) || ManagedType.Contains( "SteamParamStringArray_t" ) ) - return false; - - if ( Name == "pOutItemsArray" || Name == "handlesOut" ) - return true; - - if ( Name.Contains( "Dest" ) && ManagedType.EndsWith( "*" ) ) - return true; - - if ( ManagedType.EndsWith( "*" ) ) - { - if ( Name.EndsWith( "s" ) && !Name.EndsWith( "Bytes" ) ) return true; - } - - return false; - } - } - - bool PassedToNativeAsValue - { - get - { - if ( Name.StartsWith( "pvec" ) ) return false; - if ( TypeDef == null ) return false; - if ( ManagedType.Contains( "IntPtr" ) ) return false; - if ( Name.Contains( "IntPtr" ) ) return false; - - return true; - } - } - - - private static string ToManagedType( string type ) - { - var cleantype = Cleanup.ConvertType( type ); - if ( cleantype != type ) - { - return cleantype; - } - - type = type.Replace( "ISteamHTMLSurface::", "" ); - type = type.Replace( "class ", "" ); - type = type.Replace( "struct ", "" ); - type = type.Replace( "const void", "void" ); - - switch ( type ) - { - case "uint64": return "ulong"; - case "uint32": return "uint"; - case "int32": return "int"; - case "int64": return "long"; - case "void *": return "IntPtr"; - case "int16": return "short"; - case "uint8": return "byte"; - case "int8": return "char"; - case "unsigned short": return "ushort"; - case "unsigned int": return "uint"; - case "uint16": return "ushort"; - case "const char *": return "string"; - - case "SteamAPIWarningMessageHook_t": return "IntPtr"; - } - - //type = type.Trim( '*', ' ' ); - - // Enums - skip the 'E' - if ( type[0] == 'E' ) - { - return type.Substring( 1 ); - } - - if ( type.StartsWith( "const " ) ) - return ToManagedType( type.Replace( "const ", "" ) ); - - if ( type.StartsWith( "ISteamMatchmak" ) ) - return "IntPtr"; - - return type; - } - - internal string ManagedParameter() - { - if ( IsInputArray ) - return $"{ManagedType.Trim( '*', ' ' )}[] {Name} /*{NativeType}*/"; - - if ( ShouldBeIntPtr ) - return $"IntPtr {Name} /*{NativeType}*/"; - - if ( IsStructShouldBePassedAsRef ) - return $"ref {ManagedType.Trim( '*', ' ' )} {Name} /*{NativeType}*/"; - - if ( ShouldBePassedAsOut ) - return $"out {ManagedType.Trim( '*', ' ' )} {Name} /*{NativeType}*/"; - - return $"{ManagedType} {Name} /*{NativeType}*/"; - } - - internal string InteropVariable( bool AsRawValues ) - { - if ( IsInputArray ) - { - if ( AsRawValues && IsStruct ) return $"{Name}.Select( x => x.Value ).ToArray()"; - return $"{Name}"; - } - - if ( ShouldBeIntPtr ) - return $"{Name}"; - - var value = (PassedToNativeAsValue && AsRawValues) ? ".Value" : ""; - - if ( IsStructShouldBePassedAsRef ) - return $"ref {Name}{value}"; - - if ( ShouldBePassedAsOut ) - return $"out {Name}{value}"; - - return $"{Name}{value}"; - } - - internal string InteropParameter( bool NoPacking, bool LargePack, bool includeMarshalling ) - { - var cleantype = Cleanup.ConvertType( NativeType ); - if ( cleantype != NativeType ) return cleantype; - - var ps = NoPacking ? "" : (LargePack ? ".Pack8" : ".Pack4"); - var marshalling = ""; - if ( !NativeType.Contains( "_t" ) ) - ps = string.Empty; - - if ( TypeDef != null ) - ps = string.Empty; - - if ( includeMarshalling ) - { - if ( NativeType == "bool" ) marshalling = "[MarshalAs(UnmanagedType.U1)]"; - if ( NativeType == "bool *" ) marshalling = "[MarshalAs(UnmanagedType.U1)]"; - - if ( PassedToNativeAsValue && !ShouldBeIntPtr ) - { - if ( IsInputArray ) - return $"{TypeDef.ManagedType}[] {Name}"; - else if ( IsStructShouldBePassedAsRef ) - return $"ref {TypeDef.ManagedType} {Name}"; - else if ( ShouldBePassedAsOut ) - return $"out {TypeDef.ManagedType} {Name}"; - else - return $"{TypeDef.ManagedType} {Name}"; - } - } - - if ( NativeType == "char *" || NativeType == "char **" ) - { - return $"System.Text.StringBuilder /*{NativeType}*/ {Name}".Trim(); - } - - if ( ShouldBeIntPtr ) - return $"IntPtr /*{NativeType}*/ {Name}".Trim(); - - if ( IsStructShouldBePassedAsRef ) - return $"{marshalling} ref {ManagedType.Trim( '*', ' ' )}{ps} /*{NativeType}*/ {Name}".Trim(); - - if ( IsInputArray ) - return $"{marshalling} {ManagedType.Trim( '*', ' ' )}[] /*{NativeType}*/ {Name}".Trim(); - - if ( ShouldBePassedAsOut ) - return $"{marshalling} out {ManagedType.Trim( '*', ' ' )} /*{NativeType}*/ {Name}".Trim(); - - cleantype = Cleanup.ConvertType( ManagedType ); - if ( cleantype != ManagedType ) return cleantype; - - if ( TypeDef != null ) - { - if ( NativeType.EndsWith( "*" ) ) - { - return $"IntPtr /*{NativeType}*/ {Name}".Trim(); - } - else - { - return $"{marshalling} {TypeDef.Name} /*{NativeType}*/ {Name}".Trim(); - } - } - - - if ( NativeType.EndsWith( "*" ) && ManagedType.Contains( "_t" ) ) - { - return $"IntPtr /*{NativeType}*/ {Name} ".Trim(); - } - - return $"{marshalling} {ManagedType} /*{NativeType}*/ {Name} ".Trim(); - } - - internal string Return() - { - if ( ManagedType.EndsWith( "*" ) ) - { - return $"IntPtr /*{NativeType}*/"; - } - - if ( TypeDef != null ) - { - return $"{TypeDef.Name} /*({NativeType})*/"; - } - - if ( ManagedType == "string" ) - return "IntPtr"; - - return $"{ManagedType} /*{NativeType}*/"; - } - - - } -} diff --git a/Generator/CodeWriter/CodeWriter.cs b/Generator/CodeWriter/CodeWriter.cs index 1571bb6..edbf02a 100644 --- a/Generator/CodeWriter/CodeWriter.cs +++ b/Generator/CodeWriter/CodeWriter.cs @@ -92,20 +92,6 @@ namespace Generator } } - private List BuildArguments( SteamApiDefinition.MethodDef.ParamType[] ps ) - { - var args = new List(); - if ( ps == null ) return args; - - foreach ( var p in ps ) - { - var a = new Argument( p.Name, p.Type, TypeDefs ); - args.Add( a ); - } - - return args; - } - private void Header( string NamespaceName = "Steamworks" ) { WriteLine( "using System;" ); diff --git a/Generator/CodeWriter/Utility.cs b/Generator/CodeWriter/Utility.cs index e3ebbc5..0f6b21e 100644 --- a/Generator/CodeWriter/Utility.cs +++ b/Generator/CodeWriter/Utility.cs @@ -8,28 +8,6 @@ namespace Generator { public partial class CodeWriter { - static string[] IgnoredClasses = new string[] - { - "ISteamMatchmakingPingResponse", - "ISteamMatchmakingServerListResponse", - "ISteamMatchmakingPlayersResponse", - "ISteamMatchmakingRulesResponse", - "ISteamMatchmakingPingResponse", - }; - - public static bool ShouldIgnoreClass( string name ) - { - return IgnoredClasses.Contains( name ); - } - - public string InterfaceNameToClass( string name ) - { - if ( name[0] == 'I' ) - name = name.Substring( 1 ); - - return name; - } - string CleanMemberName( string m ) { if ( m == "m_pubParam" ) return "ParamPtr"; diff --git a/Generator/Generator.csproj b/Generator/Generator.csproj index 4bf42a4..e1edf42 100644 --- a/Generator/Generator.csproj +++ b/Generator/Generator.csproj @@ -47,7 +47,6 @@ -