pinline.pas 27 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_initialize : tnode;
  30. function inline_finalize : tnode;
  31. function inline_copy : tnode;
  32. implementation
  33. uses
  34. { common }
  35. cutils,
  36. { global }
  37. globtype,tokens,verbose,
  38. systems,
  39. { symtable }
  40. symconst,symdef,symsym,symtable,defutil,
  41. { pass 1 }
  42. pass_1,htypechk,
  43. nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  44. { parser }
  45. scanner,
  46. pbase,pexpr,
  47. { codegen }
  48. cgbase
  49. ;
  50. function new_dispose_statement(is_new:boolean) : tnode;
  51. var
  52. newstatement : tstatementnode;
  53. temp : ttempcreatenode;
  54. para : tcallparanode;
  55. p,p2 : tnode;
  56. again : boolean; { dummy for do_proc_call }
  57. destructorname : stringid;
  58. sym : tsym;
  59. classh : tobjectdef;
  60. callflag : tcallnodeflag;
  61. destructorpos,
  62. storepos : tfileposinfo;
  63. begin
  64. consume(_LKLAMMER);
  65. p:=comp_expr(true);
  66. { calc return type }
  67. if is_new then
  68. set_varstate(p,vs_assigned,false)
  69. else
  70. set_varstate(p,vs_used,true);
  71. { constructor,destructor specified }
  72. if try_to_consume(_COMMA) then
  73. begin
  74. { extended syntax of new and dispose }
  75. { function styled new is handled in factor }
  76. { destructors have no parameters }
  77. destructorname:=pattern;
  78. destructorpos:=akttokenpos;
  79. consume(_ID);
  80. if (p.resulttype.def.deftype<>pointerdef) then
  81. begin
  82. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  83. p.free;
  84. p:=factor(false);
  85. p.free;
  86. consume(_RKLAMMER);
  87. new_dispose_statement:=cerrornode.create;
  88. exit;
  89. end;
  90. { first parameter must be an object or class }
  91. if tpointerdef(p.resulttype.def).pointertype.def.deftype<>objectdef then
  92. begin
  93. Message(parser_e_pointer_to_class_expected);
  94. p.free;
  95. new_dispose_statement:=factor(false);
  96. consume_all_until(_RKLAMMER);
  97. consume(_RKLAMMER);
  98. exit;
  99. end;
  100. { check, if the first parameter is a pointer to a _class_ }
  101. classh:=tobjectdef(tpointerdef(p.resulttype.def).pointertype.def);
  102. if is_class(classh) then
  103. begin
  104. Message(parser_e_no_new_or_dispose_for_classes);
  105. new_dispose_statement:=factor(false);
  106. consume_all_until(_RKLAMMER);
  107. consume(_RKLAMMER);
  108. exit;
  109. end;
  110. { search cons-/destructor, also in parent classes }
  111. storepos:=akttokenpos;
  112. akttokenpos:=destructorpos;
  113. sym:=search_class_member(classh,destructorname);
  114. akttokenpos:=storepos;
  115. { the second parameter of new/dispose must be a call }
  116. { to a cons-/destructor }
  117. if (not assigned(sym)) or (sym.typ<>procsym) then
  118. begin
  119. if is_new then
  120. Message(parser_e_expr_have_to_be_constructor_call)
  121. else
  122. Message(parser_e_expr_have_to_be_destructor_call);
  123. p.free;
  124. new_dispose_statement:=cerrornode.create;
  125. end
  126. else
  127. begin
  128. { For new(var,constructor) we need to take a copy because
  129. p is also used in the assignmentn below }
  130. if is_new then
  131. p2:=cderefnode.create(p.getcopy)
  132. else
  133. p2:=cderefnode.create(p);
  134. do_resulttypepass(p2);
  135. if is_new then
  136. callflag:=cnf_new_call
  137. else
  138. callflag:=cnf_dispose_call;
  139. if is_new then
  140. do_member_read(classh,false,sym,p2,again,[callflag])
  141. else
  142. begin
  143. if not(m_fpc in aktmodeswitches) then
  144. do_member_read(classh,false,sym,p2,again,[callflag])
  145. else
  146. begin
  147. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2,[callflag]);
  148. { support dispose(p,done()); }
  149. if try_to_consume(_LKLAMMER) then
  150. begin
  151. if not try_to_consume(_RKLAMMER) then
  152. begin
  153. Message(parser_e_no_paras_for_destructor);
  154. consume_all_until(_RKLAMMER);
  155. consume(_RKLAMMER);
  156. end;
  157. end;
  158. end;
  159. end;
  160. { we need the real called method }
  161. do_resulttypepass(p2);
  162. if (p2.nodetype=calln) and
  163. assigned(tcallnode(p2).procdefinition) then
  164. begin
  165. if is_new then
  166. begin
  167. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  168. Message(parser_e_expr_have_to_be_constructor_call);
  169. p2.resulttype:=p.resulttype;
  170. p2:=cassignmentnode.create(p,p2);
  171. end
  172. else
  173. begin
  174. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  175. Message(parser_e_expr_have_to_be_destructor_call);
  176. end;
  177. end
  178. else
  179. begin
  180. if is_new then
  181. CGMessage(parser_e_expr_have_to_be_constructor_call)
  182. else
  183. CGMessage(parser_e_expr_have_to_be_destructor_call);
  184. end;
  185. result:=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);
  212. if is_new then
  213. begin
  214. { create temp for result }
  215. temp := ctempcreatenode.create(p.resulttype,p.resulttype.def.size,tt_persistent,true);
  216. addstatement(newstatement,temp);
  217. { create call to fpc_getmem }
  218. para := ccallparanode.create(cordconstnode.create
  219. (tpointerdef(p.resulttype.def).pointertype.def.size,s32inttype,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(cderefnode.create(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);
  284. { create temp for result }
  285. temp := ctempcreatenode.create(p1.resulttype,p1.resulttype.def.size,tt_persistent,true);
  286. addstatement(newstatement,temp);
  287. { create call to fpc_getmem }
  288. para := ccallparanode.create(cordconstnode.create
  289. (tpointerdef(p1.resulttype.def).pointertype.def.size,s32inttype,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_internal(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,[cnf_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. dims,
  356. counter : integer;
  357. isarray : boolean;
  358. def : tdef;
  359. destppn : tnode;
  360. newstatement : tstatementnode;
  361. temp : ttempcreatenode;
  362. newblock : tnode;
  363. begin
  364. { for easy exiting if something goes wrong }
  365. result := cerrornode.create;
  366. consume(_LKLAMMER);
  367. paras:=parse_paras(false,false);
  368. consume(_RKLAMMER);
  369. if not assigned(paras) then
  370. begin
  371. CGMessage(parser_e_wrong_parameter_size);
  372. exit;
  373. end;
  374. dims:=0;
  375. if assigned(paras) then
  376. begin
  377. { check type of lengths }
  378. ppn:=tcallparanode(paras);
  379. while assigned(ppn.right) do
  380. begin
  381. set_varstate(ppn.left,vs_used,true);
  382. inserttypeconv(ppn.left,sinttype);
  383. inc(dims);
  384. ppn:=tcallparanode(ppn.right);
  385. end;
  386. end;
  387. if dims=0 then
  388. begin
  389. CGMessage(parser_e_wrong_parameter_size);
  390. paras.free;
  391. exit;
  392. end;
  393. { last param must be var }
  394. destppn:=ppn.left;
  395. inc(parsing_para_level);
  396. valid_for_var(destppn);
  397. set_varstate(destppn,vs_assigned,false);
  398. dec(parsing_para_level);
  399. { first param must be a string or dynamic array ...}
  400. isarray:=is_dynamic_array(destppn.resulttype.def);
  401. if not((destppn.resulttype.def.deftype=stringdef) or
  402. isarray) then
  403. begin
  404. CGMessage(type_e_mismatch);
  405. paras.free;
  406. exit;
  407. end;
  408. { only dynamic arrays accept more dimensions }
  409. if (dims>1) then
  410. begin
  411. if (not isarray) then
  412. CGMessage(type_e_mismatch)
  413. else
  414. begin
  415. { check if the amount of dimensions is valid }
  416. def := tarraydef(destppn.resulttype.def).elementtype.def;
  417. counter:=dims;
  418. while counter > 1 do
  419. begin
  420. if not(is_dynamic_array(def)) then
  421. begin
  422. CGMessage(parser_e_wrong_parameter_size);
  423. break;
  424. end;
  425. dec(counter);
  426. def := tarraydef(def).elementtype.def;
  427. end;
  428. end;
  429. end;
  430. if isarray then
  431. begin
  432. { create statements with call initialize the arguments and
  433. call fpc_dynarr_setlength }
  434. newblock:=internalstatements(newstatement);
  435. { get temp for array of lengths }
  436. temp := ctempcreatenode.create(sinttype,dims*sinttype.def.size,tt_persistent,false);
  437. addstatement(newstatement,temp);
  438. { load array of lengths }
  439. ppn:=tcallparanode(paras);
  440. counter:=0;
  441. while assigned(ppn.right) do
  442. begin
  443. addstatement(newstatement,cassignmentnode.create(
  444. ctemprefnode.create_offset(temp,counter*sinttype.def.size),
  445. ppn.left));
  446. ppn.left:=nil;
  447. inc(counter);
  448. ppn:=tcallparanode(ppn.right);
  449. end;
  450. { destppn is also reused }
  451. ppn.left:=nil;
  452. { create call to fpc_dynarr_setlength }
  453. npara:=ccallparanode.create(caddrnode.create_internal
  454. (ctemprefnode.create(temp)),
  455. ccallparanode.create(cordconstnode.create
  456. (counter,s32inttype,true),
  457. ccallparanode.create(caddrnode.create_internal
  458. (crttinode.create(tstoreddef(destppn.resulttype.def),initrtti)),
  459. ccallparanode.create(ctypeconvnode.create_internal(destppn,voidpointertype),nil))));
  460. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  461. addstatement(newstatement,ctempdeletenode.create(temp));
  462. { we don't need original the callparanodes tree }
  463. paras.free;
  464. end
  465. else
  466. begin
  467. { we can reuse the supplied parameters }
  468. newblock:=ccallnode.createintern(
  469. 'fpc_'+tstringdef(destppn.resulttype.def).stringtypname+'_setlength',paras);
  470. end;
  471. result.free;
  472. result:=newblock;
  473. end;
  474. function inline_initialize : tnode;
  475. var
  476. newblock,
  477. paras : tnode;
  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. CGMessage(parser_e_wrong_parameter_size);
  495. paras.free;
  496. exit;
  497. end;
  498. newblock:=initialize_data_node(ppn.left);
  499. ppn.left:=nil;
  500. paras.free;
  501. result.free;
  502. result:=newblock;
  503. end;
  504. function inline_finalize : tnode;
  505. var
  506. newblock,
  507. paras : tnode;
  508. npara,
  509. destppn,
  510. ppn : tcallparanode;
  511. begin
  512. { for easy exiting if something goes wrong }
  513. result := cerrornode.create;
  514. consume(_LKLAMMER);
  515. paras:=parse_paras(false,false);
  516. consume(_RKLAMMER);
  517. if not assigned(paras) then
  518. begin
  519. CGMessage(parser_e_wrong_parameter_size);
  520. exit;
  521. end;
  522. ppn:=tcallparanode(paras);
  523. { 2 arguments? }
  524. if assigned(ppn.right) then
  525. begin
  526. destppn:=tcallparanode(ppn.right);
  527. { 3 arguments is invalid }
  528. if assigned(destppn.right) then
  529. begin
  530. CGMessage(parser_e_wrong_parameter_size);
  531. paras.free;
  532. exit;
  533. end;
  534. { create call to fpc_finalize_array }
  535. npara:=ccallparanode.create(cordconstnode.create
  536. (destppn.left.resulttype.def.size,s32inttype,true),
  537. ccallparanode.create(ctypeconvnode.create
  538. (ppn.left,s32inttype),
  539. ccallparanode.create(caddrnode.create_internal
  540. (crttinode.create(tstoreddef(destppn.left.resulttype.def),initrtti)),
  541. ccallparanode.create(caddrnode.create_internal
  542. (destppn.left),nil))));
  543. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  544. destppn.left:=nil;
  545. ppn.left:=nil;
  546. end
  547. else
  548. begin
  549. newblock:=finalize_data_node(ppn.left);
  550. ppn.left:=nil;
  551. end;
  552. paras.free;
  553. result.free;
  554. result:=newblock;
  555. end;
  556. function inline_copy : tnode;
  557. var
  558. copynode,
  559. lowppn,
  560. highppn,
  561. npara,
  562. paras : tnode;
  563. temp : ttempcreatenode;
  564. ppn : tcallparanode;
  565. paradef : tdef;
  566. counter : integer;
  567. newstatement : tstatementnode;
  568. {$ifdef ansistring_bits}
  569. mode : byte;
  570. {$endif ansistring_bits}
  571. begin
  572. { for easy exiting if something goes wrong }
  573. result := cerrornode.create;
  574. consume(_LKLAMMER);
  575. paras:=parse_paras(false,false);
  576. consume(_RKLAMMER);
  577. if not assigned(paras) then
  578. begin
  579. CGMessage(parser_e_wrong_parameter_size);
  580. exit;
  581. end;
  582. { determine copy function to use based on the first argument,
  583. also count the number of arguments in this loop }
  584. counter:=1;
  585. ppn:=tcallparanode(paras);
  586. while assigned(ppn.right) do
  587. begin
  588. inc(counter);
  589. ppn:=tcallparanode(ppn.right);
  590. end;
  591. paradef:=ppn.left.resulttype.def;
  592. {$ifdef ansistring_bits}
  593. if is_ansistring(paradef) then
  594. case Tstringdef(paradef).string_typ of
  595. st_ansistring16:
  596. mode:=16;
  597. st_ansistring32:
  598. mode:=32;
  599. st_ansistring64:
  600. mode:=64;
  601. end;
  602. if (is_chararray(paradef) and (paradef.size>255)) or
  603. ((cs_ansistrings in aktlocalswitches) and is_pchar(paradef)) then
  604. case aktansistring_bits of
  605. sb_16:
  606. mode:=16;
  607. sb_32:
  608. mode:=32;
  609. sb_64:
  610. mode:=64;
  611. end;
  612. if mode=16 then
  613. copynode:=ccallnode.createintern('fpc_ansistr16_copy',paras)
  614. else if mode=32 then
  615. copynode:=ccallnode.createintern('fpc_ansistr32_copy',paras)
  616. else if mode=64 then
  617. copynode:=ccallnode.createintern('fpc_ansistr64_copy',paras)
  618. {$else}
  619. if is_ansistring(paradef) or
  620. (is_chararray(paradef) and
  621. (paradef.size>255)) or
  622. ((cs_ansistrings in aktlocalswitches) and
  623. is_pchar(paradef)) then
  624. copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
  625. {$endif}
  626. else
  627. if is_widestring(paradef) or
  628. is_widechararray(paradef) or
  629. is_pwidechar(paradef) then
  630. copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
  631. else
  632. if is_char(paradef) then
  633. copynode:=ccallnode.createintern('fpc_char_copy',paras)
  634. else
  635. if is_dynamic_array(paradef) then
  636. begin
  637. { Only allow 1 or 3 arguments }
  638. if (counter<>1) and (counter<>3) then
  639. begin
  640. CGMessage(parser_e_wrong_parameter_size);
  641. exit;
  642. end;
  643. { create statements with call }
  644. copynode:=internalstatements(newstatement);
  645. if (counter=3) then
  646. begin
  647. highppn:=tcallparanode(paras).left.getcopy;
  648. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  649. end
  650. else
  651. begin
  652. { use special -1,-1 argument to copy the whole array }
  653. highppn:=cordconstnode.create(-1,s32inttype,false);
  654. lowppn:=cordconstnode.create(-1,s32inttype,false);
  655. end;
  656. { create typed temp for result so the temp is finalized }
  657. temp := ctempcreatenode.create(ppn.left.resulttype,ppn.left.resulttype.def.size,tt_persistent,false);
  658. addstatement(newstatement,temp);
  659. { create call to fpc_dynarray_copy }
  660. npara:=ccallparanode.create(highppn,
  661. ccallparanode.create(lowppn,
  662. ccallparanode.create(caddrnode.create_internal
  663. (crttinode.create(tstoreddef(ppn.left.resulttype.def),initrtti)),
  664. ccallparanode.create
  665. (ctypeconvnode.create_internal(ppn.left,voidpointertype),
  666. ccallparanode.create
  667. (ctypeconvnode.create_internal(ctemprefnode.create(temp),voidpointertype),nil)))));
  668. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_copy',npara));
  669. { convert the temp to normal and return the reference to the
  670. created temp, and convert the type of the temp to the dynarray type }
  671. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  672. addstatement(newstatement,ctemprefnode.create(temp));
  673. ppn.left:=nil;
  674. paras.free;
  675. end
  676. else
  677. begin
  678. { generic fallback that will give an error if a wrong
  679. type is passed }
  680. copynode:=ccallnode.createintern('fpc_shortstr_copy',paras)
  681. end;
  682. result.free;
  683. result:=copynode;
  684. end;
  685. end.
  686. {
  687. $Log$
  688. Revision 1.40 2005-03-03 19:36:42 jonas
  689. * fixed web bug 3740
  690. Revision 1.39 2005/02/14 17:13:07 peter
  691. * truncate log
  692. }