summaryrefslogtreecommitdiff
path: root/tests/test/trtti19.pp
blob: 2c0f1e433aad0e5ce6f13465a936bcc6dd416f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
program trtti19;

{$mode objfpc}

uses
  TypInfo;

type
  TTestProc = procedure(var arg1; out arg2; constref arg3);
  TTestMethod = procedure(var arg1; out arg2; constref arg3) of object;

  PParamFlags = ^TParamFlags;
  PPPTypeInfo = ^PPTypeInfo;

var
  ti: PTypeInfo;
  td: PTypeData;
  procparam: PProcedureParam;
  pb: PByte;
  i: SizeInt;
begin
  // writeln(SizeOf(TparamFlags));
  ti := PTypeInfo(TypeInfo(TTestProc));
  td := GetTypeData(ti);
  if td^.ProcSig.ParamCount <> 3 then
    Halt(1);
  procparam := td^.ProcSig.GetParam(0);
  if Assigned(procparam^.ParamType) then
    Halt(2);
  if procparam^.ParamFlags * [pfVar] <> [pfVar] then
    Halt(3);
  procparam := td^.ProcSig.GetParam(1);
  if Assigned(procparam^.ParamType) then
    Halt(4);
  if procparam^.ParamFlags * [pfOut] <> [pfOut] then
    Halt(5);
  procparam := td^.ProcSig.GetParam(2);
  if Assigned(procparam^.ParamType) then
    Halt(6);
  if procparam^.ParamFlags * [pfConstRef] <> [pfConstRef] then
    Halt(7);
  
  ti := PTypeInfo(TypeInfo(TTestMethod));
  td := GetTypeData(ti);
  if td^.ParamCount <> 4 then
    Halt(8);
  pb := @td^.ParamList[0];
  pb := AlignTParamFlags(pb);
  if PParamFlags(pb)^ * [pfHidden, pfSelf] <> [pfHidden, pfSelf] then
    Halt(9);
  pb := pb + SizeOf(TParamFlags);
  pb := pb + SizeOf(Byte) + pb^;
  pb := pb + SizeOf(Byte) + pb^;

  pb := AlignTParamFlags(pb);
  if PParamFlags(pb)^ * [pfVar] <> [pfVar] then
    Halt(10);
  pb := pb + SizeOf(TParamFlags);
  pb := pb + SizeOf(Byte) + pb^;
  pb := pb + SizeOf(Byte) + pb^;

  pb := AlignTParamFlags(pb);
  if PParamFlags(pb)^ * [pfOut] <> [pfOut] then
    Halt(11);
  pb := pb + SizeOf(TParamFlags);
  pb := pb + SizeOf(Byte) + pb^;
  pb := pb + SizeOf(Byte) + pb^;

  pb := AlignTParamFlags(pb);
  if PParamFlags(pb)^ * [pfConstRef] <> [pfConstRef] then
    Halt(12);
  pb := pb + SizeOf(TParamFlags);
  pb := pb + SizeOf(Byte) + pb^;
  pb := pb + SizeOf(Byte) + pb^;

  pb := AlignPTypeInfo(pb + SizeOf(TCallConv));
  for i := 1 to td^.ParamCount - 1 do begin
    if PPPTypeInfo(pb)[i] <> Nil then begin
      Writeln(PPPTypeInfo(pb)[i]^^.Name);
      Halt(12 + i);
    end;
  end;

  Writeln('ok');
end.