pass_1.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. implementation
  31. uses
  32. globtype,systems,
  33. cutils,globals,
  34. hcodegen,symdef,
  35. {$ifdef extdebug}
  36. verbose,
  37. htypechk,
  38. {$endif extdebug}
  39. tgcpu
  40. {$ifdef newcg}
  41. ,cgbase
  42. {$endif}
  43. ;
  44. {*****************************************************************************
  45. Global procedures
  46. *****************************************************************************}
  47. procedure resulttypepass(var p : tnode);
  48. var
  49. oldcodegenerror : boolean;
  50. oldlocalswitches : tlocalswitches;
  51. oldpos : tfileposinfo;
  52. hp : tnode;
  53. begin
  54. inc(resulttypepasscnt);
  55. if (p.resulttype.def=nil) then
  56. begin
  57. oldcodegenerror:=codegenerror;
  58. oldpos:=aktfilepos;
  59. oldlocalswitches:=aktlocalswitches;
  60. codegenerror:=false;
  61. aktfilepos:=p.fileinfo;
  62. aktlocalswitches:=p.localswitches;
  63. hp:=p.det_resulttype;
  64. { should the node be replaced? }
  65. if assigned(hp) then
  66. begin
  67. p.free;
  68. p:=hp;
  69. end;
  70. aktlocalswitches:=oldlocalswitches;
  71. aktfilepos:=oldpos;
  72. if codegenerror then
  73. begin
  74. include(p.flags,nf_error);
  75. { default to errortype if no type is set yet }
  76. if p.resulttype.def=nil then
  77. p.resulttype:=generrortype;
  78. end;
  79. codegenerror:=codegenerror or oldcodegenerror;
  80. end
  81. else
  82. inc(multiresulttypepasscnt);
  83. end;
  84. function do_resulttypepass(var p : tnode) : boolean;
  85. begin
  86. codegenerror:=false;
  87. resulttypepass(p);
  88. do_resulttypepass:=codegenerror;
  89. end;
  90. procedure firstpass(var p : tnode);
  91. var
  92. oldcodegenerror : boolean;
  93. oldlocalswitches : tlocalswitches;
  94. oldpos : tfileposinfo;
  95. hp : tnode;
  96. begin
  97. {$ifdef extdebug}
  98. inc(total_of_firstpass);
  99. if (p.firstpasscount>0) and only_one_pass then
  100. exit;
  101. {$endif extdebug}
  102. oldcodegenerror:=codegenerror;
  103. oldpos:=aktfilepos;
  104. oldlocalswitches:=aktlocalswitches;
  105. {$ifdef extdebug}
  106. if p.firstpasscount>0 then
  107. inc(firstpass_several);
  108. {$endif extdebug}
  109. if not(nf_error in p.flags) then
  110. begin
  111. codegenerror:=false;
  112. aktfilepos:=p.fileinfo;
  113. aktlocalswitches:=p.localswitches;
  114. { determine the resulttype if not done }
  115. if (p.resulttype.def=nil) then
  116. begin
  117. hp:=p.det_resulttype;
  118. { should the node be replaced? }
  119. if assigned(hp) then
  120. begin
  121. p.free;
  122. p:=hp;
  123. end;
  124. end;
  125. { first pass }
  126. hp:=p.pass_1;
  127. { should the node be replaced? }
  128. if assigned(hp) then
  129. begin
  130. p.free;
  131. p:=hp;
  132. end;
  133. aktlocalswitches:=oldlocalswitches;
  134. aktfilepos:=oldpos;
  135. if codegenerror then
  136. include(p.flags,nf_error);
  137. codegenerror:=codegenerror or oldcodegenerror;
  138. end
  139. else
  140. codegenerror:=true;
  141. {$ifdef extdebug}
  142. if count_ref then
  143. inc(p.firstpasscount);
  144. {$endif extdebug}
  145. end;
  146. function do_firstpass(var p : tnode) : boolean;
  147. begin
  148. codegenerror:=false;
  149. firstpass(p);
  150. do_firstpass:=codegenerror;
  151. end;
  152. end.
  153. {
  154. $Log$
  155. Revision 1.14 2001-04-15 09:48:30 peter
  156. * fixed crash in labelnode
  157. * easier detection of goto and label in try blocks
  158. Revision 1.13 2001/04/13 01:22:10 peter
  159. * symtable change to classes
  160. * range check generation and errors fixed, make cycle DEBUG=1 works
  161. * memory leaks fixed
  162. Revision 1.12 2001/04/02 21:20:31 peter
  163. * resulttype rewrite
  164. Revision 1.11 2000/12/18 21:56:52 peter
  165. * extdebug fixes
  166. Revision 1.10 2000/11/29 00:30:35 florian
  167. * unused units removed from uses clause
  168. * some changes for widestrings
  169. Revision 1.9 2000/10/14 10:14:51 peter
  170. * moehrendorf oct 2000 rewrite
  171. Revision 1.8 2000/10/01 19:48:25 peter
  172. * lot of compile updates for cg11
  173. Revision 1.7 2000/09/30 16:08:45 peter
  174. * more cg11 updates
  175. Revision 1.6 2000/09/28 19:49:52 florian
  176. *** empty log message ***
  177. Revision 1.5 2000/09/24 21:15:34 florian
  178. * some errors fix to get more stuff compilable
  179. Revision 1.4 2000/09/24 15:06:21 peter
  180. * use defines.inc
  181. Revision 1.3 2000/09/19 23:09:07 pierre
  182. * problems wih extdebug cond. solved
  183. Revision 1.2 2000/07/13 11:32:44 michael
  184. + removed logs
  185. }