mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 18:59:06 +02:00
codetools: added tests for type helpers
git-svn-id: trunk@50102 -
This commit is contained in:
parent
0075408ba2
commit
0ca8f14eff
@ -8254,6 +8254,9 @@ var
|
|||||||
debugln([' FindExpressionTypeOfTerm ResolveChildren']);
|
debugln([' FindExpressionTypeOfTerm ResolveChildren']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ResolveBaseTypeOfIdentifier;
|
ResolveBaseTypeOfIdentifier;
|
||||||
|
{$IFDEF ShowExprEval}
|
||||||
|
debugln([' FindExpressionTypeOfTerm ResolveChildren ExprType=',ExprTypeToString(ExprType)]);
|
||||||
|
{$ENDIF}
|
||||||
if (ExprType.Context.Node=nil) then exit;
|
if (ExprType.Context.Node=nil) then exit;
|
||||||
if (ExprType.Context.Node.Desc in AllUsableSourceTypes) then begin
|
if (ExprType.Context.Node.Desc in AllUsableSourceTypes) then begin
|
||||||
if ExprType.Context.Tool=Self then begin
|
if ExprType.Context.Tool=Self then begin
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
{
|
||||||
|
./finddeclarationtest --format=plain --suite=TestFindDeclaration_TypeHelper
|
||||||
|
}
|
||||||
unit fdt_typehelper;
|
unit fdt_typehelper;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
@ -10,31 +13,86 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TStringTypeHelper }
|
{ TShortStringTypeHelper }
|
||||||
|
|
||||||
TStringTypeHelper = type helper for ShortString
|
TShortStringTypeHelper = type helper for ShortString
|
||||||
public
|
public
|
||||||
function MyVar: integer;
|
function MyVar: integer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TStringTypeHelper }
|
||||||
|
|
||||||
|
TStringTypeHelper = type helper for String
|
||||||
|
public
|
||||||
|
function Get45: integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLongIntTypeHelper }
|
||||||
|
|
||||||
|
TLongIntTypeHelper = type helper for LongInt
|
||||||
|
public
|
||||||
|
function GetStr: string;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TEnumTypeHelper }
|
||||||
|
|
||||||
|
TEnumTypeHelper = type helper for TShiftStateEnum
|
||||||
|
public
|
||||||
|
function Get78: integer;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure DoIt;
|
procedure DoIt;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure DoIt;
|
procedure DoIt;
|
||||||
var
|
var
|
||||||
s: ShortString;
|
ShortS: ShortString;
|
||||||
|
AnsiS: string;
|
||||||
|
i: integer;
|
||||||
|
e: TShiftStateEnum;
|
||||||
begin
|
begin
|
||||||
s:='ABC';
|
ShortS:='ABC';
|
||||||
writeln('DoIt ',s.MyVar{declaration:fdt_typehelper.TStringTypeHelper.MyVar});
|
writeln('DoIt ',ShortS.MyVar{declaration:fdt_typehelper.TShortStringTypeHelper.MyVar});
|
||||||
|
|
||||||
|
i:='Hello'.Get45{declaration:fdt_typehelper.TStringTypeHelper.Get45};
|
||||||
|
if i<>45 then ;
|
||||||
|
|
||||||
|
AnsiS:=i.GetStr{declaration:fdt_typehelper.TLongIntTypeHelper.GetStr};
|
||||||
|
if AnsiS<>'' then ;
|
||||||
|
|
||||||
|
e:=ssDouble;
|
||||||
|
i:=e.Get78{ Not yet supported: declaration:fdt_typehelper.TEnumTypeHelper.Get78};
|
||||||
|
if i<>78 then ;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TStringTypeHelper }
|
{ TEnumTypeHelper }
|
||||||
|
|
||||||
function TStringTypeHelper.MyVar: integer;
|
function TEnumTypeHelper.Get78: integer;
|
||||||
|
begin
|
||||||
|
Result:=78;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TLongIntTypeHelper }
|
||||||
|
|
||||||
|
function TLongIntTypeHelper.GetStr: string;
|
||||||
|
begin
|
||||||
|
Result:=IntToStr(Self)
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TShortStringTypeHelper }
|
||||||
|
|
||||||
|
function TShortStringTypeHelper.MyVar: integer;
|
||||||
begin
|
begin
|
||||||
Result:=123;
|
Result:=123;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TStringTypeHelper }
|
||||||
|
|
||||||
|
function TStringTypeHelper.Get45: integer;
|
||||||
|
begin
|
||||||
|
Result:=45;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user