pinline.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generates nodes for routines that need compiler support
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pinline;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,
  22. node,
  23. globals,
  24. cpuinfo;
  25. function new_dispose_statement(is_new:boolean) : tnode;
  26. function new_function : tnode;
  27. function inline_setlength : tnode;
  28. function inline_initialize : tnode;
  29. function inline_finalize : tnode;
  30. function inline_copy : tnode;
  31. implementation
  32. uses
  33. { common }
  34. cutils,
  35. { global }
  36. globtype,tokens,verbose,
  37. systems,
  38. { symtable }
  39. symconst,symdef,symsym,symtable,defutil,
  40. { pass 1 }
  41. pass_1,htypechk,
  42. nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  43. { parser }
  44. scanner,
  45. pbase,pexpr,
  46. { codegen }
  47. cgbase
  48. ;
  49. function new_dispose_statement(is_new:boolean) : tnode;
  50. var
  51. newstatement : tstatementnode;
  52. temp : ttempcreatenode;
  53. para : tcallparanode;
  54. p,p2 : tnode;
  55. again : boolean; { dummy for do_proc_call }
  56. destructorname : stringid;
  57. sym : tsym;
  58. classh : tobjectdef;
  59. callflag : tcallnodeflag;
  60. destructorpos,
  61. storepos : tfileposinfo;
  62. begin
  63. consume(_LKLAMMER);
  64. p:=comp_expr(true);
  65. { calc return type }
  66. if is_new then
  67. set_varstate(p,vs_assigned,[])
  68. else
  69. set_varstate(p,vs_used,[vsf_must_be_valid]);
  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. { For new(var,constructor) we need to take a copy because
  128. p is also used in the assignmentn below }
  129. if is_new then
  130. p2:=cderefnode.create(p.getcopy)
  131. else
  132. p2:=cderefnode.create(p);
  133. do_resulttypepass(p2);
  134. if is_new then
  135. callflag:=cnf_new_call
  136. else
  137. callflag:=cnf_dispose_call;
  138. if is_new then
  139. do_member_read(classh,false,sym,p2,again,[callflag])
  140. else
  141. begin
  142. if not(m_fpc in aktmodeswitches) then
  143. do_member_read(classh,false,sym,p2,again,[callflag])
  144. else
  145. begin
  146. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2,[callflag]);
  147. { support dispose(p,done()); }
  148. if try_to_consume(_LKLAMMER) then
  149. begin
  150. if not try_to_consume(_RKLAMMER) then
  151. begin
  152. Message(parser_e_no_paras_for_destructor);
  153. consume_all_until(_RKLAMMER);
  154. consume(_RKLAMMER);
  155. end;
  156. end;
  157. end;
  158. end;
  159. { we need the real called method }
  160. do_resulttypepass(p2);
  161. if (p2.nodetype=calln) and
  162. assigned(tcallnode(p2).procdefinition) then
  163. begin
  164. if is_new then
  165. begin
  166. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  167. Message(parser_e_expr_have_to_be_constructor_call);
  168. p2.resulttype:=p.resulttype;
  169. p2:=cassignmentnode.create(p,p2);
  170. end
  171. else
  172. begin
  173. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  174. Message(parser_e_expr_have_to_be_destructor_call);
  175. end;
  176. end
  177. else
  178. begin
  179. if is_new then
  180. CGMessage(parser_e_expr_have_to_be_constructor_call)
  181. else
  182. CGMessage(parser_e_expr_have_to_be_destructor_call);
  183. end;
  184. result:=p2;
  185. end;
  186. end
  187. else
  188. begin
  189. if (p.resulttype.def.deftype<>pointerdef) then
  190. Begin
  191. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  192. new_dispose_statement:=cerrornode.create;
  193. end
  194. else
  195. begin
  196. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=objectdef) and
  197. (oo_has_vmt in tobjectdef(tpointerdef(p.resulttype.def).pointertype.def).objectoptions) then
  198. Message(parser_w_use_extended_syntax_for_objects);
  199. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=orddef) and
  200. (torddef(tpointerdef(p.resulttype.def).pointertype.def).typ=uvoid) then
  201. begin
  202. if (m_tp7 in aktmodeswitches) or
  203. (m_delphi in aktmodeswitches) then
  204. Message(parser_w_no_new_dispose_on_void_pointers)
  205. else
  206. Message(parser_e_no_new_dispose_on_void_pointers);
  207. end;
  208. { create statements with call to getmem+initialize or
  209. finalize+freemem }
  210. new_dispose_statement:=internalstatements(newstatement);
  211. if is_new then
  212. begin
  213. { create temp for result }
  214. temp := ctempcreatenode.create(p.resulttype,p.resulttype.def.size,tt_persistent,true);
  215. addstatement(newstatement,temp);
  216. { create call to fpc_getmem }
  217. para := ccallparanode.create(cordconstnode.create
  218. (tpointerdef(p.resulttype.def).pointertype.def.size,s32inttype,true),nil);
  219. addstatement(newstatement,cassignmentnode.create(
  220. ctemprefnode.create(temp),
  221. ccallnode.createintern('fpc_getmem',para)));
  222. { create call to fpc_initialize }
  223. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  224. addstatement(newstatement,initialize_data_node(cderefnode.create(ctemprefnode.create(temp))));
  225. { copy the temp to the destination }
  226. addstatement(newstatement,cassignmentnode.create(
  227. p,
  228. ctemprefnode.create(temp)));
  229. { release temp }
  230. addstatement(newstatement,ctempdeletenode.create(temp));
  231. end
  232. else
  233. begin
  234. { create call to fpc_finalize }
  235. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  236. addstatement(newstatement,finalize_data_node(cderefnode.create(p.getcopy)));
  237. { create call to fpc_freemem }
  238. para := ccallparanode.create(p,nil);
  239. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  240. end;
  241. end;
  242. end;
  243. consume(_RKLAMMER);
  244. end;
  245. function new_function : tnode;
  246. var
  247. newstatement : tstatementnode;
  248. newblock : tblocknode;
  249. temp : ttempcreatenode;
  250. para : tcallparanode;
  251. p1,p2 : tnode;
  252. classh : tobjectdef;
  253. sym : tsym;
  254. again : boolean; { dummy for do_proc_call }
  255. begin
  256. consume(_LKLAMMER);
  257. p1:=factor(false);
  258. if p1.nodetype<>typen then
  259. begin
  260. Message(type_e_type_id_expected);
  261. consume_all_until(_RKLAMMER);
  262. consume(_RKLAMMER);
  263. p1.destroy;
  264. new_function:=cerrornode.create;
  265. exit;
  266. end;
  267. if (p1.resulttype.def.deftype<>pointerdef) then
  268. begin
  269. Message1(type_e_pointer_type_expected,p1.resulttype.def.typename);
  270. consume_all_until(_RKLAMMER);
  271. consume(_RKLAMMER);
  272. p1.destroy;
  273. new_function:=cerrornode.create;
  274. exit;
  275. end;
  276. if try_to_consume(_RKLAMMER) then
  277. begin
  278. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=objectdef) and
  279. (oo_has_vmt in tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def).objectoptions) then
  280. Message(parser_w_use_extended_syntax_for_objects);
  281. { create statements with call to getmem+initialize }
  282. newblock:=internalstatements(newstatement);
  283. { create temp for result }
  284. temp := ctempcreatenode.create(p1.resulttype,p1.resulttype.def.size,tt_persistent,true);
  285. addstatement(newstatement,temp);
  286. { create call to fpc_getmem }
  287. para := ccallparanode.create(cordconstnode.create
  288. (tpointerdef(p1.resulttype.def).pointertype.def.size,s32inttype,true),nil);
  289. addstatement(newstatement,cassignmentnode.create(
  290. ctemprefnode.create(temp),
  291. ccallnode.createintern('fpc_getmem',para)));
  292. { create call to fpc_initialize }
  293. if tpointerdef(p1.resulttype.def).pointertype.def.needs_inittable then
  294. begin
  295. para := ccallparanode.create(caddrnode.create_internal(crttinode.create
  296. (tstoreddef(tpointerdef(p1.resulttype.def).pointertype.def),initrtti)),
  297. ccallparanode.create(ctemprefnode.create
  298. (temp),nil));
  299. addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
  300. end;
  301. { the last statement should return the value as
  302. location and type, this is done be referencing the
  303. temp and converting it first from a persistent temp to
  304. normal temp }
  305. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  306. addstatement(newstatement,ctemprefnode.create(temp));
  307. p1.destroy;
  308. p1:=newblock;
  309. end
  310. else
  311. begin
  312. consume(_COMMA);
  313. if tpointerdef(p1.resulttype.def).pointertype.def.deftype<>objectdef then
  314. begin
  315. Message(parser_e_pointer_to_class_expected);
  316. consume_all_until(_RKLAMMER);
  317. consume(_RKLAMMER);
  318. p1.destroy;
  319. new_function:=cerrornode.create;
  320. exit;
  321. end;
  322. classh:=tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def);
  323. { use the objectdef for loading the VMT }
  324. p2:=p1;
  325. p1:=ctypenode.create(tpointerdef(p1.resulttype.def).pointertype);
  326. do_resulttypepass(p1);
  327. { search the constructor also in the symbol tables of
  328. the parents }
  329. afterassignment:=false;
  330. sym:=searchsym_in_class(classh,pattern);
  331. consume(_ID);
  332. do_member_read(classh,false,sym,p1,again,[cnf_new_call]);
  333. { we need to know which procedure is called }
  334. do_resulttypepass(p1);
  335. if not(
  336. (p1.nodetype=calln) and
  337. assigned(tcallnode(p1).procdefinition) and
  338. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  339. ) then
  340. Message(parser_e_expr_have_to_be_constructor_call);
  341. { constructors return boolean, update resulttype to return
  342. the pointer to the object }
  343. p1.resulttype:=p2.resulttype;
  344. p2.free;
  345. consume(_RKLAMMER);
  346. end;
  347. new_function:=p1;
  348. end;
  349. function inline_setlength : tnode;
  350. var
  351. paras : tnode;
  352. npara,
  353. ppn : tcallparanode;
  354. dims,
  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,_RKLAMMER);
  367. consume(_RKLAMMER);
  368. if not assigned(paras) then
  369. begin
  370. CGMessage(parser_e_wrong_parameter_size);
  371. exit;
  372. end;
  373. dims:=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,[vsf_must_be_valid]);
  381. inserttypeconv(ppn.left,sinttype);
  382. inc(dims);
  383. ppn:=tcallparanode(ppn.right);
  384. end;
  385. end;
  386. if dims=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,[]);
  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 (dims>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. counter:=dims;
  417. while counter > 1 do
  418. begin
  419. if not(is_dynamic_array(def)) then
  420. begin
  421. CGMessage(parser_e_wrong_parameter_size);
  422. break;
  423. end;
  424. dec(counter);
  425. def := tarraydef(def).elementtype.def;
  426. end;
  427. end;
  428. end;
  429. if isarray then
  430. begin
  431. { create statements with call initialize the arguments and
  432. call fpc_dynarr_setlength }
  433. newblock:=internalstatements(newstatement);
  434. { get temp for array of lengths }
  435. temp := ctempcreatenode.create(sinttype,dims*sinttype.def.size,tt_persistent,false);
  436. addstatement(newstatement,temp);
  437. { load array of lengths }
  438. ppn:=tcallparanode(paras);
  439. counter:=0;
  440. while assigned(ppn.right) do
  441. begin
  442. addstatement(newstatement,cassignmentnode.create(
  443. ctemprefnode.create_offset(temp,counter*sinttype.def.size),
  444. ppn.left));
  445. ppn.left:=nil;
  446. inc(counter);
  447. ppn:=tcallparanode(ppn.right);
  448. end;
  449. { destppn is also reused }
  450. ppn.left:=nil;
  451. { create call to fpc_dynarr_setlength }
  452. npara:=ccallparanode.create(caddrnode.create_internal
  453. (ctemprefnode.create(temp)),
  454. ccallparanode.create(cordconstnode.create
  455. (counter,s32inttype,true),
  456. ccallparanode.create(caddrnode.create_internal
  457. (crttinode.create(tstoreddef(destppn.resulttype.def),initrtti)),
  458. ccallparanode.create(ctypeconvnode.create_internal(destppn,voidpointertype),nil))));
  459. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  460. addstatement(newstatement,ctempdeletenode.create(temp));
  461. { we don't need original the callparanodes tree }
  462. paras.free;
  463. end
  464. else
  465. begin
  466. { we can reuse the supplied parameters }
  467. newblock:=ccallnode.createintern(
  468. 'fpc_'+tstringdef(destppn.resulttype.def).stringtypname+'_setlength',paras);
  469. end;
  470. result.free;
  471. result:=newblock;
  472. end;
  473. function inline_initialize : tnode;
  474. var
  475. newblock,
  476. paras : tnode;
  477. ppn : tcallparanode;
  478. begin
  479. { for easy exiting if something goes wrong }
  480. result := cerrornode.create;
  481. consume(_LKLAMMER);
  482. paras:=parse_paras(false,_RKLAMMER);
  483. consume(_RKLAMMER);
  484. if not assigned(paras) then
  485. begin
  486. CGMessage(parser_e_wrong_parameter_size);
  487. exit;
  488. end;
  489. ppn:=tcallparanode(paras);
  490. { 2 arguments? }
  491. if assigned(ppn.right) then
  492. begin
  493. CGMessage(parser_e_wrong_parameter_size);
  494. paras.free;
  495. exit;
  496. end;
  497. newblock:=initialize_data_node(ppn.left);
  498. ppn.left:=nil;
  499. paras.free;
  500. result.free;
  501. result:=newblock;
  502. end;
  503. function inline_finalize : tnode;
  504. var
  505. newblock,
  506. paras : tnode;
  507. npara,
  508. destppn,
  509. ppn : tcallparanode;
  510. begin
  511. { for easy exiting if something goes wrong }
  512. result := cerrornode.create;
  513. consume(_LKLAMMER);
  514. paras:=parse_paras(false,_RKLAMMER);
  515. consume(_RKLAMMER);
  516. if not assigned(paras) then
  517. begin
  518. CGMessage(parser_e_wrong_parameter_size);
  519. exit;
  520. end;
  521. ppn:=tcallparanode(paras);
  522. { 2 arguments? }
  523. if assigned(ppn.right) then
  524. begin
  525. destppn:=tcallparanode(ppn.right);
  526. { 3 arguments is invalid }
  527. if assigned(destppn.right) then
  528. begin
  529. CGMessage(parser_e_wrong_parameter_size);
  530. paras.free;
  531. exit;
  532. end;
  533. { create call to fpc_finalize_array }
  534. npara:=ccallparanode.create(cordconstnode.create
  535. (destppn.left.resulttype.def.size,s32inttype,true),
  536. ccallparanode.create(ctypeconvnode.create
  537. (ppn.left,s32inttype),
  538. ccallparanode.create(caddrnode.create_internal
  539. (crttinode.create(tstoreddef(destppn.left.resulttype.def),initrtti)),
  540. ccallparanode.create(caddrnode.create_internal
  541. (destppn.left),nil))));
  542. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  543. destppn.left:=nil;
  544. ppn.left:=nil;
  545. end
  546. else
  547. begin
  548. newblock:=finalize_data_node(ppn.left);
  549. ppn.left:=nil;
  550. end;
  551. paras.free;
  552. result.free;
  553. result:=newblock;
  554. end;
  555. function inline_copy : tnode;
  556. var
  557. copynode,
  558. lowppn,
  559. highppn,
  560. npara,
  561. paras : tnode;
  562. ppn : tcallparanode;
  563. paradef : tdef;
  564. counter : integer;
  565. {$ifdef ansistring_bits}
  566. mode : byte;
  567. {$endif ansistring_bits}
  568. begin
  569. { for easy exiting if something goes wrong }
  570. result := cerrornode.create;
  571. consume(_LKLAMMER);
  572. paras:=parse_paras(false,_RKLAMMER);
  573. consume(_RKLAMMER);
  574. if not assigned(paras) then
  575. begin
  576. CGMessage(parser_e_wrong_parameter_size);
  577. exit;
  578. end;
  579. { determine copy function to use based on the first argument,
  580. also count the number of arguments in this loop }
  581. counter:=1;
  582. ppn:=tcallparanode(paras);
  583. while assigned(ppn.right) do
  584. begin
  585. inc(counter);
  586. ppn:=tcallparanode(ppn.right);
  587. end;
  588. paradef:=ppn.left.resulttype.def;
  589. {$ifdef ansistring_bits}
  590. if is_ansistring(paradef) then
  591. case Tstringdef(paradef).string_typ of
  592. st_ansistring16:
  593. mode:=16;
  594. st_ansistring32:
  595. mode:=32;
  596. st_ansistring64:
  597. mode:=64;
  598. end;
  599. if (is_chararray(paradef) and (paradef.size>255)) or
  600. ((cs_ansistrings in aktlocalswitches) and is_pchar(paradef)) then
  601. case aktansistring_bits of
  602. sb_16:
  603. mode:=16;
  604. sb_32:
  605. mode:=32;
  606. sb_64:
  607. mode:=64;
  608. end;
  609. if mode=16 then
  610. copynode:=ccallnode.createintern('fpc_ansistr16_copy',paras)
  611. else if mode=32 then
  612. copynode:=ccallnode.createintern('fpc_ansistr32_copy',paras)
  613. else if mode=64 then
  614. copynode:=ccallnode.createintern('fpc_ansistr64_copy',paras)
  615. {$else}
  616. if is_ansistring(paradef) or
  617. (is_chararray(paradef) and
  618. (paradef.size>255)) or
  619. ((cs_ansistrings in aktlocalswitches) and
  620. is_pchar(paradef)) then
  621. copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
  622. {$endif}
  623. else
  624. if is_widestring(paradef) or
  625. is_widechararray(paradef) or
  626. is_pwidechar(paradef) then
  627. copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
  628. else
  629. if is_char(paradef) then
  630. copynode:=ccallnode.createintern('fpc_char_copy',paras)
  631. else
  632. if is_dynamic_array(paradef) then
  633. begin
  634. { Only allow 1 or 3 arguments }
  635. if (counter<>1) and (counter<>3) then
  636. begin
  637. CGMessage(parser_e_wrong_parameter_size);
  638. exit;
  639. end;
  640. { create statements with call }
  641. if (counter=3) then
  642. begin
  643. highppn:=tcallparanode(paras).left.getcopy;
  644. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  645. end
  646. else
  647. begin
  648. { use special -1,-1 argument to copy the whole array }
  649. highppn:=cordconstnode.create(-1,s32inttype,false);
  650. lowppn:=cordconstnode.create(-1,s32inttype,false);
  651. end;
  652. { create call to fpc_dynarray_copy }
  653. npara:=ccallparanode.create(highppn,
  654. ccallparanode.create(lowppn,
  655. ccallparanode.create(caddrnode.create_internal
  656. (crttinode.create(tstoreddef(ppn.left.resulttype.def),initrtti)),
  657. ccallparanode.create
  658. (ctypeconvnode.create_internal(ppn.left,voidpointertype),nil))));
  659. copynode:=ccallnode.createinternres('fpc_dynarray_copy',npara,ppn.left.resulttype);
  660. ppn.left:=nil;
  661. paras.free;
  662. end
  663. else
  664. begin
  665. { generic fallback that will give an error if a wrong
  666. type is passed }
  667. copynode:=ccallnode.createintern('fpc_shortstr_copy',paras)
  668. end;
  669. result.free;
  670. result:=copynode;
  671. end;
  672. end.