mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-11-02 07:49:32 +01:00
+ pgenutil.pas:
add a procedure which adds a type symbol to a non-Delphi-mode generic class or record which has the same name as the unit global dummy symbol for that generic. I don't know why I had that idea earlier as this will simplify some of the conditions in the parser again (I haven't changed these yet, but I hope to do that at least when I start working on generic functions).
* pgenutil.pas, generate_specialization:
correctly handle "specialize TSomeGeneric<T>" as method parameter in a generic with the newly added rename symbol
* pdecobj.pas, object_dec & ptype.pas, record_dec:
call the procedure to add the rename symbol (the procedure checks whether the mode is correct)
* ppu.pas:
increase PPU version so that we don't use non-Delphi mode units with generics, but without the rename symbol
+ added tests:
the one in webtbs are for classes/objects and those in test are for records
git-svn-id: trunk@21603 -
49 lines
757 B
ObjectPascal
49 lines
757 B
ObjectPascal
{$mode objfpc}{$h+}
|
|
{$modeswitch advancedrecords}
|
|
|
|
unit tgeneric77;
|
|
|
|
interface
|
|
|
|
type
|
|
|
|
{ TPointEx }
|
|
|
|
generic TPointEx<T> = record
|
|
X, Y: T;
|
|
function Create(const AX, AY: T): TPointEx;
|
|
class procedure Swap(var A, B: TPointEx); static;
|
|
class procedure OrderByY(var A, B: TPointEx); static;
|
|
end;
|
|
|
|
//TPoint = specialize TPointEx<integer>;
|
|
TPointF = specialize TPointEx<single>;
|
|
|
|
implementation
|
|
|
|
{ TPoint<T> }
|
|
|
|
function TPointEx.Create(const AX, AY: T): TPointEx;
|
|
begin
|
|
result.X:=AX;
|
|
result.Y:=AY;
|
|
end;
|
|
|
|
class procedure TPointEx.Swap(var A, B: TPointEx);
|
|
var
|
|
tmp: TPointEx;
|
|
begin
|
|
tmp:=A;
|
|
A:=B;
|
|
B:=tmp;
|
|
end;
|
|
|
|
class procedure TPointEx.OrderByY(var A, B: TPointEx);
|
|
begin
|
|
if A.Y > B.Y then
|
|
TPointEx.Swap(A,B);
|
|
end;
|
|
|
|
|
|
end.
|