Struct member name clean

This commit is contained in:
Garry Newman 2016-10-25 15:57:46 +01:00
parent 42ccf1b050
commit 0b02bf2331
4 changed files with 1841 additions and 1812 deletions

View File

@ -6,7 +6,7 @@ using System.Text;
namespace Facepunch.Steamworks.Callbacks.User namespace Facepunch.Steamworks.Callbacks.User
{ {
[StructLayout( LayoutKind.Sequential, Pack = 1 )] [StructLayout( LayoutKind.Sequential, Pack = 4 )]
internal struct ValidateAuthTicketResponse internal struct ValidateAuthTicketResponse
{ {
public ulong SteamID; public ulong SteamID;

File diff suppressed because it is too large Load Diff

View File

@ -25,8 +25,13 @@ namespace Generator
EndBlock(); EndBlock();
} }
private void PlatformClass( string type, string libraryName )
bool LargePack;
private void PlatformClass( string type, string libraryName, bool LargePack )
{ {
this.LargePack = LargePack;
StartBlock( $"internal static partial class Platform" ); StartBlock( $"internal static partial class Platform" );
StartBlock( $"public class {type} : Interface" ); StartBlock( $"public class {type} : Interface" );
@ -114,7 +119,7 @@ namespace Generator
if ( classname == "SteamApi" ) if ( classname == "SteamApi" )
flatName = methodName; flatName = methodName;
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) ); var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( true ) ) );
if ( argstring != "" ) argstring = $" {argstring} "; if ( argstring != "" ) argstring = $" {argstring} ";
WriteLine( $"{ret.Return()} {classname}_{methodName}({argstring});" ); WriteLine( $"{ret.Return()} {classname}_{methodName}({argstring});" );
@ -143,8 +148,7 @@ namespace Generator
if ( classname == "SteamApi" ) if ( classname == "SteamApi" )
flatName = methodName; flatName = methodName;
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( true ) ) );
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) );
if ( argstring != "" ) argstring = $" {argstring} "; if ( argstring != "" ) argstring = $" {argstring} ";
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" ); StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
@ -155,10 +159,27 @@ namespace Generator
WriteLine(); WriteLine();
} }
var retcode = ""; var retcode = "";
if ( ret.NativeType != "void" ) if ( ret.NativeType != "void" )
retcode = "return "; retcode = "return ";
AfterLines = new List<string>();
foreach ( var a in arguments )
{
if ( a.InteropParameter( LargePack ).Contains( ".PackSmall" ) )
{
WriteLine( $"var {a.Name}_ps = new {a.ManagedType.Trim( '*' )}.PackSmall();" );
AfterLines.Add( $"{a.Name} = {a.Name}_ps;" );
a.Name = "ref " + a.Name + "_ps";
if ( retcode != "" )
retcode = "var ret = ";
}
}
argstring = string.Join( ", ", arguments.Select( x => x.InteropVariable() ) ); argstring = string.Join( ", ", arguments.Select( x => x.InteropVariable() ) );
if ( methodDef.NeedsSelfPointer ) if ( methodDef.NeedsSelfPointer )
@ -166,8 +187,17 @@ namespace Generator
WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" ); WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" );
WriteLines( AfterLines );
if ( retcode.StartsWith( "var" ) )
{
WriteLine( "return ret;" );
}
EndBlock(); EndBlock();
LastMethodName = methodDef.Name; LastMethodName = methodDef.Name;
} }
@ -194,7 +224,7 @@ namespace Generator
flatName = methodName; flatName = methodName;
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) ); var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack ) ) );
if ( methodDef.NeedsSelfPointer ) if ( methodDef.NeedsSelfPointer )
{ {

View File

@ -15,7 +15,8 @@ namespace Generator
if ( c.Name == "CSteamID" || if ( c.Name == "CSteamID" ||
c.Name == "CSteamAPIContext" || c.Name == "CSteamAPIContext" ||
c.Name == "CCallResult" || c.Name == "CCallResult" ||
c.Name == "CCallback" ) c.Name == "CCallback" ||
c.Name == "ValvePackingSentinel_t" )
continue; continue;
if ( c.Name.Contains( "::" ) ) if ( c.Name.Contains( "::" ) )
@ -43,11 +44,15 @@ namespace Generator
StructFields( c.Fields ); StructFields( c.Fields );
WriteLine(); WriteLine();
StartBlock( $"public static implicit operator {c.Name} ( {c.Name}.PackSmall d )" );
//
// Implicit convert from PackSmall to regular
//
StartBlock( $"public static implicit operator {c.Name} ( {c.Name}.PackSmall d )" );
StartBlock( $"return new {c.Name}()" ); StartBlock( $"return new {c.Name}()" );
foreach ( var f in c.Fields ) foreach ( var f in c.Fields )
{ {
WriteLine( $"{f.Name} = d.{f.Name}," ); WriteLine( $"{CleanMemberName( f.Name )} = d.{CleanMemberName( f.Name )}," );
} }
EndBlock( ";" ); EndBlock( ";" );
EndBlock(); EndBlock();
@ -111,13 +116,37 @@ namespace Generator
WriteLine( $"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {num}, ArraySubType = UnmanagedType.R4)]" ); WriteLine( $"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {num}, ArraySubType = UnmanagedType.R4)]" );
} }
if ( t == "const char **" ) if ( t == "const char **" )
{ {
t = "IntPtr"; t = "IntPtr";
} }
WriteLine( $"public {t} {m.Name}; // {m.Type}" ); WriteLine( $"public {t} {CleanMemberName( m.Name )}; // {m.Name} {m.Type}" );
} }
} }
string CleanMemberName( string m )
{
if ( m == "m_pubParam" ) return "ParamPtr";
if ( m == "m_cubParam" ) return "ParamCount";
var cleanName = m.Replace( "m_un", "" )
.Replace( "m_us", "" )
.Replace( "m_sz", "" )
.Replace( "m_h", "" )
.Replace( "m_e", "" )
.Replace( "m_un", "" )
.Replace( "m_ul", "" )
.Replace( "m_u", "" )
.Replace( "m_b", "" )
.Replace( "m_i", "" )
.Replace( "m_pub", "" )
.Replace( "m_cub", "" )
.Replace( "m_", "" );
return cleanName.Substring( 0, 1 ).ToUpper() + cleanName.Substring( 1 );
}
} }
} }