@ -228,7 +228,7 @@ namespace CppSharp.Generators.CSharp
GenerateNamespaceFunctionsAndVariables ( context ) ;
GenerateNamespaceFunctionsAndVariables ( context ) ;
foreach ( var childNamespace in context . Namespaces )
foreach ( var childNamespace in context . Namespaces )
childNamespace . Visit ( this ) ;
childNamespace . Visit ( this ) ;
return true ;
return true ;
@ -411,7 +411,7 @@ namespace CppSharp.Generators.CSharp
if ( @class . IsDependent & & ! @class . IsGenerated )
if ( @class . IsDependent & & ! @class . IsGenerated )
return true ;
return true ;
// disable the type maps, if any, for this class because of copy ctors, operators and others
// disable the type maps, if any, for this class because of copy ctors, operators and others
this . DisableTypeMap ( @class ) ;
this . DisableTypeMap ( @class ) ;
@ -480,7 +480,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
managed = default ;
managed = default ;
return NativeToManagedMap . TryGetValue ( native , out var wr ) & & wr . TryGetTarget ( out managed ) ;
return NativeToManagedMap . TryGetValue ( native , out var wr ) & & wr . TryGetTarget ( out managed ) ;
} } ");
} } ");
}
}
else
else
{
{
WriteLines ( $ @ "
WriteLines ( $ @ "
@ -512,7 +512,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
if ( @class . IsDynamic )
if ( @class . IsDynamic )
GenerateVTable ( @class ) ;
GenerateVTable ( @class ) ;
exit :
exit :
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
@ -542,7 +542,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
foreach ( var method in @class . Methods . Where ( m = >
foreach ( var method in @class . Methods . Where ( m = >
( m . OriginalFunction = = null | |
( m . OriginalFunction = = null | |
! ASTUtils . CheckIgnoreFunction ( m . OriginalFunction ) ) & &
! ASTUtils . CheckIgnoreFunction ( m . OriginalFunction ) ) & &
m . Access = = AccessSpecifier . Public & &
m . Access = = AccessSpecifier . Public & &
( ! shouldInheritFromIDisposable | | ! IsDisposeMethod ( m ) ) ) )
( ! shouldInheritFromIDisposable | | ! IsDisposeMethod ( m ) ) ) )
{
{
PushBlock ( BlockKind . Method ) ;
PushBlock ( BlockKind . Method ) ;
@ -568,7 +568,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
PushBlock ( BlockKind . Property ) ;
PushBlock ( BlockKind . Property ) ;
var type = prop . Type ;
var type = prop . Type ;
if ( prop . Parameters . Count > 0 & & prop . Type . IsPointerToPrimitiveType ( ) )
if ( prop . Parameters . Count > 0 & & prop . Type . IsPointerToPrimitiveType ( ) )
type = ( ( PointerType ) prop . Type ) . Pointee ;
type = ( ( PointerType ) prop . Type ) . Pointee ;
GenerateDeclarationCommon ( prop ) ;
GenerateDeclarationCommon ( prop ) ;
Write ( $"{type} {GetPropertyName(prop)} {{ " ) ;
Write ( $"{type} {GetPropertyName(prop)} {{ " ) ;
if ( prop . HasGetter )
if ( prop . HasGetter )
@ -596,7 +596,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
PushBlock ( BlockKind . InternalsClass ) ;
PushBlock ( BlockKind . InternalsClass ) ;
if ( @class . Layout . Size > 0 )
if ( @class . Layout . Size > 0 )
{
{
var layout = sequentialLayout ? "Sequential" : "Explicit" ;
var layout = sequentialLayout ? "Sequential" : "Explicit" ;
var pack = @class . MaxFieldAlignment > 0 ? $", Pack = {@class.MaxFieldAlignment}" : string . Empty ;
var pack = @class . MaxFieldAlignment > 0 ? $", Pack = {@class.MaxFieldAlignment}" : string . Empty ;
WriteLine ( $"[StructLayout(LayoutKind.{layout}, Size = {@class.Layout.Size}{pack})]" ) ;
WriteLine ( $"[StructLayout(LayoutKind.{layout}, Size = {@class.Layout.Size}{pack})]" ) ;
@ -847,7 +847,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
var fields = @class . Layout . Fields ;
var fields = @class . Layout . Fields ;
if ( fields . Count > 1 )
if ( fields . Count > 1 )
{
{
for ( var i = 1 ; i < fields . Count ; + + i )
for ( var i = 1 ; i < fields . Count ; + + i )
{
{
if ( fields [ i ] . Offset = = fields [ i - 1 ] . Offset )
if ( fields [ i ] . Offset = = fields [ i - 1 ] . Offset )
@ -916,7 +916,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
PopBlock ( NewLineKind . BeforeNextBlock ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
}
}
#endregion
#endregion
private void GeneratePropertySetter < T > ( T decl ,
private void GeneratePropertySetter < T > ( T decl ,
Class @class , bool isAbstract = false , Property property = null )
Class @class , bool isAbstract = false , Property property = null )
@ -1063,11 +1063,12 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
}
}
else
else
{
{
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
if ( @class . IsValueType )
if ( @class . IsValueType )
returnVar = $"{Helpers.InstanceField}.{name}" ;
returnVar = $"{Helpers.InstanceField}.{name}" ;
else {
else
{
var typeName = TypePrinter . PrintNative ( @class ) ;
var typeName = TypePrinter . PrintNative ( @class ) ;
if ( IsInternalClassNested ( field . Class ) )
if ( IsInternalClassNested ( field . Class ) )
typeName . RemoveNamespace ( ) ;
typeName . RemoveNamespace ( ) ;
@ -1141,7 +1142,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
else
else
type = originalType . ToString ( ) ;
type = originalType . ToString ( ) ;
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
WriteLine ( string . Format ( "fixed ({0} {1} = {2}.{3})" ,
WriteLine ( string . Format ( "fixed ({0} {1} = {2}.{3})" ,
type , arrPtr , Helpers . InstanceField , name ) ) ;
type , arrPtr , Helpers . InstanceField , name ) ) ;
@ -1276,7 +1277,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{
{
NewLine ( ) ;
NewLine ( ) ;
WriteOpenBraceAndIndent ( ) ;
WriteOpenBraceAndIndent ( ) ;
var to = ( ( Class ) property . OriginalNamespace ) . OriginalClass ;
var to = ( ( Class ) property . OriginalNamespace ) . OriginalClass ;
var baseOffset = GetOffsetToBase ( @class , to ) ;
var baseOffset = GetOffsetToBase ( @class , to ) ;
WriteLine ( "return {0} + {1};" , Helpers . InstanceIdentifier , baseOffset ) ;
WriteLine ( "return {0} + {1};" , Helpers . InstanceIdentifier , baseOffset ) ;
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
@ -1379,7 +1380,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
QualifiedType type = default ;
QualifiedType type = default ;
if ( actualProperty ! = property | |
if ( actualProperty ! = property | |
// indexers
// indexers
( property . QualifiedType . Type . IsPrimitiveType ( ) & &
( property . QualifiedType . Type . IsPrimitiveType ( ) & &
actualProperty . GetMethod . ReturnType . Type . IsPointerToPrimitiveType ( ) ) )
actualProperty . GetMethod . ReturnType . Type . IsPointerToPrimitiveType ( ) ) )
{
{
type = property . QualifiedType ;
type = property . QualifiedType ;
@ -1415,7 +1416,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
private void GenerateFieldGetter ( Field field , Class @class , QualifiedType returnType )
private void GenerateFieldGetter ( Field field , Class @class , QualifiedType returnType )
{
{
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
f = > f . FieldPtr = = field . OriginalPtr ) . Name ;
string returnVar ;
string returnVar ;
Type fieldType = field . Type . Desugar ( ) ;
Type fieldType = field . Type . Desugar ( ) ;
@ -1473,11 +1474,11 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
! final . IsPrimitiveType ( PrimitiveType . Char16 ) & &
! final . IsPrimitiveType ( PrimitiveType . Char16 ) & &
! final . IsPrimitiveType ( PrimitiveType . Char32 ) ) | |
! final . IsPrimitiveType ( PrimitiveType . Char32 ) ) | |
( ! Context . Options . MarshalCharAsManagedChar & &
( ! Context . Options . MarshalCharAsManagedChar & &
! ( ( PointerType ) fieldType ) . QualifiedPointee . Qualifiers . IsConst ) ) & &
! ( ( PointerType ) fieldType ) . QualifiedPointee . Qualifiers . IsConst ) ) & &
templateSubstitution = = null ) | |
templateSubstitution = = null ) | |
( ! ( ( PointerType ) fieldType ) . QualifiedPointee . Qualifiers . IsConst & &
( ! ( ( PointerType ) fieldType ) . QualifiedPointee . Qualifiers . IsConst & &
( final . IsPrimitiveType ( PrimitiveType . WideChar ) | |
( final . IsPrimitiveType ( PrimitiveType . WideChar ) | |
final . IsPrimitiveType ( PrimitiveType . Char16 ) | |
final . IsPrimitiveType ( PrimitiveType . Char16 ) | |
final . IsPrimitiveType ( PrimitiveType . Char32 ) ) ) )
final . IsPrimitiveType ( PrimitiveType . Char32 ) ) ) )
Write ( $"({fieldType.GetPointee().Desugar()}*) " ) ;
Write ( $"({fieldType.GetPointee().Desugar()}*) " ) ;
}
}
@ -1512,7 +1513,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
if ( methods . Count = = 0 )
if ( methods . Count = = 0 )
return ;
return ;
var @class = ( Class ) methods [ 0 ] . Namespace ;
var @class = ( Class ) methods [ 0 ] . Namespace ;
if ( @class . IsValueType )
if ( @class . IsValueType )
foreach ( var @base in @class . Bases . Where ( b = > b . IsClass & & ! b . Class . Ignore ) )
foreach ( var @base in @class . Bases . Where ( b = > b . IsClass & & ! b . Class . Ignore ) )
@ -1649,7 +1650,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
if ( ! isIndexer )
if ( ! isIndexer )
return prop . Name ;
return prop . Name ;
var @params = prop . Parameters . Select ( param = > {
var @params = prop . Parameters . Select ( param = >
{
var p = new Parameter ( param ) ;
var p = new Parameter ( param ) ;
p . Usage = ParameterUsage . In ;
p . Usage = ParameterUsage . In ;
return p ;
return p ;
@ -1671,7 +1673,8 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
if ( variable . Initializer ! = null & & ! string . IsNullOrWhiteSpace ( variable . Initializer . String ) )
if ( variable . Initializer ! = null & & ! string . IsNullOrWhiteSpace ( variable . Initializer . String ) )
GeneratePropertyGetterForVariableWithInitializer ( variable , signature ) ;
GeneratePropertyGetterForVariableWithInitializer ( variable , signature ) ;
else {
else
{
WriteLine ( signature ) ;
WriteLine ( signature ) ;
WriteOpenBraceAndIndent ( ) ;
WriteOpenBraceAndIndent ( ) ;
@ -1687,7 +1690,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
PopBlock ( NewLineKind . BeforeNextBlock ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
}
}
#region Virtual Tables
#region Virtual Tables
public List < VTableComponent > GetUniqueVTableMethodEntries ( Class @class )
public List < VTableComponent > GetUniqueVTableMethodEntries ( Class @class )
{
{
@ -1718,7 +1721,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
// Generate a delegate type for each method.
// Generate a delegate type for each method.
foreach ( var method in wrappedEntries . Select ( e = > e . Method ) . Where ( m = > ! m . Ignore ) )
foreach ( var method in wrappedEntries . Select ( e = > e . Method ) . Where ( m = > ! m . Ignore ) )
GenerateVTableMethodDelegates ( containingClass , method . Namespace . IsDependent ?
GenerateVTableMethodDelegates ( containingClass , method . Namespace . IsDependent ?
( Method ) method . InstantiatedFrom : method ) ;
( Method ) method . InstantiatedFrom : method ) ;
var hasVirtualDtor = wrappedEntries . Any ( e = > e . Method . IsDestructor ) ;
var hasVirtualDtor = wrappedEntries . Any ( e = > e . Method . IsDestructor ) ;
bool hasDynamicBase = @class . NeedsBase & & @class . BaseClass . IsDynamic ;
bool hasDynamicBase = @class . NeedsBase & & @class . BaseClass . IsDynamic ;
@ -1839,7 +1842,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{ {
{ {
if ( _ _ VTables . IsTransient )
if ( _ _ VTables . IsTransient )
_ _ VTables = VTableLoader . SetupVTables ( _ _ Instance , destructorOnly ) ;
_ _ VTables = VTableLoader . SetupVTables ( _ _ Instance , destructorOnly ) ;
} } ", trimIndentation : true);
} } ", trimIndentation: true);
WriteLine ( "#endregion" ) ;
WriteLine ( "#endregion" ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
@ -1865,7 +1868,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
private void AllocateNewVTablesMS ( Class @class , IList < VTableComponent > wrappedEntries ,
private void AllocateNewVTablesMS ( Class @class , IList < VTableComponent > wrappedEntries ,
bool destructorOnly , string table )
bool destructorOnly , string table )
{
{
for ( int i = 0 ; i < @class . Layout . VFTables . Count ; i + + )
for ( int i = 0 ; i < @class . Layout . VFTables . Count ; i + + )
{
{
VFTableInfo vftable = @class . Layout . VFTables [ i ] ;
VFTableInfo vftable = @class . Layout . VFTables [ i ] ;
@ -1892,9 +1895,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
{
{
string suffix = ( destructorOnly ? "_dtor" : string . Empty ) +
string suffix = ( destructorOnly ? "_dtor" : string . Empty ) +
( tableIndex = = 0 ? string . Empty : tableIndex . ToString ( CultureInfo . InvariantCulture ) ) ;
( tableIndex = = 0 ? string . Empty : tableIndex . ToString ( CultureInfo . InvariantCulture ) ) ;
WriteLine ( $"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count});" ) ;
WriteLine ( $"{table}[{tableIndex}] = CppSharp.Runtime.VTables.CloneTable(SafeHandles, instance, {vptrOffset}, {entries.Count});" ) ;
// fill the newly allocated v-table
// fill the newly allocated v-table
for ( var i = 0 ; i < entries . Count ; i + + )
for ( var i = 0 ; i < entries . Count ; i + + )
{
{
@ -1908,7 +1911,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
// patch with pointers to managed code where needed
// patch with pointers to managed code where needed
WriteLine ( "{0}[{1}][{2}] = Thunks[{3}];" , table , tableIndex , i - offsetRTTI , wrappedEntries . IndexOf ( entry ) ) ;
WriteLine ( "{0}[{1}][{2}] = Thunks[{3}];" , table , tableIndex , i - offsetRTTI , wrappedEntries . IndexOf ( entry ) ) ;
}
}
if ( ! destructorOnly )
if ( ! destructorOnly )
WriteLine ( $"VTables.Methods[{tableIndex}] = new Delegate[{entries.Count}];" ) ;
WriteLine ( $"VTables.Methods[{tableIndex}] = new Delegate[{entries.Count}];" ) ;
}
}
@ -1974,7 +1977,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
Type returnType = method . OriginalReturnType . Type . Desugar ( ) ;
Type returnType = method . OriginalReturnType . Type . Desugar ( ) ;
bool isPrimitive = returnType . IsPrimitiveType ( ) ;
bool isPrimitive = returnType . IsPrimitiveType ( ) ;
bool isVoid = returnType . IsPrimitiveType ( PrimitiveType . Void ) ;
bool isVoid = returnType . IsPrimitiveType ( PrimitiveType . Void ) ;
var property = ( ( Class ) method . Namespace ) . Properties . Find (
var property = ( ( Class ) method . Namespace ) . Properties . Find (
p = > p . GetMethod = = method | | p . SetMethod = = method ) ;
p = > p . GetMethod = = method | | p . SetMethod = = method ) ;
bool isSetter = property ! = null & & property . SetMethod = = method ;
bool isSetter = property ! = null & & property . SetMethod = = method ;
var hasReturn = ! isVoid & & ! isSetter ;
var hasReturn = ! isVoid & & ! isSetter ;
@ -2097,9 +2100,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
return @class . IsGenerated & & @class . IsDynamic & & GetUniqueVTableMethodEntries ( @class ) . Count > 0 ;
return @class . IsGenerated & & @class . IsDynamic & & GetUniqueVTableMethodEntries ( @class ) . Count > 0 ;
}
}
#endregion
#endregion
#region Events
#region Events
public override bool VisitEvent ( Event @event )
public override bool VisitEvent ( Event @event )
{
{
@ -2207,9 +2210,9 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
}
}
#endregion
#endregion
#region Constructors
#region Constructors
public void GenerateClassConstructors ( Class @class )
public void GenerateClassConstructors ( Class @class )
{
{
@ -2394,7 +2397,7 @@ internal static bool {Helpers.TryGetNativeToManagedMappingIdentifier}(IntPtr nat
private bool GenerateDestructorCall ( Method dtor )
private bool GenerateDestructorCall ( Method dtor )
{
{
var @class = ( Class ) dtor . Namespace ;
var @class = ( Class ) dtor . Namespace ;
GenerateVirtualFunctionCall ( dtor , true ) ;
GenerateVirtualFunctionCall ( dtor , true ) ;
if ( @class . IsAbstract )
if ( @class . IsAbstract )
{
{
@ -2518,7 +2521,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
public void GenerateNativeConstructorByValue ( Class @class , TypePrinterResult returnType )
public void GenerateNativeConstructorByValue ( Class @class , TypePrinterResult returnType )
{
{
var @internal = TypePrinter . PrintNative ( @class . IsAbstractImpl ? @class . BaseClass : @class ) ;
var @internal = TypePrinter . PrintNative ( @class . IsAbstractImpl ? @class . BaseClass : @class ) ;
if ( IsInternalClassNested ( @class ) )
if ( IsInternalClassNested ( @class ) )
@internal . RemoveNamespace ( ) ;
@internal . RemoveNamespace ( ) ;
@ -2605,9 +2608,9 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
WriteLineIndent ( ": this()" ) ;
WriteLineIndent ( ": this()" ) ;
}
}
#endregion
#endregion
#region Methods / Functions
#region Methods / Functions
public void GenerateFunction ( Function function , string parentName )
public void GenerateFunction ( Function function , string parentName )
{
{
@ -2732,7 +2735,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
c , method , method . OriginalReturnType ) ) ;
c , method , method . OriginalReturnType ) ) ;
}
}
SkipImpl :
SkipImpl :
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
@ -2829,7 +2832,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
{
{
if ( function . OriginalFunction . GenerationKind = = GenerationKind . Internal )
if ( function . OriginalFunction . GenerationKind = = GenerationKind . Internal )
{
{
var property = ( ( Class ) function . Namespace ) . Properties . First (
var property = ( ( Class ) function . Namespace ) . Properties . First (
p = > p . SetMethod = = function . OriginalFunction ) ;
p = > p . SetMethod = = function . OriginalFunction ) ;
WriteLine ( $ @ "{property.Name} = {ExpressionPrinter.VisitParameter(
WriteLine ( $ @ "{property.Name} = {ExpressionPrinter.VisitParameter(
function . Parameters . First ( p = > p . Kind = = ParameterKind . Regular ) ) } ; ");
function . Parameters . First ( p = > p . Kind = = ParameterKind . Regular ) ) } ; ");
@ -2844,7 +2847,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
parameter . Type . IsPointerToPrimitiveType ( out primitiveType ) & &
parameter . Type . IsPointerToPrimitiveType ( out primitiveType ) & &
parameter . Usage = = ParameterUsage . InOut & & parameter . HasDefaultValue )
parameter . Usage = = ParameterUsage . InOut & & parameter . HasDefaultValue )
{
{
var pointeeType = ( ( PointerType ) parameter . Type ) . Pointee . ToString ( ) ;
var pointeeType = ( ( PointerType ) parameter . Type ) . Pointee . ToString ( ) ;
WriteLine ( $ @ "{pointeeType} param{j++} = {
WriteLine ( $ @ "{pointeeType} param{j++} = {
( primitiveType = = PrimitiveType . Bool ? "false" : "0" ) } ; ");
( primitiveType = = PrimitiveType . Bool ? "false" : "0" ) } ; ");
}
}
@ -2927,16 +2930,16 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
{
{
Function @virtual = method ;
Function @virtual = method ;
if ( method . OriginalFunction ! = null & &
if ( method . OriginalFunction ! = null & &
! ( ( Class ) method . OriginalFunction . Namespace ) . IsInterface )
! ( ( Class ) method . OriginalFunction . Namespace ) . IsInterface )
@virtual = method . OriginalFunction ;
@virtual = method . OriginalFunction ;
var i = VTables . GetVTableIndex ( @virtual ) ;
var i = VTables . GetVTableIndex ( @virtual ) ;
int vtableIndex = 0 ;
int vtableIndex = 0 ;
var @class = ( Class ) method . Namespace ;
var @class = ( Class ) method . Namespace ;
var thisParam = method . Parameters . Find (
var thisParam = method . Parameters . Find (
p = > p . Kind = = ParameterKind . Extension ) ;
p = > p . Kind = = ParameterKind . Extension ) ;
if ( thisParam ! = null )
if ( thisParam ! = null )
@class = ( Class ) method . OriginalFunction . Namespace ;
@class = ( Class ) method . OriginalFunction . Namespace ;
if ( Context . ParserOptions . IsMicrosoftAbi )
if ( Context . ParserOptions . IsMicrosoftAbi )
vtableIndex = @class . Layout . VFTables . IndexOf ( @class . Layout . VFTables . First (
vtableIndex = @class . Layout . VFTables . IndexOf ( @class . Layout . VFTables . First (
@ -3094,7 +3097,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
Parameter operatorParam = null ;
Parameter operatorParam = null ;
if ( method ! = null )
if ( method ! = null )
{
{
var @class = ( Class ) method . Namespace ;
var @class = ( Class ) method . Namespace ;
isValueType = @class . IsValueType ;
isValueType = @class . IsValueType ;
operatorParam = method . Parameters . FirstOrDefault (
operatorParam = method . Parameters . FirstOrDefault (
@ -3186,7 +3189,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
if ( operatorParam = = null )
if ( operatorParam = = null )
{
{
WriteLine ( $ @ "fixed ({Helpers.InternalStruct}{
WriteLine ( $ @ "fixed ({Helpers.InternalStruct}{
Helpers . GetSuffixForInternal ( ( Class ) originalFunction . Namespace ) } * _ _ instancePtr = & {
Helpers . GetSuffixForInternal ( ( Class ) originalFunction . Namespace ) } * _ _ instancePtr = & {
Helpers . InstanceField } ) ");
Helpers . InstanceField } ) ");
WriteOpenBraceAndIndent ( ) ;
WriteOpenBraceAndIndent ( ) ;
}
}
@ -3200,10 +3203,10 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
Write ( "var {0} = " , Helpers . ReturnIdentifier ) ;
Write ( "var {0} = " , Helpers . ReturnIdentifier ) ;
if ( method ! = null & & ! method . IsConstructor & & method . OriginalFunction ! = null & &
if ( method ! = null & & ! method . IsConstructor & & method . OriginalFunction ! = null & &
( ( Method ) method . OriginalFunction ) . IsConstructor )
( ( Method ) method . OriginalFunction ) . IsConstructor )
{
{
WriteLine ( $ @ "Marshal.AllocHGlobal({
WriteLine ( $ @ "Marshal.AllocHGlobal({
( ( Class ) method . OriginalNamespace ) . Layout . Size } ) ; ");
( ( Class ) method . OriginalNamespace ) . Layout . Size } ) ; ");
names . Insert ( 0 , Helpers . ReturnIdentifier ) ;
names . Insert ( 0 , Helpers . ReturnIdentifier ) ;
}
}
WriteLine ( "{0}({1});" , functionName , string . Join ( ", " , names ) ) ;
WriteLine ( "{0}({1});" , functionName , string . Join ( ", " , names ) ) ;
@ -3241,19 +3244,19 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
var numFixedBlocks = @params . Count ( param = > param . HasUsingBlock ) ;
var numFixedBlocks = @params . Count ( param = > param . HasUsingBlock ) ;
for ( var i = 0 ; i < numFixedBlocks ; + + i )
for ( var i = 0 ; i < numFixedBlocks ; + + i )
UnindentAndWriteCloseBrace ( ) ;
UnindentAndWriteCloseBrace ( ) ;
}
}
private string GetInstanceParam ( Function function )
private string GetInstanceParam ( Function function )
{
{
var from = ( Class ) function . Namespace ;
var from = ( Class ) function . Namespace ;
var to = ( function . OriginalFunction = = null | |
var to = ( function . OriginalFunction = = null | |
// we don't need to offset the instance with Itanium if there's an existing interface impl
// we don't need to offset the instance with Itanium if there's an existing interface impl
( Context . ParserOptions . IsItaniumLikeAbi & &
( Context . ParserOptions . IsItaniumLikeAbi & &
! ( ( Class ) function . OriginalNamespace ) . IsInterface ) ) & &
! ( ( Class ) function . OriginalNamespace ) . IsInterface ) ) & &
function . SynthKind ! = FunctionSynthKind . AbstractImplCall ?
function . SynthKind ! = FunctionSynthKind . AbstractImplCall ?
@from . BaseClass : ( Class ) function . OriginalFunction . Namespace ;
@from . BaseClass : ( Class ) function . OriginalFunction . Namespace ;
var baseOffset = 0 u ;
var baseOffset = 0 u ;
if ( to ! = null )
if ( to ! = null )
@ -3320,7 +3323,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
{
{
// Do not delete instance in MS ABI.
// Do not delete instance in MS ABI.
var name = param . Name ;
var name = param . Name ;
var function = ( Function ) param . Namespace ;
var function = ( Function ) param . Namespace ;
param . Name = param . Kind = = ParameterKind . ImplicitDestructorParameter ? "0" :
param . Name = param . Kind = = ParameterKind . ImplicitDestructorParameter ? "0" :
ActiveBlock . Parent . Kind ! = BlockKind . Property | |
ActiveBlock . Parent . Kind ! = BlockKind . Property | |
function . OperatorKind = = CXXOperatorKind . Subscript ? name : "value" ;
function . OperatorKind = = CXXOperatorKind . Subscript ? name : "value" ;
@ -3377,7 +3380,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
return TypePrinter . VisitParameters ( @params , true ) . Type ;
return TypePrinter . VisitParameters ( @params , true ) . Type ;
}
}
#endregion
#endregion
public override bool VisitTypedefNameDecl ( TypedefNameDecl typedef )
public override bool VisitTypedefNameDecl ( TypedefNameDecl typedef )
{
{
@ -3394,7 +3397,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
var attributedType = typedef . Type . GetPointee ( ) as AttributedType ;
var attributedType = typedef . Type . GetPointee ( ) as AttributedType ;
var callingConvention = attributedType = = null
var callingConvention = attributedType = = null
? functionType . CallingConvention
? functionType . CallingConvention
: ( ( FunctionType ) attributedType . Equivalent . Type ) . CallingConvention ;
: ( ( FunctionType ) attributedType . Equivalent . Type ) . CallingConvention ;
TypePrinter . PushContext ( TypePrinterContextKind . Native ) ;
TypePrinter . PushContext ( TypePrinterContextKind . Native ) ;
var interopCallConv = callingConvention . ToInteropCallConv ( ) ;
var interopCallConv = callingConvention . ToInteropCallConv ( ) ;
if ( interopCallConv = = System . Runtime . InteropServices . CallingConvention . Winapi )
if ( interopCallConv = = System . Runtime . InteropServices . CallingConvention . Winapi )
@ -3530,7 +3533,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
PushBlock ( BlockKind . InternalsClassMethod ) ;
PushBlock ( BlockKind . InternalsClassMethod ) ;
var callConv = function . CallingConvention . ToInteropCallConv ( ) ;
var callConv = function . CallingConvention . ToInteropCallConv ( ) ;
WriteLine ( "[SuppressUnmanagedCodeSecurity, DllImport(\"{0}\", EntryPoint = \"{1}\", CallingConvention = __CallingConvention.{2})]" ,
WriteLine ( "[SuppressUnmanagedCodeSecurity, DllImport(\"{0}\", EntryPoint = \"{1}\", CallingConvention = __CallingConvention.{2})]" ,
GetLibraryOf ( function ) ,
GetLibraryOf ( function ) ,
function . Mangled ,
function . Mangled ,
callConv ) ;
callConv ) ;
@ -3555,7 +3558,7 @@ internal static{(@new ? " new" : string.Empty)} {printedClass} __GetInstance({Ty
string libName = declaration . TranslationUnit . Module . SharedLibraryName ;
string libName = declaration . TranslationUnit . Module . SharedLibraryName ;
NativeLibrary library ;
NativeLibrary library ;
Context . Symbols . FindLibraryBySymbol ( ( ( IMangledDecl ) declaration ) . Mangled , out library ) ;
Context . Symbols . FindLibraryBySymbol ( ( ( IMangledDecl ) declaration ) . Mangled , out library ) ;
if ( library ! = null )
if ( library ! = null )
libName = Path . GetFileNameWithoutExtension ( library . FileName ) ;
libName = Path . GetFileNameWithoutExtension ( library . FileName ) ;