nmem.pas 29 KB

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