pas2js: fixed rtti

This commit is contained in:
mattias 2020-06-06 08:17:48 +00:00
parent 52b91515d3
commit c0a4d85497

View File

@ -1847,7 +1847,7 @@ type
AContext: TConvertContext); virtual; AContext: TConvertContext); virtual;
Function CreateRTTINewType(El: TPasType; const CallFuncName: string; Function CreateRTTINewType(El: TPasType; const CallFuncName: string;
IsForward: boolean; AContext: TConvertContext; out ObjLit: TJSObjectLiteral): TJSCallExpression; virtual; IsForward: boolean; AContext: TConvertContext; out ObjLit: TJSObjectLiteral): TJSCallExpression; virtual;
Function CreateRTTIMemberField(V: TPasVariable; AContext: TConvertContext): TJSElement; virtual; Function CreateRTTIMemberField(Members: TFPList; Index: integer; AContext: TConvertContext): TJSElement; virtual;
Function CreateRTTIMemberMethod(Proc: TPasProcedure; AContext: TConvertContext): TJSElement; virtual; Function CreateRTTIMemberMethod(Proc: TPasProcedure; AContext: TConvertContext): TJSElement; virtual;
Function CreateRTTIMemberProperty(Prop: TPasProperty; AContext: TConvertContext): TJSElement; virtual; Function CreateRTTIMemberProperty(Prop: TPasProperty; AContext: TConvertContext): TJSElement; virtual;
Procedure CreateRTTIAnonymous(El: TPasType; AContext: TConvertContext); virtual; Procedure CreateRTTIAnonymous(El: TPasType; AContext: TConvertContext); virtual;
@ -15333,6 +15333,7 @@ var
VarSt: TJSVariableStatement; VarSt: TJSVariableStatement;
NewEl: TJSElement; NewEl: TJSElement;
C: TClass; C: TClass;
Members: TFPList;
begin begin
ok:=false; ok:=false;
Call:=nil; Call:=nil;
@ -15346,16 +15347,17 @@ begin
// add $r to local vars, to avoid name clashes and for nicer debugging // add $r to local vars, to avoid name clashes and for nicer debugging
FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil); FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil);
For i:=0 to El.Members.Count-1 do Members:=El.Members;
For i:=0 to Members.Count-1 do
begin begin
P:=TPasElement(El.Members[i]); P:=TPasElement(Members[i]);
if P.Visibility in [visPrivate,visStrictPrivate] then if P.Visibility in [visPrivate,visStrictPrivate] then
continue; continue;
if not IsElementUsed(P) then continue; if not IsElementUsed(P) then continue;
NewEl:=nil; NewEl:=nil;
C:=P.ClassType; C:=P.ClassType;
if C=TPasVariable then if C=TPasVariable then
NewEl:=CreateRTTIMemberField(TPasVariable(P),FuncContext) NewEl:=CreateRTTIMemberField(Members,i,FuncContext)
else if C.InheritsFrom(TPasProcedure) then else if C.InheritsFrom(TPasProcedure) then
NewEl:=CreateRTTIMemberMethod(TPasProcedure(P),FuncContext) NewEl:=CreateRTTIMemberMethod(TPasProcedure(P),FuncContext)
else if C=TPasProperty then else if C=TPasProperty then
@ -16006,14 +16008,16 @@ var
NewEl: TJSElement; NewEl: TJSElement;
VarSt: TJSVariableStatement; VarSt: TJSVariableStatement;
C: TClass; C: TClass;
Members: TFPList;
begin begin
// add $r to local vars, to avoid name clashes and for nicer debugging // add $r to local vars, to avoid name clashes and for nicer debugging
FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil); FuncContext.AddLocalVar(GetBIName(pbivnRTTILocal),nil);
HasRTTIMembers:=false; HasRTTIMembers:=false;
For i:=0 to El.Members.Count-1 do Members:=El.Members;
For i:=0 to Members.Count-1 do
begin begin
P:=TPasElement(El.Members[i]); P:=TPasElement(Members[i]);
//writeln('TPasToJSConverter.ConvertClassType RTTI El[',i,']=',GetObjName(P)); //writeln('TPasToJSConverter.ConvertClassType RTTI El[',i,']=',GetObjName(P));
if El.ObjKind=okInterface then if El.ObjKind=okInterface then
// all interface methods are published // all interface methods are published
@ -16023,7 +16027,7 @@ begin
NewEl:=nil; NewEl:=nil;
C:=P.ClassType; C:=P.ClassType;
if C=TPasVariable then if C=TPasVariable then
NewEl:=CreateRTTIMemberField(TPasVariable(P),FuncContext) NewEl:=CreateRTTIMemberField(Members,i,FuncContext)
else if C.InheritsFrom(TPasProcedure) then else if C.InheritsFrom(TPasProcedure) then
NewEl:=CreateRTTIMemberMethod(TPasProcedure(P),FuncContext) NewEl:=CreateRTTIMemberMethod(TPasProcedure(P),FuncContext)
else if C=TPasProperty then else if C=TPasProperty then
@ -16767,11 +16771,13 @@ begin
end; end;
end; end;
function TPasToJSConverter.CreateRTTIMemberField(V: TPasVariable; function TPasToJSConverter.CreateRTTIMemberField(Members: TFPList;
AContext: TConvertContext): TJSElement; Index: integer; AContext: TConvertContext): TJSElement;
// create $r.addField("varname",typeinfo); // create $r.addField("varname",typeinfo);
var var
V: TPasVariable;
Call: TJSCallExpression; Call: TJSCallExpression;
function VarTypeInfoAlreadyCreated(VarType: TPasType): boolean; function VarTypeInfoAlreadyCreated(VarType: TPasType): boolean;
var var
i: Integer; i: Integer;
@ -16795,6 +16801,7 @@ var
VarType: TPasType; VarType: TPasType;
begin begin
Result:=nil; Result:=nil;
V:=TPasVariable(Members[Index]);
VarType:=V.VarType; VarType:=V.VarType;
if (VarType<>nil) and (VarType.Name='') then if (VarType<>nil) and (VarType.Name='') then
begin begin