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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
const
types: array[1..19] of string[20] =
('formal','comp','int64','currency','longint','cardinal','word','smallint',
'byte','shortint',
'shortstring','ansistring','single','double','extended','char','boolean',
'widestring','widechar');
compidx=2;
int64idx=3;
doubleidx=14;
extendedidx=15;
curridx=4;
function tostr(i: longint): string;
begin
str(i,tostr);
end;
{$i+}
var
k: longint;
i,j: byte;
t: text;
begin
k := 1;
for i := low(types) to high(types)-1 do
for j := succ(i) to high(types) do
begin
assign(t,'tvarol'+tostr(k)+'.pp');
rewrite(t);
writeln(t,'{$ifndef bigfile}');
writeln(t,'{$ifdef fpc}');
writeln(t,'{$mode delphi}');
writeln(t,'{$else fpc}');
writeln(t,'{$define FPC_HAS_TYPE_EXTENDED}');
writeln(t,'{$endif fpc}');
writeln(t,'{$endif bigfile}');
writeln(t);
types[compidx]:='comp'+tostr(k);
writeln(t,'type ');
writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
if not(j in [doubleidx,extendedidx]) then
writeln(t,' ',types[compidx],' = double;')
else
writeln(t,' ',types[compidx],' = currency;');
writeln(t,'{$else FPC_COMP_IS_INT64}');
writeln(t,' ',types[compidx],' = comp;');
writeln(t,'{$endif FPC_COMP_IS_INT64}');
if (i in [curridx,compidx,doubleidx]) and
(j=extendedidx) then
writeln(t,'{$ifdef FPC_HAS_TYPE_EXTENDED}');
if (i <> low(types)) then
writeln(t,'procedure test',tostr(k),'(a: ',types[i],'); overload;')
else
writeln(t,'procedure test',tostr(k),'(var a); overload;');
writeln(t,' begin');
{
if (i=compidx) then
begin
writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
writeln(t,' writeln(''COMPFAILQ'');');
writeln(t,'{$endif FPC_COMP_IS_INT64}')
end;
}
writeln(t,' writeln(''',types[i],' called instead of ',types[j],''');');
writeln(t,' writeln(''XXX'')');
writeln(t,' end;');
writeln(t);
writeln(t,'procedure test',tostr(k),'(a: ',types[j],'); overload;');
writeln(t,' begin');
{
if (i=compidx) then
begin
writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
writeln(t,' writeln(''COMPFAILV'');');
writeln(t,'{$endif FPC_COMP_IS_INT64}')
end;
}
writeln(t,' writeln(''',types[j],' called instead of ',types[i],''');');
writeln(t,' writeln(''YYY'')');
writeln(t,' end;');
writeln(t);
{ global to avoid problems with invalid floats }
{ due to uninitialised variables, and to avoid }
{ having to generate type-specific init code }
writeln(t,'var');
if (i <> low(types)) then
writeln(t,' x',tostr(k),': ',types[i],';')
else
writeln(t,' x',tostr(k),': longint;');
writeln(t);
writeln(t,' y',tostr(k),': ',types[j],';');
writeln(t,'procedure dotest',tostr(k),';');
writeln(t,'var');
writeln(t,' v: variant;');
writeln(t);
writeln(t,'begin');
writeln(t,' try');
writeln(t,' v := x',tostr(k),';');
writeln(t,' test',tostr(k),'(v);');
writeln(t,' except');
writeln(t,' on E : TObject do');
writeln(t,' writeln(''QQQ'');');
writeln(t,' end;');
writeln(t);
writeln(t,' try');
writeln(t,' v := y',tostr(k),';');
writeln(t,' test',tostr(k),'(v);');
writeln(t,' except');
writeln(t,' on E : TObject do');
writeln(t,' writeln(''VVV'');');
writeln(t,' end;');
writeln(t,'end;');
writeln(t);
writeln(t,'{$ifndef bigfile} begin');
writeln(t,' dotest',tostr(k),';');
writeln(t,'end. {$endif not bigfile}');
if (((i in [curridx,compidx,doubleidx]) and
(j=extendedidx))) then
begin
writeln(t,'{$else FPC_HAS_TYPE_EXTENDED}');
writeln(t,'begin');
if (i=doubleidx) and
(j=curridx) then
{ compilation has to fail }
writeln(t,' abc');
writeln(t,'end.');
writeln(t,'{$endif FPC_HAS_TYPE_EXTENDED}');
end;
(*
if ({(i=compidx) and
((j=int64idx) or
(j=doubleidx)) or
}
((i in [curridx,compidx,doubleidx]) and
(j=extendedidx))) then
begin
writeln(t,'{$else}');
writeln(t,'begin');
if (i=doubleidx) and
(j=curridx) then
{ compilation has to fail }
writeln(t,' abc');
// writeln(t,' halt(COMPFAIL);');
writeln(t,'{$endif}');
end;
writeln(t,'end.');
*)
close(t);
inc(k);
end;
end.
|