pass_1.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit handles the typecheck and node conversion pass
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pass_1;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node;
  23. var
  24. resulttypepasscnt,
  25. multiresulttypepasscnt : longint;
  26. procedure resulttypepass(var p : tnode);
  27. function do_resulttypepass(var p : tnode) : boolean;
  28. procedure firstpass(var p : tnode);
  29. function do_firstpass(var p : tnode) : boolean;
  30. var
  31. { the block node of the current exception block to check gotos }
  32. aktexceptblock : tnode;
  33. implementation
  34. uses
  35. globtype,systems,
  36. cutils,globals,
  37. hcodegen,symdef,
  38. {$ifdef extdebug}
  39. verbose,
  40. htypechk,
  41. {$endif extdebug}
  42. tgcpu
  43. {$ifdef newcg}
  44. ,cgbase
  45. {$endif}
  46. ;
  47. {*****************************************************************************
  48. Global procedures
  49. *****************************************************************************}
  50. procedure resulttypepass(var p : tnode);
  51. var
  52. oldcodegenerror : boolean;
  53. oldlocalswitches : tlocalswitches;
  54. oldpos : tfileposinfo;
  55. hp : tnode;
  56. begin
  57. inc(resulttypepasscnt);
  58. if (p.resulttype.def=nil) then
  59. begin
  60. oldcodegenerror:=codegenerror;
  61. oldpos:=aktfilepos;
  62. oldlocalswitches:=aktlocalswitches;
  63. codegenerror:=false;
  64. aktfilepos:=p.fileinfo;
  65. aktlocalswitches:=p.localswitches;
  66. hp:=p.det_resulttype;
  67. { should the node be replaced? }
  68. if assigned(hp) then
  69. begin
  70. p.free;
  71. p:=hp;
  72. end;
  73. aktlocalswitches:=oldlocalswitches;
  74. aktfilepos:=oldpos;
  75. if codegenerror then
  76. begin
  77. include(p.flags,nf_error);
  78. { default to errortype if no type is set yet }
  79. if p.resulttype.def=nil then
  80. p.resulttype:=generrortype;
  81. end;
  82. codegenerror:=codegenerror or oldcodegenerror;
  83. end
  84. else
  85. inc(multiresulttypepasscnt);
  86. end;
  87. function do_resulttypepass(var p : tnode) : boolean;
  88. begin
  89. aktexceptblock:=nil;
  90. codegenerror:=false;
  91. resulttypepass(p);
  92. do_resulttypepass:=codegenerror;
  93. end;
  94. procedure firstpass(var p : tnode);
  95. var
  96. oldcodegenerror : boolean;
  97. oldlocalswitches : tlocalswitches;
  98. oldpos : tfileposinfo;
  99. hp : tnode;
  100. begin
  101. {$ifdef extdebug}
  102. inc(total_of_firstpass);
  103. if (p.firstpasscount>0) and only_one_pass then
  104. exit;
  105. {$endif extdebug}
  106. oldcodegenerror:=codegenerror;
  107. oldpos:=aktfilepos;
  108. oldlocalswitches:=aktlocalswitches;
  109. {$ifdef extdebug}
  110. if p.firstpasscount>0 then
  111. inc(firstpass_several);
  112. {$endif extdebug}
  113. if not(nf_error in p.flags) then
  114. begin
  115. codegenerror:=false;
  116. aktfilepos:=p.fileinfo;
  117. aktlocalswitches:=p.localswitches;
  118. { determine the resulttype if not done }
  119. if (p.resulttype.def=nil) then
  120. begin
  121. hp:=p.det_resulttype;
  122. { should the node be replaced? }
  123. if assigned(hp) then
  124. begin
  125. p.free;
  126. p:=hp;
  127. end;
  128. end;
  129. { first pass }
  130. hp:=p.pass_1;
  131. { should the node be replaced? }
  132. if assigned(hp) then
  133. begin
  134. p.free;
  135. p:=hp;
  136. end;
  137. aktlocalswitches:=oldlocalswitches;
  138. aktfilepos:=oldpos;
  139. if codegenerror then
  140. include(p.flags,nf_error);
  141. codegenerror:=codegenerror or oldcodegenerror;
  142. end
  143. else
  144. codegenerror:=true;
  145. {$ifdef extdebug}
  146. if count_ref then
  147. inc(p.firstpasscount);
  148. {$endif extdebug}
  149. end;
  150. function do_firstpass(var p : tnode) : boolean;
  151. begin
  152. aktexceptblock:=nil;
  153. codegenerror:=false;
  154. firstpass(p);
  155. do_firstpass:=codegenerror;
  156. end;
  157. end.
  158. {
  159. $Log$
  160. Revision 1.13 2001-04-13 01:22:10 peter
  161. * symtable change to classes
  162. * range check generation and errors fixed, make cycle DEBUG=1 works
  163. * memory leaks fixed
  164. Revision 1.12 2001/04/02 21:20:31 peter
  165. * resulttype rewrite
  166. Revision 1.11 2000/12/18 21:56:52 peter
  167. * extdebug fixes
  168. Revision 1.10 2000/11/29 00:30:35 florian
  169. * unused units removed from uses clause
  170. * some changes for widestrings
  171. Revision 1.9 2000/10/14 10:14:51 peter
  172. * moehrendorf oct 2000 rewrite
  173. Revision 1.8 2000/10/01 19:48:25 peter
  174. * lot of compile updates for cg11
  175. Revision 1.7 2000/09/30 16:08:45 peter
  176. * more cg11 updates
  177. Revision 1.6 2000/09/28 19:49:52 florian
  178. *** empty log message ***
  179. Revision 1.5 2000/09/24 21:15:34 florian
  180. * some errors fix to get more stuff compilable
  181. Revision 1.4 2000/09/24 15:06:21 peter
  182. * use defines.inc
  183. Revision 1.3 2000/09/19 23:09:07 pierre
  184. * problems wih extdebug cond. solved
  185. Revision 1.2 2000/07/13 11:32:44 michael
  186. + removed logs
  187. }