pinline.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generates nodes for routines that need compiler support
  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 pinline;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symtype,
  23. node,
  24. globals,
  25. cpuinfo;
  26. function new_dispose_statement(is_new:boolean) : tnode;
  27. function new_function : tnode;
  28. function inline_setlength : tnode;
  29. function inline_finalize : tnode;
  30. function inline_copy : tnode;
  31. implementation
  32. uses
  33. {$ifdef delphi}
  34. SysUtils,
  35. {$endif}
  36. { common }
  37. cutils,
  38. { global }
  39. globtype,tokens,verbose,
  40. systems,
  41. { symtable }
  42. symconst,symdef,symsym,symtable,defutil,
  43. { pass 1 }
  44. pass_1,htypechk,
  45. nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  46. { parser }
  47. scanner,
  48. pbase,pexpr,
  49. { codegen }
  50. cgbase,procinfo
  51. ;
  52. function new_dispose_statement(is_new:boolean) : tnode;
  53. var
  54. newstatement : tstatementnode;
  55. temp : ttempcreatenode;
  56. para : tcallparanode;
  57. p,p2 : tnode;
  58. again : boolean; { dummy for do_proc_call }
  59. destructorname : stringid;
  60. sym : tsym;
  61. classh : tobjectdef;
  62. callflag : tnodeflag;
  63. destructorpos,
  64. storepos : tfileposinfo;
  65. begin
  66. consume(_LKLAMMER);
  67. p:=comp_expr(true);
  68. { calc return type }
  69. if is_new then
  70. set_varstate(p,vs_assigned,false)
  71. else
  72. set_varstate(p,vs_used,true);
  73. { constructor,destructor specified }
  74. if try_to_consume(_COMMA) then
  75. begin
  76. { extended syntax of new and dispose }
  77. { function styled new is handled in factor }
  78. { destructors have no parameters }
  79. destructorname:=pattern;
  80. destructorpos:=akttokenpos;
  81. consume(_ID);
  82. if (p.resulttype.def.deftype<>pointerdef) then
  83. begin
  84. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  85. p.free;
  86. p:=factor(false);
  87. p.free;
  88. consume(_RKLAMMER);
  89. new_dispose_statement:=cerrornode.create;
  90. exit;
  91. end;
  92. { first parameter must be an object or class }
  93. if tpointerdef(p.resulttype.def).pointertype.def.deftype<>objectdef then
  94. begin
  95. Message(parser_e_pointer_to_class_expected);
  96. p.free;
  97. new_dispose_statement:=factor(false);
  98. consume_all_until(_RKLAMMER);
  99. consume(_RKLAMMER);
  100. exit;
  101. end;
  102. { check, if the first parameter is a pointer to a _class_ }
  103. classh:=tobjectdef(tpointerdef(p.resulttype.def).pointertype.def);
  104. if is_class(classh) then
  105. begin
  106. Message(parser_e_no_new_or_dispose_for_classes);
  107. new_dispose_statement:=factor(false);
  108. consume_all_until(_RKLAMMER);
  109. consume(_RKLAMMER);
  110. exit;
  111. end;
  112. { search cons-/destructor, also in parent classes }
  113. storepos:=akttokenpos;
  114. akttokenpos:=destructorpos;
  115. sym:=search_class_member(classh,destructorname);
  116. akttokenpos:=storepos;
  117. { the second parameter of new/dispose must be a call }
  118. { to a cons-/destructor }
  119. if (not assigned(sym)) or (sym.typ<>procsym) then
  120. begin
  121. if is_new then
  122. Message(parser_e_expr_have_to_be_constructor_call)
  123. else
  124. Message(parser_e_expr_have_to_be_destructor_call);
  125. p.free;
  126. new_dispose_statement:=cerrornode.create;
  127. end
  128. else
  129. begin
  130. p2:=cderefnode.create(p.getcopy);
  131. do_resulttypepass(p2);
  132. if is_new then
  133. callflag:=nf_new_call
  134. else
  135. callflag:=nf_dispose_call;
  136. if is_new then
  137. do_member_read(classh,false,sym,p2,again,[callflag])
  138. else
  139. begin
  140. if not(m_fpc in aktmodeswitches) then
  141. do_member_read(classh,false,sym,p2,again,[callflag])
  142. else
  143. begin
  144. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2);
  145. if is_new then
  146. include(p2.flags,nf_new_call)
  147. else
  148. include(p2.flags,nf_dispose_call);
  149. { support dispose(p,done()); }
  150. if try_to_consume(_LKLAMMER) then
  151. begin
  152. if not try_to_consume(_RKLAMMER) then
  153. begin
  154. Message(parser_e_no_paras_for_destructor);
  155. consume_all_until(_RKLAMMER);
  156. consume(_RKLAMMER);
  157. end;
  158. end;
  159. end;
  160. end;
  161. { we need the real called method }
  162. do_resulttypepass(p2);
  163. if p2.nodetype<>calln then
  164. begin
  165. if is_new then
  166. CGMessage(parser_e_expr_have_to_be_constructor_call)
  167. else
  168. CGMessage(parser_e_expr_have_to_be_destructor_call);
  169. end;
  170. if not codegenerror then
  171. begin
  172. if is_new then
  173. begin
  174. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  175. Message(parser_e_expr_have_to_be_constructor_call);
  176. p2.resulttype:=p.resulttype;
  177. p2:=cassignmentnode.create(p,p2);
  178. end
  179. else
  180. begin
  181. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  182. Message(parser_e_expr_have_to_be_destructor_call);
  183. end;
  184. end;
  185. new_dispose_statement:=p2;
  186. end;
  187. end
  188. else
  189. begin
  190. if (p.resulttype.def.deftype<>pointerdef) then
  191. Begin
  192. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  193. new_dispose_statement:=cerrornode.create;
  194. end
  195. else
  196. begin
  197. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=objectdef) and
  198. (oo_has_vmt in tobjectdef(tpointerdef(p.resulttype.def).pointertype.def).objectoptions) then
  199. Message(parser_w_use_extended_syntax_for_objects);
  200. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=orddef) and
  201. (torddef(tpointerdef(p.resulttype.def).pointertype.def).typ=uvoid) then
  202. begin
  203. if (m_tp7 in aktmodeswitches) or
  204. (m_delphi in aktmodeswitches) then
  205. Message(parser_w_no_new_dispose_on_void_pointers)
  206. else
  207. Message(parser_e_no_new_dispose_on_void_pointers);
  208. end;
  209. { create statements with call to getmem+initialize or
  210. finalize+freemem }
  211. new_dispose_statement:=internalstatements(newstatement,true);
  212. if is_new then
  213. begin
  214. { create temp for result }
  215. temp := ctempcreatenode.create(p.resulttype,p.resulttype.def.size,tt_persistent);
  216. addstatement(newstatement,temp);
  217. { create call to fpc_getmem }
  218. para := ccallparanode.create(cordconstnode.create
  219. (tpointerdef(p.resulttype.def).pointertype.def.size,s32bittype,true),nil);
  220. addstatement(newstatement,cassignmentnode.create(
  221. ctemprefnode.create(temp),
  222. ccallnode.createintern('fpc_getmem',para)));
  223. { create call to fpc_initialize }
  224. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  225. addstatement(newstatement,initialize_data_node(ctemprefnode.create(temp)));
  226. { copy the temp to the destination }
  227. addstatement(newstatement,cassignmentnode.create(
  228. p,
  229. ctemprefnode.create(temp)));
  230. { release temp }
  231. addstatement(newstatement,ctempdeletenode.create(temp));
  232. end
  233. else
  234. begin
  235. { create call to fpc_finalize }
  236. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  237. addstatement(newstatement,finalize_data_node(cderefnode.create(p.getcopy)));
  238. { create call to fpc_freemem }
  239. para := ccallparanode.create(p,nil);
  240. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  241. end;
  242. end;
  243. end;
  244. consume(_RKLAMMER);
  245. end;
  246. function new_function : tnode;
  247. var
  248. newstatement : tstatementnode;
  249. newblock : tblocknode;
  250. temp : ttempcreatenode;
  251. para : tcallparanode;
  252. p1,p2 : tnode;
  253. classh : tobjectdef;
  254. sym : tsym;
  255. again : boolean; { dummy for do_proc_call }
  256. begin
  257. consume(_LKLAMMER);
  258. p1:=factor(false);
  259. if p1.nodetype<>typen then
  260. begin
  261. Message(type_e_type_id_expected);
  262. consume_all_until(_RKLAMMER);
  263. consume(_RKLAMMER);
  264. p1.destroy;
  265. new_function:=cerrornode.create;
  266. exit;
  267. end;
  268. if (p1.resulttype.def.deftype<>pointerdef) then
  269. begin
  270. Message1(type_e_pointer_type_expected,p1.resulttype.def.typename);
  271. consume_all_until(_RKLAMMER);
  272. consume(_RKLAMMER);
  273. p1.destroy;
  274. new_function:=cerrornode.create;
  275. exit;
  276. end;
  277. if try_to_consume(_RKLAMMER) then
  278. begin
  279. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=objectdef) and
  280. (oo_has_vmt in tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def).objectoptions) then
  281. Message(parser_w_use_extended_syntax_for_objects);
  282. { create statements with call to getmem+initialize }
  283. newblock:=internalstatements(newstatement,true);
  284. { create temp for result }
  285. temp := ctempcreatenode.create(p1.resulttype,p1.resulttype.def.size,tt_persistent);
  286. addstatement(newstatement,temp);
  287. { create call to fpc_getmem }
  288. para := ccallparanode.create(cordconstnode.create
  289. (tpointerdef(p1.resulttype.def).pointertype.def.size,s32bittype,true),nil);
  290. addstatement(newstatement,cassignmentnode.create(
  291. ctemprefnode.create(temp),
  292. ccallnode.createintern('fpc_getmem',para)));
  293. { create call to fpc_initialize }
  294. if tpointerdef(p1.resulttype.def).pointertype.def.needs_inittable then
  295. begin
  296. para := ccallparanode.create(caddrnode.create(crttinode.create
  297. (tstoreddef(tpointerdef(p1.resulttype.def).pointertype.def),initrtti)),
  298. ccallparanode.create(ctemprefnode.create
  299. (temp),nil));
  300. addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
  301. end;
  302. { the last statement should return the value as
  303. location and type, this is done be referencing the
  304. temp and converting it first from a persistent temp to
  305. normal temp }
  306. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  307. addstatement(newstatement,ctemprefnode.create(temp));
  308. p1.destroy;
  309. p1:=newblock;
  310. end
  311. else
  312. begin
  313. consume(_COMMA);
  314. if tpointerdef(p1.resulttype.def).pointertype.def.deftype<>objectdef then
  315. begin
  316. Message(parser_e_pointer_to_class_expected);
  317. consume_all_until(_RKLAMMER);
  318. consume(_RKLAMMER);
  319. p1.destroy;
  320. new_function:=cerrornode.create;
  321. exit;
  322. end;
  323. classh:=tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def);
  324. { use the objectdef for loading the VMT }
  325. p2:=p1;
  326. p1:=ctypenode.create(tpointerdef(p1.resulttype.def).pointertype);
  327. do_resulttypepass(p1);
  328. { search the constructor also in the symbol tables of
  329. the parents }
  330. afterassignment:=false;
  331. sym:=searchsym_in_class(classh,pattern);
  332. consume(_ID);
  333. do_member_read(classh,false,sym,p1,again,[nf_new_call]);
  334. { we need to know which procedure is called }
  335. do_resulttypepass(p1);
  336. if not(
  337. (p1.nodetype=calln) and
  338. assigned(tcallnode(p1).procdefinition) and
  339. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  340. ) then
  341. Message(parser_e_expr_have_to_be_constructor_call);
  342. { constructors return boolean, update resulttype to return
  343. the pointer to the object }
  344. p1.resulttype:=p2.resulttype;
  345. p2.free;
  346. consume(_RKLAMMER);
  347. end;
  348. new_function:=p1;
  349. end;
  350. function inline_setlength : tnode;
  351. var
  352. paras : tnode;
  353. npara,
  354. ppn : tcallparanode;
  355. counter : integer;
  356. isarray : boolean;
  357. def : tdef;
  358. destppn : tnode;
  359. newstatement : tstatementnode;
  360. temp : ttempcreatenode;
  361. newblock : tnode;
  362. begin
  363. { for easy exiting if something goes wrong }
  364. result := cerrornode.create;
  365. consume(_LKLAMMER);
  366. paras:=parse_paras(false,false);
  367. consume(_RKLAMMER);
  368. if not assigned(paras) then
  369. begin
  370. CGMessage(parser_e_wrong_parameter_size);
  371. exit;
  372. end;
  373. counter:=0;
  374. if assigned(paras) then
  375. begin
  376. { check type of lengths }
  377. ppn:=tcallparanode(paras);
  378. while assigned(ppn.right) do
  379. begin
  380. set_varstate(ppn.left,vs_used,true);
  381. inserttypeconv(ppn.left,s32bittype);
  382. inc(counter);
  383. ppn:=tcallparanode(ppn.right);
  384. end;
  385. end;
  386. if counter=0 then
  387. begin
  388. CGMessage(parser_e_wrong_parameter_size);
  389. paras.free;
  390. exit;
  391. end;
  392. { last param must be var }
  393. destppn:=ppn.left;
  394. inc(parsing_para_level);
  395. valid_for_var(destppn);
  396. set_varstate(destppn,vs_assigned,false);
  397. dec(parsing_para_level);
  398. { first param must be a string or dynamic array ...}
  399. isarray:=is_dynamic_array(destppn.resulttype.def);
  400. if not((destppn.resulttype.def.deftype=stringdef) or
  401. isarray) then
  402. begin
  403. CGMessage(type_e_mismatch);
  404. paras.free;
  405. exit;
  406. end;
  407. { only dynamic arrays accept more dimensions }
  408. if (counter>1) then
  409. begin
  410. if (not isarray) then
  411. CGMessage(type_e_mismatch)
  412. else
  413. begin
  414. { check if the amount of dimensions is valid }
  415. def := tarraydef(destppn.resulttype.def).elementtype.def;
  416. while counter > 1 do
  417. begin
  418. if not(is_dynamic_array(def)) then
  419. begin
  420. CGMessage(parser_e_wrong_parameter_size);
  421. break;
  422. end;
  423. dec(counter);
  424. def := tarraydef(def).elementtype.def;
  425. end;
  426. end;
  427. end;
  428. if isarray then
  429. begin
  430. { create statements with call initialize the arguments and
  431. call fpc_dynarr_setlength }
  432. newblock:=internalstatements(newstatement,true);
  433. { get temp for array of lengths }
  434. temp := ctempcreatenode.create(s32bittype,counter*s32bittype.def.size,tt_persistent);
  435. addstatement(newstatement,temp);
  436. { load array of lengths }
  437. ppn:=tcallparanode(paras);
  438. counter:=0;
  439. while assigned(ppn.right) do
  440. begin
  441. addstatement(newstatement,cassignmentnode.create(
  442. ctemprefnode.create_offset(temp,counter*s32bittype.def.size),
  443. ppn.left));
  444. ppn.left:=nil;
  445. inc(counter);
  446. ppn:=tcallparanode(ppn.right);
  447. end;
  448. { destppn is also reused }
  449. ppn.left:=nil;
  450. { create call to fpc_dynarr_setlength }
  451. npara:=ccallparanode.create(caddrnode.create
  452. (ctemprefnode.create(temp)),
  453. ccallparanode.create(cordconstnode.create
  454. (counter,s32bittype,true),
  455. ccallparanode.create(caddrnode.create
  456. (crttinode.create(tstoreddef(destppn.resulttype.def),initrtti)),
  457. ccallparanode.create(ctypeconvnode.create_explicit(destppn,voidpointertype),nil))));
  458. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  459. addstatement(newstatement,ctempdeletenode.create(temp));
  460. { we don't need original the callparanodes tree }
  461. paras.free;
  462. end
  463. else
  464. begin
  465. { we can reuse the supplied parameters }
  466. newblock:=ccallnode.createintern(
  467. 'fpc_'+tstringdef(destppn.resulttype.def).stringtypname+'_setlength',paras);
  468. end;
  469. result.free;
  470. result:=newblock;
  471. end;
  472. function inline_finalize : tnode;
  473. var
  474. newblock,
  475. paras : tnode;
  476. npara,
  477. destppn,
  478. ppn : tcallparanode;
  479. begin
  480. { for easy exiting if something goes wrong }
  481. result := cerrornode.create;
  482. consume(_LKLAMMER);
  483. paras:=parse_paras(false,false);
  484. consume(_RKLAMMER);
  485. if not assigned(paras) then
  486. begin
  487. CGMessage(parser_e_wrong_parameter_size);
  488. exit;
  489. end;
  490. ppn:=tcallparanode(paras);
  491. { 2 arguments? }
  492. if assigned(ppn.right) then
  493. begin
  494. destppn:=tcallparanode(ppn.right);
  495. { 3 arguments is invalid }
  496. if assigned(destppn.right) then
  497. begin
  498. CGMessage(parser_e_wrong_parameter_size);
  499. paras.free;
  500. exit;
  501. end;
  502. { create call to fpc_finalize_array }
  503. npara:=ccallparanode.create(cordconstnode.create
  504. (destppn.left.resulttype.def.size,s32bittype,true),
  505. ccallparanode.create(ctypeconvnode.create
  506. (ppn.left,s32bittype),
  507. ccallparanode.create(caddrnode.create
  508. (crttinode.create(tstoreddef(destppn.left.resulttype.def),initrtti)),
  509. ccallparanode.create(caddrnode.create
  510. (destppn.left),nil))));
  511. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  512. destppn.left:=nil;
  513. ppn.left:=nil;
  514. end
  515. else
  516. begin
  517. newblock:=finalize_data_node(ppn.left);
  518. ppn.left:=nil;
  519. end;
  520. paras.free;
  521. result.free;
  522. result:=newblock;
  523. end;
  524. function inline_copy : tnode;
  525. var
  526. copynode,
  527. lowppn,
  528. highppn,
  529. npara,
  530. paras : tnode;
  531. temp : ttempcreatenode;
  532. ppn : tcallparanode;
  533. paradef : tdef;
  534. counter : integer;
  535. newstatement : tstatementnode;
  536. begin
  537. { for easy exiting if something goes wrong }
  538. result := cerrornode.create;
  539. consume(_LKLAMMER);
  540. paras:=parse_paras(false,false);
  541. consume(_RKLAMMER);
  542. if not assigned(paras) then
  543. begin
  544. CGMessage(parser_e_wrong_parameter_size);
  545. exit;
  546. end;
  547. { determine copy function to use based on the first argument,
  548. also count the number of arguments in this loop }
  549. counter:=1;
  550. ppn:=tcallparanode(paras);
  551. while assigned(ppn.right) do
  552. begin
  553. inc(counter);
  554. ppn:=tcallparanode(ppn.right);
  555. end;
  556. paradef:=ppn.left.resulttype.def;
  557. if is_ansistring(paradef) or
  558. (is_chararray(paradef) and
  559. (paradef.size>255)) or
  560. ((cs_ansistrings in aktlocalswitches) and
  561. is_pchar(paradef)) then
  562. copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
  563. else
  564. if is_widestring(paradef) or
  565. is_widechararray(paradef) or
  566. is_pwidechar(paradef) then
  567. copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
  568. else
  569. if is_char(paradef) then
  570. copynode:=ccallnode.createintern('fpc_char_copy',paras)
  571. else
  572. if is_dynamic_array(paradef) then
  573. begin
  574. { Only allow 1 or 3 arguments }
  575. if (counter<>1) and (counter<>3) then
  576. begin
  577. CGMessage(parser_e_wrong_parameter_size);
  578. exit;
  579. end;
  580. { create statements with call }
  581. copynode:=internalstatements(newstatement,true);
  582. if (counter=3) then
  583. begin
  584. highppn:=tcallparanode(paras).left.getcopy;
  585. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  586. end
  587. else
  588. begin
  589. { use special -1,-1 argument to copy the whole array }
  590. highppn:=cordconstnode.create(-1,s32bittype,false);
  591. lowppn:=cordconstnode.create(-1,s32bittype,false);
  592. end;
  593. { create temp for result, we've to use a temp because a dynarray
  594. type is handled differently from a pointer so we can't
  595. use createinternres() and a function }
  596. temp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent);
  597. addstatement(newstatement,temp);
  598. { create call to fpc_dynarray_copy }
  599. npara:=ccallparanode.create(highppn,
  600. ccallparanode.create(lowppn,
  601. ccallparanode.create(caddrnode.create
  602. (crttinode.create(tstoreddef(ppn.left.resulttype.def),initrtti)),
  603. ccallparanode.create
  604. (ctypeconvnode.create_explicit(ppn.left,voidpointertype),
  605. ccallparanode.create
  606. (ctemprefnode.create(temp),nil)))));
  607. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_copy',npara));
  608. { convert the temp to normal and return the reference to the
  609. created temp, and convert the type of the temp to the dynarray type }
  610. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  611. addstatement(newstatement,ctypeconvnode.create_explicit(ctemprefnode.create(temp),ppn.left.resulttype));
  612. ppn.left:=nil;
  613. paras.free;
  614. end
  615. else
  616. begin
  617. { generic fallback that will give an error if a wrong
  618. type is passed }
  619. copynode:=ccallnode.createintern('fpc_shortstr_copy',paras)
  620. end;
  621. result.free;
  622. result:=copynode;
  623. end;
  624. end.
  625. {
  626. $Log$
  627. Revision 1.21 2003-10-08 19:19:45 peter
  628. * set_varstate cleanup
  629. Revision 1.20 2003/10/02 21:15:31 peter
  630. * protected visibility fixes
  631. Revision 1.19 2003/10/01 20:34:49 peter
  632. * procinfo unit contains tprocinfo
  633. * cginfo renamed to cgbase
  634. * moved cgmessage to verbose
  635. * fixed ppc and sparc compiles
  636. Revision 1.18 2003/09/23 17:56:05 peter
  637. * locals and paras are allocated in the code generation
  638. * tvarsym.localloc contains the location of para/local when
  639. generating code for the current procedure
  640. Revision 1.17 2003/08/21 15:10:51 peter
  641. * fixed copy support for array of char,pchar in $H+ mode
  642. * fixed copy support for pwidechar,array of widechar
  643. Revision 1.16 2003/08/10 17:25:23 peter
  644. * fixed some reported bugs
  645. Revision 1.15 2003/05/17 13:30:08 jonas
  646. * changed tt_persistant to tt_persistent :)
  647. * tempcreatenode now doesn't accept a boolean anymore for persistent
  648. temps, but a ttemptype, so you can also create ansistring temps etc
  649. Revision 1.14 2003/05/16 14:33:31 peter
  650. * regvar fixes
  651. Revision 1.13 2003/05/09 17:47:03 peter
  652. * self moved to hidden parameter
  653. * removed hdisposen,hnewn,selfn
  654. Revision 1.12 2002/04/25 20:15:40 florian
  655. * block nodes within expressions shouldn't release the used registers,
  656. fixed using a flag till the new rg is ready
  657. Revision 1.11 2002/11/26 22:59:09 peter
  658. * fix Copy(array,x,y)
  659. Revision 1.10 2002/11/25 17:43:22 peter
  660. * splitted defbase in defutil,symutil,defcmp
  661. * merged isconvertable and is_equal into compare_defs(_ext)
  662. * made operator search faster by walking the list only once
  663. Revision 1.9 2002/10/29 10:01:22 pierre
  664. * fix crash report as webbug 2174
  665. Revision 1.8 2002/10/02 18:20:52 peter
  666. * Copy() is now internal syssym that calls compilerprocs
  667. Revision 1.7 2002/09/07 12:16:03 carl
  668. * second part bug report 1996 fix, testrange in cordconstnode
  669. only called if option is set (also make parsing a tiny faster)
  670. Revision 1.6 2002/07/20 11:57:56 florian
  671. * types.pas renamed to defbase.pas because D6 contains a types
  672. unit so this would conflicts if D6 programms are compiled
  673. + Willamette/SSE2 instructions to assembler added
  674. Revision 1.5 2002/05/18 13:34:12 peter
  675. * readded missing revisions
  676. Revision 1.4 2002/05/16 19:46:43 carl
  677. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  678. + try to fix temp allocation (still in ifdef)
  679. + generic constructor calls
  680. + start of tassembler / tmodulebase class cleanup
  681. Revision 1.2 2002/05/12 16:53:09 peter
  682. * moved entry and exitcode to ncgutil and cgobj
  683. * foreach gets extra argument for passing local data to the
  684. iterator function
  685. * -CR checks also class typecasts at runtime by changing them
  686. into as
  687. * fixed compiler to cycle with the -CR option
  688. * fixed stabs with elf writer, finally the global variables can
  689. be watched
  690. * removed a lot of routines from cga unit and replaced them by
  691. calls to cgobj
  692. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  693. u32bit then the other is typecasted also to u32bit without giving
  694. a rangecheck warning/error.
  695. * fixed pascal calling method with reversing also the high tree in
  696. the parast, detected by tcalcst3 test
  697. Revision 1.1 2002/04/23 19:16:35 peter
  698. * add pinline unit that inserts compiler supported functions using
  699. one or more statements
  700. * moved finalize and setlength from ninl to pinline
  701. }