pass_1.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. procedure firstpass(var p : tnode);
  24. function do_firstpass(var p : tnode) : boolean;
  25. var
  26. { the block node of the current exception block to check gotos }
  27. aktexceptblock : tnode;
  28. implementation
  29. uses
  30. globtype,systems,
  31. cutils,cobjects,globals,
  32. hcodegen,
  33. {$ifdef extdebug}
  34. htypechk,
  35. {$endif extdebug}
  36. tgcpu
  37. {$ifdef newcg}
  38. ,cgbase
  39. {$endif}
  40. ;
  41. {*****************************************************************************
  42. Global procedures
  43. *****************************************************************************}
  44. procedure firstpass(var p : tnode);
  45. var
  46. oldcodegenerror : boolean;
  47. oldlocalswitches : tlocalswitches;
  48. oldpos : tfileposinfo;
  49. hp : tnode;
  50. {$ifdef extdebug}
  51. {$ifdef dummy}
  52. str1,str2 : string;
  53. oldp : tnode;
  54. {$endif}
  55. not_first : boolean;
  56. {$endif extdebug}
  57. begin
  58. {$ifdef extdebug}
  59. inc(total_of_firstpass);
  60. if (p.firstpasscount>0) and only_one_pass then
  61. exit;
  62. {$endif extdebug}
  63. oldcodegenerror:=codegenerror;
  64. oldpos:=aktfilepos;
  65. oldlocalswitches:=aktlocalswitches;
  66. {$ifdef extdebug}
  67. if p.firstpasscount>0 then
  68. begin
  69. {$ifdef dummy}
  70. move(p^,str1[1],sizeof(ttree));
  71. str1[0]:=char(sizeof(ttree));
  72. new(oldp);
  73. old^:=p^;
  74. {$endif}
  75. not_first:=true;
  76. inc(firstpass_several);
  77. end
  78. else
  79. not_first:=false;
  80. {$endif extdebug}
  81. if not(nf_error in p.flags) then
  82. begin
  83. codegenerror:=false;
  84. aktfilepos:=p.fileinfo;
  85. aktlocalswitches:=p.localswitches;
  86. hp:=p.pass_1;
  87. { should the node be replaced? }
  88. if assigned(hp) then
  89. begin
  90. p.free;
  91. p:=hp;
  92. end;
  93. aktlocalswitches:=oldlocalswitches;
  94. aktfilepos:=oldpos;
  95. if codegenerror then
  96. include(p.flags,nf_error);
  97. codegenerror:=codegenerror or oldcodegenerror;
  98. end
  99. else
  100. codegenerror:=true;
  101. {$ifdef extdebug}
  102. if not_first then
  103. begin
  104. {$ifdef dummy}
  105. { dirty trick to compare two ttree's (PM) }
  106. move(p^,str2[1],sizeof(ttree));
  107. str2[0]:=char(sizeof(ttree));
  108. if str1<>str2 then
  109. begin
  110. comment(v_debug,'tree changed after first counting pass '
  111. +tostr(longint(p.treetype)));
  112. compare_trees(oldp,p);
  113. end;
  114. dispose(oldp);
  115. {$endif dummy}
  116. end;
  117. if count_ref then
  118. inc(p.firstpasscount);
  119. {$endif extdebug}
  120. end;
  121. function do_firstpass(var p : tnode) : boolean;
  122. begin
  123. aktexceptblock:=nil;
  124. codegenerror:=false;
  125. firstpass(p);
  126. do_firstpass:=codegenerror;
  127. end;
  128. end.
  129. {
  130. $Log$
  131. Revision 1.11 2000-12-18 21:56:52 peter
  132. * extdebug fixes
  133. Revision 1.10 2000/11/29 00:30:35 florian
  134. * unused units removed from uses clause
  135. * some changes for widestrings
  136. Revision 1.9 2000/10/14 10:14:51 peter
  137. * moehrendorf oct 2000 rewrite
  138. Revision 1.8 2000/10/01 19:48:25 peter
  139. * lot of compile updates for cg11
  140. Revision 1.7 2000/09/30 16:08:45 peter
  141. * more cg11 updates
  142. Revision 1.6 2000/09/28 19:49:52 florian
  143. *** empty log message ***
  144. Revision 1.5 2000/09/24 21:15:34 florian
  145. * some errors fix to get more stuff compilable
  146. Revision 1.4 2000/09/24 15:06:21 peter
  147. * use defines.inc
  148. Revision 1.3 2000/09/19 23:09:07 pierre
  149. * problems wih extdebug cond. solved
  150. Revision 1.2 2000/07/13 11:32:44 michael
  151. + removed logs
  152. }