@@ -629,7 +629,7 @@ private void GatherClassInternalFunctions(Class @class, bool includeCtors,
629
629
630
630
foreach ( var method in @class . Methods )
631
631
{
632
- if ( ! method . IsGenerated || ASTUtils . CheckIgnoreMethod ( method ) )
632
+ if ( ASTUtils . CheckIgnoreMethod ( method ) )
633
633
continue ;
634
634
635
635
if ( method . IsConstructor )
@@ -640,10 +640,11 @@ private void GatherClassInternalFunctions(Class @class, bool includeCtors,
640
640
641
641
foreach ( var prop in @class . Properties )
642
642
{
643
- if ( prop . GetMethod != null )
643
+ if ( prop . GetMethod ? . Namespace == @class )
644
644
tryAddOverload ( prop . GetMethod ) ;
645
645
646
- if ( prop . SetMethod != null && prop . SetMethod != prop . GetMethod )
646
+ if ( prop . SetMethod ? . Namespace == @class &&
647
+ prop . SetMethod != prop . GetMethod )
647
648
tryAddOverload ( prop . SetMethod ) ;
648
649
}
649
650
}
@@ -894,25 +895,12 @@ private void GenerateFunctionSetter(Class @class, Property property)
894
895
return ;
895
896
}
896
897
property = actualProperty ;
897
- var param = new Parameter
898
- {
899
- Name = "value" ,
900
- QualifiedType = property . SetMethod . Parameters [ 0 ] . QualifiedType ,
901
- Kind = ParameterKind . PropertyValue
902
- } ;
903
898
904
- var parameters = new List < Parameter > { param } ;
905
- var @void = new QualifiedType ( new BuiltinType ( PrimitiveType . Void ) ) ;
906
- if ( property . SetMethod . SynthKind == FunctionSynthKind . AbstractImplCall )
907
- GenerateVirtualPropertyCall ( property . SetMethod , @class . BaseClass ,
908
- property , parameters , @void ) ;
909
- else if ( property . SetMethod . IsVirtual )
910
- GenerateVirtualPropertyCall ( property . SetMethod , @class ,
911
- property , parameters , @void ) ;
912
- else if ( property . SetMethod . OperatorKind == CXXOperatorKind . Subscript )
899
+ if ( property . SetMethod . OperatorKind == CXXOperatorKind . Subscript )
913
900
GenerateIndexerSetter ( property . SetMethod ) ;
914
901
else
915
- GenerateInternalFunctionCall ( property . SetMethod , parameters , @void ) ;
902
+ GenerateFunctionInProperty ( @class , property . SetMethod , actualProperty ,
903
+ new QualifiedType ( new BuiltinType ( PrimitiveType . Void ) ) ) ;
916
904
}
917
905
918
906
private void GenerateFieldSetter ( Field field , Class @class , QualifiedType fieldType )
@@ -1046,7 +1034,7 @@ private void GenerateIndexerSetter(Function function)
1046
1034
1047
1035
var internalFunction = GetFunctionNativeIdentifier ( function ) ;
1048
1036
var paramMarshal = GenerateFunctionParamMarshal (
1049
- function . Parameters [ 0 ] , 0 , function ) ;
1037
+ function . Parameters [ 0 ] , 0 ) ;
1050
1038
string call = $@ "{ @internal } .{ internalFunction } ({
1051
1039
GetInstanceParam ( function ) } , { paramMarshal . Context . ArgumentPrefix } { paramMarshal . Name } )" ;
1052
1040
if ( type . IsPrimitiveType ( ) )
@@ -1205,14 +1193,8 @@ private void GenerateFunctionGetter(Class @class, Property property)
1205
1193
@class . Visit ( TypePrinter ) } ."");" ) ;
1206
1194
return ;
1207
1195
}
1208
- if ( actualProperty . GetMethod . SynthKind == FunctionSynthKind . AbstractImplCall )
1209
- GenerateVirtualPropertyCall ( actualProperty . GetMethod ,
1210
- @class . BaseClass , actualProperty ) ;
1211
- else if ( actualProperty . GetMethod . IsVirtual )
1212
- GenerateVirtualPropertyCall ( actualProperty . GetMethod ,
1213
- @class , actualProperty ) ;
1214
- else GenerateInternalFunctionCall ( actualProperty . GetMethod ,
1215
- actualProperty . GetMethod . Parameters , property . QualifiedType ) ;
1196
+ GenerateFunctionInProperty ( @class , actualProperty . GetMethod , actualProperty ,
1197
+ property . QualifiedType ) ;
1216
1198
}
1217
1199
1218
1200
private static Property GetActualProperty ( Property property , Class c )
@@ -1223,6 +1205,21 @@ private static Property GetActualProperty(Property property, Class c)
1223
1205
p . GetMethod . InstantiatedFrom == property . GetMethod ) ;
1224
1206
}
1225
1207
1208
+ private void GenerateFunctionInProperty ( Class @class , Method constituent ,
1209
+ Property property , QualifiedType type )
1210
+ {
1211
+ if ( constituent . IsVirtual && ( ! property . IsOverride ||
1212
+ @class . GetBaseProperty ( property ) . IsPure || constituent . OriginalFunction != null ) )
1213
+ GenerateFunctionCall ( GetVirtualCallDelegate ( constituent ) ,
1214
+ constituent , type ) ;
1215
+ else if ( property . IsOverride &&
1216
+ constituent . OriginalFunction == null )
1217
+ WriteLine ( property . GetMethod == constituent ?
1218
+ "return base.{0};" : "base.{0} = value;" , property . Name ) ;
1219
+ else
1220
+ GenerateInternalFunctionCall ( constituent , type ) ;
1221
+ }
1222
+
1226
1223
private void GenerateFieldGetter ( Field field , Class @class , QualifiedType returnType )
1227
1224
{
1228
1225
var name = ( ( Class ) field . Namespace ) . Layout . Fields . First (
@@ -1403,7 +1400,7 @@ private void GenerateProperties(Class @class)
1403
1400
// check if overriding a property from a secondary base
1404
1401
Property rootBaseProperty ;
1405
1402
var isOverride = prop . IsOverride &&
1406
- ( rootBaseProperty = @class . GetBaseProperty ( prop , true ) ) != null &&
1403
+ ( rootBaseProperty = @class . GetBasePropertyByName ( prop , true ) ) != null &&
1407
1404
( rootBaseProperty . IsVirtual || rootBaseProperty . IsPure ) ;
1408
1405
1409
1406
if ( isOverride )
@@ -2601,29 +2598,14 @@ private void GenerateGetHashCode(Class @class)
2601
2598
Helpers . InstanceIdentifier } ).GetHashCode();" ) ;
2602
2599
}
2603
2600
2604
- private void GenerateVirtualPropertyCall ( Method method , Class @class ,
2605
- Property property , List < Parameter > parameters = null ,
2606
- QualifiedType returnType = default ( QualifiedType ) )
2607
- {
2608
- if ( property . IsOverride && ! property . IsPure &&
2609
- method . SynthKind != FunctionSynthKind . AbstractImplCall &&
2610
- @class . HasNonAbstractBasePropertyInPrimaryBase ( property ) )
2611
- WriteLine ( parameters == null ?
2612
- "return base.{0};" : "base.{0} = value;" , property . Name ) ;
2613
- else
2614
- GenerateFunctionCall ( GetVirtualCallDelegate ( method ) ,
2615
- parameters ?? method . Parameters , method , returnType ) ;
2616
- }
2617
-
2618
2601
private void GenerateVirtualFunctionCall ( Method method ,
2619
2602
bool forceVirtualCall = false )
2620
2603
{
2621
2604
if ( ! forceVirtualCall && method . IsGeneratedOverride ( ) &&
2622
2605
! method . BaseMethod . IsPure )
2623
2606
GenerateManagedCall ( method , true ) ;
2624
2607
else
2625
- GenerateFunctionCall ( GetVirtualCallDelegate ( method ) ,
2626
- method . Parameters , method ) ;
2608
+ GenerateFunctionCall ( GetVirtualCallDelegate ( method ) , method ) ;
2627
2609
}
2628
2610
2629
2611
private string GetVirtualCallDelegate ( Method method )
@@ -2749,12 +2731,8 @@ private void GenerateClassConstructor(Method method, Class @class)
2749
2731
}
2750
2732
2751
2733
public void GenerateInternalFunctionCall ( Function function ,
2752
- List < Parameter > parameters = null ,
2753
2734
QualifiedType returnType = default ( QualifiedType ) )
2754
2735
{
2755
- if ( parameters == null )
2756
- parameters = function . Parameters ;
2757
-
2758
2736
var @class = function . Namespace as Class ;
2759
2737
2760
2738
string @internal = Helpers . InternalStruct ;
@@ -2763,11 +2741,11 @@ public void GenerateInternalFunctionCall(Function function,
2763
2741
2764
2742
var nativeFunction = GetFunctionNativeIdentifier ( function ) ;
2765
2743
var functionName = $ "{ @internal } .{ nativeFunction } ";
2766
- GenerateFunctionCall ( functionName , parameters , function , returnType ) ;
2744
+ GenerateFunctionCall ( functionName , function , returnType ) ;
2767
2745
}
2768
2746
2769
- public void GenerateFunctionCall ( string functionName , List < Parameter > parameters ,
2770
- Function function , QualifiedType returnType = default ( QualifiedType ) )
2747
+ public void GenerateFunctionCall ( string functionName , Function function ,
2748
+ QualifiedType returnType = default ( QualifiedType ) )
2771
2749
{
2772
2750
if ( function . IsPure )
2773
2751
{
@@ -2804,7 +2782,7 @@ public void GenerateFunctionCall(string functionName, List<Parameter> parameters
2804
2782
needsInstance = ! method . IsStatic || operatorParam != null ;
2805
2783
}
2806
2784
2807
- var @params = GenerateFunctionParamsMarshal ( parameters , function ) ;
2785
+ var @params = GenerateFunctionParamsMarshal ( function . Parameters ) ;
2808
2786
2809
2787
var originalFunction = function . OriginalFunction ?? function ;
2810
2788
@@ -3002,8 +2980,7 @@ public struct ParamMarshal
3002
2980
public bool HasUsingBlock ;
3003
2981
}
3004
2982
3005
- public List < ParamMarshal > GenerateFunctionParamsMarshal ( IEnumerable < Parameter > @params ,
3006
- Function function = null )
2983
+ public List < ParamMarshal > GenerateFunctionParamsMarshal ( IEnumerable < Parameter > @params )
3007
2984
{
3008
2985
var marshals = new List < ParamMarshal > ( ) ;
3009
2986
@@ -3013,18 +2990,20 @@ public List<ParamMarshal> GenerateFunctionParamsMarshal(IEnumerable<Parameter> @
3013
2990
if ( param . Kind == ParameterKind . IndirectReturnType )
3014
2991
continue ;
3015
2992
3016
- marshals . Add ( GenerateFunctionParamMarshal ( param , paramIndex ++ , function ) ) ;
2993
+ marshals . Add ( GenerateFunctionParamMarshal ( param , paramIndex ++ ) ) ;
3017
2994
}
3018
2995
3019
2996
return marshals ;
3020
2997
}
3021
2998
3022
- private ParamMarshal GenerateFunctionParamMarshal ( Parameter param , int paramIndex ,
3023
- Function function = null )
2999
+ private ParamMarshal GenerateFunctionParamMarshal ( Parameter param , int paramIndex )
3024
3000
{
3025
3001
// Do not delete instance in MS ABI.
3026
3002
var name = param . Name ;
3027
- param . Name = param . Kind == ParameterKind . ImplicitDestructorParameter ? "0" : name ;
3003
+ var function = ( Function ) param . Namespace ;
3004
+ param . Name = param . Kind == ParameterKind . ImplicitDestructorParameter ? "0" :
3005
+ function . IsGenerated || function . OperatorKind == CXXOperatorKind . Subscript ?
3006
+ name : "value" ;
3028
3007
3029
3008
var argName = Generator . GeneratedIdentifier ( "arg" ) + paramIndex . ToString ( CultureInfo . InvariantCulture ) ;
3030
3009
var paramMarshal = new ParamMarshal { Name = argName , Param = param } ;
0 commit comments