pinline.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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. 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,tt_persistent);
  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. addstatement(newstatement,initialize_data_node(ctemprefnode.create(temp)));
  223. { copy the temp to the destination }
  224. addstatement(newstatement,cassignmentnode.create(
  225. p,
  226. ctemprefnode.create(temp)));
  227. { release temp }
  228. addstatement(newstatement,ctempdeletenode.create(temp));
  229. end
  230. else
  231. begin
  232. { create call to fpc_finalize }
  233. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  234. addstatement(newstatement,finalize_data_node(cderefnode.create(p.getcopy)));
  235. { create call to fpc_freemem }
  236. para := ccallparanode.create(p,nil);
  237. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  238. end;
  239. end;
  240. end;
  241. consume(_RKLAMMER);
  242. end;
  243. function new_function : tnode;
  244. var
  245. newstatement : tstatementnode;
  246. newblock : tblocknode;
  247. temp : ttempcreatenode;
  248. para : tcallparanode;
  249. p1,p2 : tnode;
  250. classh : tobjectdef;
  251. sym : tsym;
  252. again : boolean; { dummy for do_proc_call }
  253. begin
  254. consume(_LKLAMMER);
  255. p1:=factor(false);
  256. if p1.nodetype<>typen then
  257. begin
  258. Message(type_e_type_id_expected);
  259. consume_all_until(_RKLAMMER);
  260. consume(_RKLAMMER);
  261. p1.destroy;
  262. new_function:=cerrornode.create;
  263. exit;
  264. end;
  265. if (p1.resulttype.def.deftype<>pointerdef) then
  266. begin
  267. Message1(type_e_pointer_type_expected,p1.resulttype.def.typename);
  268. consume_all_until(_RKLAMMER);
  269. consume(_RKLAMMER);
  270. p1.destroy;
  271. new_function:=cerrornode.create;
  272. exit;
  273. end;
  274. if try_to_consume(_RKLAMMER) then
  275. begin
  276. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=objectdef) and
  277. (oo_has_vmt in tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def).objectoptions) then
  278. Message(parser_w_use_extended_syntax_for_objects);
  279. { create statements with call to getmem+initialize }
  280. newblock:=internalstatements(newstatement,true);
  281. { create temp for result }
  282. temp := ctempcreatenode.create(p1.resulttype,p1.resulttype.def.size,tt_persistent);
  283. addstatement(newstatement,temp);
  284. { create call to fpc_getmem }
  285. para := ccallparanode.create(cordconstnode.create
  286. (tpointerdef(p1.resulttype.def).pointertype.def.size,s32bittype,true),nil);
  287. addstatement(newstatement,cassignmentnode.create(
  288. ctemprefnode.create(temp),
  289. ccallnode.createintern('fpc_getmem',para)));
  290. { create call to fpc_initialize }
  291. if tpointerdef(p1.resulttype.def).pointertype.def.needs_inittable then
  292. begin
  293. para := ccallparanode.create(caddrnode.create(crttinode.create
  294. (tstoreddef(tpointerdef(p1.resulttype.def).pointertype.def),initrtti)),
  295. ccallparanode.create(ctemprefnode.create
  296. (temp),nil));
  297. addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
  298. end;
  299. { the last statement should return the value as
  300. location and type, this is done be referencing the
  301. temp and converting it first from a persistent temp to
  302. normal temp }
  303. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  304. addstatement(newstatement,ctemprefnode.create(temp));
  305. p1.destroy;
  306. p1:=newblock;
  307. end
  308. else
  309. begin
  310. consume(_COMMA);
  311. if tpointerdef(p1.resulttype.def).pointertype.def.deftype<>objectdef then
  312. begin
  313. Message(parser_e_pointer_to_class_expected);
  314. consume_all_until(_RKLAMMER);
  315. consume(_RKLAMMER);
  316. p1.destroy;
  317. new_function:=cerrornode.create;
  318. exit;
  319. end;
  320. classh:=tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def);
  321. { use the objectdef for loading the VMT }
  322. p2:=p1;
  323. p1:=ctypenode.create(tpointerdef(p1.resulttype.def).pointertype);
  324. do_resulttypepass(p1);
  325. { search the constructor also in the symbol tables of
  326. the parents }
  327. afterassignment:=false;
  328. sym:=searchsym_in_class(classh,pattern);
  329. consume(_ID);
  330. do_member_read(false,sym,p1,again,[nf_new_call]);
  331. { we need to know which procedure is called }
  332. do_resulttypepass(p1);
  333. if not(
  334. (p1.nodetype=calln) and
  335. assigned(tcallnode(p1).procdefinition) and
  336. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  337. ) then
  338. Message(parser_e_expr_have_to_be_constructor_call);
  339. { constructors return boolean, update resulttype to return
  340. the pointer to the object }
  341. p1.resulttype:=p2.resulttype;
  342. p2.free;
  343. consume(_RKLAMMER);
  344. end;
  345. new_function:=p1;
  346. end;
  347. function inline_setlength : tnode;
  348. var
  349. paras : tnode;
  350. npara,
  351. ppn : tcallparanode;
  352. counter : integer;
  353. isarray : boolean;
  354. def : tdef;
  355. destppn : tnode;
  356. newstatement : tstatementnode;
  357. temp : ttempcreatenode;
  358. newblock : tnode;
  359. begin
  360. { for easy exiting if something goes wrong }
  361. result := cerrornode.create;
  362. consume(_LKLAMMER);
  363. paras:=parse_paras(false,false);
  364. consume(_RKLAMMER);
  365. if not assigned(paras) then
  366. begin
  367. CGMessage(parser_e_wrong_parameter_size);
  368. exit;
  369. end;
  370. counter:=0;
  371. if assigned(paras) then
  372. begin
  373. { check type of lengths }
  374. ppn:=tcallparanode(paras);
  375. while assigned(ppn.right) do
  376. begin
  377. set_varstate(ppn.left,true);
  378. inserttypeconv(ppn.left,s32bittype);
  379. inc(counter);
  380. ppn:=tcallparanode(ppn.right);
  381. end;
  382. end;
  383. if counter=0 then
  384. begin
  385. CGMessage(parser_e_wrong_parameter_size);
  386. paras.free;
  387. exit;
  388. end;
  389. { last param must be var }
  390. destppn:=ppn.left;
  391. inc(parsing_para_level);
  392. valid_for_var(destppn);
  393. set_varstate(destppn,false);
  394. dec(parsing_para_level);
  395. { first param must be a string or dynamic array ...}
  396. isarray:=is_dynamic_array(destppn.resulttype.def);
  397. if not((destppn.resulttype.def.deftype=stringdef) or
  398. isarray) then
  399. begin
  400. CGMessage(type_e_mismatch);
  401. paras.free;
  402. exit;
  403. end;
  404. { only dynamic arrays accept more dimensions }
  405. if (counter>1) then
  406. begin
  407. if (not isarray) then
  408. CGMessage(type_e_mismatch)
  409. else
  410. begin
  411. { check if the amount of dimensions is valid }
  412. def := tarraydef(destppn.resulttype.def).elementtype.def;
  413. while counter > 1 do
  414. begin
  415. if not(is_dynamic_array(def)) then
  416. begin
  417. CGMessage(parser_e_wrong_parameter_size);
  418. break;
  419. end;
  420. dec(counter);
  421. def := tarraydef(def).elementtype.def;
  422. end;
  423. end;
  424. end;
  425. if isarray then
  426. begin
  427. { create statements with call initialize the arguments and
  428. call fpc_dynarr_setlength }
  429. newblock:=internalstatements(newstatement,true);
  430. { get temp for array of lengths }
  431. temp := ctempcreatenode.create(s32bittype,counter*s32bittype.def.size,tt_persistent);
  432. addstatement(newstatement,temp);
  433. { load array of lengths }
  434. ppn:=tcallparanode(paras);
  435. counter:=0;
  436. while assigned(ppn.right) do
  437. begin
  438. addstatement(newstatement,cassignmentnode.create(
  439. ctemprefnode.create_offset(temp,counter*s32bittype.def.size),
  440. ppn.left));
  441. ppn.left:=nil;
  442. inc(counter);
  443. ppn:=tcallparanode(ppn.right);
  444. end;
  445. { destppn is also reused }
  446. ppn.left:=nil;
  447. { create call to fpc_dynarr_setlength }
  448. npara:=ccallparanode.create(caddrnode.create
  449. (ctemprefnode.create(temp)),
  450. ccallparanode.create(cordconstnode.create
  451. (counter,s32bittype,true),
  452. ccallparanode.create(caddrnode.create
  453. (crttinode.create(tstoreddef(destppn.resulttype.def),initrtti)),
  454. ccallparanode.create(ctypeconvnode.create_explicit(destppn,voidpointertype),nil))));
  455. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  456. addstatement(newstatement,ctempdeletenode.create(temp));
  457. { we don't need original the callparanodes tree }
  458. paras.free;
  459. end
  460. else
  461. begin
  462. { we can reuse the supplied parameters }
  463. newblock:=ccallnode.createintern(
  464. 'fpc_'+tstringdef(destppn.resulttype.def).stringtypname+'_setlength',paras);
  465. end;
  466. result.free;
  467. result:=newblock;
  468. end;
  469. function inline_finalize : tnode;
  470. var
  471. newblock,
  472. paras : tnode;
  473. npara,
  474. destppn,
  475. ppn : tcallparanode;
  476. begin
  477. { for easy exiting if something goes wrong }
  478. result := cerrornode.create;
  479. consume(_LKLAMMER);
  480. paras:=parse_paras(false,false);
  481. consume(_RKLAMMER);
  482. if not assigned(paras) then
  483. begin
  484. CGMessage(parser_e_wrong_parameter_size);
  485. exit;
  486. end;
  487. ppn:=tcallparanode(paras);
  488. { 2 arguments? }
  489. if assigned(ppn.right) then
  490. begin
  491. destppn:=tcallparanode(ppn.right);
  492. { 3 arguments is invalid }
  493. if assigned(destppn.right) then
  494. begin
  495. CGMessage(parser_e_wrong_parameter_size);
  496. paras.free;
  497. exit;
  498. end;
  499. { create call to fpc_finalize_array }
  500. npara:=ccallparanode.create(cordconstnode.create
  501. (destppn.left.resulttype.def.size,s32bittype,true),
  502. ccallparanode.create(ctypeconvnode.create
  503. (ppn.left,s32bittype),
  504. ccallparanode.create(caddrnode.create
  505. (crttinode.create(tstoreddef(destppn.left.resulttype.def),initrtti)),
  506. ccallparanode.create(caddrnode.create
  507. (destppn.left),nil))));
  508. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  509. destppn.left:=nil;
  510. ppn.left:=nil;
  511. end
  512. else
  513. begin
  514. newblock:=finalize_data_node(ppn.left);
  515. ppn.left:=nil;
  516. end;
  517. paras.free;
  518. result.free;
  519. result:=newblock;
  520. end;
  521. function inline_copy : tnode;
  522. var
  523. copynode,
  524. lowppn,
  525. highppn,
  526. npara,
  527. paras : tnode;
  528. temp : ttempcreatenode;
  529. ppn : tcallparanode;
  530. paradef : tdef;
  531. counter : integer;
  532. newstatement : tstatementnode;
  533. begin
  534. { for easy exiting if something goes wrong }
  535. result := cerrornode.create;
  536. consume(_LKLAMMER);
  537. paras:=parse_paras(false,false);
  538. consume(_RKLAMMER);
  539. if not assigned(paras) then
  540. begin
  541. CGMessage(parser_e_wrong_parameter_size);
  542. exit;
  543. end;
  544. { determine copy function to use based on the first argument,
  545. also count the number of arguments in this loop }
  546. counter:=1;
  547. ppn:=tcallparanode(paras);
  548. while assigned(ppn.right) do
  549. begin
  550. inc(counter);
  551. ppn:=tcallparanode(ppn.right);
  552. end;
  553. paradef:=ppn.left.resulttype.def;
  554. if is_ansistring(paradef) or
  555. (is_chararray(paradef) and
  556. (paradef.size>255)) or
  557. ((cs_ansistrings in aktlocalswitches) and
  558. is_pchar(paradef)) then
  559. copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
  560. else
  561. if is_widestring(paradef) or
  562. is_widechararray(paradef) or
  563. is_pwidechar(paradef) then
  564. copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
  565. else
  566. if is_char(paradef) then
  567. copynode:=ccallnode.createintern('fpc_char_copy',paras)
  568. else
  569. if is_dynamic_array(paradef) then
  570. begin
  571. { Only allow 1 or 3 arguments }
  572. if (counter<>1) and (counter<>3) then
  573. begin
  574. CGMessage(parser_e_wrong_parameter_size);
  575. exit;
  576. end;
  577. { create statements with call }
  578. copynode:=internalstatements(newstatement,true);
  579. if (counter=3) then
  580. begin
  581. highppn:=tcallparanode(paras).left.getcopy;
  582. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  583. end
  584. else
  585. begin
  586. { use special -1,-1 argument to copy the whole array }
  587. highppn:=cordconstnode.create(-1,s32bittype,false);
  588. lowppn:=cordconstnode.create(-1,s32bittype,false);
  589. end;
  590. { create temp for result, we've to use a temp because a dynarray
  591. type is handled differently from a pointer so we can't
  592. use createinternres() and a function }
  593. temp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent);
  594. addstatement(newstatement,temp);
  595. { create call to fpc_dynarray_copy }
  596. npara:=ccallparanode.create(highppn,
  597. ccallparanode.create(lowppn,
  598. ccallparanode.create(caddrnode.create
  599. (crttinode.create(tstoreddef(ppn.left.resulttype.def),initrtti)),
  600. ccallparanode.create
  601. (ctypeconvnode.create_explicit(ppn.left,voidpointertype),
  602. ccallparanode.create
  603. (ctemprefnode.create(temp),nil)))));
  604. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_copy',npara));
  605. { convert the temp to normal and return the reference to the
  606. created temp, and convert the type of the temp to the dynarray type }
  607. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  608. addstatement(newstatement,ctypeconvnode.create_explicit(ctemprefnode.create(temp),ppn.left.resulttype));
  609. ppn.left:=nil;
  610. paras.free;
  611. end
  612. else
  613. begin
  614. { generic fallback that will give an error if a wrong
  615. type is passed }
  616. copynode:=ccallnode.createintern('fpc_shortstr_copy',paras)
  617. end;
  618. result.free;
  619. result:=copynode;
  620. end;
  621. end.
  622. {
  623. $Log$
  624. Revision 1.19 2003-10-01 20:34:49 peter
  625. * procinfo unit contains tprocinfo
  626. * cginfo renamed to cgbase
  627. * moved cgmessage to verbose
  628. * fixed ppc and sparc compiles
  629. Revision 1.18 2003/09/23 17:56:05 peter
  630. * locals and paras are allocated in the code generation
  631. * tvarsym.localloc contains the location of para/local when
  632. generating code for the current procedure
  633. Revision 1.17 2003/08/21 15:10:51 peter
  634. * fixed copy support for array of char,pchar in $H+ mode
  635. * fixed copy support for pwidechar,array of widechar
  636. Revision 1.16 2003/08/10 17:25:23 peter
  637. * fixed some reported bugs
  638. Revision 1.15 2003/05/17 13:30:08 jonas
  639. * changed tt_persistant to tt_persistent :)
  640. * tempcreatenode now doesn't accept a boolean anymore for persistent
  641. temps, but a ttemptype, so you can also create ansistring temps etc
  642. Revision 1.14 2003/05/16 14:33:31 peter
  643. * regvar fixes
  644. Revision 1.13 2003/05/09 17:47:03 peter
  645. * self moved to hidden parameter
  646. * removed hdisposen,hnewn,selfn
  647. Revision 1.12 2002/04/25 20:15:40 florian
  648. * block nodes within expressions shouldn't release the used registers,
  649. fixed using a flag till the new rg is ready
  650. Revision 1.11 2002/11/26 22:59:09 peter
  651. * fix Copy(array,x,y)
  652. Revision 1.10 2002/11/25 17:43:22 peter
  653. * splitted defbase in defutil,symutil,defcmp
  654. * merged isconvertable and is_equal into compare_defs(_ext)
  655. * made operator search faster by walking the list only once
  656. Revision 1.9 2002/10/29 10:01:22 pierre
  657. * fix crash report as webbug 2174
  658. Revision 1.8 2002/10/02 18:20:52 peter
  659. * Copy() is now internal syssym that calls compilerprocs
  660. Revision 1.7 2002/09/07 12:16:03 carl
  661. * second part bug report 1996 fix, testrange in cordconstnode
  662. only called if option is set (also make parsing a tiny faster)
  663. Revision 1.6 2002/07/20 11:57:56 florian
  664. * types.pas renamed to defbase.pas because D6 contains a types
  665. unit so this would conflicts if D6 programms are compiled
  666. + Willamette/SSE2 instructions to assembler added
  667. Revision 1.5 2002/05/18 13:34:12 peter
  668. * readded missing revisions
  669. Revision 1.4 2002/05/16 19:46:43 carl
  670. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  671. + try to fix temp allocation (still in ifdef)
  672. + generic constructor calls
  673. + start of tassembler / tmodulebase class cleanup
  674. Revision 1.2 2002/05/12 16:53:09 peter
  675. * moved entry and exitcode to ncgutil and cgobj
  676. * foreach gets extra argument for passing local data to the
  677. iterator function
  678. * -CR checks also class typecasts at runtime by changing them
  679. into as
  680. * fixed compiler to cycle with the -CR option
  681. * fixed stabs with elf writer, finally the global variables can
  682. be watched
  683. * removed a lot of routines from cga unit and replaced them by
  684. calls to cgobj
  685. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  686. u32bit then the other is typecasted also to u32bit without giving
  687. a rangecheck warning/error.
  688. * fixed pascal calling method with reversing also the high tree in
  689. the parast, detected by tcalcst3 test
  690. Revision 1.1 2002/04/23 19:16:35 peter
  691. * add pinline unit that inserts compiler supported functions using
  692. one or more statements
  693. * moved finalize and setlength from ninl to pinline
  694. }