pinline.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. {$ifdef delphi}
  35. SysUtils,
  36. {$endif}
  37. { common }
  38. cutils,
  39. { global }
  40. globtype,tokens,verbose,
  41. systems,
  42. { symtable }
  43. symconst,symdef,symsym,symtable,defutil,
  44. { pass 1 }
  45. pass_1,htypechk,
  46. nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  47. { parser }
  48. scanner,
  49. pbase,pexpr,
  50. { codegen }
  51. cgbase
  52. ;
  53. function new_dispose_statement(is_new:boolean) : tnode;
  54. var
  55. newstatement : tstatementnode;
  56. temp : ttempcreatenode;
  57. para : tcallparanode;
  58. p,p2 : tnode;
  59. again : boolean; { dummy for do_proc_call }
  60. destructorname : stringid;
  61. sym : tsym;
  62. classh : tobjectdef;
  63. callflag : tcallnodeflag;
  64. destructorpos,
  65. storepos : tfileposinfo;
  66. begin
  67. consume(_LKLAMMER);
  68. p:=comp_expr(true);
  69. { calc return type }
  70. if is_new then
  71. set_varstate(p,vs_assigned,false)
  72. else
  73. set_varstate(p,vs_used,true);
  74. { constructor,destructor specified }
  75. if try_to_consume(_COMMA) then
  76. begin
  77. { extended syntax of new and dispose }
  78. { function styled new is handled in factor }
  79. { destructors have no parameters }
  80. destructorname:=pattern;
  81. destructorpos:=akttokenpos;
  82. consume(_ID);
  83. if (p.resulttype.def.deftype<>pointerdef) then
  84. begin
  85. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  86. p.free;
  87. p:=factor(false);
  88. p.free;
  89. consume(_RKLAMMER);
  90. new_dispose_statement:=cerrornode.create;
  91. exit;
  92. end;
  93. { first parameter must be an object or class }
  94. if tpointerdef(p.resulttype.def).pointertype.def.deftype<>objectdef then
  95. begin
  96. Message(parser_e_pointer_to_class_expected);
  97. p.free;
  98. new_dispose_statement:=factor(false);
  99. consume_all_until(_RKLAMMER);
  100. consume(_RKLAMMER);
  101. exit;
  102. end;
  103. { check, if the first parameter is a pointer to a _class_ }
  104. classh:=tobjectdef(tpointerdef(p.resulttype.def).pointertype.def);
  105. if is_class(classh) then
  106. begin
  107. Message(parser_e_no_new_or_dispose_for_classes);
  108. new_dispose_statement:=factor(false);
  109. consume_all_until(_RKLAMMER);
  110. consume(_RKLAMMER);
  111. exit;
  112. end;
  113. { search cons-/destructor, also in parent classes }
  114. storepos:=akttokenpos;
  115. akttokenpos:=destructorpos;
  116. sym:=search_class_member(classh,destructorname);
  117. akttokenpos:=storepos;
  118. { the second parameter of new/dispose must be a call }
  119. { to a cons-/destructor }
  120. if (not assigned(sym)) or (sym.typ<>procsym) then
  121. begin
  122. if is_new then
  123. Message(parser_e_expr_have_to_be_constructor_call)
  124. else
  125. Message(parser_e_expr_have_to_be_destructor_call);
  126. p.free;
  127. new_dispose_statement:=cerrornode.create;
  128. end
  129. else
  130. begin
  131. { For new(var,constructor) we need to take a copy because
  132. p is also used in the assignmentn below }
  133. if is_new then
  134. p2:=cderefnode.create(p.getcopy)
  135. else
  136. p2:=cderefnode.create(p);
  137. do_resulttypepass(p2);
  138. if is_new then
  139. callflag:=cnf_new_call
  140. else
  141. callflag:=cnf_dispose_call;
  142. if is_new then
  143. do_member_read(classh,false,sym,p2,again,[callflag])
  144. else
  145. begin
  146. if not(m_fpc in aktmodeswitches) then
  147. do_member_read(classh,false,sym,p2,again,[callflag])
  148. else
  149. begin
  150. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2,[callflag]);
  151. { support dispose(p,done()); }
  152. if try_to_consume(_LKLAMMER) then
  153. begin
  154. if not try_to_consume(_RKLAMMER) then
  155. begin
  156. Message(parser_e_no_paras_for_destructor);
  157. consume_all_until(_RKLAMMER);
  158. consume(_RKLAMMER);
  159. end;
  160. end;
  161. end;
  162. end;
  163. { we need the real called method }
  164. do_resulttypepass(p2);
  165. if (p2.nodetype=calln) then
  166. begin
  167. if is_new then
  168. begin
  169. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  170. Message(parser_e_expr_have_to_be_constructor_call);
  171. p2.resulttype:=p.resulttype;
  172. p2:=cassignmentnode.create(p,p2);
  173. end
  174. else
  175. begin
  176. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  177. Message(parser_e_expr_have_to_be_destructor_call);
  178. end;
  179. end
  180. else
  181. begin
  182. if is_new then
  183. CGMessage(parser_e_expr_have_to_be_constructor_call)
  184. else
  185. CGMessage(parser_e_expr_have_to_be_destructor_call);
  186. end;
  187. result:=p2;
  188. end;
  189. end
  190. else
  191. begin
  192. if (p.resulttype.def.deftype<>pointerdef) then
  193. Begin
  194. Message1(type_e_pointer_type_expected,p.resulttype.def.typename);
  195. new_dispose_statement:=cerrornode.create;
  196. end
  197. else
  198. begin
  199. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=objectdef) and
  200. (oo_has_vmt in tobjectdef(tpointerdef(p.resulttype.def).pointertype.def).objectoptions) then
  201. Message(parser_w_use_extended_syntax_for_objects);
  202. if (tpointerdef(p.resulttype.def).pointertype.def.deftype=orddef) and
  203. (torddef(tpointerdef(p.resulttype.def).pointertype.def).typ=uvoid) then
  204. begin
  205. if (m_tp7 in aktmodeswitches) or
  206. (m_delphi in aktmodeswitches) then
  207. Message(parser_w_no_new_dispose_on_void_pointers)
  208. else
  209. Message(parser_e_no_new_dispose_on_void_pointers);
  210. end;
  211. { create statements with call to getmem+initialize or
  212. finalize+freemem }
  213. new_dispose_statement:=internalstatements(newstatement);
  214. if is_new then
  215. begin
  216. { create temp for result }
  217. temp := ctempcreatenode.create_reg(p.resulttype,p.resulttype.def.size,tt_persistent);
  218. addstatement(newstatement,temp);
  219. { create call to fpc_getmem }
  220. para := ccallparanode.create(cordconstnode.create
  221. (tpointerdef(p.resulttype.def).pointertype.def.size,s32inttype,true),nil);
  222. addstatement(newstatement,cassignmentnode.create(
  223. ctemprefnode.create(temp),
  224. ccallnode.createintern('fpc_getmem',para)));
  225. { create call to fpc_initialize }
  226. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  227. addstatement(newstatement,initialize_data_node(cderefnode.create(ctemprefnode.create(temp))));
  228. { copy the temp to the destination }
  229. addstatement(newstatement,cassignmentnode.create(
  230. p,
  231. ctemprefnode.create(temp)));
  232. { release temp }
  233. addstatement(newstatement,ctempdeletenode.create(temp));
  234. end
  235. else
  236. begin
  237. { create call to fpc_finalize }
  238. if tpointerdef(p.resulttype.def).pointertype.def.needs_inittable then
  239. addstatement(newstatement,finalize_data_node(cderefnode.create(p.getcopy)));
  240. { create call to fpc_freemem }
  241. para := ccallparanode.create(p,nil);
  242. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  243. end;
  244. end;
  245. end;
  246. consume(_RKLAMMER);
  247. end;
  248. function new_function : tnode;
  249. var
  250. newstatement : tstatementnode;
  251. newblock : tblocknode;
  252. temp : ttempcreatenode;
  253. para : tcallparanode;
  254. p1,p2 : tnode;
  255. classh : tobjectdef;
  256. sym : tsym;
  257. again : boolean; { dummy for do_proc_call }
  258. begin
  259. consume(_LKLAMMER);
  260. p1:=factor(false);
  261. if p1.nodetype<>typen then
  262. begin
  263. Message(type_e_type_id_expected);
  264. consume_all_until(_RKLAMMER);
  265. consume(_RKLAMMER);
  266. p1.destroy;
  267. new_function:=cerrornode.create;
  268. exit;
  269. end;
  270. if (p1.resulttype.def.deftype<>pointerdef) then
  271. begin
  272. Message1(type_e_pointer_type_expected,p1.resulttype.def.typename);
  273. consume_all_until(_RKLAMMER);
  274. consume(_RKLAMMER);
  275. p1.destroy;
  276. new_function:=cerrornode.create;
  277. exit;
  278. end;
  279. if try_to_consume(_RKLAMMER) then
  280. begin
  281. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=objectdef) and
  282. (oo_has_vmt in tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def).objectoptions) then
  283. Message(parser_w_use_extended_syntax_for_objects);
  284. { create statements with call to getmem+initialize }
  285. newblock:=internalstatements(newstatement);
  286. { create temp for result }
  287. temp := ctempcreatenode.create_reg(p1.resulttype,p1.resulttype.def.size,tt_persistent);
  288. addstatement(newstatement,temp);
  289. { create call to fpc_getmem }
  290. para := ccallparanode.create(cordconstnode.create
  291. (tpointerdef(p1.resulttype.def).pointertype.def.size,s32inttype,true),nil);
  292. addstatement(newstatement,cassignmentnode.create(
  293. ctemprefnode.create(temp),
  294. ccallnode.createintern('fpc_getmem',para)));
  295. { create call to fpc_initialize }
  296. if tpointerdef(p1.resulttype.def).pointertype.def.needs_inittable then
  297. begin
  298. para := ccallparanode.create(caddrnode.create(crttinode.create
  299. (tstoreddef(tpointerdef(p1.resulttype.def).pointertype.def),initrtti)),
  300. ccallparanode.create(ctemprefnode.create
  301. (temp),nil));
  302. addstatement(newstatement,ccallnode.createintern('fpc_initialize',para));
  303. end;
  304. { the last statement should return the value as
  305. location and type, this is done be referencing the
  306. temp and converting it first from a persistent temp to
  307. normal temp }
  308. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  309. addstatement(newstatement,ctemprefnode.create(temp));
  310. p1.destroy;
  311. p1:=newblock;
  312. end
  313. else
  314. begin
  315. consume(_COMMA);
  316. if tpointerdef(p1.resulttype.def).pointertype.def.deftype<>objectdef then
  317. begin
  318. Message(parser_e_pointer_to_class_expected);
  319. consume_all_until(_RKLAMMER);
  320. consume(_RKLAMMER);
  321. p1.destroy;
  322. new_function:=cerrornode.create;
  323. exit;
  324. end;
  325. classh:=tobjectdef(tpointerdef(p1.resulttype.def).pointertype.def);
  326. { use the objectdef for loading the VMT }
  327. p2:=p1;
  328. p1:=ctypenode.create(tpointerdef(p1.resulttype.def).pointertype);
  329. do_resulttypepass(p1);
  330. { search the constructor also in the symbol tables of
  331. the parents }
  332. afterassignment:=false;
  333. sym:=searchsym_in_class(classh,pattern);
  334. consume(_ID);
  335. do_member_read(classh,false,sym,p1,again,[cnf_new_call]);
  336. { we need to know which procedure is called }
  337. do_resulttypepass(p1);
  338. if not(
  339. (p1.nodetype=calln) and
  340. assigned(tcallnode(p1).procdefinition) and
  341. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  342. ) then
  343. Message(parser_e_expr_have_to_be_constructor_call);
  344. { constructors return boolean, update resulttype to return
  345. the pointer to the object }
  346. p1.resulttype:=p2.resulttype;
  347. p2.free;
  348. consume(_RKLAMMER);
  349. end;
  350. new_function:=p1;
  351. end;
  352. function inline_setlength : tnode;
  353. var
  354. paras : tnode;
  355. npara,
  356. ppn : tcallparanode;
  357. dims,
  358. counter : integer;
  359. isarray : boolean;
  360. def : tdef;
  361. destppn : tnode;
  362. newstatement : tstatementnode;
  363. temp : ttempcreatenode;
  364. newblock : tnode;
  365. begin
  366. { for easy exiting if something goes wrong }
  367. result := cerrornode.create;
  368. consume(_LKLAMMER);
  369. paras:=parse_paras(false,false);
  370. consume(_RKLAMMER);
  371. if not assigned(paras) then
  372. begin
  373. CGMessage(parser_e_wrong_parameter_size);
  374. exit;
  375. end;
  376. dims:=0;
  377. if assigned(paras) then
  378. begin
  379. { check type of lengths }
  380. ppn:=tcallparanode(paras);
  381. while assigned(ppn.right) do
  382. begin
  383. set_varstate(ppn.left,vs_used,true);
  384. inserttypeconv(ppn.left,s32inttype);
  385. inc(dims);
  386. ppn:=tcallparanode(ppn.right);
  387. end;
  388. end;
  389. if dims=0 then
  390. begin
  391. CGMessage(parser_e_wrong_parameter_size);
  392. paras.free;
  393. exit;
  394. end;
  395. { last param must be var }
  396. destppn:=ppn.left;
  397. inc(parsing_para_level);
  398. valid_for_var(destppn);
  399. set_varstate(destppn,vs_assigned,false);
  400. dec(parsing_para_level);
  401. { first param must be a string or dynamic array ...}
  402. isarray:=is_dynamic_array(destppn.resulttype.def);
  403. if not((destppn.resulttype.def.deftype=stringdef) or
  404. isarray) then
  405. begin
  406. CGMessage(type_e_mismatch);
  407. paras.free;
  408. exit;
  409. end;
  410. { only dynamic arrays accept more dimensions }
  411. if (dims>1) then
  412. begin
  413. if (not isarray) then
  414. CGMessage(type_e_mismatch)
  415. else
  416. begin
  417. { check if the amount of dimensions is valid }
  418. def := tarraydef(destppn.resulttype.def).elementtype.def;
  419. counter:=dims;
  420. while counter > 1 do
  421. begin
  422. if not(is_dynamic_array(def)) then
  423. begin
  424. CGMessage(parser_e_wrong_parameter_size);
  425. break;
  426. end;
  427. dec(counter);
  428. def := tarraydef(def).elementtype.def;
  429. end;
  430. end;
  431. end;
  432. if isarray then
  433. begin
  434. { create statements with call initialize the arguments and
  435. call fpc_dynarr_setlength }
  436. newblock:=internalstatements(newstatement);
  437. { get temp for array of lengths }
  438. temp := ctempcreatenode.create(s32inttype,dims*s32inttype.def.size,tt_persistent);
  439. addstatement(newstatement,temp);
  440. { load array of lengths }
  441. ppn:=tcallparanode(paras);
  442. counter:=0;
  443. while assigned(ppn.right) do
  444. begin
  445. addstatement(newstatement,cassignmentnode.create(
  446. ctemprefnode.create_offset(temp,counter*s32inttype.def.size),
  447. ppn.left));
  448. ppn.left:=nil;
  449. inc(counter);
  450. ppn:=tcallparanode(ppn.right);
  451. end;
  452. { destppn is also reused }
  453. ppn.left:=nil;
  454. { create call to fpc_dynarr_setlength }
  455. npara:=ccallparanode.create(caddrnode.create
  456. (ctemprefnode.create(temp)),
  457. ccallparanode.create(cordconstnode.create
  458. (counter,s32inttype,true),
  459. ccallparanode.create(caddrnode.create
  460. (crttinode.create(tstoreddef(destppn.resulttype.def),initrtti)),
  461. ccallparanode.create(ctypeconvnode.create_explicit(destppn,voidpointertype),nil))));
  462. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',npara));
  463. addstatement(newstatement,ctempdeletenode.create(temp));
  464. { we don't need original the callparanodes tree }
  465. paras.free;
  466. end
  467. else
  468. begin
  469. { we can reuse the supplied parameters }
  470. newblock:=ccallnode.createintern(
  471. 'fpc_'+tstringdef(destppn.resulttype.def).stringtypname+'_setlength',paras);
  472. end;
  473. result.free;
  474. result:=newblock;
  475. end;
  476. function inline_initialize : tnode;
  477. var
  478. newblock,
  479. paras : tnode;
  480. ppn : tcallparanode;
  481. begin
  482. { for easy exiting if something goes wrong }
  483. result := cerrornode.create;
  484. consume(_LKLAMMER);
  485. paras:=parse_paras(false,false);
  486. consume(_RKLAMMER);
  487. if not assigned(paras) then
  488. begin
  489. CGMessage(parser_e_wrong_parameter_size);
  490. exit;
  491. end;
  492. ppn:=tcallparanode(paras);
  493. { 2 arguments? }
  494. if assigned(ppn.right) then
  495. begin
  496. CGMessage(parser_e_wrong_parameter_size);
  497. paras.free;
  498. exit;
  499. end;
  500. newblock:=initialize_data_node(ppn.left);
  501. ppn.left:=nil;
  502. paras.free;
  503. result.free;
  504. result:=newblock;
  505. end;
  506. function inline_finalize : tnode;
  507. var
  508. newblock,
  509. paras : tnode;
  510. npara,
  511. destppn,
  512. ppn : tcallparanode;
  513. begin
  514. { for easy exiting if something goes wrong }
  515. result := cerrornode.create;
  516. consume(_LKLAMMER);
  517. paras:=parse_paras(false,false);
  518. consume(_RKLAMMER);
  519. if not assigned(paras) then
  520. begin
  521. CGMessage(parser_e_wrong_parameter_size);
  522. exit;
  523. end;
  524. ppn:=tcallparanode(paras);
  525. { 2 arguments? }
  526. if assigned(ppn.right) then
  527. begin
  528. destppn:=tcallparanode(ppn.right);
  529. { 3 arguments is invalid }
  530. if assigned(destppn.right) then
  531. begin
  532. CGMessage(parser_e_wrong_parameter_size);
  533. paras.free;
  534. exit;
  535. end;
  536. { create call to fpc_finalize_array }
  537. npara:=ccallparanode.create(cordconstnode.create
  538. (destppn.left.resulttype.def.size,s32inttype,true),
  539. ccallparanode.create(ctypeconvnode.create
  540. (ppn.left,s32inttype),
  541. ccallparanode.create(caddrnode.create
  542. (crttinode.create(tstoreddef(destppn.left.resulttype.def),initrtti)),
  543. ccallparanode.create(caddrnode.create
  544. (destppn.left),nil))));
  545. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  546. destppn.left:=nil;
  547. ppn.left:=nil;
  548. end
  549. else
  550. begin
  551. newblock:=finalize_data_node(ppn.left);
  552. ppn.left:=nil;
  553. end;
  554. paras.free;
  555. result.free;
  556. result:=newblock;
  557. end;
  558. function inline_copy : tnode;
  559. var
  560. copynode,
  561. lowppn,
  562. highppn,
  563. npara,
  564. paras : tnode;
  565. temp : ttempcreatenode;
  566. ppn : tcallparanode;
  567. paradef : tdef;
  568. counter : integer;
  569. newstatement : tstatementnode;
  570. {$ifdef ansistring_bits}
  571. mode : byte;
  572. {$endif ansistring_bits}
  573. begin
  574. { for easy exiting if something goes wrong }
  575. result := cerrornode.create;
  576. consume(_LKLAMMER);
  577. paras:=parse_paras(false,false);
  578. consume(_RKLAMMER);
  579. if not assigned(paras) then
  580. begin
  581. CGMessage(parser_e_wrong_parameter_size);
  582. exit;
  583. end;
  584. { determine copy function to use based on the first argument,
  585. also count the number of arguments in this loop }
  586. counter:=1;
  587. ppn:=tcallparanode(paras);
  588. while assigned(ppn.right) do
  589. begin
  590. inc(counter);
  591. ppn:=tcallparanode(ppn.right);
  592. end;
  593. paradef:=ppn.left.resulttype.def;
  594. {$ifdef ansistring_bits}
  595. if is_ansistring(paradef) then
  596. case Tstringdef(paradef).string_typ of
  597. st_ansistring16:
  598. mode:=16;
  599. st_ansistring32:
  600. mode:=32;
  601. st_ansistring64:
  602. mode:=64;
  603. end;
  604. if (is_chararray(paradef) and (paradef.size>255)) or
  605. ((cs_ansistrings in aktlocalswitches) and is_pchar(paradef)) then
  606. case aktansistring_bits of
  607. sb_16:
  608. mode:=16;
  609. sb_32:
  610. mode:=32;
  611. sb_64:
  612. mode:=64;
  613. end;
  614. if mode=16 then
  615. copynode:=ccallnode.createintern('fpc_ansistr16_copy',paras)
  616. else if mode=32 then
  617. copynode:=ccallnode.createintern('fpc_ansistr32_copy',paras)
  618. else if mode=64 then
  619. copynode:=ccallnode.createintern('fpc_ansistr64_copy',paras)
  620. {$else}
  621. if is_ansistring(paradef) or
  622. (is_chararray(paradef) and
  623. (paradef.size>255)) or
  624. ((cs_ansistrings in aktlocalswitches) and
  625. is_pchar(paradef)) then
  626. copynode:=ccallnode.createintern('fpc_ansistr_copy',paras)
  627. {$endif}
  628. else
  629. if is_widestring(paradef) or
  630. is_widechararray(paradef) or
  631. is_pwidechar(paradef) then
  632. copynode:=ccallnode.createintern('fpc_widestr_copy',paras)
  633. else
  634. if is_char(paradef) then
  635. copynode:=ccallnode.createintern('fpc_char_copy',paras)
  636. else
  637. if is_dynamic_array(paradef) then
  638. begin
  639. { Only allow 1 or 3 arguments }
  640. if (counter<>1) and (counter<>3) then
  641. begin
  642. CGMessage(parser_e_wrong_parameter_size);
  643. exit;
  644. end;
  645. { create statements with call }
  646. copynode:=internalstatements(newstatement);
  647. if (counter=3) then
  648. begin
  649. highppn:=tcallparanode(paras).left.getcopy;
  650. lowppn:=tcallparanode(tcallparanode(paras).right).left.getcopy;
  651. end
  652. else
  653. begin
  654. { use special -1,-1 argument to copy the whole array }
  655. highppn:=cordconstnode.create(-1,s32inttype,false);
  656. lowppn:=cordconstnode.create(-1,s32inttype,false);
  657. end;
  658. { create temp for result, we've to use a temp because a dynarray
  659. type is handled differently from a pointer so we can't
  660. use createinternres() and a function }
  661. temp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,tt_persistent);
  662. addstatement(newstatement,temp);
  663. { create call to fpc_dynarray_copy }
  664. npara:=ccallparanode.create(highppn,
  665. ccallparanode.create(lowppn,
  666. ccallparanode.create(caddrnode.create
  667. (crttinode.create(tstoreddef(ppn.left.resulttype.def),initrtti)),
  668. ccallparanode.create
  669. (ctypeconvnode.create_explicit(ppn.left,voidpointertype),
  670. ccallparanode.create
  671. (ctemprefnode.create(temp),nil)))));
  672. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_copy',npara));
  673. { convert the temp to normal and return the reference to the
  674. created temp, and convert the type of the temp to the dynarray type }
  675. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  676. addstatement(newstatement,ctypeconvnode.create_explicit(ctemprefnode.create(temp),ppn.left.resulttype));
  677. ppn.left:=nil;
  678. paras.free;
  679. end
  680. else
  681. begin
  682. { generic fallback that will give an error if a wrong
  683. type is passed }
  684. copynode:=ccallnode.createintern('fpc_shortstr_copy',paras)
  685. end;
  686. result.free;
  687. result:=copynode;
  688. end;
  689. end.
  690. {
  691. $Log$
  692. Revision 1.32 2004-06-20 08:55:30 florian
  693. * logs truncated
  694. Revision 1.31 2004/05/23 18:28:41 peter
  695. * methodpointer is loaded into a temp when it was a calln
  696. Revision 1.30 2004/04/29 19:56:37 daniel
  697. * Prepare compiler infrastructure for multiple ansistring types
  698. Revision 1.29 2004/02/04 18:45:29 jonas
  699. + some more usage of register temps
  700. Revision 1.28 2004/02/03 22:32:54 peter
  701. * renamed xNNbittype to xNNinttype
  702. * renamed registers32 to registersint
  703. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  704. Revision 1.27 2004/02/03 16:46:51 jonas
  705. + support to store ttempcreate/ref/deletenodes in registers
  706. * put temps for withnodes and some newnodes in registers
  707. Note: this currently only works because calling ungetregister()
  708. multiple times for the same register doesn't matter. We need again
  709. a way to specify that a register is currently a regvar and as such
  710. should not be freed when you call ungetregister() on it.
  711. }