This commit is contained in:
Garry Newman 2016-10-29 13:13:25 +01:00
parent a333bc3860
commit 14ee1314de
8 changed files with 7024 additions and 10316 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -73,10 +73,6 @@ namespace Generator
WriteLine(); WriteLine();
} }
private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef methodDef ) private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef methodDef )
{ {
var arguments = BuildArguments( methodDef.Params ); var arguments = BuildArguments( methodDef.Params );
@ -97,6 +93,7 @@ namespace Generator
if ( argstring != "" ) argstring = $" {argstring} "; if ( argstring != "" ) argstring = $" {argstring} ";
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" ); StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
{
// var vars = string.Join( " + \",\" + ", arguments.Where( x => !x.InteropParameter( true, true ).StartsWith( "out " ) ).Select( x => x.Name ) ); // var vars = string.Join( " + \",\" + ", arguments.Where( x => !x.InteropParameter( true, true ).StartsWith( "out " ) ).Select( x => x.Name ) );
// if ( vars != "" ) vars = "\" + " + vars + " + \""; // if ( vars != "" ) vars = "\" + " + vars + " + \"";
@ -124,8 +121,6 @@ namespace Generator
if ( retcode != "" ) if ( retcode != "" )
retcode = "var ret = "; retcode = "var ret = ";
} }
} }
@ -134,7 +129,7 @@ namespace Generator
if ( methodDef.NeedsSelfPointer ) if ( methodDef.NeedsSelfPointer )
argstring = "_ptr" + ( argstring.Length > 0 ? ", " : "" ) + argstring; argstring = "_ptr" + ( argstring.Length > 0 ? ", " : "" ) + argstring;
WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" ); WriteLine( $"{retcode}Native.{flatName}({argstring});" );
WriteLines( AfterLines ); WriteLines( AfterLines );
@ -143,13 +138,31 @@ namespace Generator
WriteLine( "return ret;" ); WriteLine( "return ret;" );
} }
}
EndBlock(); EndBlock();
LastMethodName = methodDef.Name; LastMethodName = methodDef.Name;
} }
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( ShouldIgnoreClass( className ) ) return;
WriteLine( $"//" );
WriteLine( $"// {className} " );
WriteLine( $"//" );
LastMethodName = "";
foreach ( var m in methodDef )
{
InteropClassMethod( libraryName, className, m );
}
WriteLine();
}
private void InteropClassMethod( string library, string classname, SteamApiDefinition.MethodDef methodDef ) private void InteropClassMethod( string library, string classname, SteamApiDefinition.MethodDef methodDef )
{ {
var arguments = BuildArguments( methodDef.Params ); var arguments = BuildArguments( methodDef.Params );
@ -165,7 +178,6 @@ namespace Generator
if ( classname == "SteamApi" ) if ( classname == "SteamApi" )
flatName = methodName; flatName = methodName;
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack, true ) ) ); var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack, true ) ) );
if ( methodDef.NeedsSelfPointer ) if ( methodDef.NeedsSelfPointer )
@ -175,31 +187,14 @@ namespace Generator
if ( argstring != "" ) argstring = $" {argstring} "; if ( argstring != "" ) argstring = $" {argstring} ";
WriteLine( $"[DllImportAttribute( \"{library}\", EntryPoint = \"{flatName}\" )]" ); Write( $"[DllImportAttribute( \"{library}\" )] " );
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" ); if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
WriteLine( $"internal static extern {ret.Return()} {methodName}({argstring});" ); WriteLine( $"internal static extern {ret.Return()} {flatName}({argstring});" );
LastMethodName = methodDef.Name; LastMethodName = methodDef.Name;
} }
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
{
if ( ShouldIgnoreClass( className ) ) return;
StartBlock( $"internal static unsafe class {className}" );
LastMethodName = "";
foreach ( var m in methodDef )
{
InteropClassMethod( libraryName, className, m );
}
EndBlock();
WriteLine();
}
} }
} }

View File

@ -13,24 +13,32 @@ namespace Generator
private StringBuilder sb = new StringBuilder(); private StringBuilder sb = new StringBuilder();
private int indent = 0; private int indent = 0;
public string Indent { get { return new string( '\t', indent ); } } private bool skipIndent = false;
public string Indent { get { if ( skipIndent ) { return ""; } return new string( '\t', indent ); } }
private void EndBlock( string end = "" ) private void EndBlock( string end = "" )
{ {
indent--; indent--;
sb.AppendLine( $"{Indent}}}{end}" ); WriteLine( "}" + end );
} }
private void WriteLine( string v = "" ) private void WriteLine( string v = "" )
{ {
sb.AppendLine( $"{Indent}{v}" ); sb.AppendLine( $"{Indent}{v}" );
skipIndent = false;
}
private void Write( string v = "" )
{
sb.Append( $"{Indent}{v}" );
skipIndent = true;
} }
private void StartBlock( string v ) private void StartBlock( string v )
{ {
sb.AppendLine( $"{Indent}{v}" ); WriteLine( v );
sb.AppendLine( $"{Indent}{{" ); WriteLine( "{" );
indent++; indent++;
} }

View File

@ -62,7 +62,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<Compile Include="CodeWriter.PlatformClass.cs" /> <Compile Include="CodeWriter\PlatformClass.cs" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="steam_api.json" /> <None Include="steam_api.json" />
</ItemGroup> </ItemGroup>