tcall1.pp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondcalln() }
  6. {****************************************************************}
  7. { PRE-REQUISITES: secondload() }
  8. { secondassign() }
  9. { secondtypeconv() }
  10. { secondtryexcept() }
  11. {****************************************************************}
  12. { DEFINES: }
  13. { FPC = Target is FreePascal compiler }
  14. {****************************************************************}
  15. { REMARKS: This tests secondcalln(), genentrycode() and }
  16. { genexitcode(). }
  17. { }
  18. { }
  19. {****************************************************************}
  20. program tcall;
  21. {$ifdef fpc}{$mode objfpc}{$endif}
  22. uses SysUtils;
  23. {
  24. class:
  25. class constructor
  26. 1a - success
  27. 1b - failure
  28. 2 class destructor
  29. 3 class method
  30. 4 virtual method
  31. 5 abstract method
  32. 6 static method
  33. object:
  34. object constructor
  35. 7a - success
  36. 7b - failure
  37. 8 object destructor
  38. 9 method
  39. 10 virtual method
  40. standard:
  41. 11 function
  42. 12 procedure
  43. 13 procedure variable
  44. modifiers:
  45. no parameters 1a 1b
  46. parameters
  47. - const 1a
  48. - value 1a
  49. - variable 1a
  50. - mixed 1a
  51. explicit self parameter
  52. operator directive
  53. assembler directive
  54. interrupt directive
  55. inline directive
  56. cdecl directive
  57. pascal directive
  58. safecall directive
  59. stdcall directive
  60. oldfpcall directive
  61. register directive
  62. }
  63. const
  64. GLOBAL_RESULT = $55;
  65. var
  66. globalresult : integer;
  67. failed : boolean;
  68. type
  69. tclass1 = class
  70. constructor create_none; { class constructor }
  71. constructor create_value(l:longint;b: byte);
  72. constructor create_var(var l:longint;var b: byte);
  73. constructor create_const(const l:longint; const b: byte);
  74. constructor create_mixed(var a: byte; b: byte; var c: byte; const d: byte);
  75. end;
  76. tclass2 = class
  77. constructor create_none; { class constructor }
  78. public
  79. b: array[1..$66666666] of byte;
  80. end;
  81. constructor tclass1.create_none;
  82. begin
  83. Inherited create;
  84. globalresult:=GLOBAL_RESULT;
  85. end;
  86. constructor tclass1.create_value(l:longint;b: byte);
  87. begin
  88. Inherited create;
  89. globalresult:=b;
  90. end;
  91. constructor tclass1.create_var(var l:longint;var b: byte);
  92. begin
  93. Inherited create;
  94. b:=GLOBAL_RESULT;
  95. end;
  96. constructor tclass1.create_const(const l:longint; const b: byte);
  97. begin
  98. Inherited create;
  99. globalresult := GLOBAL_RESULT;
  100. end;
  101. constructor tclass1.create_mixed(var a: byte; b: byte; var c: byte; const d: byte);
  102. begin
  103. Inherited create;
  104. globalresult := GLOBAL_RESULT;
  105. end;
  106. constructor tclass2.create_none;
  107. begin
  108. Inherited create;
  109. { the next line will normally not be reached, else
  110. it's a failure }
  111. globalresult:=0;
  112. end;
  113. procedure fail;
  114. begin
  115. WriteLn('Failure.');
  116. halt(1);
  117. end;
  118. function myheaperrornil(size : longint): integer;
  119. begin
  120. myheaperrornil:=1;
  121. end;
  122. function myheaperrorexception(size : longint): integer;
  123. begin
  124. myheaperrorexception:=0;
  125. end;
  126. var
  127. class_none: tclass1;
  128. class_value: tclass1;
  129. class_var: tclass1;
  130. class_const: tclass1;
  131. class_mixed: tclass1;
  132. class_none_fail : tclass2;
  133. a,b,c,d: byte;
  134. l:longint;
  135. Begin
  136. { reset test variables }
  137. globalresult := 0;
  138. failed := false;
  139. write('class constructor testing...');
  140. { secondcalln : class constructor success }
  141. class_none:=tclass1.create_none;
  142. if globalresult <> GLOBAL_RESULT then
  143. failed:= true;
  144. globalresult := 0;
  145. class_value:=tclass1.create_value(0,GLOBAL_RESULT);
  146. if globalresult <> GLOBAL_RESULT then
  147. failed:= true;
  148. globalresult := 0;
  149. b:=0;
  150. class_var:=tclass1.create_var(l,b);
  151. globalresult:=b;
  152. if globalresult <> GLOBAL_RESULT then
  153. failed:= true;
  154. globalresult := 0;
  155. b:=GLOBAL_RESULT;
  156. class_const:=tclass1.create_const(l,b);
  157. if globalresult <> GLOBAL_RESULT then
  158. failed:= true;
  159. globalresult := 0;
  160. b:=0;
  161. a:=0;
  162. c:=0;
  163. d:=GLOBAL_RESULT;
  164. class_mixed:=tclass1.create_mixed(a,b,c,d);
  165. if globalresult <> GLOBAL_RESULT then
  166. failed:= true;
  167. {$ifdef dummy}
  168. globalresult := GLOBAL_RESULT;
  169. { secondcalln : class constructor failure, when getmem returns 0,
  170. that will call class_help_fail and abort class construction }
  171. heaperror := @myheaperrornil;
  172. try
  173. class_none_fail:=tclass2.create_none;
  174. except
  175. on EOutOfMemory do globalresult:=0;
  176. end;
  177. if globalresult <> GLOBAL_RESULT then
  178. failed:= true;
  179. { secondcalln : class constructor failure, getmem gives a runtime error
  180. that will be translated to a exception and the exception shall be catched
  181. here }
  182. globalresult := 0;
  183. heaperror := @myheaperrorexception;
  184. try
  185. class_none_fail:=tclass2.create_none;
  186. except
  187. on EOutOfMemory do globalresult:=GLOBAL_RESULT;
  188. end;
  189. if globalresult <> GLOBAL_RESULT then
  190. failed:= true;
  191. {$endif dummy}
  192. if failed then
  193. fail
  194. else
  195. WriteLn('Passed!');
  196. end.