pass_1.pas 6.5 KB

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