nld.pas 53 KB

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