pass_1.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. cgbase,symdef,
  35. {$ifdef extdebug}
  36. verbose,
  37. htypechk,
  38. {$endif extdebug}
  39. tgcpu
  40. ;
  41. {*****************************************************************************
  42. Global procedures
  43. *****************************************************************************}
  44. procedure resulttypepass(var p : tnode);
  45. var
  46. oldcodegenerror : boolean;
  47. oldlocalswitches : tlocalswitches;
  48. oldpos : tfileposinfo;
  49. hp : tnode;
  50. begin
  51. inc(resulttypepasscnt);
  52. if (p.resulttype.def=nil) then
  53. begin
  54. oldcodegenerror:=codegenerror;
  55. oldpos:=aktfilepos;
  56. oldlocalswitches:=aktlocalswitches;
  57. codegenerror:=false;
  58. aktfilepos:=p.fileinfo;
  59. aktlocalswitches:=p.localswitches;
  60. hp:=p.det_resulttype;
  61. { should the node be replaced? }
  62. if assigned(hp) then
  63. begin
  64. p.free;
  65. p:=hp;
  66. end;
  67. aktlocalswitches:=oldlocalswitches;
  68. aktfilepos:=oldpos;
  69. if codegenerror then
  70. begin
  71. include(p.flags,nf_error);
  72. { default to errortype if no type is set yet }
  73. if p.resulttype.def=nil then
  74. p.resulttype:=generrortype;
  75. end;
  76. codegenerror:=codegenerror or oldcodegenerror;
  77. end
  78. else
  79. inc(multiresulttypepasscnt);
  80. end;
  81. function do_resulttypepass(var p : tnode) : boolean;
  82. begin
  83. codegenerror:=false;
  84. resulttypepass(p);
  85. do_resulttypepass:=codegenerror;
  86. end;
  87. procedure firstpass(var p : tnode);
  88. var
  89. oldcodegenerror : boolean;
  90. oldlocalswitches : tlocalswitches;
  91. oldpos : tfileposinfo;
  92. hp : tnode;
  93. begin
  94. {$ifdef extdebug}
  95. inc(total_of_firstpass);
  96. {$endif extdebug}
  97. oldcodegenerror:=codegenerror;
  98. oldpos:=aktfilepos;
  99. oldlocalswitches:=aktlocalswitches;
  100. {$ifdef extdebug}
  101. if p.firstpasscount>0 then
  102. inc(firstpass_several);
  103. {$endif extdebug}
  104. if not(nf_error in p.flags) then
  105. begin
  106. codegenerror:=false;
  107. aktfilepos:=p.fileinfo;
  108. aktlocalswitches:=p.localswitches;
  109. { determine the resulttype if not done }
  110. if (p.resulttype.def=nil) then
  111. begin
  112. hp:=p.det_resulttype;
  113. { should the node be replaced? }
  114. if assigned(hp) then
  115. begin
  116. p.free;
  117. p:=hp;
  118. end;
  119. end;
  120. { first pass }
  121. hp:=p.pass_1;
  122. { should the node be replaced? }
  123. if assigned(hp) then
  124. begin
  125. p.free;
  126. p:=hp;
  127. end;
  128. aktlocalswitches:=oldlocalswitches;
  129. aktfilepos:=oldpos;
  130. if codegenerror then
  131. include(p.flags,nf_error);
  132. codegenerror:=codegenerror or oldcodegenerror;
  133. end
  134. else
  135. codegenerror:=true;
  136. {$ifdef extdebug}
  137. if count_ref then
  138. inc(p.firstpasscount);
  139. {$endif extdebug}
  140. end;
  141. function do_firstpass(var p : tnode) : boolean;
  142. begin
  143. codegenerror:=false;
  144. firstpass(p);
  145. do_firstpass:=codegenerror;
  146. end;
  147. end.
  148. {
  149. $Log$
  150. Revision 1.16 2001-08-26 13:36:44 florian
  151. * some cg reorganisation
  152. * some PPC updates
  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. }