mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 17:28:14 +02:00

symconst.pas: + extend "thelpertype" by "ht_type" which tells the code in "pdecobj.parse_extended_type" that a type helper declaration has been parsed node.pas: + add a constant which identifies all constant node types ptype.pas: + read_named_type: add a parameter "hadtypetoken" to tell the code whether a "type" token had been parsed before + read_named_type: if an identifier "helper" is parsed we need to check whether "hadtypetoken" is true and the modeswitch "m_class" is set, but the "m_delphi" one is not; in that case we have a "type helper" declaration pgenutil.pas, generate_specialization: * adjust call to read_named_type pdecl.pas, types_dec: * adjust call to read_named_type pdecobj.pas: * parse_extended_type: extend for correct handling of primitive types (includes Delphi compatible handling as well) and reject types that are explicitly not allowed * method_dec: require "static" for class methods in type helpers * method_doc: allow constructors for type helpers as well paramgr.pas, tparamanager: * set_common_funcretloc_info: handle type helper constructors like record constructors * handle_common_ret_in_param: the "self" value of a type helper constructor is also returned in a parameter pexpr.pas: + add a function to postfixoperators which tries to find and apply a type helper for a given type * postfixoperators: try to apply type helpers for ordinal constants * postfixoperators: use the correct string type for string constants * postfixoperators: try to apply type helpers for enum constants * postfixoperators: try to apply type helpers for arrays * postfixoperators: try to apply type helpers for Variant * postfixoperators: try to apply type helpers for pointer types * postfixoperators: try to apply type helpers for other types * factor: check postfixoperators after _REALNUMBER, _CCHAR, _CWCHAR, _TRUE and _FALSE * factor: also check postfixoperators if a _POINT follows a _NIL symdef.pas, tdefawaresymtablestack.addhelpers: * use "generate_objectpascal_helper_key" to generate the key symtable.pas: + add function to generate the key value for the map of extended types using the extended def * adjust "search_last_objectpascal_helper" and "search_objectpascal_helper" to handle primitive types as well * use the new "generate_objectpascal_helper_key" function to generate the key pparautl.pas: * insert_self_and_vmt_para: don't insert the $vmt symbol for record or type helpers (ToDo: check whether class helpers really need the symbol as well) * insert_self_and_vmt_para: pass "self" as var parameter for type helpers as well psub.pas, generate_bodyentry_block: * also allow type helpers for constructor methods ncal.pas, tcallnode.gen_self_tree: * also use a temp variable for type helper constructors ncgcal.pas, tcgcallnode.secondcallparan: * allow Pointers to be passed as address param if it is the Self value of a type helper extending a pointer type * correctly handle the location in case of type helper constructors + add tests git-svn-id: trunk@23580 -
155 lines
3.2 KiB
ObjectPascal
155 lines
3.2 KiB
ObjectPascal
{ this tests that constructors in helpers are working correctly }
|
|
|
|
program tthlp14;
|
|
|
|
{$mode objfpc}
|
|
{$apptype console}
|
|
|
|
uses
|
|
uthlp, math;
|
|
|
|
var
|
|
ui8: UInt8;
|
|
ui16: UInt16;
|
|
ui32: UInt32;
|
|
ui64: UInt64;
|
|
i8: Int8;
|
|
i16: Int16;
|
|
i32: Int32;
|
|
i64: Int64;
|
|
s: Single;
|
|
d: Double;
|
|
e: Extended;
|
|
ss: ShortString;
|
|
_as: AnsiString;
|
|
ws: WideString;
|
|
us: UnicodeString;
|
|
ac: AnsiChar;
|
|
wc: WideChar;
|
|
pb8: Boolean;
|
|
pb16: Boolean16;
|
|
pb32: Boolean32;
|
|
pb64: Boolean64;
|
|
b8: ByteBool;
|
|
b16: WordBool;
|
|
b32: LongBool;
|
|
b64: QWordBool;
|
|
ml: MyLongInt;
|
|
ts: TTestSet;
|
|
te: TTestEnum;
|
|
ta, ta2: TTestArray;
|
|
p: Pointer;
|
|
pl: PLongInt;
|
|
v: Variant;
|
|
begin
|
|
Writeln('Ordinal variables');
|
|
ui8 := UInt8.Create(42);
|
|
if ui8 <> 42 then
|
|
Halt(1);
|
|
ui16 := UInt16.Create(42);
|
|
if ui16 <> 42 then
|
|
Halt(2);
|
|
ui32 := UInt32.Create(42);
|
|
if ui32 <> 42 then
|
|
Halt(3);
|
|
ui64 := UInt64.Create(42);
|
|
if ui64 <> 42 then
|
|
Halt(4);
|
|
i8 := Int8.Create(42);
|
|
if i8 <> 42 then
|
|
Halt(5);
|
|
i16 := Int16.Create(42);
|
|
if i16 <> 42 then
|
|
Halt(6);
|
|
i32 := Int32.Create(42);
|
|
if i32 <> 42 then
|
|
Halt(7);
|
|
i64 := Int64.Create(42);
|
|
if i64 <> 42 then
|
|
Halt(8);
|
|
Writeln('Boolean variables');
|
|
pb8 := Boolean.Create(True);
|
|
if not pb8 then
|
|
Halt(9);
|
|
pb16 := Boolean16.Create(True);
|
|
if not pb16 then
|
|
Halt(10);
|
|
pb32 := Boolean32.Create(True);
|
|
if not pb32 then
|
|
Halt(11);
|
|
pb64 := Boolean64.Create(True);
|
|
if not pb64 then
|
|
Halt(12);
|
|
b8 := ByteBool.Create(True);
|
|
if not b8 then
|
|
Halt(13);
|
|
b16 := WordBool.Create(True);
|
|
if not b16 then
|
|
Halt(14);
|
|
b32 := LongBool.Create(True);
|
|
if not b32 then
|
|
Halt(15);
|
|
b64 := QWordBool.Create(True);
|
|
if not b64 then
|
|
Halt(16);
|
|
Writeln('Float variables');
|
|
s := Single.Create(4.2);
|
|
if not SameValue(s, Single(4.2), 1e-100) then
|
|
Halt(17);
|
|
d := Double.Create(4.2);
|
|
if not SameValue(d, Double(4.2), 1e-100) then
|
|
Halt(18);
|
|
{$if sizeof(Extended) <> sizeof(Double)}
|
|
e := Extended.Create(4.2);
|
|
if not SameValue(e, Extended(4.2), 1e-100) then
|
|
Halt(19);
|
|
{$endif}
|
|
Writeln('Char variables');
|
|
ac := AnsiChar.Create('a');
|
|
if ac <> 'a' then
|
|
Halt(20);
|
|
wc := WideChar.Create(#$1234);
|
|
if wc <> #$1234 then
|
|
Halt(21);
|
|
Writeln('String variables');
|
|
ss := ShortString.Create('Test');
|
|
if ss <> 'Test' then
|
|
Halt(22);
|
|
_as := AnsiString.Create('Test');
|
|
if _as <> 'Test' then
|
|
Halt(23);
|
|
ws := WideString.Create(#$1234#$4321);
|
|
if ws <> #$1234#$4321 then
|
|
Halt(24);
|
|
us := UnicodeString.Create(#$1234#$4321);
|
|
if us <> #$1234#$4321 then
|
|
Halt(25);
|
|
Writeln('Pointer variables');
|
|
p := Pointer.Create(@p);
|
|
if p <> @p then
|
|
Halt(26);
|
|
pl := PLongInt.Create(@pl);
|
|
if pl <> @pl then
|
|
Halt(27);
|
|
Writeln('Other variables');
|
|
ml := MyLongInt.Create(42);
|
|
if ml <> 42 then
|
|
Halt(28);
|
|
te := TTestEnum.Create(teOne);
|
|
if te <> teOne then
|
|
Halt(29);
|
|
ts := TTestSet.Create([teOne, teTwo]);
|
|
if ts <> [teOne, teTwo] then
|
|
Halt(30);
|
|
SetLength(ta2, 2);
|
|
ta2[0] := 42;
|
|
ta2[1] := 21;
|
|
ta := TTestArray.Create(ta2);
|
|
if (Length(ta) <> 2) or (ta[0] <> ta2[0]) or (ta[1] <> ta2[1]) then
|
|
Halt(31);
|
|
v := Variant.Create(42);
|
|
if v <> 42 then
|
|
Halt(32);
|
|
Writeln('OK');
|
|
end.
|