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. 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. {$endif extdebug}
  100. oldcodegenerror:=codegenerror;
  101. oldpos:=aktfilepos;
  102. oldlocalswitches:=aktlocalswitches;
  103. {$ifdef extdebug}
  104. if p.firstpasscount>0 then
  105. inc(firstpass_several);
  106. {$endif extdebug}
  107. if not(nf_error in p.flags) then
  108. begin
  109. codegenerror:=false;
  110. aktfilepos:=p.fileinfo;
  111. aktlocalswitches:=p.localswitches;
  112. { determine the resulttype if not done }
  113. if (p.resulttype.def=nil) then
  114. begin
  115. hp:=p.det_resulttype;
  116. { should the node be replaced? }
  117. if assigned(hp) then
  118. begin
  119. p.free;
  120. p:=hp;
  121. end;
  122. end;
  123. { first pass }
  124. hp:=p.pass_1;
  125. { should the node be replaced? }
  126. if assigned(hp) then
  127. begin
  128. p.free;
  129. p:=hp;
  130. end;
  131. aktlocalswitches:=oldlocalswitches;
  132. aktfilepos:=oldpos;
  133. if codegenerror then
  134. include(p.flags,nf_error);
  135. codegenerror:=codegenerror or oldcodegenerror;
  136. end
  137. else
  138. codegenerror:=true;
  139. {$ifdef extdebug}
  140. if count_ref then
  141. inc(p.firstpasscount);
  142. {$endif extdebug}
  143. end;
  144. function do_firstpass(var p : tnode) : boolean;
  145. begin
  146. codegenerror:=false;
  147. firstpass(p);
  148. do_firstpass:=codegenerror;
  149. end;
  150. end.
  151. {
  152. $Log$
  153. Revision 1.15 2001-07-06 15:29:39 peter
  154. * fixed EXTDEBUG
  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. }