mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 22:27:57 +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 -
99 lines
2.1 KiB
ObjectPascal
99 lines
2.1 KiB
ObjectPascal
{ this tests that the correct helper is used for variables }
|
|
|
|
program tthlp3;
|
|
|
|
{$mode objfpc}
|
|
{$apptype console}
|
|
|
|
uses
|
|
uthlp;
|
|
|
|
procedure TestResult(aActual, aExpected, aError: LongInt);
|
|
begin
|
|
if aActual <> aExpected then begin
|
|
Writeln('Expected: ', aExpected, ' got: ', aActual);
|
|
Halt(aError);
|
|
end;
|
|
end;
|
|
|
|
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: TTestArray;
|
|
p: Pointer;
|
|
pl: PLongInt;
|
|
v: Variant;
|
|
begin
|
|
Writeln('Ordinal variables');
|
|
TestResult(ui8.Test, 1, 1);
|
|
TestResult(ui16.Test, 2, 2);
|
|
TestResult(ui32.Test, 4, 3);
|
|
TestResult(ui64.Test, 8, 4);
|
|
TestResult(i8.Test, - 1, 5);
|
|
TestResult(i16.Test, - 2, 6);
|
|
TestResult(i32.Test, - 4, 7);
|
|
TestResult(i64.Test, - 8, 8);
|
|
Writeln('Boolean variables');
|
|
TestResult(pb8.Test, 1, 9);
|
|
TestResult(pb16.Test, 2, 10);
|
|
TestResult(pb32.Test, 4, 11);
|
|
TestResult(pb64.Test, 8, 12);
|
|
TestResult(b8.Test, - 1, 13);
|
|
TestResult(b16.Test, - 2, 14);
|
|
TestResult(b32.Test, - 4, 15);
|
|
TestResult(b64.Test, - 8, 16);
|
|
Writeln('Float variables');
|
|
TestResult(s.Test, 4, 17);
|
|
TestResult(d.Test, 8, 18);
|
|
{$if sizeof(Extended) = sizeof(Double)}
|
|
// expect the helper for Doubles
|
|
TestResult(e.Test, 8, 19);
|
|
{$else}
|
|
TestResult(e.Test, 10, 19);
|
|
{$endif}
|
|
Writeln('Char variables');
|
|
TestResult(ac.Test, - 1, 20);
|
|
TestResult(wc.Test, - 2, 21);
|
|
Writeln('String variables');
|
|
TestResult(ss.Test, 1, 22);
|
|
TestResult(_as.Test, 2, 23);
|
|
TestResult(ws.Test, 3, 24);
|
|
TestResult(us.Test, 4, 25);
|
|
Writeln('Pointer variables');
|
|
TestResult(p.Test, 1, 26);
|
|
TestResult(pl.Test, 4, 27);
|
|
Writeln('Other variables');
|
|
TestResult(ml.Test, 42, 28);
|
|
TestResult(te.Test, 1, 29);
|
|
TestResult(ts.Test, 2, 30);
|
|
TestResult(ta.Test, 0, 31);
|
|
TestResult(v.Test, 3, 32);
|
|
Writeln('OK');
|
|
end.
|