pass_1.pas 4.7 KB

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