node.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  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. registersint:=0;
  32. registersfpu:=0;
  33. {$ifdef SUPPORT_MMX}
  34. registersmmx:=0;
  35. {$endif SUPPORT_MMX}
  36. flags:=[];
  37. end;
  38. destructor tnode.destroy;
  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. function tnode.pass_1 : tnode;
  50. begin
  51. if not(assigned(resulttype)) then
  52. det_resulttype;
  53. det_temp;
  54. end;
  55. procedure tnode.concattolist(l : plinkedlist);
  56. begin
  57. {$ifdef newcg}
  58. l^.concat(self);
  59. {$endif newcg}
  60. end;
  61. function tnode.ischild(p : tnode) : boolean;
  62. begin
  63. ischild:=false;
  64. end;
  65. {$ifdef EXTDEBUG}
  66. procedure tnode.dowrite;
  67. const treetype2str : array[tnodetype] of string[20] = (
  68. 'addn',
  69. 'muln',
  70. 'subn',
  71. 'divn',
  72. 'symdifn',
  73. 'modn',
  74. 'assignn',
  75. 'loadn',
  76. 'rangen',
  77. 'ltn',
  78. 'lten',
  79. 'gtn',
  80. 'gten',
  81. 'equaln',
  82. 'unequaln',
  83. 'inn',
  84. 'orn',
  85. 'xorn',
  86. 'shrn',
  87. 'shln',
  88. 'slashn',
  89. 'andn',
  90. 'subscriptn',
  91. 'derefn',
  92. 'addrn',
  93. 'doubleaddrn',
  94. 'ordconstn',
  95. 'typeconvn',
  96. 'calln',
  97. 'callparan',
  98. 'realconstn',
  99. 'fixconstn',
  100. 'umminusn',
  101. 'asmn',
  102. 'vecn',
  103. 'stringconstn',
  104. 'funcretn',
  105. 'selfn',
  106. 'notn',
  107. 'inlinen',
  108. 'niln',
  109. 'errorn',
  110. 'typen',
  111. 'hnewn',
  112. 'hdisposen',
  113. 'newn',
  114. 'simpledisposen',
  115. 'setelementn',
  116. 'setconstn',
  117. 'blockn',
  118. 'statementn',
  119. 'loopn',
  120. 'ifn',
  121. 'breakn',
  122. 'continuen',
  123. 'repeatn',
  124. 'whilen',
  125. 'forn',
  126. 'exitn',
  127. 'withn',
  128. 'casen',
  129. 'labeln',
  130. 'goton',
  131. 'simplenewn',
  132. 'tryexceptn',
  133. 'raisen',
  134. 'switchesn',
  135. 'tryfinallyn',
  136. 'onn',
  137. 'isn',
  138. 'asn',
  139. 'caretn',
  140. 'failn',
  141. 'starstarn',
  142. 'procinlinen',
  143. 'arrayconstructn',
  144. 'arrayconstructrangen',
  145. 'nothingn',
  146. 'loadvmtn',
  147. 'pointerconstn');
  148. begin
  149. write(indention,'(',treetype2str[nodetype]);
  150. end;
  151. {$endif EXTDEBUG}
  152. function tnode.isequal(p : tnode) : boolean;
  153. begin
  154. isequal:=assigned(p) and (p.nodetype=nodetype) and
  155. (flags*flagsequal=p.flags*flagsequal) and
  156. docompare(p);
  157. end;
  158. function tnode.docompare(p : tnode) : boolean;
  159. begin
  160. docompare:=true;
  161. end;
  162. procedure tnode.set_file_line(from : tnode);
  163. begin
  164. if assigned(from) then
  165. fileinfo:=from.fileinfo;
  166. end;
  167. procedure tnode.set_tree_filepos(const filepos : tfileposinfo);
  168. begin
  169. fileinfo:=filepos;
  170. end;
  171. {****************************************************************************
  172. TUNARYNODE
  173. ****************************************************************************}
  174. constructor tunarynode.create(tt : tnodetype;l : tnode);
  175. begin
  176. inherited create(tt);
  177. left:=l;
  178. end;
  179. function tunarynode.docompare(p : tnode) : boolean;
  180. begin
  181. docompare:=(inherited docompare(p)) and
  182. left.isequal(tunarynode(p).left);
  183. end;
  184. {$ifdef extdebug}
  185. procedure tunarynode.dowrite;
  186. begin
  187. inherited dowrite;
  188. writeln(',');
  189. writenode(left);
  190. writeln(')');
  191. dec(byte(indention[0]),2);
  192. end;
  193. {$endif}
  194. procedure tunarynode.concattolist(l : plinkedlist);
  195. begin
  196. left.parent:=self;
  197. left.concattolist(l);
  198. inherited concattolist(l);
  199. end;
  200. function tunarynode.ischild(p : tnode) : boolean;
  201. begin
  202. ischild:=p=left;
  203. end;
  204. procedure tunarynode.det_resulttype;
  205. begin
  206. left.det_resulttype;
  207. end;
  208. procedure tunarynode.det_temp;
  209. begin
  210. left.det_temp;
  211. end;
  212. {****************************************************************************
  213. TBINARYNODE
  214. ****************************************************************************}
  215. constructor tbinarynode.create(tt : tnodetype;l,r : tnode);
  216. begin
  217. inherited create(tt,l);
  218. right:=r
  219. end;
  220. procedure tbinarynode.concattolist(l : plinkedlist);
  221. begin
  222. { we could change that depending on the number of }
  223. { required registers }
  224. left.parent:=self;
  225. left.concattolist(l);
  226. left.parent:=self;
  227. left.concattolist(l);
  228. inherited concattolist(l);
  229. end;
  230. function tbinarynode.ischild(p : tnode) : boolean;
  231. begin
  232. ischild:=(p=right) or (p=right);
  233. end;
  234. procedure tbinarynode.det_resulttype;
  235. begin
  236. left.det_resulttype;
  237. right.det_resulttype;
  238. end;
  239. procedure tbinarynode.det_temp;
  240. begin
  241. left.det_temp;
  242. right.det_temp;
  243. end;
  244. function tbinarynode.docompare(p : tnode) : boolean;
  245. begin
  246. docompare:=left.isequal(tbinarynode(p).left) and
  247. right.isequal(tbinarynode(p).right);
  248. end;
  249. function tbinarynode.isbinaryoverloaded(var t : tnode) : boolean;
  250. var
  251. rd,ld : pdef;
  252. optoken : ttoken;
  253. begin
  254. t:=nil;
  255. isbinaryoverloaded:=false;
  256. { overloaded operator ? }
  257. { load easier access variables }
  258. rd:=right.resulttype;
  259. ld:=left.resulttype;
  260. if isbinaryoperatoroverloadable(ld,rd,voiddef,nodetype) then
  261. begin
  262. isbinaryoverloaded:=true;
  263. {!!!!!!!!! handle paras }
  264. case nodetype of
  265. { the nil as symtable signs firstcalln that this is
  266. an overloaded operator }
  267. addn:
  268. optoken:=_PLUS;
  269. subn:
  270. optoken:=_MINUS;
  271. muln:
  272. optoken:=_STAR;
  273. starstarn:
  274. optoken:=_STARSTAR;
  275. slashn:
  276. optoken:=_SLASH;
  277. ltn:
  278. optoken:=tokens._lt;
  279. gtn:
  280. optoken:=tokens._gt;
  281. lten:
  282. optoken:=_lte;
  283. gten:
  284. optoken:=_gte;
  285. equaln,unequaln :
  286. optoken:=_EQUAL;
  287. symdifn :
  288. optoken:=_SYMDIF;
  289. modn :
  290. optoken:=_OP_MOD;
  291. orn :
  292. optoken:=_OP_OR;
  293. xorn :
  294. optoken:=_OP_XOR;
  295. andn :
  296. optoken:=_OP_AND;
  297. divn :
  298. optoken:=_OP_DIV;
  299. shln :
  300. optoken:=_OP_SHL;
  301. shrn :
  302. optoken:=_OP_SHR;
  303. else
  304. exit;
  305. end;
  306. t:=gencallnode(overloaded_operators[optoken],nil);
  307. { we have to convert p^.left and p^.right into
  308. callparanodes }
  309. if tcallnode(t).symtableprocentry=nil then
  310. begin
  311. CGMessage(parser_e_operator_not_overloaded);
  312. t.free;
  313. end
  314. else
  315. begin
  316. inc(tcallnode(t).symtableprocentry^.refs);
  317. tcallnode(t).left:=gencallparanode(left,nil);
  318. tcallnode(t).left:=gencallparanode(right,tcallnode(t).left);
  319. if nodetype=unequaln then
  320. t:=cnotnode.create(t);
  321. firstpass(t);
  322. putnode(p);
  323. p:=t;
  324. end;
  325. end;
  326. end;
  327. procedure tbinarynode.swapleftright;
  328. var
  329. swapp : tnode;
  330. begin
  331. swapp:=right;
  332. right:=left;
  333. left:=swapp;
  334. if nf_swaped in flags then
  335. exclude(flags,nf_swaped)
  336. else
  337. include(flags,nf_swaped);
  338. end;
  339. {****************************************************************************
  340. TBINOPYNODE
  341. ****************************************************************************}
  342. constructor tbinopnode.create(tt : tnodetype;l,r : tnode);
  343. begin
  344. inherited create(tt,l,r);
  345. end;
  346. function tbinopnode.docompare(p : tnode) : boolean;
  347. begin
  348. docompare:=(inherited docompare(p)) or
  349. ((nf_swapable in flags) and
  350. left.isequal(tbinopnode(p).right) and
  351. right.isequal(tbinopnode(p).left));
  352. end;
  353. {
  354. $Log$
  355. Revision 1.2 2000-09-20 21:52:38 florian
  356. * removed a lot of errors
  357. Revision 1.1 2000/08/26 12:27:17 florian
  358. * createial release
  359. }