pparautl.pas 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  3. Helpers for dealing with subroutine parameters during parsing
  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 pparautl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symconst,symdef;
  22. procedure insert_funcret_para(pd:tabstractprocdef);
  23. procedure insert_parentfp_para(pd:tabstractprocdef);
  24. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  25. procedure insert_funcret_local(pd:tprocdef);
  26. procedure insert_hidden_para(p:TObject;arg:pointer);
  27. procedure check_c_para(pd:Tabstractprocdef);
  28. procedure insert_struct_hidden_paras(astruct: tabstractrecorddef);
  29. type
  30. // flags of the *handle_calling_convention routines
  31. thccflag=(
  32. hcc_declaration, // declaration (as opposed to definition, i.e. interface rather than implementation)
  33. hcc_check, // perform checks and outup errors if found
  34. hcc_insert_hidden_paras // insert hidden parameters
  35. );
  36. thccflags=set of thccflag;
  37. const
  38. hcc_default_actions_intf=[hcc_declaration,hcc_check,hcc_insert_hidden_paras];
  39. hcc_default_actions_intf_struct=hcc_default_actions_intf-[hcc_insert_hidden_paras];
  40. hcc_default_actions_impl=[hcc_check,hcc_insert_hidden_paras];
  41. hcc_default_actions_parse=[hcc_check,hcc_insert_hidden_paras];
  42. PD_VIRTUAL_MUTEXCLPO = [po_interrupt,po_exports,po_overridingmethod,po_inline,po_staticmethod];
  43. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags);
  44. function proc_add_definition(var currpd:tprocdef):boolean;
  45. { create "parent frame pointer" record skeleton for procdef, in which local
  46. variables and parameters from pd accessed from nested routines can be
  47. stored }
  48. procedure build_parentfpstruct(pd: tprocdef);
  49. implementation
  50. uses
  51. globals,globtype,cclasses,cutils,verbose,systems,fmodule,
  52. tokens,
  53. symtype,symbase,symsym,symtable,symutil,defutil,defcmp,blockutl,
  54. {$ifdef jvm}
  55. jvmdef,
  56. {$endif jvm}
  57. node,nbas,
  58. aasmbase,
  59. paramgr;
  60. procedure insert_funcret_para(pd:tabstractprocdef);
  61. var
  62. storepos : tfileposinfo;
  63. vs : tparavarsym;
  64. paranr : word;
  65. begin
  66. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  67. not is_void(pd.returndef) and
  68. not (df_generic in pd.defoptions) and
  69. paramanager.ret_in_param(pd.returndef,pd) then
  70. begin
  71. storepos:=current_tokenpos;
  72. if pd.typ=procdef then
  73. current_tokenpos:=tprocdef(pd).fileinfo;
  74. {$if defined(i386)}
  75. { For left to right add it at the end to be delphi compatible.
  76. In the case of safecalls with safecal-exceptions support the
  77. funcret-para is (from the 'c'-point of view) a normal parameter
  78. which has to be added to the end of the parameter-list }
  79. if (pd.proccalloption in (pushleftright_pocalls)) or
  80. ((tf_safecall_exceptions in target_info.flags) and
  81. (pd.proccalloption=pocall_safecall)) then
  82. paranr:=paranr_result_leftright
  83. else
  84. {$elseif defined(SUPPORT_SAFECALL)}
  85. if (tf_safecall_exceptions in target_info.flags) and
  86. (pd.proccalloption = pocall_safecall) then
  87. paranr:=paranr_result_leftright
  88. else
  89. {$endif}
  90. paranr:=paranr_result;
  91. { Generate result variable accessing function result }
  92. vs:=cparavarsym.create('$result',paranr,vs_var,pd.returndef,[vo_is_funcret,vo_is_hidden_para]);
  93. pd.parast.insert(vs);
  94. { Store this symbol as funcretsym for procedures }
  95. if pd.typ=procdef then
  96. tprocdef(pd).funcretsym:=vs;
  97. current_tokenpos:=storepos;
  98. end;
  99. end;
  100. procedure insert_parentfp_para(pd:tabstractprocdef);
  101. var
  102. storepos : tfileposinfo;
  103. vs : tparavarsym;
  104. paranr : longint;
  105. begin
  106. if pd.parast.symtablelevel>normal_function_level then
  107. begin
  108. storepos:=current_tokenpos;
  109. if pd.typ=procdef then
  110. current_tokenpos:=tprocdef(pd).fileinfo;
  111. { if no support for nested procvars is activated, use the old
  112. calling convention to pass the parent frame pointer for backwards
  113. compatibility }
  114. if not(m_nested_procvars in current_settings.modeswitches) then
  115. paranr:=paranr_parentfp
  116. { nested procvars require Delphi-style parentfp passing, see
  117. po_delphi_nested_cc declaration for more info }
  118. {$if defined(i386) or defined(i8086)}
  119. else if (pd.proccalloption in pushleftright_pocalls) then
  120. paranr:=paranr_parentfp_delphi_cc_leftright
  121. {$endif i386 or i8086}
  122. else
  123. paranr:=paranr_parentfp_delphi_cc;
  124. { Generate frame pointer. It can't be put in a register since it
  125. must be accessable from nested routines }
  126. if not(target_info.system in systems_fpnestedstruct) or
  127. { in case of errors or declared procvardef types, prevent invalid
  128. type cast and possible nil pointer dereference }
  129. not assigned(pd.owner.defowner) or
  130. (pd.owner.defowner.typ<>procdef) then
  131. begin
  132. vs:=cparavarsym.create('$parentfp',paranr,vs_value
  133. ,parentfpvoidpointertype,[vo_is_parentfp,vo_is_hidden_para]);
  134. vs.varregable:=vr_none;
  135. end
  136. else
  137. begin
  138. if not assigned(tprocdef(pd.owner.defowner).parentfpstruct) then
  139. build_parentfpstruct(tprocdef(pd.owner.defowner));
  140. vs:=cparavarsym.create('$parentfp',paranr,vs_value,
  141. tprocdef(pd.owner.defowner).parentfpstructptrtype,[vo_is_parentfp,vo_is_hidden_para]);
  142. end;
  143. pd.parast.insert(vs);
  144. current_tokenpos:=storepos;
  145. end;
  146. end;
  147. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  148. var
  149. storepos : tfileposinfo;
  150. vs : tparavarsym;
  151. hdef : tdef;
  152. selfdef : tdef;
  153. vsp : tvarspez;
  154. aliasvs : tabsolutevarsym;
  155. sl : tpropaccesslist;
  156. begin
  157. if (pd.typ=procdef) and
  158. is_objc_class_or_protocol(tprocdef(pd).struct) and
  159. (pd.parast.symtablelevel=normal_function_level) then
  160. begin
  161. { insert Objective-C self and selector parameters }
  162. vs:=cparavarsym.create('$_cmd',paranr_objc_cmd,vs_value,objc_seltype,[vo_is_msgsel,vo_is_hidden_para]);
  163. pd.parast.insert(vs);
  164. { make accessible to code }
  165. sl:=tpropaccesslist.create;
  166. sl.addsym(sl_load,vs);
  167. aliasvs:=cabsolutevarsym.create_ref('_CMD',objc_seltype,sl);
  168. include(aliasvs.varoptions,vo_is_msgsel);
  169. tlocalsymtable(tprocdef(pd).localst).insert(aliasvs);
  170. if (po_classmethod in pd.procoptions) then
  171. { compatible with what gcc does }
  172. hdef:=objc_idtype
  173. else
  174. hdef:=tprocdef(pd).struct;
  175. vs:=cparavarsym.create('$self',paranr_objc_self,vs_value,hdef,[vo_is_self,vo_is_hidden_para]);
  176. pd.parast.insert(vs);
  177. end
  178. else if (pd.typ=procvardef) and
  179. pd.is_methodpointer then
  180. begin
  181. { Generate self variable }
  182. vs:=cparavarsym.create('$self',paranr_self,vs_value,voidpointertype,[vo_is_self,vo_is_hidden_para]);
  183. pd.parast.insert(vs);
  184. end
  185. { while only procvardefs of this type can be declared in Pascal code,
  186. internally we also generate procdefs of this type when creating
  187. block wrappers }
  188. else if (po_is_block in pd.procoptions) then
  189. begin
  190. { generate the first hidden parameter, which is a so-called "block
  191. literal" describing the block and containing its invocation
  192. procedure }
  193. hdef:=cpointerdef.getreusable(get_block_literal_type_for_proc(pd));
  194. { mark as vo_is_parentfp so that proc2procvar comparisons will
  195. succeed when assigning arbitrary routines to the block }
  196. vs:=cparavarsym.create('$_block_literal',paranr_blockselfpara,vs_value,
  197. hdef,[vo_is_hidden_para,vo_is_parentfp]
  198. );
  199. pd.parast.insert(vs);
  200. if pd.typ=procdef then
  201. begin
  202. { make accessible to code }
  203. sl:=tpropaccesslist.create;
  204. sl.addsym(sl_load,vs);
  205. aliasvs:=cabsolutevarsym.create_ref('FPC_BLOCK_SELF',hdef,sl);
  206. include(aliasvs.varoptions,vo_is_parentfp);
  207. tlocalsymtable(tprocdef(pd).localst).insert(aliasvs);
  208. end;
  209. end
  210. else
  211. begin
  212. if (pd.typ=procdef) and
  213. assigned(tprocdef(pd).struct) and
  214. (pd.parast.symtablelevel=normal_function_level) then
  215. begin
  216. { static class methods have no hidden self/vmt pointer }
  217. if pd.no_self_node then
  218. exit;
  219. storepos:=current_tokenpos;
  220. current_tokenpos:=tprocdef(pd).fileinfo;
  221. { Generate VMT variable for constructor/destructor }
  222. if (pd.proctypeoption in [potype_constructor,potype_destructor]) and
  223. not(is_cppclass(tprocdef(pd).struct) or
  224. is_record(tprocdef(pd).struct) or
  225. is_javaclass(tprocdef(pd).struct) or
  226. (
  227. { no vmt for record/type helper constructors }
  228. is_objectpascal_helper(tprocdef(pd).struct) and
  229. (tobjectdef(tprocdef(pd).struct).extendeddef.typ<>objectdef)
  230. )) then
  231. begin
  232. vs:=cparavarsym.create('$vmt',paranr_vmt,vs_value,cclassrefdef.create(tprocdef(pd).struct),[vo_is_vmt,vo_is_hidden_para]);
  233. pd.parast.insert(vs);
  234. end;
  235. { for helpers the type of Self is equivalent to the extended
  236. type or equal to an instance of it }
  237. if is_objectpascal_helper(tprocdef(pd).struct) then
  238. selfdef:=tobjectdef(tprocdef(pd).struct).extendeddef
  239. else if is_objccategory(tprocdef(pd).struct) then
  240. selfdef:=tobjectdef(tprocdef(pd).struct).childof
  241. else
  242. selfdef:=tprocdef(pd).struct;
  243. { Generate self variable, for classes we need
  244. to use the generic voidpointer to be compatible with
  245. methodpointers }
  246. vsp:=vs_value;
  247. if (po_staticmethod in pd.procoptions) or
  248. (po_classmethod in pd.procoptions) then
  249. hdef:=cclassrefdef.create(selfdef)
  250. else
  251. begin
  252. if is_object(selfdef) or (selfdef.typ<>objectdef) then
  253. vsp:=vs_var;
  254. hdef:=selfdef;
  255. end;
  256. vs:=cparavarsym.create('$self',paranr_self,vsp,hdef,[vo_is_self,vo_is_hidden_para]);
  257. pd.parast.insert(vs);
  258. current_tokenpos:=storepos;
  259. end;
  260. end;
  261. end;
  262. procedure insert_funcret_local(pd:tprocdef);
  263. var
  264. storepos : tfileposinfo;
  265. vs : tlocalvarsym;
  266. aliasvs : tabsolutevarsym;
  267. sl : tpropaccesslist;
  268. hs : string;
  269. begin
  270. storepos:=current_tokenpos;
  271. current_tokenpos:=pd.fileinfo;
  272. { The result from constructors and destructors can't be accessed directly }
  273. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  274. not is_void(pd.returndef) and
  275. (not(po_assembler in pd.procoptions) or paramanager.asm_result_var(pd.returndef,pd)) then
  276. begin
  277. { We need to insert a varsym for the result in the localst
  278. when it is returning in a register }
  279. { we also need to do this for a generic procdef as we didn't allow
  280. the creation of a result symbol in insert_funcret_para, but we need
  281. a valid funcretsym }
  282. if (df_generic in pd.defoptions) or
  283. not paramanager.ret_in_param(pd.returndef,pd) then
  284. begin
  285. vs:=clocalvarsym.create('$result',vs_value,pd.returndef,[vo_is_funcret]);
  286. pd.localst.insert(vs);
  287. pd.funcretsym:=vs;
  288. end;
  289. { insert the name of the procedure as alias for the function result,
  290. we can't use realname because that will not work for compilerprocs
  291. as the name is lowercase and unreachable from the code }
  292. if (pd.proctypeoption<>potype_operator) or assigned(pd.resultname) then
  293. begin
  294. if assigned(pd.resultname) then
  295. hs:=pd.resultname^
  296. else
  297. hs:=pd.procsym.name;
  298. sl:=tpropaccesslist.create;
  299. sl.addsym(sl_load,pd.funcretsym);
  300. aliasvs:=cabsolutevarsym.create_ref(hs,pd.returndef,sl);
  301. include(aliasvs.varoptions,vo_is_funcret);
  302. tlocalsymtable(pd.localst).insert(aliasvs);
  303. end;
  304. { insert result also if support is on }
  305. if (m_result in current_settings.modeswitches) then
  306. begin
  307. sl:=tpropaccesslist.create;
  308. sl.addsym(sl_load,pd.funcretsym);
  309. aliasvs:=cabsolutevarsym.create_ref('RESULT',pd.returndef,sl);
  310. include(aliasvs.varoptions,vo_is_funcret);
  311. include(aliasvs.varoptions,vo_is_result);
  312. tlocalsymtable(pd.localst).insert(aliasvs);
  313. end;
  314. end;
  315. if pd.generate_safecall_wrapper then
  316. begin
  317. { vo_is_funcret is necessary so the local only gets freed after we loaded its
  318. value into the return register }
  319. vs:=clocalvarsym.create('$safecallresult',vs_value,search_system_type('HRESULT').typedef,[vo_is_funcret]);
  320. { do not put this variable in a register. The register which will be bound
  321. to this symbol will not be allocated automatically. Which means it will
  322. be re-used wich breaks the code. Besides this it is questionable if it is
  323. an optimization if one of the registers is kept allocated during the complete
  324. function, without ever using it.
  325. (It would be better to re-write the safecall-support in such a way that this
  326. variable it not needed at all, but that the HRESULT is set when the method
  327. is finalized) }
  328. vs.varregable:=vr_none;
  329. pd.localst.insert(vs);
  330. end;
  331. current_tokenpos:=storepos;
  332. end;
  333. procedure insert_hidden_para(p:TObject;arg:pointer);
  334. var
  335. hvs : tparavarsym;
  336. pd : tabstractprocdef absolute arg;
  337. begin
  338. if (tsym(p).typ<>paravarsym) then
  339. exit;
  340. with tparavarsym(p) do
  341. begin
  342. { We need a local copy for a value parameter when only the
  343. address is pushed. Open arrays and Array of Const are
  344. an exception because they are allocated at runtime and the
  345. address that is pushed is patched.
  346. Arrays passed to cdecl routines are special: they are pointers in
  347. C and hence must be passed as such. Due to historical reasons, if
  348. a cdecl routine is implemented in Pascal, we still make a copy on
  349. the callee side. Do this the same on platforms that normally must
  350. make a copy on the caller side, as otherwise the behaviour will
  351. be different (and less perfomant) for routines implemented in C }
  352. if (varspez=vs_value) and
  353. paramanager.push_addr_param(varspez,vardef,pd.proccalloption) and
  354. not(is_open_array(vardef) or
  355. is_array_of_const(vardef)) and
  356. (not(target_info.system in systems_caller_copy_addr_value_para) or
  357. ((pd.proccalloption in cdecl_pocalls) and
  358. (vardef.typ=arraydef))) then
  359. include(varoptions,vo_has_local_copy);
  360. { needs high parameter ? }
  361. if paramanager.push_high_param(varspez,vardef,pd.proccalloption) then
  362. begin
  363. hvs:=cparavarsym.create('$high'+name,paranr+1,vs_const,sizesinttype,[vo_is_high_para,vo_is_hidden_para]);
  364. hvs.symoptions:=[];
  365. owner.insert(hvs);
  366. { don't place to register if it will be accessed from implicit finally block }
  367. if (varspez=vs_value) and
  368. is_open_array(vardef) and
  369. is_managed_type(vardef) then
  370. hvs.varregable:=vr_none;
  371. end
  372. else
  373. begin
  374. { Give a warning that cdecl routines does not include high()
  375. support }
  376. if (pd.proccalloption in cdecl_pocalls) and
  377. paramanager.push_high_param(varspez,vardef,pocall_default) then
  378. begin
  379. if is_open_string(vardef) then
  380. MessagePos(fileinfo,parser_w_cdecl_no_openstring);
  381. if not(po_external in pd.procoptions) and
  382. (pd.typ<>procvardef) and
  383. not is_objc_class_or_protocol(tprocdef(pd).struct) then
  384. if is_array_of_const(vardef) then
  385. MessagePos(fileinfo,parser_e_varargs_need_cdecl_and_external)
  386. else
  387. MessagePos(fileinfo,parser_w_cdecl_has_no_high);
  388. end;
  389. if (vardef.typ=formaldef) and (Tformaldef(vardef).typed) then
  390. begin
  391. hvs:=cparavarsym.create('$typinfo'+name,paranr+1,vs_const,voidpointertype,
  392. [vo_is_typinfo_para,vo_is_hidden_para]);
  393. owner.insert(hvs);
  394. end;
  395. end;
  396. end;
  397. end;
  398. procedure check_c_para(pd:Tabstractprocdef);
  399. var
  400. i,
  401. lastparaidx : longint;
  402. sym : TSym;
  403. begin
  404. lastparaidx:=pd.parast.SymList.Count-1;
  405. for i:=0 to pd.parast.SymList.Count-1 do
  406. begin
  407. sym:=tsym(pd.parast.SymList[i]);
  408. if (sym.typ=paravarsym) and
  409. (tparavarsym(sym).vardef.typ=arraydef) then
  410. begin
  411. if not is_variant_array(tparavarsym(sym).vardef) and
  412. not is_array_of_const(tparavarsym(sym).vardef) and
  413. (tparavarsym(sym).varspez<>vs_var) then
  414. MessagePos(tparavarsym(sym).fileinfo,parser_h_c_arrays_are_references);
  415. if is_array_of_const(tparavarsym(sym).vardef) and
  416. (i<lastparaidx) and
  417. (tsym(pd.parast.SymList[i+1]).typ=paravarsym) and
  418. not(vo_is_high_para in tparavarsym(pd.parast.SymList[i+1]).varoptions) then
  419. MessagePos(tparavarsym(sym).fileinfo,parser_e_C_array_of_const_must_be_last);
  420. end;
  421. end;
  422. end;
  423. procedure insert_struct_hidden_paras(astruct: tabstractrecorddef);
  424. var
  425. pd: tdef;
  426. i: longint;
  427. oldpos: tfileposinfo;
  428. begin
  429. // handle calling conventions of record methods
  430. oldpos:=current_filepos;
  431. { don't keep track of procdefs in a separate list, because the
  432. compiler may add additional procdefs (e.g. property wrappers for
  433. the jvm backend) }
  434. for i := 0 to astruct.symtable.deflist.count - 1 do
  435. begin
  436. pd:=tdef(astruct.symtable.deflist[i]);
  437. if pd.typ<>procdef then
  438. continue;
  439. current_filepos:=tprocdef(pd).fileinfo;
  440. handle_calling_convention(tprocdef(pd),[hcc_declaration,hcc_insert_hidden_paras]);
  441. end;
  442. current_filepos:=oldpos;
  443. end;
  444. procedure set_addr_param_regable(p:TObject;arg:pointer);
  445. begin
  446. if (tsym(p).typ<>paravarsym) then
  447. exit;
  448. with tparavarsym(p) do
  449. begin
  450. if (not needs_finalization) and
  451. paramanager.push_addr_param(varspez,vardef,tprocdef(arg).proccalloption) then
  452. varregable:=vr_addr;
  453. end;
  454. end;
  455. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags);
  456. begin
  457. if hcc_check in flags then
  458. begin
  459. { set the default calling convention if none provided }
  460. if (pd.typ=procdef) and
  461. (is_objc_class_or_protocol(tprocdef(pd).struct) or
  462. is_cppclass(tprocdef(pd).struct)) then
  463. begin
  464. { none of the explicit calling conventions should be allowed }
  465. if (po_hascallingconvention in pd.procoptions) then
  466. internalerror(2009032501);
  467. if is_cppclass(tprocdef(pd).struct) then
  468. pd.proccalloption:=pocall_cppdecl
  469. else
  470. pd.proccalloption:=pocall_cdecl;
  471. end
  472. else if not(po_hascallingconvention in pd.procoptions) then
  473. pd.proccalloption:=current_settings.defproccall
  474. else
  475. begin
  476. if pd.proccalloption=pocall_none then
  477. internalerror(200309081);
  478. end;
  479. { handle proccall specific settings }
  480. case pd.proccalloption of
  481. pocall_cdecl,
  482. pocall_cppdecl,
  483. pocall_sysv_abi_cdecl,
  484. pocall_ms_abi_cdecl:
  485. begin
  486. { check C cdecl para types }
  487. check_c_para(pd);
  488. end;
  489. pocall_far16 :
  490. begin
  491. { Temporary stub, must be rewritten to support OS/2 far16 }
  492. Message1(parser_w_proc_directive_ignored,'FAR16');
  493. end;
  494. else
  495. ;
  496. end;
  497. { Inlining is enabled and supported? }
  498. if (po_inline in pd.procoptions) and
  499. not(cs_do_inline in current_settings.localswitches) then
  500. begin
  501. { Give an error if inline is not supported by the compiler mode,
  502. otherwise only give a hint that this procedure will not be inlined }
  503. if not(m_default_inline in current_settings.modeswitches) then
  504. Message(parser_e_proc_inline_not_supported)
  505. else
  506. Message(parser_h_inlining_disabled);
  507. exclude(pd.procoptions,po_inline);
  508. end;
  509. { For varargs directive also cdecl and external must be defined }
  510. if (po_varargs in pd.procoptions) then
  511. begin
  512. { check first for external in the interface, if available there
  513. then the cdecl must also be there since there is no implementation
  514. available to contain it }
  515. if hcc_declaration in flags then
  516. begin
  517. { if external is available, then cdecl must also be available,
  518. procvars don't need external }
  519. if not((po_external in pd.procoptions) or
  520. (pd.typ=procvardef) or
  521. { for objcclasses this is checked later, because the entire
  522. class may be external. }
  523. is_objc_class_or_protocol(tprocdef(pd).struct)) and
  524. not(pd.proccalloption in (cdecl_pocalls + [pocall_stdcall])) then
  525. Message(parser_e_varargs_need_cdecl_and_external);
  526. end
  527. else
  528. begin
  529. { both must be defined now }
  530. if not((po_external in pd.procoptions) or
  531. (pd.typ=procvardef)) or
  532. not(pd.proccalloption in (cdecl_pocalls + [pocall_stdcall])) then
  533. Message(parser_e_varargs_need_cdecl_and_external);
  534. end;
  535. end;
  536. end;
  537. if hcc_insert_hidden_paras in flags then
  538. begin
  539. { If the paraloc info has been calculated already, it will be missing for
  540. the new parameters we add below. This should never be necessary before
  541. we add them, as users of this information would not process these extra
  542. parameters in that case }
  543. if pd.has_paraloc_info<>callnoside then
  544. internalerror(2019031610);
  545. { insert hidden high parameters }
  546. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  547. { insert hidden self parameter }
  548. insert_self_and_vmt_para(pd);
  549. { insert funcret parameter if required }
  550. insert_funcret_para(pd);
  551. { Make var parameters regable, this must be done after the calling
  552. convention is set. }
  553. { this must be done before parentfp is insert, because getting all cases
  554. where parentfp must be in a memory location isn't catched properly so
  555. we put parentfp never in a register }
  556. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  557. { insert parentfp parameter if required }
  558. insert_parentfp_para(pd);
  559. end;
  560. { Calculate parameter tlist }
  561. pd.calcparas;
  562. end;
  563. function proc_add_definition(var currpd:tprocdef):boolean;
  564. function check_generic_parameters(fwpd,currpd:tprocdef):boolean;
  565. var
  566. i : longint;
  567. fwtype,
  568. currtype : ttypesym;
  569. begin
  570. result:=true;
  571. if fwpd.genericparas.count<>currpd.genericparas.count then
  572. internalerror(2018090101);
  573. for i:=0 to fwpd.genericparas.count-1 do
  574. begin
  575. fwtype:=ttypesym(fwpd.genericparas[i]);
  576. currtype:=ttypesym(currpd.genericparas[i]);
  577. if fwtype.name<>currtype.name then
  578. begin
  579. messagepos1(currtype.fileinfo,sym_e_generic_type_param_mismatch,currtype.realname);
  580. messagepos1(fwtype.fileinfo,sym_e_generic_type_param_decl,fwtype.realname);
  581. result:=false;
  582. end;
  583. end;
  584. end;
  585. function equal_generic_procdefs(fwpd,currpd:tprocdef):boolean;
  586. var
  587. i : longint;
  588. fwtype,
  589. currtype : ttypesym;
  590. foundretdef : boolean;
  591. begin
  592. result:=false;
  593. if fwpd.genericparas.count<>currpd.genericparas.count then
  594. exit;
  595. { comparing generic declarations is a bit more cumbersome as the
  596. defs of the generic parameter types are not equal, especially if the
  597. declaration contains constraints; essentially we have two cases:
  598. - proc declared in interface of unit (or in class/record/object)
  599. and defined in implementation; here the fwpd might contain
  600. constraints while currpd must only contain undefineddefs
  601. - forward declaration in implementation }
  602. foundretdef:=false;
  603. for i:=0 to fwpd.genericparas.count-1 do
  604. begin
  605. fwtype:=ttypesym(fwpd.genericparas[i]);
  606. currtype:=ttypesym(currpd.genericparas[i]);
  607. { if the type in the currpd isn't a pure undefineddef, then we can
  608. stop right there }
  609. if (currtype.typedef.typ<>undefineddef) or (df_genconstraint in currtype.typedef.defoptions) then
  610. exit;
  611. if not foundretdef then
  612. begin
  613. { if the returndef is the same as this parameter's def then this
  614. needs to be the case for both procdefs }
  615. foundretdef:=fwpd.returndef=fwtype.typedef;
  616. if foundretdef xor (currpd.returndef=currtype.typedef) then
  617. exit;
  618. end;
  619. end;
  620. if compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv,cpo_generic])<>te_exact then
  621. exit;
  622. if not foundretdef then
  623. begin
  624. if (df_specialization in tstoreddef(fwpd.returndef).defoptions) and (df_specialization in tstoreddef(currpd.returndef).defoptions) then
  625. { for specializations we're happy with equal defs instead of exactly the same defs }
  626. result:=equal_defs(fwpd.returndef,currpd.returndef)
  627. else
  628. { the returndef isn't a type parameter, so compare as usual }
  629. result:=compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact;
  630. end
  631. else
  632. result:=true;
  633. end;
  634. {
  635. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  636. forwarddef is found and reused it returns true
  637. }
  638. var
  639. fwpd : tprocdef;
  640. currparasym,
  641. fwparasym : tsym;
  642. currparacnt,
  643. fwparacnt,
  644. curridx,
  645. fwidx,
  646. i : longint;
  647. po_comp : tprocoptions;
  648. paracompopt: tcompare_paras_options;
  649. forwardfound : boolean;
  650. symentry: TSymEntry;
  651. item : tlinkedlistitem;
  652. begin
  653. forwardfound:=false;
  654. { check overloaded functions if the same function already exists }
  655. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  656. begin
  657. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  658. { can happen for internally generated routines }
  659. if (fwpd=currpd) then
  660. begin
  661. result:=true;
  662. exit;
  663. end;
  664. { Skip overloaded definitions that are declared in other units }
  665. if fwpd.procsym<>currpd.procsym then
  666. continue;
  667. { check the parameters, for delphi/tp it is possible to
  668. leave the parameters away in the implementation (forwarddef=false).
  669. But for an overload declared function this is not allowed }
  670. if { check if empty implementation arguments match is allowed }
  671. (
  672. not(m_repeat_forward in current_settings.modeswitches) and
  673. not(currpd.forwarddef) and
  674. is_bareprocdef(currpd) and
  675. not(po_overload in fwpd.procoptions)
  676. ) or
  677. (
  678. fwpd.is_generic and
  679. currpd.is_generic and
  680. equal_generic_procdefs(fwpd,currpd)
  681. ) or
  682. { check arguments, we need to check only the user visible parameters. The hidden parameters
  683. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  684. don't check default values here, because routines that are the same except for their default
  685. values should be reported as mismatches (since you can't overload based on different default
  686. parameter values) }
  687. (
  688. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  689. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  690. ) then
  691. begin
  692. { Check if we've found the forwarddef, if found then
  693. we need to update the forward def with the current
  694. implementation settings }
  695. if fwpd.forwarddef then
  696. begin
  697. forwardfound:=true;
  698. if not(m_repeat_forward in current_settings.modeswitches) and
  699. (fwpd.proccalloption<>currpd.proccalloption) then
  700. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  701. else
  702. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  703. { Check calling convention }
  704. if (fwpd.proccalloption<>currpd.proccalloption) then
  705. begin
  706. { In delphi it is possible to specify the calling
  707. convention in the interface or implementation if
  708. there was no convention specified in the other
  709. part }
  710. if (m_delphi in current_settings.modeswitches) then
  711. begin
  712. if not(po_hascallingconvention in currpd.procoptions) then
  713. currpd.proccalloption:=fwpd.proccalloption
  714. else
  715. if not(po_hascallingconvention in fwpd.procoptions) then
  716. fwpd.proccalloption:=currpd.proccalloption
  717. else
  718. begin
  719. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  720. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  721. { restore interface settings }
  722. currpd.proccalloption:=fwpd.proccalloption;
  723. end;
  724. end
  725. else
  726. begin
  727. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  728. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  729. { restore interface settings }
  730. currpd.proccalloption:=fwpd.proccalloption;
  731. end;
  732. end;
  733. { Check static }
  734. if (po_staticmethod in fwpd.procoptions) then
  735. begin
  736. if not (po_staticmethod in currpd.procoptions) then
  737. begin
  738. include(currpd.procoptions, po_staticmethod);
  739. if (po_classmethod in currpd.procoptions) then
  740. begin
  741. { remove self from the hidden paras }
  742. symentry:=currpd.parast.Find('self');
  743. if symentry<>nil then
  744. begin
  745. currpd.parast.Delete(symentry);
  746. currpd.calcparas;
  747. end;
  748. end;
  749. end;
  750. end;
  751. { Check if the procedure type and return type are correct,
  752. also the parameters must match also with the type and that
  753. if the implementation has default parameters, the interface
  754. also has them and that if they both have them, that they
  755. have the same value }
  756. if ((m_repeat_forward in current_settings.modeswitches) or
  757. not is_bareprocdef(currpd)) and
  758. (
  759. (
  760. fwpd.is_generic and
  761. currpd.is_generic and
  762. not equal_generic_procdefs(fwpd,currpd)
  763. ) or
  764. (
  765. (
  766. not fwpd.is_generic or
  767. not currpd.is_generic
  768. ) and
  769. (
  770. (compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  771. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)
  772. )
  773. )
  774. ) then
  775. begin
  776. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  777. fwpd.fullprocname(false));
  778. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  779. break;
  780. end;
  781. { Check if both are declared forward }
  782. if fwpd.forwarddef and currpd.forwarddef then
  783. begin
  784. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  785. currpd.fullprocname(false));
  786. end;
  787. { internconst or internproc only need to be defined once }
  788. if (fwpd.proccalloption=pocall_internproc) then
  789. currpd.proccalloption:=fwpd.proccalloption
  790. else
  791. if (currpd.proccalloption=pocall_internproc) then
  792. fwpd.proccalloption:=currpd.proccalloption;
  793. { Check procedure options, Delphi requires that class is
  794. repeated in the implementation for class methods }
  795. if (m_fpc in current_settings.modeswitches) then
  796. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  797. else
  798. po_comp:=[po_classmethod,po_methodpointer];
  799. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  800. (fwpd.proctypeoption <> currpd.proctypeoption) or
  801. { if the implementation version has an "overload" modifier,
  802. the interface version must also have it (otherwise we can
  803. get annoying crashes due to interface crc changes) }
  804. (not(po_overload in fwpd.procoptions) and
  805. (po_overload in currpd.procoptions)) or
  806. { same with noreturn }
  807. (not(po_noreturn in fwpd.procoptions) and
  808. (po_noreturn in currpd.procoptions)) then
  809. begin
  810. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  811. fwpd.fullprocname(false));
  812. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  813. { This error is non-fatal, we can recover }
  814. end;
  815. { Forward declaration is external? }
  816. if (po_external in fwpd.procoptions) then
  817. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  818. { check for conflicts with "virtual" if this is a virtual
  819. method, as "virtual" cannot be repeated in the
  820. implementation and hence does not get checked against }
  821. if (po_virtualmethod in fwpd.procoptions) then
  822. begin
  823. po_comp:=currpd.procoptions*PD_VIRTUAL_MUTEXCLPO;
  824. if po_comp<>[] then
  825. MessagePos2(currpd.fileinfo,parser_e_proc_dir_conflict,tokeninfo^[_VIRTUAL].str,get_first_proc_str(po_comp));
  826. end;
  827. { Check parameters }
  828. if (m_repeat_forward in current_settings.modeswitches) or
  829. (currpd.minparacount>0) then
  830. begin
  831. { If mangled names are equal then they have the same amount of arguments }
  832. { We can check the names of the arguments }
  833. { both symtables are in the same order from left to right }
  834. curridx:=0;
  835. fwidx:=0;
  836. currparacnt:=currpd.parast.SymList.Count;
  837. fwparacnt:=fwpd.parast.SymList.Count;
  838. repeat
  839. { skip default parameter constsyms }
  840. while (curridx<currparacnt) and
  841. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  842. inc(curridx);
  843. while (fwidx<fwparacnt) and
  844. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  845. inc(fwidx);
  846. { stop when one of the two lists is at the end }
  847. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  848. break;
  849. { compare names of parameters, ignore implictly
  850. renamed parameters }
  851. currparasym:=tsym(currpd.parast.SymList[curridx]);
  852. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  853. if not(sp_implicitrename in currparasym.symoptions) and
  854. not(sp_implicitrename in fwparasym.symoptions) then
  855. begin
  856. if (currparasym.name<>fwparasym.name) then
  857. begin
  858. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  859. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  860. break;
  861. end;
  862. end;
  863. { next parameter }
  864. inc(curridx);
  865. inc(fwidx);
  866. until false;
  867. end;
  868. { check that the type parameter names for generic methods match;
  869. we check this here and not in equal_generic_procdefs as the defs
  870. might still be different due to their parameters, so we'd generate
  871. errors without any need }
  872. if currpd.is_generic and fwpd.is_generic then
  873. { an error here is recoverable, so we simply continue }
  874. check_generic_parameters(fwpd,currpd);
  875. { Everything is checked, now we can update the forward declaration
  876. with the new data from the implementation }
  877. fwpd.forwarddef:=currpd.forwarddef;
  878. fwpd.hasforward:=true;
  879. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  880. { marked as local but exported from unit? }
  881. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  882. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  883. if fwpd.extnumber=$ffff then
  884. fwpd.extnumber:=currpd.extnumber;
  885. while not currpd.aliasnames.empty do
  886. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  887. { update fileinfo so position references the implementation,
  888. also update funcretsym if it is already generated }
  889. fwpd.fileinfo:=currpd.fileinfo;
  890. if assigned(fwpd.funcretsym) then
  891. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  892. if assigned(currpd.deprecatedmsg) then
  893. begin
  894. stringdispose(fwpd.deprecatedmsg);
  895. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  896. end;
  897. { import names }
  898. if assigned(currpd.import_dll) then
  899. begin
  900. stringdispose(fwpd.import_dll);
  901. fwpd.import_dll:=stringdup(currpd.import_dll^);
  902. end;
  903. if assigned(currpd.import_name) then
  904. begin
  905. stringdispose(fwpd.import_name);
  906. fwpd.import_name:=stringdup(currpd.import_name^);
  907. end;
  908. fwpd.import_nr:=currpd.import_nr;
  909. { for compilerproc defines we need to rename and update the
  910. symbolname to lowercase so users can' access it (can't do
  911. it immediately, because then the implementation symbol
  912. won't be matched) }
  913. if po_compilerproc in fwpd.procoptions then
  914. begin
  915. fwpd.setcompilerprocname;
  916. current_module.add_public_asmsym(fwpd.procsym.realname,AB_GLOBAL,AT_FUNCTION);
  917. end;
  918. if po_public in fwpd.procoptions then
  919. begin
  920. item:=fwpd.aliasnames.first;
  921. while assigned(item) do
  922. begin
  923. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  924. item:=item.next;
  925. end;
  926. end;
  927. { Release current procdef }
  928. currpd.owner.deletedef(currpd);
  929. currpd:=fwpd;
  930. end
  931. else
  932. begin
  933. { abstract methods aren't forward defined, but this }
  934. { needs another error message }
  935. if (po_abstractmethod in fwpd.procoptions) then
  936. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  937. else
  938. begin
  939. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  940. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  941. end;
  942. end;
  943. { we found one proc with the same arguments, there are no others
  944. so we can stop }
  945. break;
  946. end;
  947. { check for allowing overload directive }
  948. if not(m_fpc in current_settings.modeswitches) then
  949. begin
  950. { overload directive turns on overloading }
  951. if ((po_overload in currpd.procoptions) or
  952. (po_overload in fwpd.procoptions)) then
  953. begin
  954. { check if all procs have overloading, but not if the proc is a method or
  955. already declared forward, then the check is already done }
  956. if not(fwpd.hasforward or
  957. assigned(currpd.struct) or
  958. (currpd.forwarddef<>fwpd.forwarddef) or
  959. ((po_overload in currpd.procoptions) and
  960. (po_overload in fwpd.procoptions))) then
  961. begin
  962. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  963. break;
  964. end
  965. end
  966. else
  967. begin
  968. if not(fwpd.forwarddef) then
  969. begin
  970. if (m_tp7 in current_settings.modeswitches) then
  971. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  972. else
  973. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  974. break;
  975. end;
  976. end;
  977. end; { equal arguments }
  978. end;
  979. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  980. list }
  981. if not forwardfound then
  982. begin
  983. { can happen in Delphi mode }
  984. if (currpd.proctypeoption = potype_function) and
  985. is_void(currpd.returndef) then
  986. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  987. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  988. if not currpd.forwarddef and (po_public in currpd.procoptions) then
  989. begin
  990. item:=currpd.aliasnames.first;
  991. while assigned(item) do
  992. begin
  993. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  994. item:=item.next;
  995. end;
  996. end;
  997. end;
  998. proc_add_definition:=forwardfound;
  999. end;
  1000. procedure build_parentfpstruct(pd: tprocdef);
  1001. var
  1002. nestedvars: tsym;
  1003. nestedvarsst: tsymtable;
  1004. pnestedvarsdef,
  1005. nestedvarsdef: tdef;
  1006. old_symtablestack: tsymtablestack;
  1007. begin
  1008. { make sure the defs are not registered in the current symtablestack,
  1009. because they may be for a parent procdef (changeowner does remove a def
  1010. from the symtable in which it was originally created, so that by itself
  1011. is not enough) }
  1012. old_symtablestack:=symtablestack;
  1013. symtablestack:=old_symtablestack.getcopyuntil(current_module.localsymtable);
  1014. { create struct to hold local variables and parameters that are
  1015. accessed from within nested routines (start with extra dollar to prevent
  1016. the JVM from thinking this is a nested class in the unit) }
  1017. nestedvarsst:=trecordsymtable.create('$'+current_module.realmodulename^+'$$_fpc_nestedvars$'+pd.unique_id_str,
  1018. current_settings.alignment.localalignmax,current_settings.alignment.localalignmin);
  1019. nestedvarsdef:=crecorddef.create(nestedvarsst.name^,nestedvarsst);
  1020. {$ifdef jvm}
  1021. maybe_guarantee_record_typesym(nestedvarsdef,nestedvarsdef.owner);
  1022. { don't add clone/FpcDeepCopy, because the field names are not all
  1023. representable in source form and we don't need them anyway }
  1024. symtablestack.push(trecorddef(nestedvarsdef).symtable);
  1025. maybe_add_public_default_java_constructor(trecorddef(nestedvarsdef));
  1026. insert_struct_hidden_paras(trecorddef(nestedvarsdef));
  1027. symtablestack.pop(trecorddef(nestedvarsdef).symtable);
  1028. {$endif}
  1029. symtablestack.free;
  1030. symtablestack:=old_symtablestack.getcopyuntil(pd.localst);
  1031. pnestedvarsdef:=cpointerdef.getreusable(nestedvarsdef);
  1032. if not(po_assembler in pd.procoptions) then
  1033. begin
  1034. nestedvars:=clocalvarsym.create('$nestedvars',vs_var,nestedvarsdef,[]);
  1035. include(nestedvars.symoptions,sp_internal);
  1036. pd.localst.insert(nestedvars);
  1037. pd.parentfpstruct:=nestedvars;
  1038. pd.parentfpinitblock:=cblocknode.create(nil);
  1039. end;
  1040. symtablestack.free;
  1041. pd.parentfpstructptrtype:=pnestedvarsdef;
  1042. symtablestack:=old_symtablestack;
  1043. end;
  1044. end.