pinline.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. if is_new then
  151. p2.free;
  152. new_dispose_statement := cerrornode.create;
  153. consume_all_until(_RKLAMMER);
  154. consume(_RKLAMMER);
  155. exit;
  156. end;
  157. do_member_read(classh,false,sym,p2,again,[],nil);
  158. { we need the real called method }
  159. do_typecheckpass(p2);
  160. if (p2.nodetype=calln) and
  161. assigned(tcallnode(p2).procdefinition) then
  162. begin
  163. if is_new then
  164. begin
  165. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  166. Message(parser_e_expr_have_to_be_constructor_call);
  167. p2.resultdef:=p.resultdef;
  168. p2:=cassignmentnode.create(p,p2);
  169. typecheckpass(p2);
  170. end
  171. else
  172. begin
  173. { Free is not a destructor
  174. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  175. Message(parser_e_expr_have_to_be_destructor_call);
  176. }
  177. end
  178. end
  179. else
  180. internalerror(2005061202);
  181. new_dispose_statement := p2;
  182. end
  183. { constructor,destructor specified }
  184. else if (([m_mac,m_iso,m_extpas]*current_settings.modeswitches)=[]) and
  185. try_to_consume(_COMMA) then
  186. begin
  187. { extended syntax of new and dispose }
  188. { function styled new is handled in factor }
  189. { destructors have no parameters }
  190. destructorname:=pattern;
  191. destructorpos:=current_tokenpos;
  192. consume(_ID);
  193. if is_typeparam(p.resultdef) then
  194. begin
  195. p.free;
  196. p:=factor(false,[]);
  197. p.free;
  198. consume(_RKLAMMER);
  199. new_dispose_statement:=cnothingnode.create;
  200. exit;
  201. end;
  202. if (p.resultdef.typ<>pointerdef) then
  203. begin
  204. Message1(type_e_pointer_type_expected,p.resultdef.typename);
  205. p.free;
  206. p:=factor(false,[]);
  207. p.free;
  208. consume(_RKLAMMER);
  209. new_dispose_statement:=cerrornode.create;
  210. exit;
  211. end;
  212. { first parameter must be an object or class }
  213. if tpointerdef(p.resultdef).pointeddef.typ<>objectdef then
  214. begin
  215. Message(parser_e_pointer_to_class_expected);
  216. p.free;
  217. new_dispose_statement:=factor(false,[]);
  218. consume_all_until(_RKLAMMER);
  219. consume(_RKLAMMER);
  220. exit;
  221. end;
  222. { check, if the first parameter is a pointer to a _class_ }
  223. classh:=tobjectdef(tpointerdef(p.resultdef).pointeddef);
  224. if is_class(classh) then
  225. begin
  226. Message(parser_e_no_new_or_dispose_for_classes);
  227. new_dispose_statement:=factor(false,[]);
  228. consume_all_until(_RKLAMMER);
  229. consume(_RKLAMMER);
  230. exit;
  231. end;
  232. { search cons-/destructor, also in parent classes }
  233. storepos:=current_tokenpos;
  234. current_tokenpos:=destructorpos;
  235. sym:=search_struct_member(classh,destructorname);
  236. current_tokenpos:=storepos;
  237. { the second parameter of new/dispose must be a call }
  238. { to a cons-/destructor }
  239. if (not assigned(sym)) or (sym.typ<>procsym) then
  240. begin
  241. if is_new then
  242. Message(parser_e_expr_have_to_be_constructor_call)
  243. else
  244. Message(parser_e_expr_have_to_be_destructor_call);
  245. p.free;
  246. new_dispose_statement:=cerrornode.create;
  247. end
  248. else
  249. begin
  250. { For new(var,constructor) we need to take a copy because
  251. p is also used in the assignmentn below }
  252. if is_new then
  253. begin
  254. p2:=cderefnode.create(p.getcopy);
  255. include(p2.flags,nf_no_checkpointer);
  256. end
  257. else
  258. p2:=cderefnode.create(p);
  259. do_typecheckpass(p2);
  260. if is_new then
  261. callflag:=cnf_new_call
  262. else
  263. callflag:=cnf_dispose_call;
  264. if is_new then
  265. do_member_read(classh,false,sym,p2,again,[callflag],nil)
  266. else
  267. begin
  268. if not(m_fpc in current_settings.modeswitches) then
  269. do_member_read(classh,false,sym,p2,again,[callflag],nil)
  270. else
  271. begin
  272. p2:=ccallnode.create(nil,tprocsym(sym),sym.owner,p2,[callflag],nil);
  273. { support dispose(p,done()); }
  274. if try_to_consume(_LKLAMMER) then
  275. begin
  276. if not try_to_consume(_RKLAMMER) then
  277. begin
  278. Message(parser_e_no_paras_for_destructor);
  279. consume_all_until(_RKLAMMER);
  280. consume(_RKLAMMER);
  281. end;
  282. end;
  283. end;
  284. end;
  285. { we need the real called method }
  286. do_typecheckpass(p2);
  287. if (p2.nodetype=calln) and
  288. assigned(tcallnode(p2).procdefinition) then
  289. begin
  290. if is_new then
  291. begin
  292. if (tcallnode(p2).procdefinition.proctypeoption<>potype_constructor) then
  293. Message(parser_e_expr_have_to_be_constructor_call);
  294. p2.resultdef:=p.resultdef;
  295. p2:=cassignmentnode.create(p,p2);
  296. end
  297. else
  298. begin
  299. if (tcallnode(p2).procdefinition.proctypeoption<>potype_destructor) then
  300. Message(parser_e_expr_have_to_be_destructor_call);
  301. end;
  302. end
  303. else
  304. begin
  305. if is_new then
  306. CGMessage(parser_e_expr_have_to_be_constructor_call)
  307. else
  308. CGMessage(parser_e_expr_have_to_be_destructor_call);
  309. end;
  310. result:=p2;
  311. end;
  312. end
  313. else
  314. begin
  315. if (p.resultdef.typ<>pointerdef) then
  316. Begin
  317. if is_typeparam(p.resultdef) then
  318. begin
  319. p.free;
  320. consume(_RKLAMMER);
  321. new_dispose_statement:=cnothingnode.create;
  322. exit;
  323. end
  324. else
  325. begin
  326. Message1(type_e_pointer_type_expected,p.resultdef.typename);
  327. new_dispose_statement:=cerrornode.create;
  328. end;
  329. end
  330. else
  331. begin
  332. if (tpointerdef(p.resultdef).pointeddef.typ=objectdef) and
  333. (oo_has_vmt in tobjectdef(tpointerdef(p.resultdef).pointeddef).objectoptions) then
  334. Message(parser_w_use_extended_syntax_for_objects);
  335. if (tpointerdef(p.resultdef).pointeddef.typ=orddef) and
  336. (torddef(tpointerdef(p.resultdef).pointeddef).ordtype=uvoid) then
  337. begin
  338. if (m_tp7 in current_settings.modeswitches) or
  339. (m_delphi in current_settings.modeswitches) then
  340. Message(parser_w_no_new_dispose_on_void_pointers)
  341. else
  342. Message(parser_e_no_new_dispose_on_void_pointers);
  343. end;
  344. { create statements with call to getmem+initialize or
  345. finalize+freemem }
  346. new_dispose_statement:=internalstatements(newstatement);
  347. if is_new then
  348. begin
  349. { create temp for result }
  350. temp := ctempcreatenode.create(p.resultdef,p.resultdef.size,tt_persistent,true);
  351. addstatement(newstatement,temp);
  352. { create call to fpc_getmem }
  353. para := ccallparanode.create(cordconstnode.create
  354. (tpointerdef(p.resultdef).pointeddef.size,s32inttype,true),nil);
  355. addstatement(newstatement,cassignmentnode.create(
  356. ctemprefnode.create(temp),
  357. ccallnode.createintern('fpc_getmem',para)));
  358. { create call to fpc_initialize }
  359. if is_managed_type(tpointerdef(p.resultdef).pointeddef) or
  360. ((m_isolike_io in current_settings.modeswitches) and (tpointerdef(p.resultdef).pointeddef.typ=filedef)) then
  361. addstatement(newstatement,cnodeutils.initialize_data_node(cderefnode.create(ctemprefnode.create(temp)),false));
  362. { copy the temp to the destination }
  363. addstatement(newstatement,cassignmentnode.create(
  364. p,
  365. ctemprefnode.create(temp)));
  366. ReadVariantRecordConstants;
  367. { release temp }
  368. addstatement(newstatement,ctempdeletenode.create(temp));
  369. end
  370. else
  371. begin
  372. temp:=nil;
  373. { create call to fpc_finalize }
  374. if is_managed_type(tpointerdef(p.resultdef).pointeddef) then
  375. if might_have_sideeffects(p) then
  376. begin
  377. { ensure that p gets evaluated only once, in case it is e.g. a call }
  378. temp:=ctempcreatenode.create_value(p.resultdef,p.resultdef.size,tt_persistent,true,p);
  379. addstatement(newstatement,temp);
  380. addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(ctemprefnode.create(temp))));
  381. end
  382. else
  383. addstatement(newstatement,cnodeutils.finalize_data_node(cderefnode.create(p.getcopy)));
  384. ReadVariantRecordConstants;
  385. { create call to fpc_freemem }
  386. if not assigned(temp) then
  387. para := ccallparanode.create(p,nil)
  388. else
  389. para := ccallparanode.create(ctemprefnode.create(temp),nil);
  390. addstatement(newstatement,ccallnode.createintern('fpc_freemem',para));
  391. if assigned(temp) then
  392. addstatement(newstatement,ctempdeletenode.create(temp));
  393. end;
  394. end;
  395. end;
  396. consume(_RKLAMMER);
  397. end;
  398. function new_function : tnode;
  399. var
  400. p1,p2 : tnode;
  401. classh : tobjectdef;
  402. srsym : tsym;
  403. srsymtable : TSymtable;
  404. again : boolean; { dummy for do_proc_call }
  405. begin
  406. if target_info.system in systems_managed_vm then
  407. message(parser_e_feature_unsupported_for_vm);
  408. consume(_LKLAMMER);
  409. p1:=factor(false,[]);
  410. if p1.nodetype<>typen then
  411. begin
  412. Message(type_e_type_id_expected);
  413. consume_all_until(_RKLAMMER);
  414. consume(_RKLAMMER);
  415. p1.destroy;
  416. new_function:=cerrornode.create;
  417. exit;
  418. end;
  419. if (p1.resultdef.typ<>pointerdef) then
  420. begin
  421. Message1(type_e_pointer_type_expected,p1.resultdef.typename);
  422. consume_all_until(_RKLAMMER);
  423. consume(_RKLAMMER);
  424. p1.destroy;
  425. new_function:=cerrornode.create;
  426. exit;
  427. end;
  428. if try_to_consume(_RKLAMMER) then
  429. begin
  430. if (tpointerdef(p1.resultdef).pointeddef.typ=objectdef) and
  431. (oo_has_vmt in tobjectdef(tpointerdef(p1.resultdef).pointeddef).objectoptions) then
  432. Message(parser_w_use_extended_syntax_for_objects);
  433. if p1.nodetype=typen then
  434. ttypenode(p1).allowed:=true;
  435. p1:=cinlinenode.create(in_new_x,false,p1);
  436. end
  437. else
  438. begin
  439. consume(_COMMA);
  440. if tpointerdef(p1.resultdef).pointeddef.typ<>objectdef then
  441. begin
  442. Message(parser_e_pointer_to_class_expected);
  443. consume_all_until(_RKLAMMER);
  444. consume(_RKLAMMER);
  445. p1.destroy;
  446. new_function:=cerrornode.create;
  447. exit;
  448. end;
  449. classh:=tobjectdef(tpointerdef(p1.resultdef).pointeddef);
  450. { use the objectdef for loading the VMT }
  451. p2:=p1;
  452. p1:=ctypenode.create(tpointerdef(p1.resultdef).pointeddef);
  453. do_typecheckpass(p1);
  454. { search the constructor also in the symbol tables of
  455. the parents }
  456. afterassignment:=false;
  457. searchsym_in_class(classh,classh,pattern,srsym,srsymtable,[ssf_search_helper]);
  458. consume(_ID);
  459. do_member_read(classh,false,srsym,p1,again,[cnf_new_call],nil);
  460. { we need to know which procedure is called }
  461. do_typecheckpass(p1);
  462. if not(
  463. (p1.nodetype=calln) and
  464. assigned(tcallnode(p1).procdefinition) and
  465. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor)
  466. ) then
  467. Message(parser_e_expr_have_to_be_constructor_call);
  468. { constructors return boolean, update resultdef to return
  469. the pointer to the object }
  470. p1.resultdef:=p2.resultdef;
  471. p2.free;
  472. consume(_RKLAMMER);
  473. end;
  474. new_function:=p1;
  475. end;
  476. function inline_setlength : tnode;
  477. var
  478. paras: tnode;
  479. begin
  480. consume(_LKLAMMER);
  481. paras:=parse_paras(false,false,_RKLAMMER);
  482. consume(_RKLAMMER);
  483. if not assigned(paras) then
  484. begin
  485. result:=cerrornode.create;
  486. CGMessage1(parser_e_wrong_parameter_size,'SetLength');
  487. exit;
  488. end;
  489. result:=cinlinenode.create(in_setlength_x,false,paras);
  490. end;
  491. function inline_setstring : tnode;
  492. var
  493. paras, strpara, pcharpara: tnode;
  494. procname: string;
  495. cp: tstringencoding;
  496. begin
  497. consume(_LKLAMMER);
  498. paras:=parse_paras(false,false,_RKLAMMER);
  499. consume(_RKLAMMER);
  500. procname:='';
  501. if assigned(paras) and
  502. assigned(tcallparanode(paras).right) and
  503. assigned(tcallparanode(tcallparanode(paras).right).right) then
  504. begin
  505. do_typecheckpass(tcallparanode(tcallparanode(paras).right).left);
  506. do_typecheckpass(tcallparanode(tcallparanode(tcallparanode(paras).right).right).left);
  507. pcharpara:=tcallparanode(tcallparanode(paras).right).left;
  508. strpara:=tcallparanode(tcallparanode(tcallparanode(paras).right).right).left;
  509. if strpara.resultdef.typ=stringdef then
  510. begin
  511. { if there are three parameters and the first parameter
  512. ( = paras.right.right) is an ansistring, add a codepage
  513. parameter }
  514. if is_ansistring(strpara.resultdef) then
  515. begin
  516. cp:=tstringdef(strpara.resultdef).encoding;
  517. if (cp=globals.CP_NONE) then
  518. cp:=0;
  519. paras:=ccallparanode.create(genintconstnode(cp),paras);
  520. end;
  521. procname:='fpc_setstring_'+tstringdef(strpara.resultdef).stringtypname;
  522. { decide which version to call based on the second parameter }
  523. if not is_shortstring(strpara.resultdef) then
  524. if is_pwidechar(pcharpara.resultdef) or
  525. is_widechar(pcharpara.resultdef) or
  526. ((pcharpara.resultdef.typ=arraydef) and
  527. is_widechar(tarraydef(pcharpara.resultdef).elementdef)) then
  528. procname:=procname+'_pwidechar'
  529. else
  530. procname:=procname+'_pansichar';
  531. end;
  532. end;
  533. { default version (for error message) in case of missing or wrong
  534. parameters }
  535. if procname='' then
  536. if m_default_unicodestring in current_settings.modeswitches then
  537. procname:='fpc_setstring_unicodestr_pwidechar'
  538. else if m_default_ansistring in current_settings.modeswitches then
  539. procname:='fpc_setstring_ansistr_pansichar'
  540. else
  541. procname:='fpc_setstring_shortstr';
  542. result:=ccallnode.createintern(procname,paras)
  543. end;
  544. function inline_initfinal(isinit: boolean): tnode;
  545. var
  546. newblock,
  547. paras : tnode;
  548. npara,
  549. destppn,
  550. ppn : tcallparanode;
  551. begin
  552. { for easy exiting if something goes wrong }
  553. result := cerrornode.create;
  554. consume(_LKLAMMER);
  555. paras:=parse_paras(false,false,_RKLAMMER);
  556. consume(_RKLAMMER);
  557. ppn:=tcallparanode(paras);
  558. if not assigned(paras) or
  559. (assigned(ppn.right) and
  560. assigned(tcallparanode(ppn.right).right)) then
  561. begin
  562. if isinit then
  563. CGMessage1(parser_e_wrong_parameter_size,'Initialize')
  564. else
  565. CGMessage1(parser_e_wrong_parameter_size,'Finalize');
  566. exit;
  567. end;
  568. { 2 arguments? }
  569. if assigned(ppn.right) then
  570. begin
  571. destppn:=tcallparanode(ppn.right);
  572. { create call to fpc_initialize/finalize_array }
  573. npara:=ccallparanode.create(ctypeconvnode.create
  574. (ppn.left,s32inttype),
  575. ccallparanode.create(caddrnode.create_internal
  576. (crttinode.create(tstoreddef(destppn.left.resultdef),initrtti,rdt_normal)),
  577. ccallparanode.create(caddrnode.create_internal
  578. (destppn.left),nil)));
  579. if isinit then
  580. newblock:=ccallnode.createintern('fpc_initialize_array',npara)
  581. else
  582. newblock:=ccallnode.createintern('fpc_finalize_array',npara);
  583. destppn.left:=nil;
  584. end
  585. else
  586. begin
  587. if isinit then
  588. newblock:=cnodeutils.initialize_data_node(ppn.left,true)
  589. else
  590. newblock:=cnodeutils.finalize_data_node(ppn.left);
  591. end;
  592. ppn.left:=nil;
  593. paras.free;
  594. result.free;
  595. result:=newblock;
  596. end;
  597. function inline_initialize : tnode;
  598. begin
  599. result:=inline_initfinal(true);
  600. end;
  601. function inline_finalize : tnode;
  602. begin
  603. result:=inline_initfinal(false);
  604. end;
  605. function inline_copy_insert_delete(nr:tinlinenumber;name:string;checkempty:boolean) : tnode;
  606. var
  607. paras : tnode;
  608. { for easy exiting if something goes wrong }
  609. begin
  610. result := cerrornode.create;
  611. consume(_LKLAMMER);
  612. paras:=parse_paras(false,false,_RKLAMMER);
  613. consume(_RKLAMMER);
  614. if not assigned(paras) and checkempty then
  615. begin
  616. CGMessage1(parser_e_wrong_parameter_size,name);
  617. exit;
  618. end;
  619. result.free;
  620. result:=cinlinenode.create(nr,false,paras);
  621. end;
  622. function inline_copy: tnode;
  623. begin
  624. result:=inline_copy_insert_delete(in_copy_x,'Copy',false);
  625. end;
  626. function inline_insert: tnode;
  627. begin
  628. result:=inline_copy_insert_delete(in_insert_x_y_z,'Insert',false);
  629. end;
  630. function inline_delete: tnode;
  631. begin
  632. result:=inline_copy_insert_delete(in_delete_x_y_z,'Delete',false);
  633. end;
  634. function inline_concat: tnode;
  635. begin
  636. result:=inline_copy_insert_delete(in_concat_x,'Concat',false);
  637. end;
  638. end.