pas2js: fixed rtti record field anonymous array

git-svn-id: trunk@45574 -
This commit is contained in:
Mattias Gaertner 2020-06-03 13:25:15 +00:00
parent 533312c619
commit dbc2d630c0
2 changed files with 40 additions and 5 deletions

View File

@ -18287,19 +18287,41 @@ var
ObjLit.Expr:=JS;
end;
function VarTypeInfoAlreadyCreated(VarType: TPasType): boolean;
var
i: Integer;
PrevMember: TPasElement;
begin
i:=Index-1;
while (i>=0) do
begin
PrevMember:=TPasElement(Members[i]);
if (PrevMember is TPasVariable) and (TPasVariable(PrevMember).VarType=VarType)
and IsElementUsed(PrevMember) then
exit(true);
dec(i);
end;
Result:=false;
end;
var
JSTypeInfo: TJSElement;
aName: String;
aResolver: TPas2JSResolver;
Attr: TPasExprArray;
VarType: TPasType;
begin
Result:=nil;
aResolver:=AContext.Resolver;
V:=TPasVariable(Members[Index]);
if (V.VarType<>nil) and (V.VarType.Name='') then
CreateRTTIAnonymous(V.VarType,AContext);
VarType:=V.VarType;
if (VarType<>nil) and (VarType.Name='') then
begin
if not VarTypeInfoAlreadyCreated(VarType) then
CreateRTTIAnonymous(VarType,AContext);
end;
JSTypeInfo:=CreateTypeInfoRef(V.VarType,AContext,V);
JSTypeInfo:=CreateTypeInfoRef(VarType,AContext,V);
OptionsEl:=nil;
// Note: create JSTypeInfo first, it may raise an exception
Call:=CreateCallExpression(V);

View File

@ -28690,6 +28690,7 @@ begin
Add(' VarShI: shortint;');
Add(' VarBy: byte;');
Add(' VarExt: longint external name ''VarExt'';');
Add(' ArrA, ArrB: array of byte;');
Add(' end;');
Add('var p: pointer;');
Add(' Obj: tobject;');
@ -28713,8 +28714,12 @@ begin
' this.VarW = 0;',
' this.VarShI = 0;',
' this.VarBy = 0;',
' this.ArrA = [];',
' this.ArrB = [];',
' };',
' this.$final = function () {',
' this.ArrA = undefined;',
' this.ArrB = undefined;',
' };',
' var $r = this.$rtti;',
' $r.addField("VarLI", rtl.longint);',
@ -28728,6 +28733,11 @@ begin
' $r.addField("VarShI", rtl.shortint);',
' $r.addField("VarBy", rtl.byte);',
' $r.addField("VarExt", rtl.longint);',
' $mod.$rtti.$DynArray("TObject.ArrB$a", {',
' eltype: rtl.byte',
' });',
' $r.addField("ArrA", $mod.$rtti["TObject.ArrB$a"]);',
' $r.addField("ArrB", $mod.$rtti["TObject.ArrB$a"]);',
'});',
'this.p = null;',
'this.Obj = null;',
@ -29747,7 +29757,7 @@ begin
StartProgram(false);
Add('type');
Add(' TFloatRec = record');
Add(' d: array of char;');
Add(' c,d: array of char;');
// Add(' i: array of array of longint;');
Add(' end;');
Add('var p: pointer;');
@ -29760,11 +29770,13 @@ begin
CheckSource('TestRTTI_Record',
LinesToStr([ // statements
'rtl.recNewT($mod, "TFloatRec", function () {',
' this.c = [];',
' this.d = [];',
' this.$eq = function (b) {',
' return this.d === b.d;',
' return (this.c === b.c) && (this.d === b.d);',
' };',
' this.$assign = function (s) {',
' this.c = s.c;',
' this.d = s.d;',
' return this;',
' };',
@ -29772,6 +29784,7 @@ begin
' eltype: rtl.char',
' });',
' var $r = $mod.$rtti.$Record("TFloatRec", {});',
' $r.addField("c", $mod.$rtti["TFloatRec.d$a"]);',
' $r.addField("d", $mod.$rtti["TFloatRec.d$a"]);',
'});',
'this.p = null;',