node.inc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. The implementation of the abstract nodes
  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. {****************************************************************************
  19. TNODE
  20. ****************************************************************************}
  21. constructor tnode.init(tt : tnodetype);
  22. begin
  23. inherited init;
  24. treetype:=tt;
  25. { this allows easier error tracing }
  26. location.loc:=LOC_INVALID;
  27. { save local info }
  28. fileinfo:=aktfilepos;
  29. localswitches:=aktlocalswitches;
  30. resulttype:=nil;
  31. registersint:=0;
  32. registersfpu:=0;
  33. {$ifdef SUPPORT_MMX}
  34. registersmmx:=0;
  35. {$endif SUPPORT_MMX}
  36. flags:=[];
  37. end;
  38. destructor tnode.done;
  39. begin
  40. { reference info }
  41. if (location.loc in [LOC_MEM,LOC_REFERENCE]) and
  42. assigned(location.reference.symbol) then
  43. dispose(location.reference.symbol,done);
  44. {$ifdef EXTDEBUG}
  45. if firstpasscount>maxfirstpasscount then
  46. maxfirstpasscount:=firstpasscount;
  47. {$endif EXTDEBUG}
  48. end;
  49. procedure tnode.pass_1;
  50. begin
  51. if not(assigned(resulttype)) then
  52. det_resulttype;
  53. det_temp;
  54. end;
  55. procedure tnode.det_resulttype;
  56. begin
  57. abstract;
  58. end;
  59. procedure tnode.det_temp;
  60. begin
  61. abstract;
  62. end;
  63. procedure tnode.secondpass;
  64. begin
  65. abstract;
  66. end;
  67. procedure tnode.concattolist(l : plinkedlist);
  68. begin
  69. l^.concat(@self);
  70. end;
  71. function tnode.ischild(p : pnode) : boolean;
  72. begin
  73. ischild:=false;
  74. end;
  75. {$ifdef EXTDEBUG}
  76. procedure tnode.dowrite;
  77. const treetype2str : array[tnodetype] of string[20] = (
  78. 'addn',
  79. 'muln',
  80. 'subn',
  81. 'divn',
  82. 'symdifn',
  83. 'modn',
  84. 'assignn',
  85. 'loadn',
  86. 'rangen',
  87. 'ltn',
  88. 'lten',
  89. 'gtn',
  90. 'gten',
  91. 'equaln',
  92. 'unequaln',
  93. 'inn',
  94. 'orn',
  95. 'xorn',
  96. 'shrn',
  97. 'shln',
  98. 'slashn',
  99. 'andn',
  100. 'subscriptn',
  101. 'derefn',
  102. 'addrn',
  103. 'doubleaddrn',
  104. 'ordconstn',
  105. 'typeconvn',
  106. 'calln',
  107. 'callparan',
  108. 'realconstn',
  109. 'fixconstn',
  110. 'umminusn',
  111. 'asmn',
  112. 'vecn',
  113. 'stringconstn',
  114. 'funcretn',
  115. 'selfn',
  116. 'notn',
  117. 'inlinen',
  118. 'niln',
  119. 'errorn',
  120. 'typen',
  121. 'hnewn',
  122. 'hdisposen',
  123. 'newn',
  124. 'simpledisposen',
  125. 'setelementn',
  126. 'setconstn',
  127. 'blockn',
  128. 'statementn',
  129. 'loopn',
  130. 'ifn',
  131. 'breakn',
  132. 'continuen',
  133. 'repeatn',
  134. 'whilen',
  135. 'forn',
  136. 'exitn',
  137. 'withn',
  138. 'casen',
  139. 'labeln',
  140. 'goton',
  141. 'simplenewn',
  142. 'tryexceptn',
  143. 'raisen',
  144. 'switchesn',
  145. 'tryfinallyn',
  146. 'onn',
  147. 'isn',
  148. 'asn',
  149. 'caretn',
  150. 'failn',
  151. 'starstarn',
  152. 'procinlinen',
  153. 'arrayconstructn',
  154. 'arrayconstructrangen',
  155. 'nothingn',
  156. 'loadvmtn',
  157. 'pointerconstn');
  158. begin
  159. write(indention,'(',treetype2str[nodetype]);
  160. end;
  161. {$endif EXTDEBUG}
  162. function tnode.isequal(p : node) : boolean;
  163. begin
  164. isequal:=assigned(p) and (p^.nodetype=nodetype) and
  165. (flags*flagsequal=p^.flags*flagsequal) and
  166. docompare(p);
  167. end;
  168. function tnode.docompare(p : pnode) : boolean;
  169. begin
  170. docompare:=true;
  171. end;
  172. {****************************************************************************
  173. TUNARYNODE
  174. ****************************************************************************}
  175. constructor tunarynode.init(tt : tnodetype;l : pnode);
  176. begin
  177. inherited init(tt);
  178. left:=l;
  179. end;
  180. function tunarynode.docompare(p : pnode) : boolean;
  181. begin
  182. docompare:=(inherited docompare(p)) and
  183. left^.isequal(p^.left);
  184. end;
  185. {$ifdef extdebug}
  186. procedure tunarynode.dowrite;
  187. begin
  188. inherited dowrite;
  189. writeln(',');
  190. writenode(left);
  191. writeln(')');
  192. dec(byte(indention[0]),2);
  193. end;
  194. {$endif}
  195. procedure tunarynode.concattolist(l : plinkedlist);
  196. begin
  197. left^.parent:=@self;
  198. left^.concattolist(l);
  199. inherited concattolist(l);
  200. end;
  201. function tunarynode.ischild(p : pnode) : boolean;
  202. begin
  203. ischild:=p=left;
  204. end;
  205. procedure tunarynode.det_resulttype;
  206. begin
  207. left^.det_resulttype;
  208. end;
  209. procedure tunarynode.det_temp;
  210. begin
  211. left^.det_temp;
  212. end;
  213. {****************************************************************************
  214. TBINARYNODE
  215. ****************************************************************************}
  216. constructor tbinarynode.init(tt : tnodetype;l,r : pnode);
  217. begin
  218. inherited init(tt,l);
  219. right:=r
  220. end;
  221. procedure tbinarynode.concattolist(l : plinkedlist);
  222. begin
  223. { we could change that depending on the number of }
  224. { required registers }
  225. left^.parent:=@self;
  226. left^.concattolist(l);
  227. left^.parent:=@self;
  228. left^.concattolist(l);
  229. inherited concattolist(l);
  230. end;
  231. function tbinarynode.ischild(p : pnode) : boolean;
  232. begin
  233. ischild:=(p=right) or (p=right);
  234. end;
  235. procedure tbinarynode.det_resulttype;
  236. begin
  237. left^.det_resulttype;
  238. right^.det_resulttype;
  239. end;
  240. procedure tbinarynode.det_temp;
  241. begin
  242. left^.det_temp;
  243. right^.det_temp;
  244. end;
  245. function tbinarynode.docompare(p : pnode) : boolean;
  246. begin
  247. docompare:=left^.isequal(p^.left) and
  248. right^.isequal(p^.right);
  249. end;
  250. {****************************************************************************
  251. TBINOPYNODE
  252. ****************************************************************************}
  253. constructor tbinopnode.init(tt : tnodetype;l,r : pnode);
  254. begin
  255. inherited init(tt,l,r);
  256. end;
  257. function tbinopnode.docompare(p : pnode) : boolean;
  258. begin
  259. docompare:=(inherited docompare(p)) or
  260. ((nf_swapable in flags) and
  261. left^.isequal(p^.right) and
  262. right^.isequal(p^.left));
  263. end;
  264. {
  265. $Log$
  266. Revision 1.1 2000-08-26 12:27:17 florian
  267. * initial release
  268. }