pparautl.pas 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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. if assigned(currpd.struct) and
  655. (currpd.struct.symtable.moduleid<>current_module.moduleid) and
  656. not currpd.is_specialization then
  657. begin
  658. result:=false;
  659. exit;
  660. end;
  661. { check overloaded functions if the same function already exists }
  662. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  663. begin
  664. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  665. { can happen for internally generated routines }
  666. if (fwpd=currpd) then
  667. begin
  668. result:=true;
  669. exit;
  670. end;
  671. { Skip overloaded definitions that are declared in other units }
  672. if fwpd.procsym<>currpd.procsym then
  673. continue;
  674. { check the parameters, for delphi/tp it is possible to
  675. leave the parameters away in the implementation (forwarddef=false).
  676. But for an overload declared function this is not allowed }
  677. if { check if empty implementation arguments match is allowed }
  678. (
  679. not(m_repeat_forward in current_settings.modeswitches) and
  680. not(currpd.forwarddef) and
  681. is_bareprocdef(currpd) and
  682. not(po_overload in fwpd.procoptions)
  683. ) or
  684. (
  685. fwpd.is_generic and
  686. currpd.is_generic and
  687. equal_generic_procdefs(fwpd,currpd)
  688. ) or
  689. { check arguments, we need to check only the user visible parameters. The hidden parameters
  690. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  691. don't check default values here, because routines that are the same except for their default
  692. values should be reported as mismatches (since you can't overload based on different default
  693. parameter values) }
  694. (
  695. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  696. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  697. ) then
  698. begin
  699. { Check if we've found the forwarddef, if found then
  700. we need to update the forward def with the current
  701. implementation settings }
  702. if fwpd.forwarddef then
  703. begin
  704. forwardfound:=true;
  705. if not(m_repeat_forward in current_settings.modeswitches) and
  706. (fwpd.proccalloption<>currpd.proccalloption) then
  707. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  708. else
  709. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  710. { Check calling convention }
  711. if (fwpd.proccalloption<>currpd.proccalloption) then
  712. begin
  713. { In delphi it is possible to specify the calling
  714. convention in the interface or implementation if
  715. there was no convention specified in the other
  716. part }
  717. if (m_delphi in current_settings.modeswitches) then
  718. begin
  719. if not(po_hascallingconvention in currpd.procoptions) then
  720. currpd.proccalloption:=fwpd.proccalloption
  721. else
  722. if not(po_hascallingconvention in fwpd.procoptions) then
  723. fwpd.proccalloption:=currpd.proccalloption
  724. else
  725. begin
  726. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  727. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  728. { restore interface settings }
  729. currpd.proccalloption:=fwpd.proccalloption;
  730. end;
  731. end
  732. else
  733. begin
  734. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  735. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  736. { restore interface settings }
  737. currpd.proccalloption:=fwpd.proccalloption;
  738. end;
  739. end;
  740. { Check static }
  741. if (po_staticmethod in fwpd.procoptions) then
  742. begin
  743. if not (po_staticmethod in currpd.procoptions) then
  744. begin
  745. include(currpd.procoptions, po_staticmethod);
  746. if (po_classmethod in currpd.procoptions) then
  747. begin
  748. { remove self from the hidden paras }
  749. symentry:=currpd.parast.Find('self');
  750. if symentry<>nil then
  751. begin
  752. currpd.parast.Delete(symentry);
  753. currpd.calcparas;
  754. end;
  755. end;
  756. end;
  757. end;
  758. { Check if the procedure type and return type are correct,
  759. also the parameters must match also with the type and that
  760. if the implementation has default parameters, the interface
  761. also has them and that if they both have them, that they
  762. have the same value }
  763. if ((m_repeat_forward in current_settings.modeswitches) or
  764. not is_bareprocdef(currpd)) and
  765. (
  766. (
  767. fwpd.is_generic and
  768. currpd.is_generic and
  769. not equal_generic_procdefs(fwpd,currpd)
  770. ) or
  771. (
  772. (
  773. not fwpd.is_generic or
  774. not currpd.is_generic
  775. ) and
  776. (
  777. (compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  778. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)
  779. )
  780. )
  781. ) then
  782. begin
  783. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  784. fwpd.fullprocname(false));
  785. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  786. break;
  787. end;
  788. { Check if both are declared forward }
  789. if fwpd.forwarddef and currpd.forwarddef then
  790. begin
  791. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  792. currpd.fullprocname(false));
  793. end;
  794. { internconst or internproc only need to be defined once }
  795. if (fwpd.proccalloption=pocall_internproc) then
  796. currpd.proccalloption:=fwpd.proccalloption
  797. else
  798. if (currpd.proccalloption=pocall_internproc) then
  799. fwpd.proccalloption:=currpd.proccalloption;
  800. { Check procedure options, Delphi requires that class is
  801. repeated in the implementation for class methods }
  802. if (m_fpc in current_settings.modeswitches) then
  803. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  804. else
  805. po_comp:=[po_classmethod,po_methodpointer];
  806. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  807. (fwpd.proctypeoption <> currpd.proctypeoption) or
  808. { if the implementation version has an "overload" modifier,
  809. the interface version must also have it (otherwise we can
  810. get annoying crashes due to interface crc changes) }
  811. (not(po_overload in fwpd.procoptions) and
  812. (po_overload in currpd.procoptions)) or
  813. { same with noreturn }
  814. (not(po_noreturn in fwpd.procoptions) and
  815. (po_noreturn in currpd.procoptions)) then
  816. begin
  817. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  818. fwpd.fullprocname(false));
  819. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  820. { This error is non-fatal, we can recover }
  821. end;
  822. { Forward declaration is external? }
  823. if (po_external in fwpd.procoptions) then
  824. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  825. { check for conflicts with "virtual" if this is a virtual
  826. method, as "virtual" cannot be repeated in the
  827. implementation and hence does not get checked against }
  828. if (po_virtualmethod in fwpd.procoptions) then
  829. begin
  830. po_comp:=currpd.procoptions*PD_VIRTUAL_MUTEXCLPO;
  831. if po_comp<>[] then
  832. MessagePos2(currpd.fileinfo,parser_e_proc_dir_conflict,tokeninfo^[_VIRTUAL].str,get_first_proc_str(po_comp));
  833. end;
  834. { Check parameters }
  835. if (m_repeat_forward in current_settings.modeswitches) or
  836. (currpd.minparacount>0) then
  837. begin
  838. { If mangled names are equal then they have the same amount of arguments }
  839. { We can check the names of the arguments }
  840. { both symtables are in the same order from left to right }
  841. curridx:=0;
  842. fwidx:=0;
  843. currparacnt:=currpd.parast.SymList.Count;
  844. fwparacnt:=fwpd.parast.SymList.Count;
  845. repeat
  846. { skip default parameter constsyms }
  847. while (curridx<currparacnt) and
  848. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  849. inc(curridx);
  850. while (fwidx<fwparacnt) and
  851. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  852. inc(fwidx);
  853. { stop when one of the two lists is at the end }
  854. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  855. break;
  856. { compare names of parameters, ignore implictly
  857. renamed parameters }
  858. currparasym:=tsym(currpd.parast.SymList[curridx]);
  859. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  860. if not(sp_implicitrename in currparasym.symoptions) and
  861. not(sp_implicitrename in fwparasym.symoptions) then
  862. begin
  863. if (currparasym.name<>fwparasym.name) then
  864. begin
  865. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  866. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  867. break;
  868. end;
  869. end;
  870. { next parameter }
  871. inc(curridx);
  872. inc(fwidx);
  873. until false;
  874. end;
  875. { check that the type parameter names for generic methods match;
  876. we check this here and not in equal_generic_procdefs as the defs
  877. might still be different due to their parameters, so we'd generate
  878. errors without any need }
  879. if currpd.is_generic and fwpd.is_generic then
  880. { an error here is recoverable, so we simply continue }
  881. check_generic_parameters(fwpd,currpd);
  882. { Everything is checked, now we can update the forward declaration
  883. with the new data from the implementation }
  884. fwpd.forwarddef:=currpd.forwarddef;
  885. fwpd.hasforward:=true;
  886. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  887. { marked as local but exported from unit? }
  888. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  889. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  890. if fwpd.extnumber=$ffff then
  891. fwpd.extnumber:=currpd.extnumber;
  892. while not currpd.aliasnames.empty do
  893. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  894. { update fileinfo so position references the implementation,
  895. also update funcretsym if it is already generated }
  896. fwpd.fileinfo:=currpd.fileinfo;
  897. if assigned(fwpd.funcretsym) then
  898. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  899. if assigned(currpd.deprecatedmsg) then
  900. begin
  901. stringdispose(fwpd.deprecatedmsg);
  902. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  903. end;
  904. { import names }
  905. if assigned(currpd.import_dll) then
  906. begin
  907. stringdispose(fwpd.import_dll);
  908. fwpd.import_dll:=stringdup(currpd.import_dll^);
  909. end;
  910. if assigned(currpd.import_name) then
  911. begin
  912. stringdispose(fwpd.import_name);
  913. fwpd.import_name:=stringdup(currpd.import_name^);
  914. end;
  915. fwpd.import_nr:=currpd.import_nr;
  916. { for compilerproc defines we need to rename and update the
  917. symbolname to lowercase so users can' access it (can't do
  918. it immediately, because then the implementation symbol
  919. won't be matched) }
  920. if po_compilerproc in fwpd.procoptions then
  921. begin
  922. fwpd.setcompilerprocname;
  923. current_module.add_public_asmsym(fwpd.procsym.realname,AB_GLOBAL,AT_FUNCTION);
  924. end;
  925. if po_public in fwpd.procoptions then
  926. begin
  927. item:=fwpd.aliasnames.first;
  928. while assigned(item) do
  929. begin
  930. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  931. item:=item.next;
  932. end;
  933. end;
  934. { Release current procdef }
  935. currpd.owner.deletedef(currpd);
  936. currpd:=fwpd;
  937. end
  938. else
  939. begin
  940. { abstract methods aren't forward defined, but this }
  941. { needs another error message }
  942. if (po_abstractmethod in fwpd.procoptions) then
  943. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  944. else
  945. begin
  946. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  947. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  948. end;
  949. end;
  950. { we found one proc with the same arguments, there are no others
  951. so we can stop }
  952. break;
  953. end;
  954. { check for allowing overload directive }
  955. if not(m_fpc in current_settings.modeswitches) then
  956. begin
  957. { overload directive turns on overloading }
  958. if ((po_overload in currpd.procoptions) or
  959. (po_overload in fwpd.procoptions)) then
  960. begin
  961. { check if all procs have overloading, but not if the proc is a method or
  962. already declared forward, then the check is already done }
  963. if not(fwpd.hasforward or
  964. assigned(currpd.struct) or
  965. (currpd.forwarddef<>fwpd.forwarddef) or
  966. ((po_overload in currpd.procoptions) and
  967. (po_overload in fwpd.procoptions))) then
  968. begin
  969. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  970. break;
  971. end
  972. end
  973. else
  974. begin
  975. if not(fwpd.forwarddef) then
  976. begin
  977. if (m_tp7 in current_settings.modeswitches) then
  978. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  979. else
  980. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  981. break;
  982. end;
  983. end;
  984. end; { equal arguments }
  985. end;
  986. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  987. list }
  988. if not forwardfound then
  989. begin
  990. { can happen in Delphi mode }
  991. if (currpd.proctypeoption = potype_function) and
  992. is_void(currpd.returndef) then
  993. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  994. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  995. if not currpd.forwarddef and (po_public in currpd.procoptions) then
  996. begin
  997. item:=currpd.aliasnames.first;
  998. while assigned(item) do
  999. begin
  1000. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  1001. item:=item.next;
  1002. end;
  1003. end;
  1004. end;
  1005. proc_add_definition:=forwardfound;
  1006. end;
  1007. procedure build_parentfpstruct(pd: tprocdef);
  1008. var
  1009. nestedvars: tsym;
  1010. nestedvarsst: tsymtable;
  1011. pnestedvarsdef,
  1012. nestedvarsdef: tdef;
  1013. old_symtablestack: tsymtablestack;
  1014. begin
  1015. { make sure the defs are not registered in the current symtablestack,
  1016. because they may be for a parent procdef (changeowner does remove a def
  1017. from the symtable in which it was originally created, so that by itself
  1018. is not enough) }
  1019. old_symtablestack:=symtablestack;
  1020. symtablestack:=old_symtablestack.getcopyuntil(current_module.localsymtable);
  1021. { create struct to hold local variables and parameters that are
  1022. accessed from within nested routines (start with extra dollar to prevent
  1023. the JVM from thinking this is a nested class in the unit) }
  1024. nestedvarsst:=trecordsymtable.create('$'+current_module.realmodulename^+'$$_fpc_nestedvars$'+pd.unique_id_str,
  1025. current_settings.alignment.localalignmax,current_settings.alignment.localalignmin);
  1026. nestedvarsdef:=crecorddef.create(nestedvarsst.name^,nestedvarsst);
  1027. {$ifdef jvm}
  1028. maybe_guarantee_record_typesym(nestedvarsdef,nestedvarsdef.owner);
  1029. { don't add clone/FpcDeepCopy, because the field names are not all
  1030. representable in source form and we don't need them anyway }
  1031. symtablestack.push(trecorddef(nestedvarsdef).symtable);
  1032. maybe_add_public_default_java_constructor(trecorddef(nestedvarsdef));
  1033. insert_struct_hidden_paras(trecorddef(nestedvarsdef));
  1034. symtablestack.pop(trecorddef(nestedvarsdef).symtable);
  1035. {$endif}
  1036. symtablestack.free;
  1037. symtablestack:=old_symtablestack.getcopyuntil(pd.localst);
  1038. pnestedvarsdef:=cpointerdef.getreusable(nestedvarsdef);
  1039. if not(po_assembler in pd.procoptions) then
  1040. begin
  1041. nestedvars:=clocalvarsym.create('$nestedvars',vs_var,nestedvarsdef,[]);
  1042. include(nestedvars.symoptions,sp_internal);
  1043. pd.localst.insert(nestedvars);
  1044. pd.parentfpstruct:=nestedvars;
  1045. pd.parentfpinitblock:=cblocknode.create(nil);
  1046. end;
  1047. symtablestack.free;
  1048. pd.parentfpstructptrtype:=pnestedvarsdef;
  1049. symtablestack:=old_symtablestack;
  1050. end;
  1051. end.