mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 14:49:16 +02:00
+ add CreateImplementation to TRttiMethod to create an implementation of a method that can be used with a VMT
git-svn-id: trunk@41835 -
This commit is contained in:
parent
69f54b31e7
commit
bbac2c1fbf
@ -399,6 +399,7 @@ type
|
|||||||
TRttiMethod = class(TRttiMember)
|
TRttiMethod = class(TRttiMember)
|
||||||
private
|
private
|
||||||
FString: String;
|
FString: String;
|
||||||
|
function GetFlags: TFunctionCallFlags;
|
||||||
protected
|
protected
|
||||||
function GetCallingConvention: TCallConv; virtual; abstract;
|
function GetCallingConvention: TCallConv; virtual; abstract;
|
||||||
function GetCodeAddress: CodePointer; virtual; abstract;
|
function GetCodeAddress: CodePointer; virtual; abstract;
|
||||||
@ -429,6 +430,9 @@ type
|
|||||||
function Invoke(aInstance: TObject; const aArgs: array of TValue): TValue;
|
function Invoke(aInstance: TObject; const aArgs: array of TValue): TValue;
|
||||||
function Invoke(aInstance: TClass; const aArgs: array of TValue): TValue;
|
function Invoke(aInstance: TClass; const aArgs: array of TValue): TValue;
|
||||||
function Invoke(aInstance: TValue; const aArgs: array of TValue): TValue;
|
function Invoke(aInstance: TValue; const aArgs: array of TValue): TValue;
|
||||||
|
{ Note: once "reference to" is supported these will be replaced by a single method }
|
||||||
|
function CreateImplementation(aUserData: Pointer; aCallback: TMethodImplementationCallbackMethod): TMethodImplementation;
|
||||||
|
function CreateImplementation(aUserData: Pointer; aCallback: TMethodImplementationCallbackProc): TMethodImplementation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TRttiStructuredType = class(TRttiType)
|
TRttiStructuredType = class(TRttiType)
|
||||||
@ -2610,6 +2614,13 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TRttiMethod.GetFlags: TFunctionCallFlags;
|
||||||
|
begin
|
||||||
|
Result := [];
|
||||||
|
if IsStatic then
|
||||||
|
Include(Result, fcfStatic);
|
||||||
|
end;
|
||||||
|
|
||||||
function TRttiMethod.GetParameters: specialize TArray<TRttiParameter>;
|
function TRttiMethod.GetParameters: specialize TArray<TRttiParameter>;
|
||||||
begin
|
begin
|
||||||
Result := GetParameters(False);
|
Result := GetParameters(False);
|
||||||
@ -2714,6 +2725,76 @@ begin
|
|||||||
Result := Rtti.Invoke(Name, addr, CallingConvention, IsStatic, aInstance, aArgs, GetParameters(True), ReturnType);
|
Result := Rtti.Invoke(Name, addr, CallingConvention, IsStatic, aInstance, aArgs, GetParameters(True), ReturnType);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TRttiMethod.CreateImplementation(aUserData: Pointer; aCallback: TMethodImplementationCallbackMethod): TMethodImplementation;
|
||||||
|
var
|
||||||
|
params: specialize TArray<TRttiParameter>;
|
||||||
|
args: specialize TArray<TFunctionCallParameterInfo>;
|
||||||
|
res: PTypeInfo;
|
||||||
|
restype: TRttiType;
|
||||||
|
resinparam: Boolean;
|
||||||
|
i: SizeInt;
|
||||||
|
begin
|
||||||
|
if not Assigned(aCallback) then
|
||||||
|
raise EArgumentNilException.Create(SErrMethodImplNoCallback);
|
||||||
|
|
||||||
|
resinparam := False;
|
||||||
|
params := GetParameters(True);
|
||||||
|
SetLength(args, Length(params));
|
||||||
|
for i := 0 to High(params) do begin
|
||||||
|
if Assigned(params[i].ParamType) then
|
||||||
|
args[i].ParamType := params[i].ParamType.FTypeInfo
|
||||||
|
else
|
||||||
|
args[i].ParamType := Nil;
|
||||||
|
args[i].ParamFlags := params[i].Flags;
|
||||||
|
args[i].ParaLocs := Nil;
|
||||||
|
if pfResult in params[i].Flags then
|
||||||
|
resinparam := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
restype := GetReturnType;
|
||||||
|
if Assigned(restype) and not resinparam then
|
||||||
|
res := restype.FTypeInfo
|
||||||
|
else
|
||||||
|
res := Nil;
|
||||||
|
|
||||||
|
Result := TMethodImplementation.Create(GetCallingConvention, args, res, GetFlags, aUserData, aCallback);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TRttiMethod.CreateImplementation(aUserData: Pointer; aCallback: TMethodImplementationCallbackProc): TMethodImplementation;
|
||||||
|
var
|
||||||
|
params: specialize TArray<TRttiParameter>;
|
||||||
|
args: specialize TArray<TFunctionCallParameterInfo>;
|
||||||
|
res: PTypeInfo;
|
||||||
|
restype: TRttiType;
|
||||||
|
resinparam: Boolean;
|
||||||
|
i: SizeInt;
|
||||||
|
begin
|
||||||
|
if not Assigned(aCallback) then
|
||||||
|
raise EArgumentNilException.Create(SErrMethodImplNoCallback);
|
||||||
|
|
||||||
|
resinparam := False;
|
||||||
|
params := GetParameters(True);
|
||||||
|
SetLength(args, Length(params));
|
||||||
|
for i := 0 to High(params) do begin
|
||||||
|
if Assigned(params[i].ParamType) then
|
||||||
|
args[i].ParamType := params[i].ParamType.FTypeInfo
|
||||||
|
else
|
||||||
|
args[i].ParamType := Nil;
|
||||||
|
args[i].ParamFlags := params[i].Flags;
|
||||||
|
args[i].ParaLocs := Nil;
|
||||||
|
if pfResult in params[i].Flags then
|
||||||
|
resinparam := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
restype := GetReturnType;
|
||||||
|
if Assigned(restype) and not resinparam then
|
||||||
|
res := restype.FTypeInfo
|
||||||
|
else
|
||||||
|
res := Nil;
|
||||||
|
|
||||||
|
Result := TMethodImplementation.Create(GetCallingConvention, args, res, GetFlags, aUserData, aCallback);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TRttiInvokableType }
|
{ TRttiInvokableType }
|
||||||
|
|
||||||
function TRttiInvokableType.GetParameters: specialize TArray<TRttiParameter>;
|
function TRttiInvokableType.GetParameters: specialize TArray<TRttiParameter>;
|
||||||
|
Loading…
Reference in New Issue
Block a user