nmem.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. {
  2. $Id$
  3. Copyright (c) 2000 by Florian Klaempfl
  4. Type checking and register allocation for memory related 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. unit nmem;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,symtable,cpubase;
  23. type
  24. tloadvmtnode = class(tnode)
  25. constructor create;virtual;
  26. function pass_1 : tnode;override;
  27. end;
  28. thnewnode = class(tnode) // fixme
  29. function pass_1 : tnode;override;
  30. end;
  31. tnewnode = class(tunarynode)
  32. constructor create(l : tnode);virtual;
  33. function pass_1 : tnode;override;
  34. end;
  35. thdisposenode = class(tnode) // fixme
  36. end;
  37. tsimplenewdisposenode = class(tnode) // fixme
  38. function pass_1 : tnode;override;
  39. end;
  40. taddrnode = class(tunarynode)
  41. constructor create(l : tnode);virtual;
  42. function pass_1 : tnode;override;
  43. end;
  44. tdoubleaddrnode = class(tunarynode)
  45. constructor create(l : tnode);virtual;
  46. function pass_1 : tnode;override;
  47. end;
  48. tderefnode = class(tunarynode)
  49. constructor create(l : tnode);virtual;
  50. function pass_1 : tnode;override;
  51. end;
  52. tsubscriptnode = class(tunarynode)
  53. vs : pvarsym;
  54. constructor create(varsym : psym;l : tnode);virtual;
  55. function getcopy : tnode;
  56. function pass_1 : tnode;override;
  57. end;
  58. tvecnode = class(tbinarynode)
  59. constructor create(l,r : tnode);virtual;
  60. function pass_1 : tnode;override;
  61. end;
  62. tselfnode = class(tnode)
  63. constructor create(_class : pdef);virtual;
  64. function pass_1 : tnode;override;
  65. end;
  66. twithnode = class(tbinarynode)
  67. {$IFDEF NEWST}
  68. withsymtables : Pcollection;
  69. withreference : preference;
  70. {$ELSE}
  71. withsymtable : pwithsymtable;
  72. tablecount : longint;
  73. withreference:preference;
  74. {$ENDIF NEWST}
  75. constructor create(symtable : pwithsymtable;l,r : tnode;count : longint);virtual;
  76. function getcopy : tnode;
  77. function pass_1 : tnode;override;
  78. end;
  79. function gensubscriptnode(varsym : pvarsym;l : tnode) : tsubscriptnode;
  80. function genselfnode(_class : pdef) : tselfnode;
  81. {$IFDEF NEWST}
  82. function genwithnode(symtables:Pcollection;l,r : tnode) : twithnode;
  83. {$ELSE}
  84. function genwithnode(symtable:pwithsymtable;l,r : tnode;count : longint) : twithnode;
  85. {$ENDIF NEWST}
  86. var
  87. cloadvmtnode : class of tloadvmtnode;
  88. chnewnode : class of thnewnode;
  89. cnewnode : class of tnewnode;
  90. chdisposenode : class of thdisposenode;
  91. csimplenewdisposenode : class of tsimplenewdisposenode;
  92. caddrnode : class of taddrnode;
  93. cdoubleaddrnode : class of tdoubleaddrnode;
  94. cderefnode : class of tderefnode;
  95. csubscriptnode : class of tsubscriptnode;
  96. cvecnode : class of tvecnode;
  97. cselfnode : class of tselfnode;
  98. cwithnode : class of twithnode;
  99. implementation
  100. uses
  101. globtype,systems,
  102. cutils,cobjects,verbose,globals,
  103. symconst,aasm,types,
  104. htypechk,pass_1
  105. {$ifdef newcg}
  106. ,cgbase
  107. {$else newcg}
  108. ,hcodegen
  109. {$endif newcg}
  110. ;
  111. function genselfnode(_class : pdef) : tselfnode;
  112. var
  113. p : tnode;
  114. begin
  115. genselfnode:=cselfnode.create(_class);
  116. end;
  117. {$IFDEF NEWST}
  118. function genwithnode(symtables:Pcollection;l,r : tnode) : tnode;
  119. var
  120. p : tnode;
  121. begin
  122. !!!!!!!!! fixme
  123. p:=getnode;
  124. disposetyp:=dt_with;
  125. treetype:=withn;
  126. left:=l;
  127. right:=r;
  128. registers32:=0;
  129. {$ifdef SUPPORT_MMX}
  130. registersmmx:=0;
  131. {$endif SUPPORT_MMX}
  132. resulttype:=nil;
  133. withsymtables:=symtables;
  134. withreference:=nil;
  135. set_file_line(l,p);
  136. genwithnode:=p;
  137. end;
  138. {$ELSE}
  139. function genwithnode(symtable : pwithsymtable;l,r : tnode;count : longint) : twithnode;
  140. begin
  141. genwithnode:=cwithnode.create(symtable,l,r,count);
  142. end;
  143. {$ENDIF NEWST}
  144. function gensubscriptnode(varsym : pvarsym;l : tnode) : tsubscriptnode;
  145. begin
  146. gensubscriptnode:=csubscriptnode.create(varsym,l);
  147. end;
  148. {*****************************************************************************
  149. TLOADVMTNODE
  150. *****************************************************************************}
  151. constructor tloadvmtnode.create;
  152. begin
  153. inherited create(loadvmtn);
  154. end;
  155. function tloadvmtnode.pass_1 : tnode;
  156. begin
  157. pass_1:=nil;
  158. registers32:=1;
  159. location.loc:=LOC_REGISTER;
  160. end;
  161. {*****************************************************************************
  162. THNEWNODE
  163. *****************************************************************************}
  164. function thnewnode.pass_1 : tnode;
  165. begin
  166. pass_1:=nil;
  167. end;
  168. {*****************************************************************************
  169. TNEWNODE
  170. *****************************************************************************}
  171. constructor tnewnode.create(l : tnode);
  172. begin
  173. inherited create(newn,l);
  174. end;
  175. function tnewnode.pass_1 : tnode;
  176. begin
  177. pass_1:=nil;
  178. if assigned(left) then
  179. firstpass(left);
  180. if codegenerror then
  181. exit;
  182. if assigned(left) then
  183. begin
  184. registers32:=left.registers32;
  185. registersfpu:=left.registersfpu;
  186. {$ifdef SUPPORT_MMX}
  187. registersmmx:=left.registersmmx;
  188. {$endif SUPPORT_MMX}
  189. end;
  190. { result type is already set }
  191. procinfo^.flags:=procinfo^.flags or pi_do_call;
  192. if assigned(left) then
  193. location.loc:=LOC_REGISTER
  194. else
  195. location.loc:=LOC_REFERENCE;
  196. end;
  197. {*****************************************************************************
  198. THDISPOSENODE
  199. *****************************************************************************}
  200. function thdisposenode.pass_1 : tnode;
  201. begin
  202. pass_1:=nil;
  203. firstpass(left);
  204. if codegenerror then
  205. exit;
  206. registers32:=left.registers32;
  207. registersfpu:=left.registersfpu;
  208. {$ifdef SUPPORT_MMX}
  209. registersmmx:=left.registersmmx;
  210. {$endif SUPPORT_MMX}
  211. if registers32<1 then
  212. registers32:=1;
  213. {
  214. if left.location.loc<>LOC_REFERENCE then
  215. CGMessage(cg_e_illegal_expression);
  216. }
  217. if left.location.loc=LOC_CREGISTER then
  218. inc(registers32);
  219. location.loc:=LOC_REFERENCE;
  220. resulttype:=ppointerdef(left.resulttype)^.pointertype.def;
  221. end;
  222. {*****************************************************************************
  223. TSIMPLENEWDISPOSENODE
  224. *****************************************************************************}
  225. function tsimplenewdisposenode.pass_1 : tnode;
  226. begin
  227. pass_1:=nil;
  228. { this cannot be in a register !! }
  229. make_not_regable(left);
  230. firstpass(left);
  231. if codegenerror then
  232. exit;
  233. { check the type }
  234. if left.resulttype=nil then
  235. left.resulttype:=generrordef;
  236. if (left.resulttype^.deftype<>pointerdef) then
  237. CGMessage1(type_e_pointer_type_expected,left.resulttype^.typename);
  238. if (left.location.loc<>LOC_REFERENCE) {and
  239. (left.location.loc<>LOC_CREGISTER)} then
  240. CGMessage(cg_e_illegal_expression);
  241. registers32:=left.registers32;
  242. registersfpu:=left.registersfpu;
  243. {$ifdef SUPPORT_MMX}
  244. registersmmx:=left.registersmmx;
  245. {$endif SUPPORT_MMX}
  246. resulttype:=voiddef;
  247. procinfo^.flags:=procinfo^.flags or pi_do_call;
  248. end;
  249. {*****************************************************************************
  250. TADDRNODE
  251. *****************************************************************************}
  252. constructor taddrnode.create(l : tnode);
  253. begin
  254. inherited create(addrn,l);
  255. end;
  256. function taddrnode.pass_1 : tnode;
  257. var
  258. hp : tnode;
  259. hp2 : pparaitem;
  260. hp3 : pabstractprocdef;
  261. begin
  262. pass_1:=nil;
  263. make_not_regable(left);
  264. if not(assigned(resulttype)) then
  265. begin
  266. { tp @procvar support (type of @procvar is a void pointer)
  267. Note: we need to leave the addrn in the tree,
  268. else we can't see the difference between @procvar and procvar.
  269. we set the procvarload flag so a secondpass does nothing for
  270. this node (PFV) }
  271. if (m_tp_procvar in aktmodeswitches) then
  272. begin
  273. hp:=left;
  274. case hp.treetype of
  275. calln :
  276. begin
  277. { is it a procvar? }
  278. hp:=hp.right;
  279. if assigned(hp) then
  280. begin
  281. { remove calln node }
  282. putnode(left);
  283. left:=hp;
  284. firstpass(hp);
  285. procvarload:=true;
  286. end;
  287. end;
  288. loadn,
  289. subscriptn,
  290. typeconvn,
  291. vecn,
  292. derefn :
  293. begin
  294. firstpass(hp);
  295. if codegenerror then
  296. exit;
  297. if hp.resulttype^.deftype=procvardef then
  298. begin
  299. procvarload:=true;
  300. end;
  301. end;
  302. end;
  303. end;
  304. if procvarload then
  305. begin
  306. registers32:=left.registers32;
  307. registersfpu:=left.registersfpu;
  308. {$ifdef SUPPORT_MMX}
  309. registersmmx:=left.registersmmx;
  310. {$endif SUPPORT_MMX}
  311. if registers32<1 then
  312. registers32:=1;
  313. location.loc:=left.location.loc;
  314. resulttype:=voidpointerdef;
  315. exit;
  316. end;
  317. { proc 2 procvar ? }
  318. if left.treetype=calln then
  319. begin
  320. { generate a methodcallnode or proccallnode }
  321. { we shouldn't convert things like @tcollection.load }
  322. if (left.symtableprocentry^.owner^.symtabletype=objectsymtable) and
  323. not(assigned(left.methodpointer) and (left.methodpointer^.treetype=typen)) then
  324. begin
  325. hp:=genloadmethodcallnode(pprocsym(left.symtableprocentry),left.symtableproc,
  326. getcopy(left.methodpointer));
  327. disposetree(p);
  328. firstpass(hp);
  329. p:=hp;
  330. exit;
  331. end
  332. else
  333. hp:=genloadcallnode(pprocsym(left.symtableprocentry),left.symtableproc);
  334. { result is a procedure variable }
  335. { No, to be TP compatible, you must return a pointer to
  336. the procedure that is stored in the procvar.}
  337. if not(m_tp_procvar in aktmodeswitches) then
  338. begin
  339. resulttype:=new(pprocvardef,init);
  340. { it could also be a procvar, not only pprocsym ! }
  341. if left.symtableprocentry^.typ=varsym then
  342. hp3:=pabstractprocdef(pvarsym(left.symtableentry)^.vartype.def)
  343. else
  344. hp3:=pabstractprocdef(pprocsym(left.symtableprocentry)^.definition);
  345. pprocvardef(resulttype)^.proctypeoption:=hp3^.proctypeoption;
  346. pprocvardef(resulttype)^.proccalloptions:=hp3^.proccalloptions;
  347. pprocvardef(resulttype)^.procoptions:=hp3^.procoptions;
  348. pprocvardef(resulttype)^.rettype:=hp3^.rettype;
  349. pprocvardef(resulttype)^.symtablelevel:=hp3^.symtablelevel;
  350. { method ? then set the methodpointer flag }
  351. if (hp3^.owner^.symtabletype=objectsymtable) and
  352. (pobjectdef(hp3^.owner^.defowner)^.is_class) then
  353. include(pprocvardef(resulttype)^.procoptions,po_methodpointer);
  354. { we need to process the parameters reverse so they are inserted
  355. in the correct right2left order (PFV) }
  356. hp2^.:=pparaitem(hp3^.para^.last);
  357. while assigned(hp2^.) do
  358. begin
  359. pprocvardef(resulttype)^.concatpara(hp2^.paratype,hp2^.paratyp,hp2^.defaultvalue);
  360. hp2^.:=pparaitem(hp2^.previous);
  361. end;
  362. end
  363. else
  364. resulttype:=voidpointerdef;
  365. disposetree(left);
  366. left:=hp;
  367. end
  368. else
  369. begin
  370. firstpass(left);
  371. { what are we getting the address from an absolute sym? }
  372. hp:=left;
  373. while assigned(hp) and (hp.treetype in [vecn,derefn,subscriptn]) do
  374. hp:=hp.left;
  375. if assigned(hp) and (hp.treetype=loadn) and
  376. ((hp.symtableentry^.typ=absolutesym) and
  377. pabsolutesym(hp.symtableentry)^.absseg) then
  378. begin
  379. if not(cs_typed_addresses in aktlocalswitches) then
  380. resulttype:=voidfarpointerdef
  381. else
  382. resulttype:=new(ppointerdef,initfardef(left.resulttype));
  383. end
  384. else
  385. begin
  386. if not(cs_typed_addresses in aktlocalswitches) then
  387. resulttype:=voidpointerdef
  388. else
  389. resulttype:=new(ppointerdef,initdef(left.resulttype));
  390. end;
  391. end;
  392. end;
  393. firstpass(left);
  394. { this is like the function addr }
  395. inc(parsing_para_level);
  396. set_varstate(left,false);
  397. dec(parsing_para_level);
  398. if codegenerror then
  399. exit;
  400. { don't allow constants }
  401. if is_constnode(left) then
  402. begin
  403. aktfilepos:=left.fileinfo;
  404. CGMessage(type_e_no_addr_of_constant);
  405. end
  406. else
  407. begin
  408. { we should allow loc_mem for @string }
  409. if not(left.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  410. begin
  411. aktfilepos:=left.fileinfo;
  412. CGMessage(cg_e_illegal_expression);
  413. end;
  414. end;
  415. registers32:=left.registers32;
  416. registersfpu:=left.registersfpu;
  417. {$ifdef SUPPORT_MMX}
  418. registersmmx:=left.registersmmx;
  419. {$endif SUPPORT_MMX}
  420. if registers32<1 then
  421. registers32:=1;
  422. { is this right for object of methods ?? }
  423. location.loc:=LOC_REGISTER;
  424. end;
  425. {*****************************************************************************
  426. TDOUBLEADDRNODE
  427. *****************************************************************************}
  428. constructor tdoubleaddrnode.create(l : tnode);
  429. begin
  430. inherited create(doubleaddrn,l);
  431. end;
  432. function tdoubleaddrnode.pass_1 : tnode;
  433. begin
  434. pass_1:=nil;
  435. make_not_regable(left);
  436. firstpass(left);
  437. inc(parsing_para_level);
  438. set_varstate(left,false);
  439. dec(parsing_para_level);
  440. if resulttype=nil then
  441. resulttype:=voidpointerdef;
  442. if codegenerror then
  443. exit;
  444. if (left.resulttype^.deftype)<>procvardef then
  445. CGMessage(cg_e_illegal_expression);
  446. if (left.location.loc<>LOC_REFERENCE) then
  447. CGMessage(cg_e_illegal_expression);
  448. registers32:=left.registers32;
  449. registersfpu:=left.registersfpu;
  450. {$ifdef SUPPORT_MMX}
  451. registersmmx:=left.registersmmx;
  452. {$endif SUPPORT_MMX}
  453. if registers32<1 then
  454. registers32:=1;
  455. location.loc:=LOC_REGISTER;
  456. end;
  457. {*****************************************************************************
  458. TDEREFNODE
  459. *****************************************************************************}
  460. constructor tderefnode.create(l : tnode);
  461. begin
  462. inherited create(derefn,l);
  463. end;
  464. function tderefnode.pass_1 : tnode;
  465. begin
  466. pass_1:=nil;
  467. firstpass(left);
  468. set_varstate(left,true);
  469. if codegenerror then
  470. begin
  471. resulttype:=generrordef;
  472. exit;
  473. end;
  474. registers32:=max(left.registers32,1);
  475. registersfpu:=left.registersfpu;
  476. {$ifdef SUPPORT_MMX}
  477. registersmmx:=left.registersmmx;
  478. {$endif SUPPORT_MMX}
  479. if left.resulttype^.deftype<>pointerdef then
  480. CGMessage(cg_e_invalid_qualifier);
  481. resulttype:=ppointerdef(left.resulttype)^.pointertype.def;
  482. location.loc:=LOC_REFERENCE;
  483. end;
  484. {*****************************************************************************
  485. TSUBSCRIPTNODE
  486. *****************************************************************************}
  487. constructor tsubscriptnode.create(varsym : pvarsym;l : tnode);
  488. begin
  489. inherited create(subscriptn,l);
  490. vs:=varsym;
  491. end;
  492. function tsubscriptnode.getcopy : tnode;
  493. var
  494. p : tsubscriptnode;
  495. begin
  496. p:=tsubscriptnode(inherited getcopy);
  497. p.vs:=vs;
  498. getcopy:=p;
  499. end;
  500. function tsubscriptnode.pass_1 : tnode;
  501. begin
  502. pass_1:=nil;
  503. firstpass(left);
  504. if codegenerror then
  505. begin
  506. resulttype:=generrordef;
  507. exit;
  508. end;
  509. resulttype:=vs^.vartype.def;
  510. registers32:=left.registers32;
  511. registersfpu:=left.registersfpu;
  512. {$ifdef SUPPORT_MMX}
  513. registersmmx:=left.registersmmx;
  514. {$endif SUPPORT_MMX}
  515. { classes must be dereferenced implicit }
  516. if (left.resulttype^.deftype=objectdef) and
  517. pobjectdef(left.resulttype)^.is_class then
  518. begin
  519. if registers32=0 then
  520. registers32:=1;
  521. location.loc:=LOC_REFERENCE;
  522. end
  523. else
  524. begin
  525. if (left.location.loc<>LOC_MEM) and
  526. (left.location.loc<>LOC_REFERENCE) then
  527. CGMessage(cg_e_illegal_expression);
  528. set_location(location,left.location);
  529. end;
  530. end;
  531. {*****************************************************************************
  532. TVECNODE
  533. *****************************************************************************}
  534. constructor tvecnode.create(l,r : tnode);
  535. begin
  536. inherited create(vecn,l,r);
  537. end;
  538. function tvecnode.pass_1 : tnode;
  539. var
  540. harr : pdef;
  541. ct : tconverttype;
  542. {$ifdef consteval}
  543. tcsym : ptypedconstsym;
  544. {$endif}
  545. begin
  546. pass_1:=nil;
  547. firstpass(left);
  548. firstpass(right);
  549. if codegenerror then
  550. exit;
  551. { range check only for arrays }
  552. if (left.resulttype^.deftype=arraydef) then
  553. begin
  554. if (isconvertable(right.resulttype,parraydef(left.resulttype)^.rangetype.def,
  555. ct,ordconstn,false)=0) and
  556. not(is_equal(right.resulttype,parraydef(left.resulttype)^.rangetype.def)) then
  557. CGMessage(type_e_mismatch);
  558. end;
  559. { Never convert a boolean or a char !}
  560. { maybe type conversion }
  561. if (right.resulttype^.deftype<>enumdef) and
  562. not(is_char(right.resulttype)) and
  563. not(is_boolean(right.resulttype)) then
  564. begin
  565. right:=gentypeconvnode(right,s32bitdef);
  566. firstpass(right);
  567. if codegenerror then
  568. exit;
  569. end;
  570. { are we accessing a pointer[], then convert the pointer to
  571. an array first, in FPC this is allowed for all pointers in
  572. delphi/tp7 it's only allowed for pchars }
  573. if (left.resulttype^.deftype=pointerdef) and
  574. ((m_fpc in aktmodeswitches) or
  575. is_pchar(left.resulttype)) then
  576. begin
  577. { convert pointer to array }
  578. harr:=new(parraydef,init(0,$7fffffff,s32bitdef));
  579. parraydef(harr)^.elementtype.def:=ppointerdef(left.resulttype)^.pointertype.def;
  580. left:=gentypeconvnode(left,harr);
  581. firstpass(left);
  582. if codegenerror then
  583. exit;
  584. resulttype:=parraydef(harr)^.elementtype.def
  585. end;
  586. { determine return type }
  587. if not assigned(resulttype) then
  588. if left.resulttype^.deftype=arraydef then
  589. resulttype:=parraydef(left.resulttype)^.elementtype.def
  590. else if left.resulttype^.deftype=stringdef then
  591. begin
  592. { indexed access to strings }
  593. case pstringdef(left.resulttype)^.string_typ of
  594. {
  595. st_widestring : resulttype:=cwchardef;
  596. }
  597. st_ansistring : resulttype:=cchardef;
  598. st_longstring : resulttype:=cchardef;
  599. st_shortstring : resulttype:=cchardef;
  600. end;
  601. end
  602. else
  603. CGMessage(type_e_array_required);
  604. { the register calculation is easy if a const index is used }
  605. if right.treetype=ordconstn then
  606. begin
  607. {$ifdef consteval}
  608. { constant evaluation }
  609. if (left.treetype=loadn) and
  610. (left.symtableentry^.typ=typedconstsym) then
  611. begin
  612. tcsym:=ptypedconstsym(left.symtableentry);
  613. if tcsym^.defintion^.typ=stringdef then
  614. begin
  615. end;
  616. end;
  617. {$endif}
  618. registers32:=left.registers32;
  619. { for ansi/wide strings, we need at least one register }
  620. if is_ansistring(left.resulttype) or
  621. is_widestring(left.resulttype) then
  622. registers32:=max(registers32,1);
  623. end
  624. else
  625. begin
  626. { this rules are suboptimal, but they should give }
  627. { good results }
  628. registers32:=max(left.registers32,right.registers32);
  629. { for ansi/wide strings, we need at least one register }
  630. if is_ansistring(left.resulttype) or
  631. is_widestring(left.resulttype) then
  632. registers32:=max(registers32,1);
  633. { need we an extra register when doing the restore ? }
  634. if (left.registers32<=right.registers32) and
  635. { only if the node needs less than 3 registers }
  636. { two for the right node and one for the }
  637. { left address }
  638. (registers32<3) then
  639. inc(registers32);
  640. { need we an extra register for the index ? }
  641. if (right.location.loc<>LOC_REGISTER)
  642. { only if the right node doesn't need a register }
  643. and (right.registers32<1) then
  644. inc(registers32);
  645. { not correct, but what works better ?
  646. if left.registers32>0 then
  647. registers32:=max(registers32,2)
  648. else
  649. min. one register
  650. registers32:=max(registers32,1);
  651. }
  652. end;
  653. registersfpu:=max(left.registersfpu,right.registersfpu);
  654. {$ifdef SUPPORT_MMX}
  655. registersmmx:=max(left.registersmmx,right.registersmmx);
  656. {$endif SUPPORT_MMX}
  657. if left.location.loc in [LOC_CREGISTER,LOC_REFERENCE] then
  658. location.loc:=LOC_REFERENCE
  659. else
  660. location.loc:=LOC_MEM;
  661. end;
  662. {*****************************************************************************
  663. TSELFNODE
  664. *****************************************************************************}
  665. constructor tselfnode.create(_class : pdef);
  666. begin
  667. inherited create(selfn);
  668. resulttype:=_class;
  669. end;
  670. function tselfnode.pass_1 : tnode;
  671. begin
  672. pass_1:=nil;
  673. if (resulttype^.deftype=classrefdef) or
  674. ((resulttype^.deftype=objectdef)
  675. and pobjectdef(resulttype)^.is_class
  676. ) then
  677. location.loc:=LOC_CREGISTER
  678. else
  679. location.loc:=LOC_REFERENCE;
  680. end;
  681. {*****************************************************************************
  682. TWITHNODE
  683. *****************************************************************************}
  684. constructor twithnode.create(symtable : pwithsymtable;l,r : tnode;count : longint);
  685. begin
  686. inherited create(withn,l,r);
  687. withsymtable:=symtable;
  688. tablecount:=count;
  689. withreference:=nil;
  690. set_file_line(l);
  691. end;
  692. function twithnode.getcopy : tnode;
  693. var
  694. p : twithnode;
  695. begin
  696. p:=twithnode(inherited getcopy);
  697. p.withsymtable:=withsymtable;
  698. p.tablecount:=count;
  699. p.withreference:=withreference;
  700. end;
  701. function twithnode.pass_1 : tnode;
  702. var
  703. symtable : pwithsymtable;
  704. i : longint;
  705. begin
  706. pass_1:=nil;
  707. if assigned(left) and assigned(right) then
  708. begin
  709. firstpass(left);
  710. left.unset_varstate;
  711. left.set_varstate(true);
  712. if codegenerror then
  713. exit;
  714. symtable:=withsymtable;
  715. for i:=1 to tablecount do
  716. begin
  717. if (left.treetype=loadn) and
  718. (left.symtable=aktprocsym^.definition^.localst) then
  719. symtable^.direct_with:=true;
  720. symtable^.withnode:=p;
  721. symtable:=pwithsymtable(symtable^.next);
  722. end;
  723. firstpass(right);
  724. if codegenerror then
  725. exit;
  726. left_right_max(p);
  727. resulttype:=voiddef;
  728. end
  729. else
  730. begin
  731. { optimization }
  732. disposetree(p);
  733. p:=nil;
  734. end;
  735. end;
  736. end.
  737. {
  738. $Log$
  739. Revision 1.1 2000-09-25 09:58:22 florian
  740. * first revision for testing purpose
  741. }