pinline.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. function new_dispose_statement(is_new:boolean) : tnode;
  25. function new_function : tnode;
  26. function inline_setlength : tnode;
  27. function inline_setstring : tnode;
  28. function inline_initialize : tnode;
  29. function inline_finalize : tnode;
  30. function inline_copy : tnode;
  31. function inline_insert : tnode;
  32. function inline_delete : tnode;
  33. function inline_concat : tnode;
  34. implementation
  35. uses
  36. { global }
  37. globtype,tokens,verbose,constexp,
  38. systems,compinnr,
  39. { symtable }
  40. symbase,symconst,symdef,symsym,symtable,defutil,
  41. { pass 1 }
  42. pass_1,htypechk,
  43. ncal,nmem,ncnv,ninl,ncon,nld,nbas,ngenutil,nutils,
  44. { parser }
  45. scanner,
  46. pbase,pexpr;
  47. function new_dispose_statement(is_new:boolean) : tnode;
  48. var
  49. newstatement : tstatementnode;
  50. temp : ttempcreatenode;
  51. para : tcallparanode;
  52. p,p2 : tnode;
  53. again : boolean; { dummy for do_proc_call }
  54. destructorname : TIDString;
  55. sym : tsym;
  56. classh : tobjectdef;
  57. callflag : tcallnodeflag;
  58. destructorpos,
  59. storepos : tfileposinfo;
  60. variantdesc : pvariantrecdesc;
  61. found : boolean;
  62. variantselectsymbol : tfieldvarsym;
  63. procedure ReadVariantRecordConstants;
  64. var
  65. i,j : longint;
  66. begin
  67. if (([m_iso,m_extpas]*current_settings.modeswitches)<>[]) and (is_record(tpointerdef(p.resultdef).pointeddef)) then
  68. begin
  69. variantdesc:=trecorddef(tpointerdef(p.resultdef).pointeddef).variantrecdesc;
  70. while (token=_COMMA) and assigned(variantdesc) do
  71. begin
  72. consume(_COMMA);
  73. p2:=factor(false,[]);
  74. do_typecheckpass(p2);
  75. if p2.nodetype=ordconstn then
  76. begin
  77. found:=false;
  78. { we do not have dynamic dfa, so avoid warning on variantselectsymbol below }
  79. variantselectsymbol:=nil;
  80. for i:=0 to high(variantdesc^.branches) do
  81. begin
  82. for j:=0 to high(variantdesc^.branches[i].values) do
  83. if variantdesc^.branches[i].values[j]=tordconstnode(p2).value then
  84. begin
  85. found:=true;
  86. variantselectsymbol:=tfieldvarsym(variantdesc^.variantselector);
  87. variantdesc:=variantdesc^.branches[i].nestedvariant;
  88. break;
  89. end;
  90. if found then
  91. break;
  92. end;
  93. if found then
  94. begin
  95. if is_new then
  96. begin
  97. { if no tag-field is given, do not create an assignment statement for it }
  98. if assigned(variantselectsymbol) then
  99. { setup variant selector }
  100. addstatement(newstatement,cassignmentnode.create(
  101. csubscriptnode.create(variantselectsymbol,
  102. cderefnode.create(ctemprefnode.create(temp))),
  103. p2));
  104. end;
  105. end
  106. else
  107. Message(parser_e_illegal_expression);
  108. end
  109. else
  110. Message(parser_e_illegal_expression);
  111. end;
  112. end;
  113. end;
  114. begin
  115. if target_info.system in systems_managed_vm then
  116. message(parser_e_feature_unsupported_for_vm);
  117. consume(_LKLAMMER);
  118. p:=comp_expr([ef_accept_equal]);
  119. { calc return type }
  120. if is_new then
  121. begin
  122. set_varstate(p,vs_written,[]);
  123. valid_for_var(p,true);
  124. end
  125. else
  126. set_varstate(p,vs_readwritten,[vsf_must_be_valid]);
  127. if (m_mac in current_settings.modeswitches) and
  128. is_class(p.resultdef) then
  129. begin
  130. classh:=tobjectdef(p.resultdef);
  131. { make sure we call ObjPas.TObject.Create/Free and not a random }
  132. { create/free method in a macpas descendent object (since those }
  133. { are not supposed to be called automatically when you call }
  134. { new/dispose) }
  135. while assigned(classh.childof) do
  136. classh := classh.childof;
  137. if is_new then
  138. begin
  139. sym:=search_struct_member(classh,'CREATE');
  140. p2 := cloadvmtaddrnode.create(ctypenode.create(p.resultdef));
  141. end
  142. else
  143. begin
  144. sym:=search_struct_member(classh,'FREE');
  145. p2 := p;
  146. end;
  147. if not(assigned(sym)) then
  148. begin
  149. p.free;
  150. p := nil;
  151. if is_new then
  152. p2.free;
  153. p2 := nil;
  154. new_dispose_statement := cerrornode.create;
  155. consume_all_until(_RKLAMMER);
  156. consume(_RKLAMMER);
  157. exit;
  158. end;
  159. do_member_read(classh,false,sym,p2,again,[],nil);
  160. { we need the real called method }
  161. do_typecheckpass(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.resultdef:=p.resultdef;
  170. p2:=cassignmentnode.create(p,p2);
  171. typecheckpass(p2);
  172. end
  173. else
  174. begin
  175. { Free is not a destructor
  176. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  177. Message(parser_e_expr_have_to_be_destructor_call);
  178. }
  179. end
  180. end
  181. else
  182. internalerror(2005061202);
  183. new_dispose_statement := p2;
  184. end
  185. { constructor,destructor specified }
  186. else if (([m_mac,m_iso,m_extpas]*current_settings.modeswitches)=[]) and
  187. try_to_consume(_COMMA) then
  188. begin
  189. { extended syntax of new and dispose }
  190. { function styled new is handled in factor }
  191. { destructors have no parameters }
  192. destructorname:=pattern;
  193. destructorpos:=current_tokenpos;
  194. consume(_ID);
  195. if is_typeparam(p.resultdef) then
  196. begin
  197. p.free;
  198. p:=factor(false,[]);
  199. p.free;
  200. p := nil;
  201. consume(_RKLAMMER);
  202. new_dispose_statement:=cnothingnode.create;
  203. exit;
  204. end;
  205. if (p.resultdef.typ<>pointerdef) then
  206. begin
  207. Message1(type_e_pointer_type_expected,p.resultdef.typename);
  208. p.free;
  209. p:=factor(false,[]);
  210. p.free;
  211. p := nil;
  212. consume(_RKLAMMER);
  213. new_dispose_statement:=cerrornode.create;
  214. exit;
  215. end;
  216. { first parameter must be an object or class }
  217. if tpointerdef(p.resultdef).pointeddef.typ<>objectdef then
  218. begin
  219. Message(parser_e_pointer_to_class_expected);
  220. p.free;
  221. p := nil;
  222. new_dispose_statement:=factor(false,[]);
  223. consume_all_until(_RKLAMMER);
  224. consume(_RKLAMMER);
  225. exit;
  226. end;
  227. { check, if the first parameter is a pointer to a _class_ }
  228. classh:=tobjectdef(tpointerdef(p.resultdef).pointeddef);
  229. if is_class(classh) then
  230. begin
  231. Message(parser_e_no_new_or_dispose_for_classes);
  232. new_dispose_statement:=factor(false,[]);
  233. consume_all_until(_RKLAMMER);
  234. consume(_RKLAMMER);
  235. exit;
  236. end;
  237. { search cons-/destructor, also in parent classes }
  238. storepos:=current_tokenpos;
  239. current_tokenpos:=destructorpos;
  240. sym:=search_struct_member(classh,destructorname);
  241. current_tokenpos:=storepos;
  242. { the second parameter of new/dispose must be a call }
  243. { to a cons-/destructor }
  244. if (not assigned(sym)) or (sym.typ<>procsym) then
  245. begin
  246. if is_new then
  247. Message(parser_e_expr_have_to_be_constructor_call)
  248. else
  249. Message(parser_e_expr_have_to_be_destructor_call);
  250. p.free;
  251. p := nil;
  252. new_dispose_statement:=cerrornode.create;
  253. end
  254. else
  255. begin
  256. { For new(var,constructor) we need to take a copy because
  257. p is also used in the assignmentn below }
  258. if is_new then
  259. begin
  260. p2:=cderefnode.create(p.getcopy);
  261. include(TDerefNode(p2).derefnodeflags,drnf_no_checkpointer);
  262. end
  263. else
  264. p2:=cderefnode.create(p);
  265. do_typecheckpass(p2);
  266. if is_new then
  267. callflag:=cnf_new_call
  268. else
  269. callflag:=cnf_dispose_call;
  270. if is_new then
  271. do_member_read(classh,false,sym,p2,again,[callflag],nil)
  272. else
  273. begin
  274. if not(m_fpc in current_settings.modeswitches) then
  275. do_member_read(classh,false,sym,p2,again,[callflag],nil)
  276. else
  277. begin
  278. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2,[callflag],nil);
  279. { support dispose(p,done()); }
  280. if try_to_consume(_LKLAMMER) then
  281. begin
  282. if not try_to_consume(_RKLAMMER) then
  283. begin
  284. Message(parser_e_no_paras_for_destructor);
  285. consume_all_until(_RKLAMMER);
  286. consume(_RKLAMMER);
  287. end;
  288. end;
  289. end;
  290. end;
  291. { we need the real called method }
  292. do_typecheckpass(p2);
  293. if (p2.nodetype=calln) and
  294. assigned(tcallnode(p2).procdefinition) then
  295. begin
  296. if is_new then
  297. begin
  298. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  299. Message(parser_e_expr_have_to_be_constructor_call);
  300. p2.resultdef:=p.resultdef;
  301. p2:=cassignmentnode.create(p,p2);
  302. end
  303. else
  304. begin
  305. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  306. Message(parser_e_expr_have_to_be_destructor_call);
  307. end;
  308. end
  309. else
  310. begin
  311. if is_new then
  312. CGMessage(parser_e_expr_have_to_be_constructor_call)
  313. else
  314. CGMessage(parser_e_expr_have_to_be_destructor_call);
  315. end;
  316. result:=p2;
  317. end;
  318. end
  319. else
  320. begin
  321. if (p.resultdef.typ<>pointerdef) then
  322. Begin
  323. if is_typeparam(p.resultdef) then
  324. begin
  325. p.free;
  326. p := nil;
  327. consume(_RKLAMMER);
  328. new_dispose_statement:=cnothingnode.create;
  329. exit;
  330. end
  331. else
  332. begin
  333. Message1(type_e_pointer_type_expected,p.resultdef.typename);
  334. new_dispose_statement:=cerrornode.create;
  335. end;
  336. end
  337. else
  338. begin
  339. if (tpointerdef(p.resultdef).pointeddef.typ=objectdef) and
  340. (oo_has_vmt in tobjectdef(tpointerdef(p.resultdef).pointeddef).objectoptions) then
  341. Message(parser_w_use_extended_syntax_for_objects);
  342. if (tpointerdef(p.resultdef).pointeddef.typ=orddef) and
  343. (torddef(tpointerdef(p.resultdef).pointeddef).ordtype=uvoid) then
  344. begin
  345. if (m_tp7 in current_settings.modeswitches) or
  346. (m_delphi in current_settings.modeswitches) then
  347. Message(parser_w_no_new_dispose_on_void_pointers)
  348. else
  349. Message(parser_e_no_new_dispose_on_void_pointers);
  350. end;
  351. { create statements with call to getmem+initialize or
  352. finalize+freemem }
  353. new_dispose_statement:=internalstatements(newstatement);
  354. if is_new then
  355. begin
  356. { create temp for result }
  357. temp := ctempcreatenode.create(p.resultdef,p.resultdef.size,tt_persistent,true);
  358. addstatement(newstatement,temp);
  359. { create call to fpc_getmem }
  360. para := ccallparanode.create(cordconstnode.create
  361. (tpointerdef(p.resultdef).pointeddef.size,ptruinttype,true),nil);
  362. addstatement(newstatement,cassignmentnode.create(
  363. ctemprefnode.create(temp),
  364. ccallnode.createintern('fpc_getmem',para)));
  365. { create call to fpc_initialize }
  366. if is_managed_type(tpointerdef(p.resultdef).pointeddef) or
  367. ((m_isolike_io in current_settings.modeswitches) and (tpointerdef(p.resultdef).pointeddef.typ=filedef)) then
  368. addstatement(newstatement,cnodeutils.initialize_data_node(cderefnode.create(ctemprefnode.create(temp)),false));
  369. { copy the temp to the destination }
  370. addstatement(newstatement,cassignmentnode.create(
  371. p,
  372. ctemprefnode.create(temp)));
  373. ReadVariantRecordConstants;
  374. { release temp }
  375. addstatement(newstatement,ctempdeletenode.create(temp));
  376. end
  377. else
  378. begin
  379. temp:=nil;
  380. { create call to fpc_finalize }
  381. if is_managed_type(tpointerdef(p.resultdef).pointeddef) then
  382. if might_have_sideeffects(p) then
  383. begin
  384. { ensure that p gets evaluated only once, in case it is e.g. a call }
  385. temp:=ctempcreatenode.create_value(p.resultdef,p.resultdef.size,tt_persistent,true,p);
  386. addstatement(newstatement,temp);
  387. addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(ctemprefnode.create(temp))));
  388. end
  389. else
  390. addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(p.getcopy)));
  391. ReadVariantRecordConstants;
  392. { create call to fpc_freemem }
  393. if not assigned(temp) then
  394. para := ccallparanode.create(p,nil)
  395. else
  396. para := ccallparanode.create(ctemprefnode.create(temp),nil);
  397. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  398. if assigned(temp) then
  399. addstatement(newstatement,ctempdeletenode.create(temp));
  400. end;
  401. end;
  402. end;
  403. consume(_RKLAMMER);
  404. end;
  405. function new_function : tnode;
  406. var
  407. p1,p2 : tnode;
  408. classh : tobjectdef;
  409. srsym : tsym;
  410. srsymtable : TSymtable;
  411. again : boolean; { dummy for do_proc_call }
  412. begin
  413. if target_info.system in systems_managed_vm then
  414. message(parser_e_feature_unsupported_for_vm);
  415. consume(_LKLAMMER);
  416. p1:=factor(false,[]);
  417. if p1.nodetype<>typen then
  418. begin
  419. Message(type_e_type_id_expected);
  420. consume_all_until(_RKLAMMER);
  421. consume(_RKLAMMER);
  422. p1.free;
  423. p1 := nil;
  424. new_function:=cerrornode.create;
  425. exit;
  426. end;
  427. if (p1.resultdef.typ<>pointerdef) then
  428. begin
  429. Message1(type_e_pointer_type_expected,p1.resultdef.typename);
  430. consume_all_until(_RKLAMMER);
  431. consume(_RKLAMMER);
  432. p1.free;
  433. p1 := nil;
  434. new_function:=cerrornode.create;
  435. exit;
  436. end;
  437. if try_to_consume(_RKLAMMER) then
  438. begin
  439. if (tpointerdef(p1.resultdef).pointeddef.typ=objectdef) and
  440. (oo_has_vmt in tobjectdef(tpointerdef(p1.resultdef).pointeddef).objectoptions) then
  441. Message(parser_w_use_extended_syntax_for_objects);
  442. if p1.nodetype=typen then
  443. ttypenode(p1).allowed:=true;
  444. p1:=cinlinenode.create(in_new_x,false,p1);
  445. end
  446. else
  447. begin
  448. consume(_COMMA);
  449. if tpointerdef(p1.resultdef).pointeddef.typ<>objectdef then
  450. begin
  451. Message(parser_e_pointer_to_class_expected);
  452. consume_all_until(_RKLAMMER);
  453. consume(_RKLAMMER);
  454. p1.free;
  455. p1 := nil;
  456. new_function:=cerrornode.create;
  457. exit;
  458. end;
  459. classh:=tobjectdef(tpointerdef(p1.resultdef).pointeddef);
  460. { use the objectdef for loading the VMT }
  461. p2:=p1;
  462. p1:=ctypenode.create(tpointerdef(p1.resultdef).pointeddef);
  463. do_typecheckpass(p1);
  464. { search the constructor also in the symbol tables of
  465. the parents }
  466. afterassignment:=false;
  467. searchsym_in_class(classh,classh,pattern,srsym,srsymtable,[ssf_search_helper]);
  468. consume(_ID);
  469. do_member_read(classh,false,srsym,p1,again,[cnf_new_call],nil);
  470. { we need to know which procedure is called }
  471. do_typecheckpass(p1);
  472. if not(
  473. (p1.nodetype=calln) and
  474. assigned(tcallnode(p1).procdefinition) and
  475. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  476. ) then
  477. Message(parser_e_expr_have_to_be_constructor_call);
  478. { constructors return boolean, update resultdef to return
  479. the pointer to the object }
  480. p1.resultdef:=p2.resultdef;
  481. p2.free;
  482. p2 := nil;
  483. consume(_RKLAMMER);
  484. end;
  485. new_function:=p1;
  486. end;
  487. function inline_setlength : tnode;
  488. var
  489. paras: tnode;
  490. begin
  491. consume(_LKLAMMER);
  492. paras:=parse_paras(false,false,_RKLAMMER);
  493. consume(_RKLAMMER);
  494. if not assigned(paras) then
  495. begin
  496. result:=cerrornode.create;
  497. CGMessage1(parser_e_wrong_parameter_size,'SetLength');
  498. exit;
  499. end;
  500. result:=cinlinenode.create(in_setlength_x,false,paras);
  501. end;
  502. function inline_setstring : tnode;
  503. var
  504. paras, strpara, pcharpara: tnode;
  505. procname: string;
  506. cp: tstringencoding;
  507. begin
  508. consume(_LKLAMMER);
  509. paras:=parse_paras(false,false,_RKLAMMER);
  510. consume(_RKLAMMER);
  511. procname:='';
  512. if assigned(paras) and
  513. assigned(tcallparanode(paras).right) and
  514. assigned(tcallparanode(tcallparanode(paras).right).right) then
  515. begin
  516. do_typecheckpass(tcallparanode(tcallparanode(paras).right).left);
  517. do_typecheckpass(tcallparanode(tcallparanode(tcallparanode(paras).right).right).left);
  518. pcharpara:=tcallparanode(tcallparanode(paras).right).left;
  519. strpara:=tcallparanode(tcallparanode(tcallparanode(paras).right).right).left;
  520. if strpara.resultdef.typ=stringdef then
  521. begin
  522. { if there are three parameters and the first parameter
  523. ( = paras.right.right) is an ansistring, add a codepage
  524. parameter }
  525. if is_ansistring(strpara.resultdef) then
  526. begin
  527. cp:=tstringdef(strpara.resultdef).encoding;
  528. if (cp=globals.CP_NONE) then
  529. cp:=0;
  530. paras:=ccallparanode.create(genintconstnode(cp),paras);
  531. end;
  532. procname:='fpc_setstring_'+tstringdef(strpara.resultdef).stringtypname;
  533. { decide which version to call based on the second parameter }
  534. if not is_shortstring(strpara.resultdef) then
  535. if is_pwidechar(pcharpara.resultdef) or
  536. is_widechar(pcharpara.resultdef) or
  537. ((pcharpara.resultdef.typ=arraydef) and
  538. is_widechar(tarraydef(pcharpara.resultdef).elementdef)) then
  539. procname:=procname+'_pwidechar'
  540. else
  541. procname:=procname+'_pansichar';
  542. end;
  543. end;
  544. { default version (for error message) in case of missing or wrong
  545. parameters }
  546. if procname='' then
  547. if m_default_unicodestring in current_settings.modeswitches then
  548. procname:='fpc_setstring_unicodestr_pwidechar'
  549. else if m_default_ansistring in current_settings.modeswitches then
  550. procname:='fpc_setstring_ansistr_pansichar'
  551. else
  552. procname:='fpc_setstring_shortstr';
  553. result:=ccallnode.createintern(procname,paras)
  554. end;
  555. function inline_initfinal(isinit: boolean): tnode;
  556. var
  557. newblock,
  558. paras : tnode;
  559. npara,
  560. destppn,
  561. ppn : tcallparanode;
  562. begin
  563. { for easy exiting if something goes wrong }
  564. result := cerrornode.create;
  565. consume(_LKLAMMER);
  566. paras:=parse_paras(false,false,_RKLAMMER);
  567. consume(_RKLAMMER);
  568. ppn:=tcallparanode(paras);
  569. if not assigned(paras) or
  570. (assigned(ppn.right) and
  571. assigned(tcallparanode(ppn.right).right)) then
  572. begin
  573. if isinit then
  574. CGMessage1(parser_e_wrong_parameter_size,'Initialize')
  575. else
  576. CGMessage1(parser_e_wrong_parameter_size,'Finalize');
  577. exit;
  578. end;
  579. { 2 arguments? }
  580. if assigned(ppn.right) then
  581. begin
  582. destppn:=tcallparanode(ppn.right);
  583. { create call to fpc_initialize/finalize_array }
  584. npara:=ccallparanode.create(ctypeconvnode.create
  585. (ppn.left,s32inttype),
  586. ccallparanode.create(caddrnode.create_internal
  587. (crttinode.create(tstoreddef(destppn.left.resultdef),initrtti,rdt_normal)),
  588. ccallparanode.create(caddrnode.create_internal
  589. (destppn.left),nil)));
  590. if isinit then
  591. newblock:=ccallnode.createintern('fpc_initialize_array',npara)
  592. else
  593. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  594. destppn.left:=nil;
  595. end
  596. else
  597. begin
  598. if isinit then
  599. newblock:=cnodeutils.initialize_data_node(ppn.left,true)
  600. else
  601. newblock:=cnodeutils.finalize_data_node(ppn.left);
  602. end;
  603. ppn.left:=nil;
  604. paras.free;
  605. paras := nil;
  606. result.free;
  607. result:=newblock;
  608. end;
  609. function inline_initialize : tnode;
  610. begin
  611. result:=inline_initfinal(true);
  612. end;
  613. function inline_finalize : tnode;
  614. begin
  615. result:=inline_initfinal(false);
  616. end;
  617. function inline_copy_insert_delete(nr:tinlinenumber;const name:string;checkempty:boolean) : tnode;
  618. var
  619. paras : tnode;
  620. { for easy exiting if something goes wrong }
  621. begin
  622. result := cerrornode.create;
  623. consume(_LKLAMMER);
  624. paras:=parse_paras(false,false,_RKLAMMER);
  625. consume(_RKLAMMER);
  626. if not assigned(paras) and checkempty then
  627. begin
  628. CGMessage1(parser_e_wrong_parameter_size,name);
  629. exit;
  630. end;
  631. result.free;
  632. result:=cinlinenode.create(nr,false,paras);
  633. end;
  634. function inline_copy: tnode;
  635. begin
  636. result:=inline_copy_insert_delete(in_copy_x,'Copy',false);
  637. end;
  638. function inline_insert: tnode;
  639. begin
  640. result:=inline_copy_insert_delete(in_insert_x_y_z,'Insert',false);
  641. end;
  642. function inline_delete: tnode;
  643. begin
  644. result:=inline_copy_insert_delete(in_delete_x_y_z,'Delete',false);
  645. end;
  646. function inline_concat: tnode;
  647. begin
  648. result:=inline_copy_insert_delete(in_concat_x,'Concat',false);
  649. end;
  650. end.