mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-21 11:20:24 +02:00
pastojs: shortrefglobals: enumvalue
This commit is contained in:
parent
fd28aa84e3
commit
8ae6ee1771
@ -2072,7 +2072,7 @@ type
|
|||||||
Procedure AddImplHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
Procedure AddImplHeaderStatement(JS: TJSElement; PosEl: TPasElement; aContext: TConvertContext); virtual;
|
||||||
Procedure AddDelayedInits(El: TPasProgram; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
Procedure AddDelayedInits(El: TPasProgram; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
||||||
Procedure AddDelaySpecializeInit(El: TPasGenericType; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
Procedure AddDelaySpecializeInit(El: TPasGenericType; Src: TJSSourceElements; AContext: TConvertContext); virtual;
|
||||||
// set
|
// enum and sets
|
||||||
Function CreateReferencedSet(El: TPasElement; SetExpr: TJSElement): TJSElement; virtual;
|
Function CreateReferencedSet(El: TPasElement; SetExpr: TJSElement): TJSElement; virtual;
|
||||||
// record
|
// record
|
||||||
Function CreateRecordInit(aRecord: TPasRecordType; Expr: TPasExpr;
|
Function CreateRecordInit(aRecord: TPasRecordType; Expr: TPasExpr;
|
||||||
@ -9659,6 +9659,12 @@ begin
|
|||||||
DoError(20190211111038,nNoMemberIsProvidedToAccessProperty,sNoMemberIsProvidedToAccessProperty,[],RightEl);
|
DoError(20190211111038,nNoMemberIsProvidedToAccessProperty,sNoMemberIsProvidedToAccessProperty,[],RightEl);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
else if RightRefDecl.ClassType=TPasEnumValue then
|
||||||
|
begin
|
||||||
|
// enum value
|
||||||
|
Result:=ConvertIdentifierExpr(RightEl,'',aContext);
|
||||||
|
exit;
|
||||||
end;
|
end;
|
||||||
if (AContext.Access=caAssign)
|
if (AContext.Access=caAssign)
|
||||||
and aResolver.IsClassField(RightRefDecl) then
|
and aResolver.IsClassField(RightRefDecl) then
|
||||||
|
@ -53,7 +53,8 @@ type
|
|||||||
supTObject,
|
supTObject,
|
||||||
supTVarRec,
|
supTVarRec,
|
||||||
supTypeInfo,
|
supTypeInfo,
|
||||||
supTInterfacedObject
|
supTInterfacedObject,
|
||||||
|
supWriteln
|
||||||
);
|
);
|
||||||
TSystemUnitParts = set of TSystemUnitPart;
|
TSystemUnitParts = set of TSystemUnitPart;
|
||||||
|
|
||||||
@ -1748,6 +1749,9 @@ begin
|
|||||||
' TTypeInfoInterface = class external name ''rtl.tTypeInfoInterface''(TTypeInfo) end;',
|
' TTypeInfoInterface = class external name ''rtl.tTypeInfoInterface''(TTypeInfo) end;',
|
||||||
'']);
|
'']);
|
||||||
end;
|
end;
|
||||||
|
if supWriteln in Parts then
|
||||||
|
Intf.Add('procedure writeln; varargs; external name ''console.log'';');
|
||||||
|
|
||||||
Intf.Add('var');
|
Intf.Add('var');
|
||||||
Intf.Add(' ExitCode: Longint = 0;');
|
Intf.Add(' ExitCode: Longint = 0;');
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ type
|
|||||||
// unit optimization: jsshortrefglobals
|
// unit optimization: jsshortrefglobals
|
||||||
procedure TestOptShortRefGlobals_Program;
|
procedure TestOptShortRefGlobals_Program;
|
||||||
procedure TestOptShortRefGlobals_Unit_FromIntfImpl_ToIntfImpl;
|
procedure TestOptShortRefGlobals_Unit_FromIntfImpl_ToIntfImpl;
|
||||||
|
procedure TestOptShortRefGlobals_Enums;
|
||||||
procedure TestOptShortRefGlobals_Property;
|
procedure TestOptShortRefGlobals_Property;
|
||||||
procedure TestOptShortRefGlobals_ExternalAbstract;
|
procedure TestOptShortRefGlobals_ExternalAbstract;
|
||||||
procedure TestOptShortRefGlobals_Class;
|
procedure TestOptShortRefGlobals_Class;
|
||||||
@ -414,6 +415,77 @@ begin
|
|||||||
'']));
|
'']));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestOptimizations.TestOptShortRefGlobals_Enums;
|
||||||
|
begin
|
||||||
|
AddModuleWithIntfImplSrc('UnitA.pas',
|
||||||
|
LinesToStr([
|
||||||
|
'type',
|
||||||
|
' TColor = (red,green,blue);',
|
||||||
|
'',
|
||||||
|
'']),
|
||||||
|
LinesToStr([
|
||||||
|
'']));
|
||||||
|
AddModuleWithIntfImplSrc('UnitB.pas',
|
||||||
|
LinesToStr([
|
||||||
|
'type',
|
||||||
|
' TSize = (small,big);',
|
||||||
|
'',
|
||||||
|
'']),
|
||||||
|
LinesToStr([
|
||||||
|
'']));
|
||||||
|
StartUnit(true,[supWriteln]);
|
||||||
|
Add([
|
||||||
|
'{$optimization JSShortRefGlobals}',
|
||||||
|
'interface',
|
||||||
|
'uses unita;',
|
||||||
|
'const',
|
||||||
|
' ColorRed = TColor.Red;',
|
||||||
|
'procedure Fly;',
|
||||||
|
'implementation',
|
||||||
|
'uses unitb;',
|
||||||
|
'const',
|
||||||
|
' SizeSmall = TSize.Small;',
|
||||||
|
'procedure Fly;',
|
||||||
|
'begin',
|
||||||
|
' writeln(ColorRed);',
|
||||||
|
' writeln(TColor.Blue);',
|
||||||
|
' writeln(SizeSmall);',
|
||||||
|
' writeln(TSize.Big);',
|
||||||
|
' writeln(unitb.TSize.Big);',
|
||||||
|
'end;',
|
||||||
|
'']);
|
||||||
|
ConvertUnit;
|
||||||
|
CheckSource('TestOptShortRefGlobals_Enums',
|
||||||
|
LinesToStr([
|
||||||
|
'var $impl = $mod.$impl;',
|
||||||
|
'var $lm = pas.UnitA;',
|
||||||
|
'var $lt = $lm.TColor;',
|
||||||
|
'var $lt1 = $lt.red;',
|
||||||
|
'var $lt2 = $lt.blue;',
|
||||||
|
'var $lm1 = null;',
|
||||||
|
'var $lt3 = null;',
|
||||||
|
'var $lt4 = null;',
|
||||||
|
'var $lt5 = null;',
|
||||||
|
'this.ColorRed = $lt1;',
|
||||||
|
'this.Fly = function () {',
|
||||||
|
' console.log($lt1);',
|
||||||
|
' console.log($lt2);',
|
||||||
|
' console.log($lt4);',
|
||||||
|
' console.log($lt5);',
|
||||||
|
' console.log($lt5);',
|
||||||
|
'};',
|
||||||
|
'']),
|
||||||
|
LinesToStr([
|
||||||
|
'']),
|
||||||
|
LinesToStr([
|
||||||
|
'$lm1 = pas.UnitB;',
|
||||||
|
'$lt3 = $lm1.TSize;',
|
||||||
|
'$lt4 = $lt3.small;',
|
||||||
|
'$lt5 = $lt3.big;',
|
||||||
|
'$impl.SizeSmall = $lt4;',
|
||||||
|
'']));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestOptimizations.TestOptShortRefGlobals_Property;
|
procedure TTestOptimizations.TestOptShortRefGlobals_Property;
|
||||||
begin
|
begin
|
||||||
AddModuleWithIntfImplSrc('UnitA.pas',
|
AddModuleWithIntfImplSrc('UnitA.pas',
|
||||||
|
Loading…
Reference in New Issue
Block a user