nld.pas 55 KB

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