2
0

genvartests.pp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. const
  2. types: array[1..19] of string[20] =
  3. ('formal','comp','int64','currency','longint','cardinal','word','smallint',
  4. 'byte','shortint',
  5. 'shortstring','ansistring','single','double','extended','char','boolean',
  6. 'widestring','widechar');
  7. compidx=2;
  8. int64idx=3;
  9. doubleidx=14;
  10. extendedidx=15;
  11. curridx=4;
  12. function tostr(i: longint): string;
  13. begin
  14. str(i,tostr);
  15. end;
  16. {$i+}
  17. var
  18. k: longint;
  19. i,j: byte;
  20. t: text;
  21. begin
  22. k := 1;
  23. for i := low(types) to high(types)-1 do
  24. for j := succ(i) to high(types) do
  25. begin
  26. assign(t,'tvarol'+tostr(k)+'.pp');
  27. rewrite(t);
  28. writeln(t,'{$ifndef bigfile}');
  29. writeln(t,'{$ifdef fpc}');
  30. writeln(t,'{$mode delphi}');
  31. writeln(t,'{$else fpc}');
  32. writeln(t,'{$define FPC_HAS_TYPE_EXTENDED}');
  33. writeln(t,'{$endif fpc}');
  34. writeln(t,'{$endif bigfile}');
  35. writeln(t);
  36. types[compidx]:='comp'+tostr(k);
  37. writeln(t,'type ');
  38. writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
  39. if not(j in [doubleidx,extendedidx]) then
  40. writeln(t,' ',types[compidx],' = double;')
  41. else
  42. writeln(t,' ',types[compidx],' = currency;');
  43. writeln(t,'{$else FPC_COMP_IS_INT64}');
  44. writeln(t,' ',types[compidx],' = comp;');
  45. writeln(t,'{$endif FPC_COMP_IS_INT64}');
  46. if (i in [curridx,compidx,doubleidx]) and
  47. (j=extendedidx) then
  48. writeln(t,'{$ifdef FPC_HAS_TYPE_EXTENDED}');
  49. if (i <> low(types)) then
  50. writeln(t,'procedure test',tostr(k),'(a: ',types[i],'); overload;')
  51. else
  52. writeln(t,'procedure test',tostr(k),'(var a); overload;');
  53. writeln(t,' begin');
  54. {
  55. if (i=compidx) then
  56. begin
  57. writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
  58. writeln(t,' writeln(''COMPFAILQ'');');
  59. writeln(t,'{$endif FPC_COMP_IS_INT64}')
  60. end;
  61. }
  62. writeln(t,' writeln(''',types[i],' called instead of ',types[j],''');');
  63. writeln(t,' writeln(''XXX'')');
  64. writeln(t,' end;');
  65. writeln(t);
  66. writeln(t,'procedure test',tostr(k),'(a: ',types[j],'); overload;');
  67. writeln(t,' begin');
  68. {
  69. if (i=compidx) then
  70. begin
  71. writeln(t,'{$ifdef FPC_COMP_IS_INT64}');
  72. writeln(t,' writeln(''COMPFAILV'');');
  73. writeln(t,'{$endif FPC_COMP_IS_INT64}')
  74. end;
  75. }
  76. writeln(t,' writeln(''',types[j],' called instead of ',types[i],''');');
  77. writeln(t,' writeln(''YYY'')');
  78. writeln(t,' end;');
  79. writeln(t);
  80. { global to avoid problems with invalid floats }
  81. { due to uninitialised variables, and to avoid }
  82. { having to generate type-specific init code }
  83. writeln(t,'var');
  84. if (i <> low(types)) then
  85. writeln(t,' x',tostr(k),': ',types[i],';')
  86. else
  87. writeln(t,' x',tostr(k),': longint;');
  88. writeln(t);
  89. writeln(t,' y',tostr(k),': ',types[j],';');
  90. writeln(t,'procedure dotest',tostr(k),';');
  91. writeln(t,'var');
  92. writeln(t,' v: variant;');
  93. writeln(t);
  94. writeln(t,'begin');
  95. writeln(t,' try');
  96. writeln(t,' v := x',tostr(k),';');
  97. writeln(t,' test',tostr(k),'(v);');
  98. writeln(t,' except');
  99. writeln(t,' on E : TObject do');
  100. writeln(t,' writeln(''QQQ'');');
  101. writeln(t,' end;');
  102. writeln(t);
  103. writeln(t,' try');
  104. writeln(t,' v := y',tostr(k),';');
  105. writeln(t,' test',tostr(k),'(v);');
  106. writeln(t,' except');
  107. writeln(t,' on E : TObject do');
  108. writeln(t,' writeln(''VVV'');');
  109. writeln(t,' end;');
  110. writeln(t,'end;');
  111. writeln(t);
  112. writeln(t,'{$ifndef bigfile} begin');
  113. writeln(t,' dotest',tostr(k),';');
  114. writeln(t,'end. {$endif not bigfile}');
  115. if (((i in [curridx,compidx,doubleidx]) and
  116. (j=extendedidx))) then
  117. begin
  118. writeln(t,'{$else FPC_HAS_TYPE_EXTENDED}');
  119. writeln(t,'begin');
  120. if (i=doubleidx) and
  121. (j=curridx) then
  122. { compilation has to fail }
  123. writeln(t,' abc');
  124. writeln(t,'end.');
  125. writeln(t,'{$endif FPC_HAS_TYPE_EXTENDED}');
  126. end;
  127. (*
  128. if ({(i=compidx) and
  129. ((j=int64idx) or
  130. (j=doubleidx)) or
  131. }
  132. ((i in [curridx,compidx,doubleidx]) and
  133. (j=extendedidx))) then
  134. begin
  135. writeln(t,'{$else}');
  136. writeln(t,'begin');
  137. if (i=doubleidx) and
  138. (j=curridx) then
  139. { compilation has to fail }
  140. writeln(t,' abc');
  141. // writeln(t,' halt(COMPFAIL);');
  142. writeln(t,'{$endif}');
  143. end;
  144. writeln(t,'end.');
  145. *)
  146. close(t);
  147. inc(k);
  148. end;
  149. end.