nld.pas 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Type checking and register allocation for load/assignment 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 nld;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,
  23. {$ifdef state_tracking}
  24. nstate,
  25. {$endif}
  26. symconst,symppu,symbase,symtype,symsym,symdef;
  27. type
  28. tloadnode = class(tunarynode)
  29. symtableentry : tsym;
  30. symtableentryderef : tderef;
  31. symtable : tsymtable;
  32. procdef : tprocdef;
  33. procdefderef : tderef;
  34. constructor create(v : tsym;st : tsymtable);virtual;
  35. constructor create_procvar(v : tsym;d:tprocdef;st : tsymtable);virtual;
  36. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  37. procedure ppuwrite(ppufile:tcompilerppufile);override;
  38. procedure derefimpl;override;
  39. procedure set_mp(p:tnode);
  40. function getcopy : tnode;override;
  41. function pass_1 : tnode;override;
  42. function det_resulttype:tnode;override;
  43. procedure mark_write;override;
  44. function docompare(p: tnode): boolean; override;
  45. procedure printnodedata(var t:text);override;
  46. end;
  47. tloadnodeclass = class of tloadnode;
  48. { different assignment types }
  49. tassigntype = (at_normal,at_plus,at_minus,at_star,at_slash);
  50. tassignmentnode = class(tbinarynode)
  51. assigntype : tassigntype;
  52. constructor create(l,r : tnode);virtual;
  53. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  54. procedure ppuwrite(ppufile:tcompilerppufile);override;
  55. function getcopy : tnode;override;
  56. function pass_1 : tnode;override;
  57. function det_resulttype:tnode;override;
  58. {$ifdef state_tracking}
  59. function track_state_pass(exec_known:boolean):boolean;override;
  60. {$endif state_tracking}
  61. function docompare(p: tnode): boolean; override;
  62. end;
  63. tassignmentnodeclass = class of tassignmentnode;
  64. tarrayconstructorrangenode = class(tbinarynode)
  65. constructor create(l,r : tnode);virtual;
  66. function pass_1 : tnode;override;
  67. function det_resulttype:tnode;override;
  68. end;
  69. tarrayconstructorrangenodeclass = class of tarrayconstructorrangenode;
  70. tarrayconstructornode = class(tbinarynode)
  71. constructor create(l,r : tnode);virtual;
  72. function getcopy : tnode;override;
  73. function pass_1 : tnode;override;
  74. function det_resulttype:tnode;override;
  75. function docompare(p: tnode): boolean; override;
  76. procedure force_type(tt:ttype);
  77. end;
  78. tarrayconstructornodeclass = class of tarrayconstructornode;
  79. ttypenode = class(tnode)
  80. allowed : boolean;
  81. restype : ttype;
  82. constructor create(t : ttype);virtual;
  83. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  84. procedure ppuwrite(ppufile:tcompilerppufile);override;
  85. procedure derefimpl;override;
  86. function pass_1 : tnode;override;
  87. function det_resulttype:tnode;override;
  88. function docompare(p: tnode): boolean; override;
  89. end;
  90. ttypenodeclass = class of ttypenode;
  91. trttinode = class(tnode)
  92. l1,l2 : longint;
  93. rttitype : trttitype;
  94. rttidef : tstoreddef;
  95. rttidefderef : tderef;
  96. constructor create(def:tstoreddef;rt:trttitype);virtual;
  97. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  98. procedure ppuwrite(ppufile:tcompilerppufile);override;
  99. procedure derefimpl;override;
  100. function getcopy : tnode;override;
  101. function pass_1 : tnode;override;
  102. procedure pass_2;override;
  103. function det_resulttype:tnode;override;
  104. function docompare(p: tnode): boolean; override;
  105. end;
  106. trttinodeclass = class of trttinode;
  107. var
  108. cloadnode : tloadnodeclass;
  109. cassignmentnode : tassignmentnodeclass;
  110. carrayconstructorrangenode : tarrayconstructorrangenodeclass;
  111. carrayconstructornode : tarrayconstructornodeclass;
  112. ctypenode : ttypenodeclass;
  113. crttinode : trttinodeclass;
  114. procedure load_procvar_from_calln(var p1:tnode);
  115. function load_high_value_node(vs:tvarsym):tnode;
  116. function load_self_node:tnode;
  117. function load_result_node:tnode;
  118. function load_self_pointer_node:tnode;
  119. function load_vmt_pointer_node:tnode;
  120. function is_self_node(p:tnode):boolean;
  121. implementation
  122. uses
  123. cutils,verbose,globtype,globals,systems,
  124. symtable,paramgr,defutil,defcmp,
  125. htypechk,pass_1,
  126. ncon,ninl,ncnv,nmem,ncal,cpubase,rgobj,cginfo,cgbase
  127. ,symnot
  128. ;
  129. {*****************************************************************************
  130. Helpers
  131. *****************************************************************************}
  132. procedure load_procvar_from_calln(var p1:tnode);
  133. var
  134. p2 : tnode;
  135. begin
  136. if p1.nodetype<>calln then
  137. internalerror(200212251);
  138. { was it a procvar, then we simply remove the calln and
  139. reuse the right }
  140. if assigned(tcallnode(p1).right) then
  141. begin
  142. p2:=tcallnode(p1).right;
  143. tcallnode(p1).right:=nil;
  144. end
  145. else
  146. begin
  147. p2:=cloadnode.create_procvar(tcallnode(p1).symtableprocentry,
  148. tprocdef(tcallnode(p1).procdefinition),tcallnode(p1).symtableproc);
  149. { when the methodpointer is typen we've something like:
  150. tobject.create. Then only the address is needed of the
  151. method without a self pointer }
  152. if assigned(tcallnode(p1).methodpointer) and
  153. (tcallnode(p1).methodpointer.nodetype<>typen) then
  154. begin
  155. tloadnode(p2).set_mp(tcallnode(p1).methodpointer);
  156. tcallnode(p1).methodpointer:=nil;
  157. end;
  158. end;
  159. resulttypepass(p2);
  160. p1.free;
  161. p1:=p2;
  162. end;
  163. function load_high_value_node(vs:tvarsym):tnode;
  164. var
  165. srsym : tsym;
  166. srsymtable : tsymtable;
  167. begin
  168. result:=nil;
  169. srsymtable:=vs.owner;
  170. if vo_is_local_copy in vs.varoptions then
  171. begin
  172. { next symtable is always the para symtable }
  173. srsymtable:=srsymtable.next;
  174. if not(srsymtable.symtabletype in [parasymtable,inlineparasymtable]) then
  175. internalerror(200212171);
  176. end;
  177. srsym:=searchsymonlyin(srsymtable,'high'+vs.name);
  178. if assigned(srsym) then
  179. begin
  180. result:=cloadnode.create(srsym,srsymtable);
  181. resulttypepass(result);
  182. end
  183. else
  184. CGMessage(cg_e_illegal_expression);
  185. end;
  186. function load_self_node:tnode;
  187. var
  188. srsym : tsym;
  189. srsymtable : tsymtable;
  190. begin
  191. result:=nil;
  192. searchsym('self',srsym,srsymtable);
  193. if assigned(srsym) then
  194. begin
  195. result:=cloadnode.create(srsym,srsymtable);
  196. resulttypepass(result);
  197. end
  198. else
  199. CGMessage(cg_e_illegal_expression);
  200. end;
  201. function load_result_node:tnode;
  202. var
  203. srsym : tsym;
  204. srsymtable : tsymtable;
  205. begin
  206. result:=nil;
  207. searchsym('result',srsym,srsymtable);
  208. if assigned(srsym) then
  209. begin
  210. result:=cloadnode.create(srsym,srsymtable);
  211. resulttypepass(result);
  212. end
  213. else
  214. CGMessage(cg_e_illegal_expression);
  215. end;
  216. function load_self_pointer_node:tnode;
  217. var
  218. srsym : tsym;
  219. srsymtable : tsymtable;
  220. begin
  221. result:=nil;
  222. searchsym('self',srsym,srsymtable);
  223. if assigned(srsym) then
  224. begin
  225. result:=cloadnode.create(srsym,srsymtable);
  226. include(result.flags,nf_load_self_pointer);
  227. resulttypepass(result);
  228. end
  229. else
  230. CGMessage(cg_e_illegal_expression);
  231. end;
  232. function load_vmt_pointer_node:tnode;
  233. var
  234. srsym : tsym;
  235. srsymtable : tsymtable;
  236. begin
  237. result:=nil;
  238. searchsym('vmt',srsym,srsymtable);
  239. if assigned(srsym) then
  240. begin
  241. result:=cloadnode.create(srsym,srsymtable);
  242. resulttypepass(result);
  243. end
  244. else
  245. CGMessage(cg_e_illegal_expression);
  246. end;
  247. function is_self_node(p:tnode):boolean;
  248. begin
  249. is_self_node:=(p.nodetype=loadn) and
  250. (tloadnode(p).symtableentry.typ=varsym) and
  251. (vo_is_self in tvarsym(tloadnode(p).symtableentry).varoptions);
  252. end;
  253. {*****************************************************************************
  254. TLOADNODE
  255. *****************************************************************************}
  256. constructor tloadnode.create(v : tsym;st : tsymtable);
  257. begin
  258. inherited create(loadn,nil);
  259. if not assigned(v) then
  260. internalerror(200108121);
  261. symtableentry:=v;
  262. symtable:=st;
  263. procdef:=nil;
  264. end;
  265. constructor tloadnode.create_procvar(v : tsym;d:tprocdef;st : tsymtable);
  266. begin
  267. inherited create(loadn,nil);
  268. if not assigned(v) then
  269. internalerror(200108121);
  270. symtableentry:=v;
  271. symtable:=st;
  272. procdef:=d;
  273. end;
  274. constructor tloadnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  275. begin
  276. inherited ppuload(t,ppufile);
  277. ppufile.getderef(symtableentryderef);
  278. symtable:=nil;
  279. ppufile.getderef(procdefderef);
  280. end;
  281. procedure tloadnode.ppuwrite(ppufile:tcompilerppufile);
  282. begin
  283. inherited ppuwrite(ppufile);
  284. ppufile.putderef(symtableentry,symtableentryderef);
  285. ppufile.putderef(procdef,procdefderef);
  286. end;
  287. procedure tloadnode.derefimpl;
  288. begin
  289. inherited derefimpl;
  290. symtableentry:=tsym(symtableentryderef.resolve);
  291. symtable:=symtableentry.owner;
  292. procdef:=tprocdef(procdefderef.resolve);
  293. end;
  294. procedure tloadnode.set_mp(p:tnode);
  295. begin
  296. { typen nodes should not be set }
  297. if p.nodetype=typen then
  298. internalerror(200301042);
  299. left:=p;
  300. end;
  301. function tloadnode.getcopy : tnode;
  302. var
  303. n : tloadnode;
  304. begin
  305. n:=tloadnode(inherited getcopy);
  306. n.symtable:=symtable;
  307. n.symtableentry:=symtableentry;
  308. result:=n;
  309. end;
  310. function tloadnode.det_resulttype:tnode;
  311. begin
  312. result:=nil;
  313. { handle first absolute as it will replace the symtableentry }
  314. if symtableentry.typ=absolutesym then
  315. begin
  316. { force the resulttype to the type of the absolute }
  317. resulttype:=tabsolutesym(symtableentry).vartype;
  318. { replace the symtableentry when it points to a var, else
  319. we are finished }
  320. if (tabsolutesym(symtableentry).abstyp=tovar) then
  321. begin
  322. symtableentry:=tabsolutesym(symtableentry).ref;
  323. symtable:=symtableentry.owner;
  324. include(flags,nf_absolute);
  325. end
  326. else
  327. exit;
  328. end;
  329. case symtableentry.typ of
  330. constsym:
  331. begin
  332. if tconstsym(symtableentry).consttyp=constresourcestring then
  333. resulttype:=cansistringtype
  334. else
  335. internalerror(22799);
  336. end;
  337. varsym :
  338. begin
  339. inc(tvarsym(symtableentry).refs);
  340. { if it's refered by absolute then it's used }
  341. if nf_absolute in flags then
  342. tvarsym(symtableentry).varstate:=vs_used
  343. else
  344. begin
  345. { fix self type which is declared as voidpointer in the
  346. definition }
  347. if vo_is_self in tvarsym(symtableentry).varoptions then
  348. begin
  349. resulttype.setdef(tprocdef(symtableentry.owner.defowner)._class);
  350. if (po_classmethod in tprocdef(symtableentry.owner.defowner).procoptions) or
  351. (po_staticmethod in tprocdef(symtableentry.owner.defowner).procoptions) then
  352. resulttype.setdef(tclassrefdef.create(resulttype))
  353. else if is_object(resulttype.def) and
  354. (nf_load_self_pointer in flags) then
  355. resulttype.setdef(tpointerdef.create(resulttype));
  356. end
  357. else if vo_is_vmt in tvarsym(symtableentry).varoptions then
  358. begin
  359. resulttype.setdef(tprocdef(symtableentry.owner.defowner)._class);
  360. resulttype.setdef(tclassrefdef.create(resulttype));
  361. end
  362. else
  363. resulttype:=tvarsym(symtableentry).vartype;
  364. end;
  365. end;
  366. typedconstsym :
  367. if not(nf_absolute in flags) then
  368. resulttype:=ttypedconstsym(symtableentry).typedconsttype;
  369. procsym :
  370. begin
  371. if not assigned(procdef) then
  372. begin
  373. if Tprocsym(symtableentry).procdef_count>1 then
  374. CGMessage(parser_e_no_overloaded_procvars);
  375. procdef:=tprocsym(symtableentry).first_procdef;
  376. end;
  377. { the result is a procdef, addrn and proc_to_procvar
  378. typeconvn need this as resulttype so they know
  379. that the address needs to be returned }
  380. resulttype.setdef(procdef);
  381. { process methodpointer }
  382. if assigned(left) then
  383. resulttypepass(left);
  384. end;
  385. else
  386. internalerror(200104141);
  387. end;
  388. end;
  389. procedure Tloadnode.mark_write;
  390. begin
  391. include(flags,nf_write);
  392. end;
  393. function tloadnode.pass_1 : tnode;
  394. begin
  395. result:=nil;
  396. expectloc:=LOC_REFERENCE;
  397. registers32:=0;
  398. registersfpu:=0;
  399. {$ifdef SUPPORT_MMX}
  400. registersmmx:=0;
  401. {$endif SUPPORT_MMX}
  402. case symtableentry.typ of
  403. absolutesym :
  404. ;
  405. constsym:
  406. begin
  407. if tconstsym(symtableentry).consttyp=constresourcestring then
  408. begin
  409. include(current_procinfo.flags,pi_needs_implicit_finally);
  410. expectloc:=LOC_CREFERENCE;
  411. end;
  412. end;
  413. varsym :
  414. begin
  415. if (symtable.symtabletype in [parasymtable,localsymtable]) and
  416. (current_procdef.parast.symtablelevel>symtable.symtablelevel) then
  417. begin
  418. { if the variable is in an other stackframe then we need
  419. a register to dereference }
  420. if symtable.symtablelevel>normal_function_level then
  421. begin
  422. registers32:=1;
  423. { further, the variable can't be put into a register }
  424. tvarsym(symtableentry).varoptions:=
  425. tvarsym(symtableentry).varoptions-[vo_fpuregable,vo_regable];
  426. end;
  427. end;
  428. if (tvarsym(symtableentry).varspez=vs_const) then
  429. expectloc:=LOC_CREFERENCE;
  430. { we need a register for call by reference parameters }
  431. if (tvarsym(symtableentry).varspez in [vs_var,vs_out]) or
  432. ((tvarsym(symtableentry).varspez=vs_const) and
  433. paramanager.push_addr_param(tvarsym(symtableentry).vartype.def,pocall_none)) or
  434. { call by value open arrays are also indirect addressed }
  435. is_open_array(tvarsym(symtableentry).vartype.def) then
  436. registers32:=1;
  437. if ([vo_is_thread_var,vo_is_dll_var]*tvarsym(symtableentry).varoptions)<>[] then
  438. registers32:=1;
  439. { call to get address of threadvar }
  440. if (vo_is_thread_var in tvarsym(symtableentry).varoptions) then
  441. include(current_procinfo.flags,pi_do_call);
  442. if nf_write in flags then
  443. Tvarsym(symtableentry).trigger_notifications(vn_onwrite)
  444. else
  445. Tvarsym(symtableentry).trigger_notifications(vn_onread);
  446. { count variable references }
  447. if rg.t_times>1 then
  448. inc(tvarsym(symtableentry).refs,rg.t_times-1);
  449. end;
  450. typedconstsym :
  451. ;
  452. procsym :
  453. begin
  454. { method pointer ? }
  455. if assigned(left) then
  456. begin
  457. expectloc:=LOC_CREFERENCE;
  458. firstpass(left);
  459. registers32:=max(registers32,left.registers32);
  460. registersfpu:=max(registersfpu,left.registersfpu);
  461. {$ifdef SUPPORT_MMX}
  462. registersmmx:=max(registersmmx,left.registersmmx);
  463. {$endif SUPPORT_MMX}
  464. end;
  465. end;
  466. else
  467. internalerror(200104143);
  468. end;
  469. end;
  470. function tloadnode.docompare(p: tnode): boolean;
  471. begin
  472. docompare :=
  473. inherited docompare(p) and
  474. (symtableentry = tloadnode(p).symtableentry) and
  475. (symtable = tloadnode(p).symtable);
  476. end;
  477. procedure Tloadnode.printnodedata(var t:text);
  478. begin
  479. inherited printnodedata(t);
  480. writeln(t,printnodeindention,'symbol = ',symtableentry.name);
  481. end;
  482. {*****************************************************************************
  483. TASSIGNMENTNODE
  484. *****************************************************************************}
  485. constructor tassignmentnode.create(l,r : tnode);
  486. begin
  487. inherited create(assignn,l,r);
  488. l.mark_write;
  489. assigntype:=at_normal;
  490. end;
  491. constructor tassignmentnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  492. begin
  493. inherited ppuload(t,ppufile);
  494. assigntype:=tassigntype(ppufile.getbyte);
  495. end;
  496. procedure tassignmentnode.ppuwrite(ppufile:tcompilerppufile);
  497. begin
  498. inherited ppuwrite(ppufile);
  499. ppufile.putbyte(byte(assigntype));
  500. end;
  501. function tassignmentnode.getcopy : tnode;
  502. var
  503. n : tassignmentnode;
  504. begin
  505. n:=tassignmentnode(inherited getcopy);
  506. n.assigntype:=assigntype;
  507. getcopy:=n;
  508. end;
  509. function tassignmentnode.det_resulttype:tnode;
  510. var
  511. hp : tnode;
  512. useshelper : boolean;
  513. original_size : longint;
  514. begin
  515. result:=nil;
  516. resulttype:=voidtype;
  517. original_size := 0;
  518. { must be made unique }
  519. set_unique(left);
  520. resulttypepass(left);
  521. if is_ansistring(left.resulttype.def) then
  522. begin
  523. { fold <ansistring>:=<ansistring>+<char|shortstring|ansistring> }
  524. if (right.nodetype=addn) and
  525. left.isequal(tbinarynode(right).left) and
  526. { don't fold multiple concatenations else we could get trouble
  527. with multiple uses of s
  528. }
  529. (tbinarynode(right).left.nodetype<>addn) and
  530. (tbinarynode(right).right.nodetype<>addn) then
  531. begin
  532. { don't do a resulttypepass(right), since then the addnode }
  533. { may insert typeconversions that make this optimization }
  534. { opportunity quite difficult to detect (JM) }
  535. resulttypepass(tbinarynode(right).left);
  536. resulttypepass(tbinarynode(right).right);
  537. if (is_char(tbinarynode(right).right.resulttype.def) or
  538. is_shortstring(tbinarynode(right).right.resulttype.def) or
  539. is_ansistring(tbinarynode(right).right.resulttype.def)) then
  540. begin
  541. { remove property flag so it'll not trigger an error }
  542. exclude(left.flags,nf_isproperty);
  543. { generate call to helper }
  544. hp:=ccallparanode.create(tbinarynode(right).right,
  545. ccallparanode.create(left,nil));
  546. if is_char(tbinarynode(right).right.resulttype.def) then
  547. result:=ccallnode.createintern('fpc_ansistr_append_char',hp)
  548. else if is_shortstring(tbinarynode(right).right.resulttype.def) then
  549. result:=ccallnode.createintern('fpc_ansistr_append_shortstring',hp)
  550. else
  551. result:=ccallnode.createintern('fpc_ansistr_append_ansistring',hp);
  552. tbinarynode(right).right:=nil;
  553. left:=nil;
  554. exit;
  555. end;
  556. end;
  557. end
  558. else
  559. if is_shortstring(left.resulttype.def) then
  560. begin
  561. { fold <shortstring>:=<shortstring>+<shortstring>,
  562. <shortstring>+<char> is handled by an optimized node }
  563. if (right.nodetype=addn) and
  564. left.isequal(tbinarynode(right).left) and
  565. { don't fold multiple concatenations else we could get trouble
  566. with multiple uses of s }
  567. (tbinarynode(right).left.nodetype<>addn) and
  568. (tbinarynode(right).right.nodetype<>addn) then
  569. begin
  570. { don't do a resulttypepass(right), since then the addnode }
  571. { may insert typeconversions that make this optimization }
  572. { opportunity quite difficult to detect (JM) }
  573. resulttypepass(tbinarynode(right).left);
  574. resulttypepass(tbinarynode(right).right);
  575. if is_shortstring(tbinarynode(right).right.resulttype.def) then
  576. begin
  577. { remove property flag so it'll not trigger an error }
  578. exclude(left.flags,nf_isproperty);
  579. { generate call to helper }
  580. hp:=ccallparanode.create(tbinarynode(right).right,
  581. ccallparanode.create(left,nil));
  582. if is_shortstring(tbinarynode(right).right.resulttype.def) then
  583. result:=ccallnode.createintern('fpc_shortstr_append_shortstr',hp);
  584. tbinarynode(right).right:=nil;
  585. left:=nil;
  586. exit;
  587. end;
  588. end;
  589. end;
  590. resulttypepass(right);
  591. set_varstate(left,false);
  592. set_varstate(right,true);
  593. { set_funcret_is_valid(left); }
  594. if codegenerror then
  595. exit;
  596. { assignments to open arrays aren't allowed }
  597. if is_open_array(left.resulttype.def) then
  598. CGMessage(type_e_mismatch);
  599. { test if node can be assigned, properties are allowed }
  600. valid_for_assignment(left);
  601. { assigning nil to a dynamic array clears the array }
  602. if is_dynamic_array(left.resulttype.def) and
  603. (right.nodetype=niln) then
  604. begin
  605. hp:=ccallparanode.create(caddrnode.create
  606. (crttinode.create(tstoreddef(left.resulttype.def),initrtti)),
  607. ccallparanode.create(ctypeconvnode.create_explicit(left,voidpointertype),nil));
  608. result := ccallnode.createintern('fpc_dynarray_clear',hp);
  609. left:=nil;
  610. exit;
  611. end;
  612. { shortstring helpers can do the conversion directly,
  613. so treat them separatly }
  614. if (is_shortstring(left.resulttype.def)) then
  615. begin
  616. { insert typeconv, except for chars that are handled in
  617. secondpass and except for ansi/wide string that can
  618. be converted immediatly }
  619. if not(is_char(right.resulttype.def) or
  620. (right.resulttype.def.deftype=stringdef)) then
  621. inserttypeconv(right,left.resulttype);
  622. if right.resulttype.def.deftype=stringdef then
  623. begin
  624. useshelper:=true;
  625. { convert constant strings to shortstrings. But
  626. skip empty constant strings, that will be handled
  627. in secondpass }
  628. if (right.nodetype=stringconstn) then
  629. begin
  630. { verify if range fits within shortstring }
  631. { just emit a warning, delphi gives an }
  632. { error, only if the type definition of }
  633. { of the string is less < 255 characters }
  634. if not is_open_string(left.resulttype.def) and
  635. (tstringconstnode(right).len > tstringdef(left.resulttype.def).len) then
  636. cgmessage(type_w_string_too_long);
  637. inserttypeconv(right,left.resulttype);
  638. if (tstringconstnode(right).len=0) then
  639. useshelper:=false;
  640. end;
  641. { rest is done in pass 1 (JM) }
  642. if useshelper then
  643. exit;
  644. end
  645. end
  646. else
  647. begin
  648. { get the size before the type conversion - check for all nodes }
  649. if assigned(right.resulttype.def) and (right.nodetype in [loadn,vecn,calln]) then
  650. original_size := right.resulttype.def.size;
  651. inserttypeconv(right,left.resulttype);
  652. end;
  653. { check if the assignment may cause a range check error }
  654. { if its not explicit, and only if the values are }
  655. { ordinals, enumdef and floatdef }
  656. if (right.nodetype = typeconvn) and
  657. not (nf_explicit in ttypeconvnode(right).flags) then
  658. begin
  659. if assigned(left.resulttype.def) and
  660. (left.resulttype.def.deftype in [enumdef,orddef,floatdef]) then
  661. begin
  662. if (original_size <> 0) and (left.resulttype.def.size < original_size) then
  663. begin
  664. if (cs_check_range in aktlocalswitches) then
  665. Message(type_w_smaller_possible_range_check)
  666. else
  667. Message(type_h_smaller_possible_range_check);
  668. end;
  669. end;
  670. end;
  671. { call helpers for interface }
  672. if is_interfacecom(left.resulttype.def) then
  673. begin
  674. hp:=ccallparanode.create(ctypeconvnode.create_explicit
  675. (right,voidpointertype),
  676. ccallparanode.create(ctypeconvnode.create_explicit
  677. (left,voidpointertype),nil));
  678. result:=ccallnode.createintern('fpc_intf_assign',hp);
  679. left:=nil;
  680. right:=nil;
  681. exit;
  682. end;
  683. { check if local proc/func is assigned to procvar }
  684. if right.resulttype.def.deftype=procvardef then
  685. test_local_to_procvar(tprocvardef(right.resulttype.def),left.resulttype.def);
  686. end;
  687. function tassignmentnode.pass_1 : tnode;
  688. var
  689. hp: tnode;
  690. begin
  691. result:=nil;
  692. expectloc:=LOC_VOID;
  693. firstpass(left);
  694. firstpass(right);
  695. { assignment to refcounted variable -> inc/decref }
  696. if (not is_class(left.resulttype.def) and
  697. left.resulttype.def.needs_inittable) then
  698. include(current_procinfo.flags,pi_do_call);
  699. if codegenerror then
  700. exit;
  701. if (is_shortstring(left.resulttype.def)) then
  702. begin
  703. if right.resulttype.def.deftype=stringdef then
  704. begin
  705. if (right.nodetype<>stringconstn) or
  706. (tstringconstnode(right).len<>0) then
  707. begin
  708. if (cs_optimize in aktglobalswitches) and
  709. (right.nodetype in [calln,blockn]) and
  710. (left.nodetype = temprefn) and
  711. is_shortstring(right.resulttype.def) and
  712. not is_open_string(left.resulttype.def) and
  713. (tstringdef(left.resulttype.def).len = 255) then
  714. begin
  715. { the blocknode case is handled in pass_2 at the temp }
  716. { reference level (mainly for callparatemp) (JM) }
  717. if (right.nodetype = calln) then
  718. begin
  719. tcallnode(right).funcretnode := left;
  720. result := right;
  721. end
  722. else
  723. exit;
  724. end
  725. else
  726. begin
  727. hp:=ccallparanode.create
  728. (right,
  729. ccallparanode.create(cinlinenode.create
  730. (in_high_x,false,left.getcopy),nil));
  731. result:=ccallnode.createinternreturn('fpc_'+tstringdef(right.resulttype.def).stringtypname+'_to_shortstr',hp,left);
  732. firstpass(result);
  733. end;
  734. left:=nil;
  735. right:=nil;
  736. exit;
  737. end;
  738. end;
  739. end;
  740. if (cs_optimize in aktglobalswitches) and
  741. (right.nodetype = calln) and
  742. { left must be a temp, since otherwise as soon as you modify the }
  743. { result, the current left node is modified and that one may }
  744. { still be an argument to the function or even accessed in the }
  745. { function }
  746. (((left.nodetype = temprefn) and
  747. paramanager.ret_in_param(right.resulttype.def,
  748. tcallnode(right).procdefinition.proccalloption)) or
  749. { there's special support for ansi/widestrings in the callnode }
  750. is_ansistring(right.resulttype.def) or
  751. is_widestring(right.resulttype.def)) then
  752. begin
  753. tcallnode(right).funcretnode := left;
  754. result := right;
  755. left := nil;
  756. right := nil;
  757. exit;
  758. end;
  759. registers32:=left.registers32+right.registers32;
  760. registersfpu:=max(left.registersfpu,right.registersfpu);
  761. {$ifdef SUPPORT_MMX}
  762. registersmmx:=max(left.registersmmx,right.registersmmx);
  763. {$endif SUPPORT_MMX}
  764. end;
  765. function tassignmentnode.docompare(p: tnode): boolean;
  766. begin
  767. docompare :=
  768. inherited docompare(p) and
  769. (assigntype = tassignmentnode(p).assigntype);
  770. end;
  771. {$ifdef state_tracking}
  772. function Tassignmentnode.track_state_pass(exec_known:boolean):boolean;
  773. var se:Tstate_entry;
  774. begin
  775. track_state_pass:=false;
  776. if exec_known then
  777. begin
  778. track_state_pass:=right.track_state_pass(exec_known);
  779. {Force a new resulttype pass.}
  780. right.resulttype.def:=nil;
  781. do_resulttypepass(right);
  782. resulttypepass(right);
  783. aktstate.store_fact(left.getcopy,right.getcopy);
  784. end
  785. else
  786. aktstate.delete_fact(left);
  787. end;
  788. {$endif}
  789. {*****************************************************************************
  790. TARRAYCONSTRUCTORRANGENODE
  791. *****************************************************************************}
  792. constructor tarrayconstructorrangenode.create(l,r : tnode);
  793. begin
  794. inherited create(arrayconstructorrangen,l,r);
  795. end;
  796. function tarrayconstructorrangenode.det_resulttype:tnode;
  797. begin
  798. result:=nil;
  799. resulttypepass(left);
  800. resulttypepass(right);
  801. set_varstate(left,true);
  802. set_varstate(right,true);
  803. if codegenerror then
  804. exit;
  805. resulttype:=left.resulttype;
  806. end;
  807. function tarrayconstructorrangenode.pass_1 : tnode;
  808. begin
  809. firstpass(left);
  810. firstpass(right);
  811. expectloc:=LOC_CREFERENCE;
  812. calcregisters(self,0,0,0);
  813. result:=nil;
  814. end;
  815. {****************************************************************************
  816. TARRAYCONSTRUCTORNODE
  817. *****************************************************************************}
  818. constructor tarrayconstructornode.create(l,r : tnode);
  819. begin
  820. inherited create(arrayconstructorn,l,r);
  821. end;
  822. function tarrayconstructornode.getcopy : tnode;
  823. var
  824. n : tarrayconstructornode;
  825. begin
  826. n:=tarrayconstructornode(inherited getcopy);
  827. result:=n;
  828. end;
  829. function tarrayconstructornode.det_resulttype:tnode;
  830. var
  831. htype : ttype;
  832. hp : tarrayconstructornode;
  833. len : longint;
  834. varia : boolean;
  835. begin
  836. result:=nil;
  837. { are we allowing array constructor? Then convert it to a set }
  838. if not allow_array_constructor then
  839. begin
  840. hp:=tarrayconstructornode(getcopy);
  841. arrayconstructor_to_set(tnode(hp));
  842. result:=hp;
  843. exit;
  844. end;
  845. { only pass left tree, right tree contains next construct if any }
  846. htype.reset;
  847. len:=0;
  848. varia:=false;
  849. if assigned(left) then
  850. begin
  851. hp:=self;
  852. while assigned(hp) do
  853. begin
  854. resulttypepass(hp.left);
  855. set_varstate(hp.left,true);
  856. if (htype.def=nil) then
  857. htype:=hp.left.resulttype
  858. else
  859. begin
  860. if ((nf_novariaallowed in flags) or (not varia)) and
  861. (not equal_defs(htype.def,hp.left.resulttype.def)) then
  862. begin
  863. varia:=true;
  864. end;
  865. end;
  866. inc(len);
  867. hp:=tarrayconstructornode(hp.right);
  868. end;
  869. end;
  870. if not assigned(htype.def) then
  871. htype:=voidtype;
  872. resulttype.setdef(tarraydef.create(0,len-1,s32bittype));
  873. tarraydef(resulttype.def).setelementtype(htype);
  874. tarraydef(resulttype.def).IsConstructor:=true;
  875. tarraydef(resulttype.def).IsVariant:=varia;
  876. end;
  877. procedure tarrayconstructornode.force_type(tt:ttype);
  878. var
  879. hp : tarrayconstructornode;
  880. begin
  881. tarraydef(resulttype.def).setelementtype(tt);
  882. tarraydef(resulttype.def).IsConstructor:=true;
  883. tarraydef(resulttype.def).IsVariant:=false;
  884. if assigned(left) then
  885. begin
  886. hp:=self;
  887. while assigned(hp) do
  888. begin
  889. inserttypeconv(hp.left,tt);
  890. hp:=tarrayconstructornode(hp.right);
  891. end;
  892. end;
  893. end;
  894. function tarrayconstructornode.pass_1 : tnode;
  895. var
  896. thp,
  897. chp,
  898. hp : tarrayconstructornode;
  899. dovariant : boolean;
  900. htype : ttype;
  901. orgflags : tnodeflags;
  902. begin
  903. dovariant:=(nf_forcevaria in flags) or tarraydef(resulttype.def).isvariant;
  904. result:=nil;
  905. { only pass left tree, right tree contains next construct if any }
  906. if assigned(left) then
  907. begin
  908. hp:=self;
  909. while assigned(hp) do
  910. begin
  911. firstpass(hp.left);
  912. { Insert typeconvs for array of const }
  913. if dovariant then
  914. begin
  915. case hp.left.resulttype.def.deftype of
  916. enumdef :
  917. begin
  918. hp.left:=ctypeconvnode.create_explicit(hp.left,s32bittype);
  919. firstpass(hp.left);
  920. end;
  921. arraydef :
  922. begin
  923. hp.left:=ctypeconvnode.create(hp.left,charpointertype);
  924. firstpass(hp.left);
  925. end;
  926. orddef :
  927. begin
  928. if is_integer(hp.left.resulttype.def) and
  929. not(is_64bitint(hp.left.resulttype.def)) then
  930. begin
  931. hp.left:=ctypeconvnode.create(hp.left,s32bittype);
  932. firstpass(hp.left);
  933. end;
  934. end;
  935. floatdef :
  936. begin
  937. { C uses 64bit floats }
  938. if nf_cargs in flags then
  939. hp.left:=ctypeconvnode.create(hp.left,s64floattype)
  940. else
  941. hp.left:=ctypeconvnode.create(hp.left,pbestrealtype^);
  942. firstpass(hp.left);
  943. end;
  944. stringdef :
  945. begin
  946. if nf_cargs in flags then
  947. begin
  948. hp.left:=ctypeconvnode.create(hp.left,charpointertype);
  949. firstpass(hp.left);
  950. end;
  951. end;
  952. procvardef :
  953. begin
  954. hp.left:=ctypeconvnode.create(hp.left,voidpointertype);
  955. firstpass(hp.left);
  956. end;
  957. variantdef,
  958. pointerdef,
  959. classrefdef,
  960. objectdef : ;
  961. else
  962. CGMessagePos1(hp.left.fileinfo,type_e_wrong_type_in_array_constructor,hp.left.resulttype.def.typename);
  963. end;
  964. end;
  965. hp:=tarrayconstructornode(hp.right);
  966. end;
  967. { swap the tree for cargs }
  968. if (nf_cargs in flags) and (not(nf_cargswap in flags)) then
  969. begin
  970. chp:=nil;
  971. { save resulttype }
  972. htype:=resulttype;
  973. { we need a copy here, because self is destroyed }
  974. { by firstpass later }
  975. hp:=tarrayconstructornode(getcopy);
  976. { we also need a copy of the nf_ forcevaria flag to restore }
  977. { later) (JM) }
  978. orgflags := flags * [nf_forcevaria];
  979. while assigned(hp) do
  980. begin
  981. thp:=tarrayconstructornode(hp.right);
  982. hp.right:=chp;
  983. chp:=hp;
  984. hp:=thp;
  985. end;
  986. chp.flags := chp.flags+orgflags;
  987. include(chp.flags,nf_cargs);
  988. include(chp.flags,nf_cargswap);
  989. chp.expectloc:=LOC_CREFERENCE;
  990. calcregisters(chp,0,0,0);
  991. chp.resulttype:=htype;
  992. result:=chp;
  993. exit;
  994. end;
  995. end;
  996. { C style has pushed everything on the stack, so
  997. there is no return value }
  998. if (nf_cargs in flags) then
  999. expectloc:=LOC_VOID
  1000. else
  1001. expectloc:=LOC_CREFERENCE;
  1002. { Calculate registers }
  1003. calcregisters(self,0,0,0);
  1004. end;
  1005. function tarrayconstructornode.docompare(p: tnode): boolean;
  1006. begin
  1007. docompare :=
  1008. inherited docompare(p);
  1009. end;
  1010. {*****************************************************************************
  1011. TTYPENODE
  1012. *****************************************************************************}
  1013. constructor ttypenode.create(t : ttype);
  1014. begin
  1015. inherited create(typen);
  1016. restype:=t;
  1017. allowed:=false;
  1018. end;
  1019. constructor ttypenode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1020. begin
  1021. inherited ppuload(t,ppufile);
  1022. ppufile.gettype(restype);
  1023. allowed:=boolean(ppufile.getbyte);
  1024. end;
  1025. procedure ttypenode.ppuwrite(ppufile:tcompilerppufile);
  1026. begin
  1027. inherited ppuwrite(ppufile);
  1028. ppufile.puttype(restype);
  1029. ppufile.putbyte(byte(allowed));
  1030. end;
  1031. procedure ttypenode.derefimpl;
  1032. begin
  1033. inherited derefimpl;
  1034. restype.resolve;
  1035. end;
  1036. function ttypenode.det_resulttype:tnode;
  1037. begin
  1038. result:=nil;
  1039. resulttype:=restype;
  1040. { check if it's valid }
  1041. if restype.def.deftype = errordef then
  1042. CGMessage(cg_e_illegal_expression);
  1043. end;
  1044. function ttypenode.pass_1 : tnode;
  1045. begin
  1046. result:=nil;
  1047. expectloc:=LOC_VOID;
  1048. { a typenode can't generate code, so we give here
  1049. an error. Else it'll be an abstract error in pass_2.
  1050. Only when the allowed flag is set we don't generate
  1051. an error }
  1052. if not allowed then
  1053. Message(parser_e_no_type_not_allowed_here);
  1054. end;
  1055. function ttypenode.docompare(p: tnode): boolean;
  1056. begin
  1057. docompare :=
  1058. inherited docompare(p);
  1059. end;
  1060. {*****************************************************************************
  1061. TRTTINODE
  1062. *****************************************************************************}
  1063. constructor trttinode.create(def:tstoreddef;rt:trttitype);
  1064. begin
  1065. inherited create(rttin);
  1066. rttidef:=def;
  1067. rttitype:=rt;
  1068. end;
  1069. constructor trttinode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  1070. begin
  1071. inherited ppuload(t,ppufile);
  1072. ppufile.getderef(rttidefderef);
  1073. rttitype:=trttitype(ppufile.getbyte);
  1074. end;
  1075. procedure trttinode.ppuwrite(ppufile:tcompilerppufile);
  1076. begin
  1077. inherited ppuwrite(ppufile);
  1078. ppufile.putderef(rttidef,rttidefderef);
  1079. ppufile.putbyte(byte(rttitype));
  1080. end;
  1081. procedure trttinode.derefimpl;
  1082. begin
  1083. inherited derefimpl;
  1084. rttidef:=tstoreddef(rttidefderef.resolve);
  1085. end;
  1086. function trttinode.getcopy : tnode;
  1087. var
  1088. n : trttinode;
  1089. begin
  1090. n:=trttinode(inherited getcopy);
  1091. n.rttidef:=rttidef;
  1092. n.rttitype:=rttitype;
  1093. result:=n;
  1094. end;
  1095. function trttinode.det_resulttype:tnode;
  1096. begin
  1097. { rtti information will be returned as a void pointer }
  1098. result:=nil;
  1099. resulttype:=voidpointertype;
  1100. end;
  1101. function trttinode.pass_1 : tnode;
  1102. begin
  1103. result:=nil;
  1104. expectloc:=LOC_CREFERENCE;
  1105. end;
  1106. function trttinode.docompare(p: tnode): boolean;
  1107. begin
  1108. docompare :=
  1109. inherited docompare(p) and
  1110. (rttidef = trttinode(p).rttidef) and
  1111. (rttitype = trttinode(p).rttitype);
  1112. end;
  1113. procedure trttinode.pass_2;
  1114. begin
  1115. location_reset(location,LOC_CREFERENCE,OS_NO);
  1116. location.reference.symbol:=rttidef.get_rtti_label(rttitype);
  1117. end;
  1118. begin
  1119. cloadnode:=tloadnode;
  1120. cassignmentnode:=tassignmentnode;
  1121. carrayconstructorrangenode:=tarrayconstructorrangenode;
  1122. carrayconstructornode:=tarrayconstructornode;
  1123. ctypenode:=ttypenode;
  1124. crttinode:=trttinode;
  1125. end.
  1126. {
  1127. $Log$
  1128. Revision 1.101 2003-06-08 20:01:53 jonas
  1129. * optimized assignments with on the right side a function that returns
  1130. an ansi- or widestring
  1131. Revision 1.100 2003/06/08 18:27:15 jonas
  1132. + ability to change the location of a ttempref node with changelocation()
  1133. method. Useful to use instead of copying the contents from one temp to
  1134. another
  1135. + some shortstring optimizations in tassignmentnode that avoid some
  1136. copying (required some shortstring optimizations to be moved from
  1137. resulttype to firstpass, because they work on callnodes and string
  1138. addnodes are only changed to callnodes in the firstpass)
  1139. * allow setting/changing the funcretnode of callnodes after the
  1140. resulttypepass has been done, funcretnode is now a property
  1141. (all of the above should have a quite big effect on callparatemp)
  1142. Revision 1.99 2003/06/07 20:26:32 peter
  1143. * re-resolving added instead of reloading from ppu
  1144. * tderef object added to store deref info for resolving
  1145. Revision 1.98 2003/06/07 18:57:04 jonas
  1146. + added freeintparaloc
  1147. * ppc get/freeintparaloc now check whether the parameter regs are
  1148. properly allocated/deallocated (and get an extra list para)
  1149. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1150. * fixed lot of missing pi_do_call's
  1151. Revision 1.97 2003/06/07 14:39:18 jonas
  1152. * set pi_do_call for accesses to threadvars
  1153. Revision 1.96 2003/05/26 19:38:28 peter
  1154. * generic fpc_shorstr_concat
  1155. + fpc_shortstr_append_shortstr optimization
  1156. Revision 1.95 2003/05/23 17:05:13 peter
  1157. * loadn procsym need to return procdef
  1158. Revision 1.94 2003/05/23 14:27:35 peter
  1159. * remove some unit dependencies
  1160. * current_procinfo changes to store more info
  1161. Revision 1.93 2003/05/11 21:37:03 peter
  1162. * moved implicit exception frame from ncgutil to psub
  1163. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1164. Revision 1.92 2003/05/11 14:45:12 peter
  1165. * tloadnode does not support objectsymtable,withsymtable anymore
  1166. * withnode cleanup
  1167. * direct with rewritten to use temprefnode
  1168. Revision 1.91 2003/05/09 17:47:02 peter
  1169. * self moved to hidden parameter
  1170. * removed hdisposen,hnewn,selfn
  1171. Revision 1.90 2003/04/27 11:21:33 peter
  1172. * aktprocdef renamed to current_procdef
  1173. * procinfo renamed to current_procinfo
  1174. * procinfo will now be stored in current_module so it can be
  1175. cleaned up properly
  1176. * gen_main_procsym changed to create_main_proc and release_main_proc
  1177. to also generate a tprocinfo structure
  1178. * fixed unit implicit initfinal
  1179. Revision 1.89 2003/04/27 07:29:50 peter
  1180. * current_procdef cleanup, current_procdef is now always nil when parsing
  1181. a new procdef declaration
  1182. * aktprocsym removed
  1183. * lexlevel removed, use symtable.symtablelevel instead
  1184. * implicit init/final code uses the normal genentry/genexit
  1185. * funcret state checking updated for new funcret handling
  1186. Revision 1.88 2003/04/26 00:28:42 peter
  1187. * removed load_funcret
  1188. Revision 1.87 2003/04/25 20:59:33 peter
  1189. * removed funcretn,funcretsym, function result is now in varsym
  1190. and aliases for result and function name are added using absolutesym
  1191. * vs_hidden parameter for funcret passed in parameter
  1192. * vs_hidden fixes
  1193. * writenode changed to printnode and released from extdebug
  1194. * -vp option added to generate a tree.log with the nodetree
  1195. * nicer printnode for statements, callnode
  1196. Revision 1.86 2003/04/23 20:16:04 peter
  1197. + added currency support based on int64
  1198. + is_64bit for use in cg units instead of is_64bitint
  1199. * removed cgmessage from n386add, replace with internalerrors
  1200. Revision 1.85 2003/04/23 10:10:54 peter
  1201. * procvar is not compared in addrn
  1202. Revision 1.84 2003/04/22 23:50:23 peter
  1203. * firstpass uses expectloc
  1204. * checks if there are differences between the expectloc and
  1205. location.loc from secondpass in EXTDEBUG
  1206. Revision 1.83 2003/04/11 15:01:23 peter
  1207. * fix bug 2438
  1208. Revision 1.82 2003/03/28 19:16:56 peter
  1209. * generic constructor working for i386
  1210. * remove fixed self register
  1211. * esi added as address register for i386
  1212. Revision 1.81 2003/03/11 21:46:24 jonas
  1213. * lots of new regallocator fixes, both in generic and ppc-specific code
  1214. (ppc compiler still can't compile the linux system unit though)
  1215. Revision 1.80 2003/01/07 16:52:58 jonas
  1216. * fixed ansistring+char and ansistring+shortstring optimizations (those
  1217. cases were always handled as ansistring+ansistring due to
  1218. typeconversions inserted by the add-node)
  1219. Revision 1.79 2003/01/05 22:44:14 peter
  1220. * remove a lot of code to support typen in loadn-procsym
  1221. Revision 1.78 2003/01/03 12:15:56 daniel
  1222. * Removed ifdefs around notifications
  1223. ifdefs around for loop optimizations remain
  1224. Revision 1.77 2002/12/31 09:55:58 daniel
  1225. + Notification implementation complete
  1226. + Add for loop code optimization using notifications
  1227. results in 1.5-1.9% speed improvement in nestloop benchmark
  1228. Optimization incomplete, compiler does not cycle yet with
  1229. notifications enabled.
  1230. Revision 1.76 2002/12/30 22:44:53 daniel
  1231. * Some work on notifications
  1232. Revision 1.75 2002/12/27 15:27:25 peter
  1233. * remove property indicator when calling internal helpers
  1234. Revision 1.74 2002/12/24 16:53:19 peter
  1235. * fix for tb0438
  1236. Revision 1.73 2002/12/20 18:14:53 peter
  1237. * fix result of high_tree when high was not available
  1238. Revision 1.72 2002/12/17 22:19:33 peter
  1239. * fixed pushing of records>8 bytes with stdcall
  1240. * simplified hightree loading
  1241. Revision 1.71 2002/12/07 14:27:07 carl
  1242. * 3% memory optimization
  1243. * changed some types
  1244. + added type checking with different size for call node and for
  1245. parameters
  1246. Revision 1.70 2002/12/02 19:38:06 carl
  1247. * fix some errors
  1248. Revision 1.69 2002/11/29 20:02:44 carl
  1249. * warning / hint for possible loss of data in assignment
  1250. Revision 1.68 2002/11/27 20:04:39 peter
  1251. * cdecl array of const fixes
  1252. Revision 1.67 2002/11/27 15:33:47 peter
  1253. * the never ending story of tp procvar hacks
  1254. Revision 1.66 2002/11/25 17:43:20 peter
  1255. * splitted defbase in defutil,symutil,defcmp
  1256. * merged isconvertable and is_equal into compare_defs(_ext)
  1257. * made operator search faster by walking the list only once
  1258. Revision 1.65 2002/11/18 17:31:57 peter
  1259. * pass proccalloption to ret_in_xxx and push_xxx functions
  1260. Revision 1.64 2002/11/15 01:58:52 peter
  1261. * merged changes from 1.0.7 up to 04-11
  1262. - -V option for generating bug report tracing
  1263. - more tracing for option parsing
  1264. - errors for cdecl and high()
  1265. - win32 import stabs
  1266. - win32 records<=8 are returned in eax:edx (turned off by default)
  1267. - heaptrc update
  1268. - more info for temp management in .s file with EXTDEBUG
  1269. Revision 1.63 2002/10/17 12:44:09 florian
  1270. + s:=s+<string type> where s is an ansistring is done via calls to append_ansistring_*
  1271. Revision 1.62 2002/10/05 12:43:25 carl
  1272. * fixes for Delphi 6 compilation
  1273. (warning : Some features do not work under Delphi)
  1274. Revision 1.61 2002/10/03 21:26:08 carl
  1275. + compile-time range checking for strings
  1276. Revision 1.60 2002/09/27 21:13:28 carl
  1277. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  1278. Revision 1.59 2002/09/26 15:02:05 florian
  1279. + support of passing variants to "array of const"
  1280. Revision 1.58 2002/09/07 15:25:03 peter
  1281. * old logs removed and tabs fixed
  1282. Revision 1.57 2002/09/03 16:26:26 daniel
  1283. * Make Tprocdef.defs protected
  1284. Revision 1.56 2002/09/01 13:28:37 daniel
  1285. - write_access fields removed in favor of a flag
  1286. Revision 1.55 2002/09/01 08:01:16 daniel
  1287. * Removed sets from Tcallnode.det_resulttype
  1288. + Added read/write notifications of variables. These will be usefull
  1289. for providing information for several optimizations. For example
  1290. the value of the loop variable of a for loop does matter is the
  1291. variable is read after the for loop, but if it's no longer used
  1292. or written, it doesn't matter and this can be used to optimize
  1293. the loop code generation.
  1294. Revision 1.54 2002/08/25 19:25:19 peter
  1295. * sym.insert_in_data removed
  1296. * symtable.insertvardata/insertconstdata added
  1297. * removed insert_in_data call from symtable.insert, it needs to be
  1298. called separatly. This allows to deref the address calculation
  1299. * procedures now calculate the parast addresses after the procedure
  1300. directives are parsed. This fixes the cdecl parast problem
  1301. * push_addr_param has an extra argument that specifies if cdecl is used
  1302. or not
  1303. Revision 1.53 2002/08/19 19:36:43 peter
  1304. * More fixes for cross unit inlining, all tnodes are now implemented
  1305. * Moved pocall_internconst to po_internconst because it is not a
  1306. calling type at all and it conflicted when inlining of these small
  1307. functions was requested
  1308. Revision 1.52 2002/08/18 20:06:23 peter
  1309. * inlining is now also allowed in interface
  1310. * renamed write/load to ppuwrite/ppuload
  1311. * tnode storing in ppu
  1312. * nld,ncon,nbas are already updated for storing in ppu
  1313. Revision 1.51 2002/08/17 22:09:46 florian
  1314. * result type handling in tcgcal.pass_2 overhauled
  1315. * better tnode.dowrite
  1316. * some ppc stuff fixed
  1317. Revision 1.50 2002/08/17 09:23:37 florian
  1318. * first part of procinfo rewrite
  1319. Revision 1.49 2002/07/20 11:57:54 florian
  1320. * types.pas renamed to defbase.pas because D6 contains a types
  1321. unit so this would conflicts if D6 programms are compiled
  1322. + Willamette/SSE2 instructions to assembler added
  1323. Revision 1.48 2002/07/20 07:44:37 daniel
  1324. * Forgot to add a $ifdef extdebug
  1325. Revision 1.47 2002/07/19 12:55:27 daniel
  1326. * Further developed state tracking in whilerepeatn
  1327. Revision 1.46 2002/07/19 11:41:36 daniel
  1328. * State tracker work
  1329. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1330. allows the state tracker to change while nodes automatically into
  1331. repeat nodes.
  1332. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1333. 'not(a>b)' is optimized into 'a<=b'.
  1334. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1335. by removing the notn and later switchting the true and falselabels. The
  1336. same is done with 'repeat until not a'.
  1337. Revision 1.45 2002/07/15 18:03:15 florian
  1338. * readded removed changes
  1339. Revision 1.43 2002/07/11 14:41:28 florian
  1340. * start of the new generic parameter handling
  1341. Revision 1.44 2002/07/14 18:00:44 daniel
  1342. + Added the beginning of a state tracker. This will track the values of
  1343. variables through procedures and optimize things away.
  1344. Revision 1.42 2002/05/18 13:34:10 peter
  1345. * readded missing revisions
  1346. Revision 1.41 2002/05/16 19:46:38 carl
  1347. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1348. + try to fix temp allocation (still in ifdef)
  1349. + generic constructor calls
  1350. + start of tassembler / tmodulebase class cleanup
  1351. Revision 1.39 2002/05/12 16:53:07 peter
  1352. * moved entry and exitcode to ncgutil and cgobj
  1353. * foreach gets extra argument for passing local data to the
  1354. iterator function
  1355. * -CR checks also class typecasts at runtime by changing them
  1356. into as
  1357. * fixed compiler to cycle with the -CR option
  1358. * fixed stabs with elf writer, finally the global variables can
  1359. be watched
  1360. * removed a lot of routines from cga unit and replaced them by
  1361. calls to cgobj
  1362. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1363. u32bit then the other is typecasted also to u32bit without giving
  1364. a rangecheck warning/error.
  1365. * fixed pascal calling method with reversing also the high tree in
  1366. the parast, detected by tcalcst3 test
  1367. Revision 1.38 2002/04/25 20:16:39 peter
  1368. * moved more routines from cga/n386util
  1369. Revision 1.37 2002/04/23 19:16:34 peter
  1370. * add pinline unit that inserts compiler supported functions using
  1371. one or more statements
  1372. * moved finalize and setlength from ninl to pinline
  1373. }