pass_1.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. { run resulttypepass }
  66. resulttypepass(hp);
  67. { switch to new node }
  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. begin
  83. { update the codegenerror boolean with the previous result of this node }
  84. if (nf_error in p.flags) then
  85. codegenerror:=true;
  86. inc(multiresulttypepasscnt);
  87. end;
  88. end;
  89. function do_resulttypepass(var p : tnode) : boolean;
  90. begin
  91. codegenerror:=false;
  92. resulttypepass(p);
  93. do_resulttypepass:=codegenerror;
  94. end;
  95. procedure firstpass(var p : tnode);
  96. var
  97. oldcodegenerror : boolean;
  98. oldlocalswitches : tlocalswitches;
  99. oldpos : tfileposinfo;
  100. hp : tnode;
  101. begin
  102. {$ifdef extdebug}
  103. inc(total_of_firstpass);
  104. {$endif extdebug}
  105. oldcodegenerror:=codegenerror;
  106. oldpos:=aktfilepos;
  107. oldlocalswitches:=aktlocalswitches;
  108. {$ifdef extdebug}
  109. if p.firstpasscount>0 then
  110. inc(firstpass_several);
  111. {$endif extdebug}
  112. if not(nf_error in p.flags) then
  113. begin
  114. codegenerror:=false;
  115. aktfilepos:=p.fileinfo;
  116. aktlocalswitches:=p.localswitches;
  117. { determine the resulttype if not done }
  118. if (p.resulttype.def=nil) then
  119. begin
  120. hp:=p.det_resulttype;
  121. { should the node be replaced? }
  122. if assigned(hp) then
  123. begin
  124. p.free;
  125. p:=hp;
  126. end;
  127. end;
  128. { first pass }
  129. hp:=p.pass_1;
  130. { should the node be replaced? }
  131. if assigned(hp) then
  132. begin
  133. p.free;
  134. p:=hp;
  135. end;
  136. aktlocalswitches:=oldlocalswitches;
  137. aktfilepos:=oldpos;
  138. if codegenerror then
  139. include(p.flags,nf_error);
  140. codegenerror:=codegenerror or oldcodegenerror;
  141. end
  142. else
  143. codegenerror:=true;
  144. {$ifdef extdebug}
  145. if count_ref then
  146. inc(p.firstpasscount);
  147. {$endif extdebug}
  148. end;
  149. function do_firstpass(var p : tnode) : boolean;
  150. begin
  151. codegenerror:=false;
  152. firstpass(p);
  153. do_firstpass:=codegenerror;
  154. end;
  155. end.
  156. {
  157. $Log$
  158. Revision 1.17 2001-09-02 21:18:28 peter
  159. * split constsym.value in valueord,valueordptr,valueptr. The valueordptr
  160. is used for holding target platform pointer values. As those can be
  161. bigger than the source platform.
  162. Revision 1.16 2001/08/26 13:36:44 florian
  163. * some cg reorganisation
  164. * some PPC updates
  165. Revision 1.15 2001/07/06 15:29:39 peter
  166. * fixed EXTDEBUG
  167. Revision 1.14 2001/04/15 09:48:30 peter
  168. * fixed crash in labelnode
  169. * easier detection of goto and label in try blocks
  170. Revision 1.13 2001/04/13 01:22:10 peter
  171. * symtable change to classes
  172. * range check generation and errors fixed, make cycle DEBUG=1 works
  173. * memory leaks fixed
  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. }