node.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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.create(tt : tnodetype);
  22. begin
  23. inherited create;
  24. nodetype:=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. registers32:=0;
  32. registersfpu:=0;
  33. {$ifdef SUPPORT_MMX}
  34. registersmmx:=0;
  35. {$endif SUPPORT_MMX}
  36. flags:=[];
  37. end;
  38. constructor tnode.createforcopy;
  39. begin
  40. end;
  41. procedure tnode.toggleflag(f : tnodeflags);
  42. begin
  43. if f in flags then
  44. exclude(flags,f)
  45. else
  46. include(flags,f);
  47. end;
  48. destructor tnode.destroy;
  49. begin
  50. { reference info }
  51. {if (location.loc in [LOC_MEM,LOC_REFERENCE]) and
  52. assigned(location.reference.symbol) then
  53. dispose(location.reference.symbol,done);}
  54. {$ifdef EXTDEBUG}
  55. if firstpasscount>maxfirstpasscount then
  56. maxfirstpasscount:=firstpasscount;
  57. {$endif EXTDEBUG}
  58. end;
  59. function tnode.pass_1 : tnode;
  60. begin
  61. pass_1:=nil;
  62. if not(assigned(resulttype)) then
  63. det_resulttype;
  64. det_temp;
  65. end;
  66. procedure tnode.concattolist(l : plinkedlist);
  67. begin
  68. {$ifdef newcg}
  69. l^.concat(self);
  70. {$endif newcg}
  71. end;
  72. function tnode.ischild(p : tnode) : boolean;
  73. begin
  74. ischild:=false;
  75. end;
  76. {$ifdef EXTDEBUG}
  77. procedure tnode.dowrite;
  78. begin
  79. dowritenodetype;
  80. end;
  81. procedure tnode.dowritenodetype;
  82. const nodetype2str : array[tnodetype] of string[20] = (
  83. 'addn',
  84. 'muln',
  85. 'subn',
  86. 'divn',
  87. 'symdifn',
  88. 'modn',
  89. 'assignn',
  90. 'loadn',
  91. 'rangen',
  92. 'ltn',
  93. 'lten',
  94. 'gtn',
  95. 'gten',
  96. 'equaln',
  97. 'unequaln',
  98. 'inn',
  99. 'orn',
  100. 'xorn',
  101. 'shrn',
  102. 'shln',
  103. 'slashn',
  104. 'andn',
  105. 'subscriptn',
  106. 'derefn',
  107. 'addrn',
  108. 'doubleaddrn',
  109. 'ordconstn',
  110. 'typeconvn',
  111. 'calln',
  112. 'callparan',
  113. 'realconstn',
  114. 'fixconstn',
  115. 'umminusn',
  116. 'asmn',
  117. 'vecn',
  118. 'pointerconstn',
  119. 'stringconstn',
  120. 'funcretn',
  121. 'selfn',
  122. 'notn',
  123. 'inlinen',
  124. 'niln',
  125. 'errorn',
  126. 'typen',
  127. 'hnewn',
  128. 'hdisposen',
  129. 'newn',
  130. 'simpledisposen',
  131. 'setelementn',
  132. 'setconstn',
  133. 'blockn',
  134. 'statementn',
  135. 'loopn',
  136. 'ifn',
  137. 'breakn',
  138. 'continuen',
  139. 'repeatn',
  140. 'whilen',
  141. 'forn',
  142. 'exitn',
  143. 'withn',
  144. 'casen',
  145. 'labeln',
  146. 'goton',
  147. 'simplenewn',
  148. 'tryexceptn',
  149. 'raisen',
  150. 'switchesn',
  151. 'tryfinallyn',
  152. 'onn',
  153. 'isn',
  154. 'asn',
  155. 'caretn',
  156. 'failn',
  157. 'starstarn',
  158. 'procinlinen',
  159. 'arrayconstructn',
  160. 'arrayconstructrangen',
  161. 'nothingn',
  162. 'loadvmtn');
  163. begin
  164. write(writenodeindention,'(',nodetype2str[nodetype]);
  165. end;
  166. {$endif EXTDEBUG}
  167. function tnode.isequal(p : tnode) : boolean;
  168. begin
  169. isequal:=assigned(p) and (p.nodetype=nodetype) and
  170. (flags*flagsequal=p.flags*flagsequal) and
  171. docompare(p);
  172. end;
  173. function tnode.docompare(p : tnode) : boolean;
  174. begin
  175. docompare:=true;
  176. end;
  177. function tnode.getcopy : tnode;
  178. var
  179. p : tnode;
  180. begin
  181. { this is quite tricky because we need a node of the current }
  182. { node type and not one of tnode! }
  183. p:=tnodeclass(classtype).createforcopy;
  184. p.nodetype:=nodetype;
  185. p.location:=location;
  186. p.parent:=parent;
  187. p.flags:=flags;
  188. p.registers32:=registers32;
  189. p.registersfpu:=registersfpu;
  190. {$ifdef SUPPORT_MMX}
  191. p.registersmmx:=registersmmx;
  192. p.registerskni:=registerskni;
  193. {$endif SUPPORT_MMX}
  194. p.resulttype:=resulttype;
  195. p.fileinfo:=fileinfo;
  196. p.localswitches:=localswitches;
  197. {$ifdef extdebug}
  198. p.firstpasscount:=firstpasscount;
  199. {$endif extdebug}
  200. p.list:=list;
  201. getcopy:=p;
  202. end;
  203. procedure tnode.insertintolist(l : tnodelist);
  204. begin
  205. end;
  206. procedure tnode.set_file_line(from : tnode);
  207. begin
  208. if assigned(from) then
  209. fileinfo:=from.fileinfo;
  210. end;
  211. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  212. begin
  213. fileinfo:=filepos;
  214. end;
  215. {****************************************************************************
  216. TUNARYNODE
  217. ****************************************************************************}
  218. constructor tunarynode.create(tt : tnodetype;l : tnode);
  219. begin
  220. inherited create(tt);
  221. left:=l;
  222. end;
  223. destructor tunarynode.destroy;
  224. begin
  225. left.free;
  226. inherited destroy;
  227. end;
  228. function tunarynode.docompare(p : tnode) : boolean;
  229. begin
  230. docompare:=(inherited docompare(p)) and
  231. left.isequal(tunarynode(p).left);
  232. end;
  233. function tunarynode.getcopy : tnode;
  234. var
  235. p : tunarynode;
  236. begin
  237. p:=tunarynode(inherited getcopy);
  238. if assigned(left) then
  239. p.left:=left.getcopy
  240. else
  241. p.left:=nil;
  242. getcopy:=p;
  243. end;
  244. procedure tunarynode.insertintolist(l : tnodelist);
  245. begin
  246. end;
  247. {$ifdef extdebug}
  248. procedure tunarynode.dowrite;
  249. begin
  250. inherited dowrite;
  251. writeln(',');
  252. writenodeindention:=writenodeindention+' ';
  253. writenode(left);
  254. write(')');
  255. delete(writenodeindention,1,4);
  256. end;
  257. {$endif}
  258. procedure tunarynode.left_max;
  259. begin
  260. registers32:=left.registers32;
  261. registersfpu:=left.registersfpu;
  262. {$ifdef SUPPORT_MMX}
  263. registersmmx:=left.registersmmx;
  264. {$endif SUPPORT_MMX}
  265. end;
  266. procedure tunarynode.concattolist(l : plinkedlist);
  267. begin
  268. left.parent:=self;
  269. left.concattolist(l);
  270. inherited concattolist(l);
  271. end;
  272. function tunarynode.ischild(p : tnode) : boolean;
  273. begin
  274. ischild:=p=left;
  275. end;
  276. procedure tunarynode.det_resulttype;
  277. begin
  278. left.det_resulttype;
  279. end;
  280. procedure tunarynode.det_temp;
  281. begin
  282. left.det_temp;
  283. end;
  284. {****************************************************************************
  285. TBINARYNODE
  286. ****************************************************************************}
  287. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  288. begin
  289. inherited create(tt,l);
  290. right:=r
  291. end;
  292. destructor tbinarynode.destroy;
  293. begin
  294. right.free;
  295. inherited destroy;
  296. end;
  297. procedure tbinarynode.concattolist(l : plinkedlist);
  298. begin
  299. { we could change that depending on the number of }
  300. { required registers }
  301. left.parent:=self;
  302. left.concattolist(l);
  303. left.parent:=self;
  304. left.concattolist(l);
  305. inherited concattolist(l);
  306. end;
  307. function tbinarynode.ischild(p : tnode) : boolean;
  308. begin
  309. ischild:=(p=right) or (p=right);
  310. end;
  311. procedure tbinarynode.det_resulttype;
  312. begin
  313. left.det_resulttype;
  314. right.det_resulttype;
  315. end;
  316. procedure tbinarynode.det_temp;
  317. begin
  318. left.det_temp;
  319. right.det_temp;
  320. end;
  321. function tbinarynode.docompare(p : tnode) : boolean;
  322. begin
  323. docompare:=left.isequal(tbinarynode(p).left) and
  324. right.isequal(tbinarynode(p).right);
  325. end;
  326. function tbinarynode.getcopy : tnode;
  327. var
  328. p : tbinarynode;
  329. begin
  330. p:=tbinarynode(inherited getcopy);
  331. if assigned(right) then
  332. p.right:=right.getcopy
  333. else
  334. p.right:=nil;
  335. getcopy:=p;
  336. end;
  337. procedure tbinarynode.insertintolist(l : tnodelist);
  338. begin
  339. end;
  340. procedure tbinarynode.swapleftright;
  341. var
  342. swapp : tnode;
  343. begin
  344. swapp:=right;
  345. right:=left;
  346. left:=
  347. swapp;
  348. if nf_swaped in flags then
  349. exclude(flags,nf_swaped)
  350. else
  351. include(flags,nf_swaped);
  352. end;
  353. procedure tbinarynode.left_right_max;
  354. begin
  355. if assigned(left) then
  356. begin
  357. if assigned(right) then
  358. begin
  359. registers32:=max(left.registers32,right.registers32);
  360. registersfpu:=max(left.registersfpu,right.registersfpu);
  361. {$ifdef SUPPORT_MMX}
  362. registersmmx:=max(left.registersmmx,right.registersmmx);
  363. {$endif SUPPORT_MMX}
  364. end
  365. else
  366. begin
  367. registers32:=left.registers32;
  368. registersfpu:=left.registersfpu;
  369. {$ifdef SUPPORT_MMX}
  370. registersmmx:=left.registersmmx;
  371. {$endif SUPPORT_MMX}
  372. end;
  373. end;
  374. end;
  375. {$ifdef extdebug}
  376. procedure tbinarynode.dowrite;
  377. begin
  378. inherited dowrite;
  379. writeln(',');
  380. writenodeindention:=writenodeindention+' ';
  381. writenode(right);
  382. write(')');
  383. delete(writenodeindention,1,4);
  384. end;
  385. {$endif}
  386. {****************************************************************************
  387. TBINOPYNODE
  388. ****************************************************************************}
  389. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  390. begin
  391. inherited create(tt,l,r);
  392. end;
  393. function tbinopnode.docompare(p : tnode) : boolean;
  394. begin
  395. docompare:=(inherited docompare(p)) or
  396. ((nf_swapable in flags) and
  397. left.isequal(tbinopnode(p).right) and
  398. right.isequal(tbinopnode(p).left));
  399. end;
  400. {****************************************************************************
  401. WRITENODE
  402. ****************************************************************************}
  403. {$ifdef EXTDEBUG}
  404. procedure writenode(t:tnode);
  405. begin
  406. if assigned(t) then
  407. t.dowrite
  408. else
  409. write(writenodeindention,'nil');
  410. if writenodeindention='' then
  411. writeln;
  412. end;
  413. {$endif EXTDEBUG}
  414. {
  415. $Log$
  416. Revision 1.12 2000-11-04 13:10:15 jonas
  417. - removed check for self = nil in getcopy
  418. Revision 1.11 2000/10/21 18:16:11 florian
  419. * a lot of changes:
  420. - basic dyn. array support
  421. - basic C++ support
  422. - some work for interfaces done
  423. ....
  424. Revision 1.10 2000/10/14 21:52:55 peter
  425. * fixed memory leaks
  426. Revision 1.9 2000/10/14 10:14:51 peter
  427. * moehrendorf oct 2000 rewrite
  428. Revision 1.8 2000/10/01 19:48:24 peter
  429. * lot of compile updates for cg11
  430. Revision 1.7 2000/09/29 15:45:23 florian
  431. * make cycle fixed
  432. Revision 1.6 2000/09/28 19:49:52 florian
  433. *** empty log message ***
  434. Revision 1.5 2000/09/27 18:14:31 florian
  435. * fixed a lot of syntax errors in the n*.pas stuff
  436. Revision 1.4 2000/09/26 20:06:13 florian
  437. * hmm, still a lot of work to get things compilable
  438. Revision 1.3 2000/09/22 21:45:36 florian
  439. * some updates e.g. getcopy added
  440. Revision 1.2 2000/09/20 21:52:38 florian
  441. * removed a lot of errors
  442. Revision 1.1 2000/08/26 12:27:17 florian
  443. * createial release
  444. }