mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-13 16:49:22 +02:00
* FindType implementation from Henrique Werlang (bug ID 38252)
This commit is contained in:
parent
761b632d8f
commit
0642e13f57
@ -82,6 +82,7 @@ type
|
||||
class function Create: TRTTIContext; static;
|
||||
procedure Free;
|
||||
|
||||
function FindType(const AQualifiedName: String): TRttiType;
|
||||
function GetType(aTypeInfo: PTypeInfo): TRTTIType; overload;
|
||||
function GetType(aClass: TClass): TRTTIType; overload;
|
||||
end;
|
||||
@ -387,6 +388,7 @@ implementation
|
||||
|
||||
var
|
||||
GRttiContext: TRTTIContext;
|
||||
pas: TJSObject; external name 'pas';
|
||||
|
||||
procedure CreateVirtualCorbaInterface(InterfaceTypeInfo: Pointer;
|
||||
const MethodImplementation: TVirtualInterfaceInvokeEvent; out IntfVar); assembler;
|
||||
@ -1083,6 +1085,32 @@ begin
|
||||
Result:=GetType(TypeInfo(aClass));
|
||||
end;
|
||||
|
||||
function TRTTIContext.FindType(const AQualifiedName: String): TRttiType;
|
||||
var
|
||||
ModuleName, TypeName: String;
|
||||
|
||||
Module: TTypeInfoModule;
|
||||
|
||||
TypeFound: PTypeInfo;
|
||||
|
||||
begin
|
||||
Result := nil;
|
||||
|
||||
for ModuleName in TJSObject.Keys(pas) do
|
||||
if AQualifiedName.StartsWith(ModuleName + '.') then
|
||||
begin
|
||||
Module := TTypeInfoModule(pas[ModuleName]);
|
||||
TypeName := Copy(AQualifiedName, Length(ModuleName) + 2, Length(AQualifiedName));
|
||||
|
||||
if Module.RTTI.HasOwnProperty(TypeName) then
|
||||
begin
|
||||
TypeFound := PTypeInfo(Module.RTTI[TypeName]);
|
||||
|
||||
Exit(GetType(TypeFound));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TRttiObject }
|
||||
|
||||
function TRttiObject.GetAttributes: TCustomAttributeArray;
|
||||
|
@ -25,11 +25,17 @@ type
|
||||
TCallConv = (ccReg, ccCdecl, ccPascal, ccStdCall, ccSafeCall, ccCppdecl,
|
||||
ccFar16, ccOldFPCCall, ccInternProc, ccSysCall, ccSoftFloat, ccMWPascal);
|
||||
|
||||
|
||||
{ TSectionRTTI }
|
||||
TSectionRTTI = class external name 'rtl.tSectionRTTI'(TJSObject)
|
||||
end;
|
||||
|
||||
{ TTypeInfoModule }
|
||||
|
||||
TTypeInfoModule = class external name 'pasmodule'
|
||||
public
|
||||
Name: String external name '$name';
|
||||
RTTI: TSectionRTTI external name '$rtti';
|
||||
end;
|
||||
|
||||
TTypeInfoAttributes = type TJSValueDynArray;
|
||||
|
Loading…
Reference in New Issue
Block a user