pparautl.pas 51 KB

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