pinline.pas 28 KB

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