psub.pas 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  3. Does the parsing and codegeneration at subroutine level
  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 psub;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,globals,
  22. node,nbas,
  23. symdef,procinfo,optdfa;
  24. type
  25. tcgprocinfo = class(tprocinfo)
  26. private
  27. procedure add_entry_exit_code;
  28. public
  29. { code for the subroutine as tree }
  30. code : tnode;
  31. { positions in the tree for init/final }
  32. entry_asmnode,
  33. loadpara_asmnode,
  34. exitlabel_asmnode,
  35. stackcheck_asmnode,
  36. init_asmnode,
  37. final_asmnode : tasmnode;
  38. { list to store the procinfo's of the nested procedures }
  39. nestedprocs : tlinkedlist;
  40. dfabuilder : TDFABuilder;
  41. constructor create(aparent:tprocinfo);override;
  42. destructor destroy;override;
  43. procedure printproc;
  44. procedure generate_code;
  45. procedure resetprocdef;
  46. procedure add_to_symtablestack;
  47. procedure remove_from_symtablestack;
  48. procedure parse_body;
  49. function stack_tainting_parameter : boolean;
  50. function has_assembler_child : boolean;
  51. end;
  52. procedure printnode_reset;
  53. { reads the declaration blocks }
  54. procedure read_declarations(islibrary : boolean);
  55. { reads declarations in the interface part of a unit }
  56. procedure read_interface_declarations;
  57. procedure generate_specialization_procs;
  58. implementation
  59. uses
  60. sysutils,
  61. { common }
  62. cutils,
  63. { global }
  64. globtype,tokens,verbose,comphook,constexp,
  65. systems,
  66. { aasm }
  67. cpuinfo,cpubase,aasmbase,aasmtai,aasmdata,
  68. { symtable }
  69. symconst,symbase,symsym,symtype,symtable,defutil,
  70. paramgr,
  71. ppu,fmodule,
  72. { pass 1 }
  73. nutils,nld,ncal,ncon,nflw,nadd,ncnv,nmem,
  74. pass_1,
  75. {$ifdef state_tracking}
  76. nstate,
  77. {$endif state_tracking}
  78. { pass 2 }
  79. {$ifndef NOPASS2}
  80. pass_2,
  81. {$endif}
  82. { parser }
  83. scanner,import,gendef,
  84. pbase,pstatmnt,pdecl,pdecsub,pexports,
  85. { codegen }
  86. tgobj,cgbase,cgobj,cgcpu,dbgbase,
  87. ncgutil,regvars,
  88. optbase,
  89. opttail,
  90. optcse,optloop,
  91. optutils
  92. {$if defined(arm) or defined(powerpc) or defined(powerpc64)}
  93. ,aasmcpu
  94. {$endif arm}
  95. {$ifndef NOOPT}
  96. {$ifdef i386}
  97. ,aopt386
  98. {$else i386}
  99. ,aopt
  100. {$endif i386}
  101. {$endif}
  102. ;
  103. {****************************************************************************
  104. PROCEDURE/FUNCTION BODY PARSING
  105. ****************************************************************************}
  106. procedure initializevars(p:TObject;arg:pointer);
  107. var
  108. b : tblocknode;
  109. begin
  110. if not (tsym(p).typ in [localvarsym,staticvarsym]) then
  111. exit;
  112. with tabstractnormalvarsym(p) do
  113. begin
  114. if assigned(defaultconstsym) then
  115. begin
  116. b:=tblocknode(arg);
  117. b.left:=cstatementnode.create(
  118. cassignmentnode.create(
  119. cloadnode.create(tsym(p),tsym(p).owner),
  120. cloadnode.create(defaultconstsym,defaultconstsym.owner)),
  121. b.left);
  122. end;
  123. end;
  124. end;
  125. procedure check_finalize_paras(p:TObject;arg:pointer);
  126. begin
  127. if (tsym(p).typ=paravarsym) and
  128. (tparavarsym(p).varspez=vs_value) and
  129. not is_class(tparavarsym(p).vardef) and
  130. tparavarsym(p).vardef.needs_inittable then
  131. include(current_procinfo.flags,pi_needs_implicit_finally);
  132. end;
  133. procedure check_finalize_locals(p:TObject;arg:pointer);
  134. begin
  135. { include the result: it needs to be finalized in case an exception }
  136. { occurs }
  137. if (tsym(p).typ=localvarsym) and
  138. (tlocalvarsym(p).refs>0) and
  139. not(is_class(tlocalvarsym(p).vardef)) and
  140. tlocalvarsym(p).vardef.needs_inittable then
  141. include(current_procinfo.flags,pi_needs_implicit_finally);
  142. end;
  143. function block(islibrary : boolean) : tnode;
  144. begin
  145. { parse const,types and vars }
  146. read_declarations(islibrary);
  147. { do we have an assembler block without the po_assembler?
  148. we should allow this for Delphi compatibility (PFV) }
  149. if (token=_ASM) and (m_delphi in current_settings.modeswitches) then
  150. include(current_procinfo.procdef.procoptions,po_assembler);
  151. { Handle assembler block different }
  152. if (po_assembler in current_procinfo.procdef.procoptions) then
  153. begin
  154. block:=assembler_block;
  155. exit;
  156. end;
  157. {Unit initialization?.}
  158. if (
  159. assigned(current_procinfo.procdef.localst) and
  160. (current_procinfo.procdef.localst.symtablelevel=main_program_level) and
  161. (current_module.is_unit)
  162. ) or
  163. islibrary then
  164. begin
  165. if (token=_END) then
  166. begin
  167. consume(_END);
  168. { We need at least a node, else the entry/exit code is not
  169. generated and thus no PASCALMAIN symbol which we need (PFV) }
  170. if islibrary then
  171. block:=cnothingnode.create
  172. else
  173. block:=nil;
  174. end
  175. else
  176. begin
  177. if token=_INITIALIZATION then
  178. begin
  179. { The library init code is already called and does not
  180. need to be in the initfinal table (PFV) }
  181. if not islibrary then
  182. current_module.flags:=current_module.flags or uf_init;
  183. block:=statement_block(_INITIALIZATION);
  184. end
  185. else if (token=_FINALIZATION) then
  186. begin
  187. if (current_module.flags and uf_finalize)<>0 then
  188. block:=statement_block(_FINALIZATION)
  189. else
  190. begin
  191. { can we allow no INITIALIZATION for DLL ??
  192. I think it should work PM }
  193. block:=nil;
  194. exit;
  195. end;
  196. end
  197. else
  198. begin
  199. { The library init code is already called and does not
  200. need to be in the initfinal table (PFV) }
  201. if not islibrary then
  202. current_module.flags:=current_module.flags or uf_init;
  203. block:=statement_block(_BEGIN);
  204. end;
  205. end;
  206. end
  207. else
  208. begin
  209. block:=statement_block(_BEGIN);
  210. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  211. current_procinfo.procdef.localst.SymList.ForEachCall(@initializevars,block);
  212. end;
  213. end;
  214. {****************************************************************************
  215. PROCEDURE/FUNCTION COMPILING
  216. ****************************************************************************}
  217. procedure printnode_reset;
  218. begin
  219. assign(printnodefile,treelogfilename);
  220. {$I-}
  221. rewrite(printnodefile);
  222. {$I+}
  223. if ioresult<>0 then
  224. begin
  225. Comment(V_Error,'Error creating '+treelogfilename);
  226. exit;
  227. end;
  228. close(printnodefile);
  229. end;
  230. function generate_bodyentry_block:tnode;
  231. var
  232. srsym : tsym;
  233. para : tcallparanode;
  234. newstatement : tstatementnode;
  235. begin
  236. result:=internalstatements(newstatement);
  237. if assigned(current_objectdef) then
  238. begin
  239. { a constructor needs a help procedure }
  240. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  241. begin
  242. if is_class(current_objectdef) then
  243. begin
  244. include(current_procinfo.flags,pi_needs_implicit_finally);
  245. srsym:=search_class_member(current_objectdef,'NEWINSTANCE');
  246. if assigned(srsym) and
  247. (srsym.typ=procsym) then
  248. begin
  249. { if vmt>1 then newinstance }
  250. addstatement(newstatement,cifnode.create(
  251. caddnode.create(gtn,
  252. ctypeconvnode.create_internal(
  253. load_vmt_pointer_node,
  254. voidpointertype),
  255. cpointerconstnode.create(1,voidpointertype)),
  256. cassignmentnode.create(
  257. ctypeconvnode.create_internal(
  258. load_self_pointer_node,
  259. voidpointertype),
  260. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_vmt_pointer_node,[])),
  261. nil));
  262. end
  263. else
  264. internalerror(200305108);
  265. end
  266. else
  267. if is_object(current_objectdef) then
  268. begin
  269. { parameter 3 : vmt_offset }
  270. { parameter 2 : address of pointer to vmt,
  271. this is required to allow setting the vmt to -1 to indicate
  272. that memory was allocated }
  273. { parameter 1 : self pointer }
  274. para:=ccallparanode.create(
  275. cordconstnode.create(current_objectdef.vmt_offset,s32inttype,false),
  276. ccallparanode.create(
  277. ctypeconvnode.create_internal(
  278. load_vmt_pointer_node,
  279. voidpointertype),
  280. ccallparanode.create(
  281. ctypeconvnode.create_internal(
  282. load_self_pointer_node,
  283. voidpointertype),
  284. nil)));
  285. addstatement(newstatement,cassignmentnode.create(
  286. ctypeconvnode.create_internal(
  287. load_self_pointer_node,
  288. voidpointertype),
  289. ccallnode.createintern('fpc_help_constructor',para)));
  290. end
  291. else
  292. internalerror(200305103);
  293. { if self=nil then exit
  294. calling fail instead of exit is useless because
  295. there is nothing to dispose (PFV) }
  296. addstatement(newstatement,cifnode.create(
  297. caddnode.create(equaln,
  298. load_self_pointer_node,
  299. cnilnode.create),
  300. cexitnode.create(nil),
  301. nil));
  302. end;
  303. { maybe call BeforeDestruction for classes }
  304. if (current_procinfo.procdef.proctypeoption=potype_destructor) and
  305. is_class(current_objectdef) then
  306. begin
  307. srsym:=search_class_member(current_objectdef,'BEFOREDESTRUCTION');
  308. if assigned(srsym) and
  309. (srsym.typ=procsym) then
  310. begin
  311. { if vmt>0 then beforedestruction }
  312. addstatement(newstatement,cifnode.create(
  313. caddnode.create(gtn,
  314. ctypeconvnode.create_internal(
  315. load_vmt_pointer_node,ptrsinttype),
  316. ctypeconvnode.create_internal(
  317. cnilnode.create,ptrsinttype)),
  318. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  319. nil));
  320. end
  321. else
  322. internalerror(200305104);
  323. end;
  324. end;
  325. end;
  326. function generate_bodyexit_block:tnode;
  327. var
  328. srsym : tsym;
  329. para : tcallparanode;
  330. newstatement : tstatementnode;
  331. oldlocalswitches: tlocalswitches;
  332. begin
  333. result:=internalstatements(newstatement);
  334. if assigned(current_objectdef) then
  335. begin
  336. { Don't test self and the vmt here. The reason is that }
  337. { a constructor already checks whether these are valid }
  338. { before. Further, in case of TThread the thread may }
  339. { free the class instance right after AfterConstruction }
  340. { has been called, so it may no longer be valid (JM) }
  341. oldlocalswitches:=current_settings.localswitches;
  342. current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];
  343. { maybe call AfterConstruction for classes }
  344. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  345. is_class(current_objectdef) then
  346. begin
  347. srsym:=search_class_member(current_objectdef,'AFTERCONSTRUCTION');
  348. if assigned(srsym) and
  349. (srsym.typ=procsym) then
  350. begin
  351. { Self can be nil when fail is called }
  352. { if self<>nil and vmt<>nil then afterconstruction }
  353. addstatement(newstatement,cifnode.create(
  354. caddnode.create(andn,
  355. caddnode.create(unequaln,
  356. load_self_pointer_node,
  357. cnilnode.create),
  358. caddnode.create(unequaln,
  359. load_vmt_pointer_node,
  360. cnilnode.create)),
  361. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  362. nil));
  363. end
  364. else
  365. internalerror(200305106);
  366. end;
  367. { a destructor needs a help procedure }
  368. if (current_procinfo.procdef.proctypeoption=potype_destructor) then
  369. begin
  370. if is_class(current_objectdef) then
  371. begin
  372. srsym:=search_class_member(current_objectdef,'FREEINSTANCE');
  373. if assigned(srsym) and
  374. (srsym.typ=procsym) then
  375. begin
  376. { if self<>0 and vmt<>0 then freeinstance }
  377. addstatement(newstatement,cifnode.create(
  378. caddnode.create(andn,
  379. caddnode.create(unequaln,
  380. load_self_pointer_node,
  381. cnilnode.create),
  382. caddnode.create(unequaln,
  383. ctypeconvnode.create(
  384. load_vmt_pointer_node,
  385. voidpointertype),
  386. cpointerconstnode.create(0,voidpointertype))),
  387. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  388. nil));
  389. end
  390. else
  391. internalerror(200305108);
  392. end
  393. else
  394. if is_object(current_objectdef) then
  395. begin
  396. { finalize object data }
  397. if current_objectdef.needs_inittable then
  398. addstatement(newstatement,finalize_data_node(load_self_node));
  399. { parameter 3 : vmt_offset }
  400. { parameter 2 : pointer to vmt }
  401. { parameter 1 : self pointer }
  402. para:=ccallparanode.create(
  403. cordconstnode.create(current_objectdef.vmt_offset,s32inttype,false),
  404. ccallparanode.create(
  405. ctypeconvnode.create_internal(
  406. load_vmt_pointer_node,
  407. voidpointertype),
  408. ccallparanode.create(
  409. ctypeconvnode.create_internal(
  410. load_self_pointer_node,
  411. voidpointertype),
  412. nil)));
  413. addstatement(newstatement,
  414. ccallnode.createintern('fpc_help_destructor',para));
  415. end
  416. else
  417. internalerror(200305105);
  418. end;
  419. current_settings.localswitches:=oldlocalswitches;
  420. end;
  421. end;
  422. function generate_except_block:tnode;
  423. var
  424. pd : tprocdef;
  425. newstatement : tstatementnode;
  426. oldlocalswitches: tlocalswitches;
  427. begin
  428. generate_except_block:=internalstatements(newstatement);
  429. { a constructor needs call destructor (if available) when it
  430. is not inherited }
  431. if assigned(current_objectdef) and
  432. (current_procinfo.procdef.proctypeoption=potype_constructor) then
  433. begin
  434. { Don't test self and the vmt here. See generate_bodyexit_block }
  435. { why (JM) }
  436. oldlocalswitches:=current_settings.localswitches;
  437. current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];
  438. pd:=current_objectdef.Finddestructor;
  439. if assigned(pd) then
  440. begin
  441. { if vmt<>0 then call destructor }
  442. addstatement(newstatement,cifnode.create(
  443. caddnode.create(unequaln,
  444. load_vmt_pointer_node,
  445. cnilnode.create),
  446. { cnf_create_failed -> don't call BeforeDestruction }
  447. ccallnode.create(nil,tprocsym(pd.procsym),pd.procsym.owner,load_self_node,[cnf_create_failed]),
  448. nil));
  449. end;
  450. current_settings.localswitches:=oldlocalswitches;
  451. end
  452. else
  453. begin
  454. { no constructor }
  455. { must be the return value finalized before reraising the exception? }
  456. if (not is_void(current_procinfo.procdef.returndef)) and
  457. (current_procinfo.procdef.returndef.needs_inittable) and
  458. (not paramanager.ret_in_param(current_procinfo.procdef.returndef, current_procinfo.procdef.proccalloption)) and
  459. (not is_class(current_procinfo.procdef.returndef)) then
  460. addstatement(newstatement,finalize_data_node(load_result_node));
  461. end;
  462. end;
  463. {****************************************************************************
  464. TCGProcInfo
  465. ****************************************************************************}
  466. constructor tcgprocinfo.create(aparent:tprocinfo);
  467. begin
  468. inherited Create(aparent);
  469. nestedprocs:=tlinkedlist.create;
  470. end;
  471. destructor tcgprocinfo.destroy;
  472. begin
  473. nestedprocs.free;
  474. if assigned(code) then
  475. code.free;
  476. inherited destroy;
  477. end;
  478. procedure tcgprocinfo.printproc;
  479. begin
  480. assign(printnodefile,treelogfilename);
  481. {$I-}
  482. append(printnodefile);
  483. if ioresult<>0 then
  484. rewrite(printnodefile);
  485. {$I+}
  486. if ioresult<>0 then
  487. begin
  488. Comment(V_Error,'Error creating '+treelogfilename);
  489. exit;
  490. end;
  491. writeln(printnodefile);
  492. writeln(printnodefile,'*******************************************************************************');
  493. writeln(printnodefile,procdef.fullprocname(false));
  494. writeln(printnodefile,'*******************************************************************************');
  495. printnode(printnodefile,code);
  496. close(printnodefile);
  497. end;
  498. procedure tcgprocinfo.add_entry_exit_code;
  499. var
  500. finalcode,
  501. bodyentrycode,
  502. bodyexitcode,
  503. exceptcode : tnode;
  504. newblock : tblocknode;
  505. codestatement,
  506. newstatement : tstatementnode;
  507. oldfilepos : tfileposinfo;
  508. begin
  509. oldfilepos:=current_filepos;
  510. { Generate code/locations used at start of proc }
  511. current_filepos:=entrypos;
  512. entry_asmnode:=casmnode.create_get_position;
  513. loadpara_asmnode:=casmnode.create_get_position;
  514. stackcheck_asmnode:=casmnode.create_get_position;
  515. init_asmnode:=casmnode.create_get_position;
  516. bodyentrycode:=generate_bodyentry_block;
  517. { Generate code/locations used at end of proc }
  518. current_filepos:=exitpos;
  519. exitlabel_asmnode:=casmnode.create_get_position;
  520. final_asmnode:=casmnode.create_get_position;
  521. bodyexitcode:=generate_bodyexit_block;
  522. { Generate procedure by combining init+body+final,
  523. depending on the implicit finally we need to add
  524. an try...finally...end wrapper }
  525. newblock:=internalstatements(newstatement);
  526. if (cs_implicit_exceptions in current_settings.moduleswitches) and
  527. (pi_needs_implicit_finally in flags) and
  528. { but it's useless in init/final code of units }
  529. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) then
  530. begin
  531. { Generate special exception block only needed when
  532. implicit finaly is used }
  533. current_filepos:=exitpos;
  534. exceptcode:=generate_except_block;
  535. { Generate code that will be in the try...finally }
  536. finalcode:=internalstatements(codestatement);
  537. addstatement(codestatement,final_asmnode);
  538. { Initialize before try...finally...end frame }
  539. addstatement(newstatement,loadpara_asmnode);
  540. addstatement(newstatement,stackcheck_asmnode);
  541. addstatement(newstatement,entry_asmnode);
  542. addstatement(newstatement,init_asmnode);
  543. addstatement(newstatement,bodyentrycode);
  544. current_filepos:=entrypos;
  545. addstatement(newstatement,ctryfinallynode.create_implicit(
  546. code,
  547. finalcode,
  548. exceptcode));
  549. addstatement(newstatement,exitlabel_asmnode);
  550. addstatement(newstatement,bodyexitcode);
  551. { set flag the implicit finally has been generated }
  552. include(flags,pi_has_implicit_finally);
  553. end
  554. else
  555. begin
  556. addstatement(newstatement,loadpara_asmnode);
  557. addstatement(newstatement,stackcheck_asmnode);
  558. addstatement(newstatement,entry_asmnode);
  559. addstatement(newstatement,init_asmnode);
  560. addstatement(newstatement,bodyentrycode);
  561. addstatement(newstatement,code);
  562. addstatement(newstatement,exitlabel_asmnode);
  563. addstatement(newstatement,bodyexitcode);
  564. addstatement(newstatement,final_asmnode);
  565. end;
  566. do_firstpass(tnode(newblock));
  567. code:=newblock;
  568. current_filepos:=oldfilepos;
  569. end;
  570. procedure clearrefs(p:TObject;arg:pointer);
  571. begin
  572. if (tsym(p).typ in [localvarsym,paravarsym,staticvarsym]) then
  573. if tabstractvarsym(p).refs>1 then
  574. tabstractvarsym(p).refs:=1;
  575. end;
  576. procedure translate_registers(p:TObject;list:pointer);
  577. begin
  578. if (tsym(p).typ in [localvarsym,paravarsym,staticvarsym]) and
  579. (tabstractnormalvarsym(p).localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  580. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  581. begin
  582. if not(cs_no_regalloc in current_settings.globalswitches) then
  583. cg.translate_register(tabstractnormalvarsym(p).localloc.register);
  584. if cs_asm_source in current_settings.globalswitches then
  585. TAsmList(list).concat(Tai_comment.Create(strpnew('Var '+tabstractnormalvarsym(p).realname+' located in register '+
  586. std_regname(tabstractnormalvarsym(p).localloc.register))))
  587. end;
  588. end;
  589. procedure check_for_stack(p:TObject;arg:pointer);
  590. begin
  591. if tsym(p).typ=paravarsym then
  592. begin
  593. { check if there no parameter of the current procedure is stack dependend }
  594. if is_open_array(tparavarsym(p).vardef) or
  595. is_array_of_const(tparavarsym(p).vardef) then
  596. pboolean(arg)^:=true;
  597. if assigned(p) and
  598. assigned(tparavarsym(p).paraloc[calleeside].location) and
  599. (tparavarsym(p).paraloc[calleeside].location^.loc=LOC_REFERENCE) then
  600. pboolean(arg)^:=true;
  601. end;
  602. end;
  603. function tcgprocinfo.stack_tainting_parameter : boolean;
  604. begin
  605. result:=false;
  606. procdef.parast.SymList.ForEachCall(@check_for_stack,@result);
  607. end;
  608. function tcgprocinfo.has_assembler_child : boolean;
  609. var
  610. hp : tcgprocinfo;
  611. begin
  612. result:=false;
  613. hp:=tcgprocinfo(nestedprocs.first);
  614. while assigned(hp) do
  615. begin
  616. if (hp.flags*[pi_has_assembler_block,pi_is_assembler])<>[] then
  617. begin
  618. result:=true;
  619. exit;
  620. end;
  621. hp:=tcgprocinfo(hp.next);
  622. end;
  623. end;
  624. procedure tcgprocinfo.generate_code;
  625. var
  626. old_current_procinfo : tprocinfo;
  627. oldmaxfpuregisters : longint;
  628. oldfilepos : tfileposinfo;
  629. old_current_objectdef : tobjectdef;
  630. templist : TAsmList;
  631. headertai : tai;
  632. i : integer;
  633. varsym : tabstractnormalvarsym;
  634. {RedoDFA : boolean;}
  635. begin
  636. { the initialization procedure can be empty, then we
  637. don't need to generate anything. When it was an empty
  638. procedure there would be at least a blocknode }
  639. if not assigned(code) then
  640. exit;
  641. { We need valid code }
  642. if Errorcount<>0 then
  643. exit;
  644. { No code can be generated for generic template }
  645. if (df_generic in procdef.defoptions) then
  646. internalerror(200511152);
  647. { The RA and Tempgen shall not be available yet }
  648. if assigned(tg) then
  649. internalerror(200309201);
  650. old_current_procinfo:=current_procinfo;
  651. oldfilepos:=current_filepos;
  652. old_current_objectdef:=current_objectdef;
  653. oldmaxfpuregisters:=current_settings.maxfpuregisters;
  654. current_procinfo:=self;
  655. current_filepos:=entrypos;
  656. current_objectdef:=procdef._class;
  657. templist:=TAsmList.create;
  658. { add parast/localst to symtablestack }
  659. add_to_symtablestack;
  660. { clear register count }
  661. procdef.localst.SymList.ForEachCall(@clearrefs,nil);
  662. procdef.parast.SymList.ForEachCall(@clearrefs,nil);
  663. { there's always a call to FPC_INITIALIZEUNITS/FPC_DO_EXIT in the main program }
  664. if (procdef.localst.symtablelevel=main_program_level) and
  665. (not current_module.is_unit) then
  666. include(flags,pi_do_call);
  667. { set implicit_finally flag when there are locals/paras to be finalized }
  668. procdef.parast.SymList.ForEachCall(@check_finalize_paras,nil);
  669. procdef.localst.SymList.ForEachCall(@check_finalize_locals,nil);
  670. {$if defined(x86) or defined(arm)}
  671. { set implicit_finally flag for if procedure is safecall }
  672. if (target_info.system in system_all_windows) and
  673. (procdef.proccalloption=pocall_safecall) then
  674. include(flags, pi_needs_implicit_finally);
  675. {$endif}
  676. { firstpass everything }
  677. flowcontrol:=[];
  678. do_firstpass(code);
  679. {$ifdef i386}
  680. procdef.fpu_used:=node_resources_fpu(code);
  681. if procdef.fpu_used>0 then
  682. include(flags,pi_uses_fpu);
  683. {$endif i386}
  684. { do this before adding the entry code else the tail recursion recognition won't work,
  685. if this causes troubles, it must be if'ed
  686. }
  687. if (cs_opt_tailrecursion in current_settings.optimizerswitches) and
  688. (pi_is_recursive in flags) then
  689. do_opttail(code,procdef);
  690. if (cs_opt_nodedfa in current_settings.optimizerswitches) and
  691. { creating dfa is not always possible }
  692. ((flags*[pi_has_assembler_block,pi_uses_exceptions,pi_is_assembler,
  693. pi_needs_implicit_finally,pi_has_implicit_finally])=[]) then
  694. begin
  695. dfabuilder:=TDFABuilder.Create;
  696. dfabuilder.createdfainfo(code);
  697. { when life info is available, we can give more sophisticated warning about unintialized
  698. variables }
  699. { iterate through life info of the first node }
  700. for i:=0 to dfabuilder.nodemap.count-1 do
  701. begin
  702. if DFASetIn(code.optinfo^.life,i) then
  703. case tnode(dfabuilder.nodemap[i]).nodetype of
  704. loadn:
  705. begin
  706. varsym:=tabstractnormalvarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry);
  707. { Give warning/note for living locals }
  708. if assigned(varsym.owner) and
  709. not(vo_is_external in varsym.varoptions) then
  710. begin
  711. if (vo_is_funcret in varsym.varoptions) then
  712. CGMessage(sym_w_function_result_uninitialized)
  713. else
  714. begin
  715. if varsym.owner=procdef.localst then
  716. CGMessage1(sym_w_uninitialized_local_variable,varsym.realname);
  717. end;
  718. end;
  719. end;
  720. end;
  721. end;
  722. include(flags,pi_dfaavailable);
  723. end;
  724. if (cs_opt_loopstrength in current_settings.optimizerswitches)
  725. { our induction variable strength reduction doesn't like
  726. for loops with more than one entry }
  727. and not(pi_has_goto in current_procinfo.flags) then
  728. begin
  729. {RedoDFA:=}OptimizeInductionVariables(code);
  730. end;
  731. if cs_opt_nodecse in current_settings.optimizerswitches then
  732. do_optcse(code);
  733. { add implicit entry and exit code }
  734. add_entry_exit_code;
  735. { only do secondpass if there are no errors }
  736. if (ErrorCount=0) then
  737. begin
  738. create_codegen;
  739. { set the start offset to the start of the temp area in the stack }
  740. tg:=ttgobj.create;
  741. {$if defined(x86) or defined(arm)}
  742. { try to strip the stack frame }
  743. { set the framepointer to esp if:
  744. - no assembler directive, those are handled in assembler_block
  745. in pstatment.pas (for cases not caught by the Delphi
  746. exception below)
  747. - no exceptions are used
  748. - no pushes are used/esp modifications, could be:
  749. * outgoing parameters on the stack
  750. * incoming parameters on the stack
  751. * open arrays
  752. - no inline assembler
  753. or
  754. - Delphi mode
  755. - assembler directive
  756. - no pushes are used/esp modifications, could be:
  757. * outgoing parameters on the stack
  758. * incoming parameters on the stack
  759. * open arrays
  760. - no local variables
  761. }
  762. if ((po_assembler in procdef.procoptions) and
  763. (m_delphi in current_settings.modeswitches) and
  764. { localst at main_program_level is a staticsymtable }
  765. (procdef.localst.symtablelevel<>main_program_level) and
  766. (tabstractlocalsymtable(procdef.localst).count_locals = 0)) or
  767. ((cs_opt_stackframe in current_settings.optimizerswitches) and
  768. not(cs_generate_stackframes in current_settings.localswitches) and
  769. not(po_assembler in procdef.procoptions) and
  770. ((flags*[pi_has_assembler_block,pi_uses_exceptions,pi_is_assembler,
  771. pi_needs_implicit_finally,pi_has_implicit_finally,pi_has_stackparameter,
  772. pi_needs_stackframe])=[])
  773. )
  774. then
  775. begin
  776. { we need the parameter info here to determine if the procedure gets
  777. parameters on the stack
  778. calling generate_parameter_info doesn't hurt but it costs time
  779. }
  780. generate_parameter_info;
  781. if not(stack_tainting_parameter) and
  782. not(has_assembler_child) and (para_stack_size=0) then
  783. begin
  784. { Only need to set the framepointer }
  785. framepointer:=NR_STACK_POINTER_REG;
  786. tg.direction:=1;
  787. end;
  788. end;
  789. {$endif}
  790. { Create register allocator }
  791. cg.init_register_allocators;
  792. set_first_temp_offset;
  793. generate_parameter_info;
  794. { allocate got register if needed }
  795. current_procinfo.allocate_got_register(aktproccode);
  796. { Allocate space in temp/registers for parast and localst }
  797. current_filepos:=entrypos;
  798. gen_alloc_symtable(aktproccode,procdef.parast);
  799. gen_alloc_symtable(aktproccode,procdef.localst);
  800. { Store temp offset for information about 'real' temps }
  801. tempstart:=tg.lasttemp;
  802. { Generate code to load register parameters in temps and insert local
  803. copies for values parameters. This must be done before the code for the
  804. body is generated because the localloc is updated.
  805. Note: The generated code will be inserted after the code generation of
  806. the body is finished, because only then the position is known }
  807. {$ifdef oldregvars}
  808. assign_regvars(code);
  809. {$endif oldreg}
  810. current_filepos:=entrypos;
  811. { record which registers are allocated here, since all code }
  812. { allocating registers comes after it }
  813. cg.set_regalloc_live_range_direction(rad_backwards);
  814. gen_load_para_value(templist);
  815. cg.set_regalloc_live_range_direction(rad_forward);
  816. { caller paraloc info is also necessary in the stackframe_entry
  817. code of the ppc (and possibly other processors) }
  818. if not procdef.has_paraloc_info then
  819. begin
  820. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  821. procdef.has_paraloc_info:=true;
  822. end;
  823. { generate code for the node tree }
  824. do_secondpass(code);
  825. aktproccode.concatlist(current_asmdata.CurrAsmList);
  826. { The position of the loadpara_asmnode is now known }
  827. aktproccode.insertlistafter(loadpara_asmnode.currenttai,templist);
  828. { first generate entry and initialize code with the correct
  829. position and switches }
  830. current_filepos:=entrypos;
  831. current_settings.localswitches:=entryswitches;
  832. cg.set_regalloc_live_range_direction(rad_backwards);
  833. gen_entry_code(templist);
  834. aktproccode.insertlistafter(entry_asmnode.currenttai,templist);
  835. gen_initialize_code(templist);
  836. aktproccode.insertlistafter(init_asmnode.currenttai,templist);
  837. { now generate finalize and exit code with the correct position
  838. and switches }
  839. current_filepos:=exitpos;
  840. current_settings.localswitches:=exitswitches;
  841. cg.set_regalloc_live_range_direction(rad_forward);
  842. gen_finalize_code(templist);
  843. { the finalcode must be concated if there was no position available,
  844. using insertlistafter will result in an insert at the start
  845. when currentai=nil }
  846. if assigned(final_asmnode.currenttai) then
  847. aktproccode.insertlistafter(final_asmnode.currenttai,templist)
  848. else
  849. aktproccode.concatlist(templist);
  850. { insert exit label at the correct position }
  851. cg.a_label(templist,CurrExitLabel);
  852. if assigned(exitlabel_asmnode.currenttai) then
  853. aktproccode.insertlistafter(exitlabel_asmnode.currenttai,templist)
  854. else
  855. aktproccode.concatlist(templist);
  856. { exit code }
  857. gen_exit_code(templist);
  858. aktproccode.concatlist(templist);
  859. {$ifdef OLDREGVARS}
  860. { note: this must be done only after as much code as possible has }
  861. { been generated. The result is that when you ungetregister() a }
  862. { regvar, it will actually free the regvar (and alse free the }
  863. { the regvars at the same time). Doing this too early will }
  864. { confuse the register allocator, as the regvars will still be }
  865. { used. It should be done before loading the result regs (so }
  866. { they don't conflict with the regvars) and before }
  867. { gen_entry_code (that one has to be able to allocate the }
  868. { regvars again) (JM) }
  869. free_regvars(aktproccode);
  870. {$endif OLDREGVARS}
  871. { generate symbol and save end of header position }
  872. current_filepos:=entrypos;
  873. gen_proc_symbol(templist);
  874. headertai:=tai(templist.last);
  875. { insert symbol }
  876. aktproccode.insertlist(templist);
  877. { Free space in temp/registers for parast and localst, must be
  878. done after gen_entry_code }
  879. current_filepos:=exitpos;
  880. { make sure the got/pic register doesn't get freed in the }
  881. { middle of a loop }
  882. if (cs_create_pic in current_settings.moduleswitches) and
  883. (pi_needs_got in current_procinfo.flags) and
  884. (current_procinfo.got<>NR_NO) then
  885. cg.a_reg_sync(aktproccode,current_procinfo.got);
  886. gen_free_symtable(aktproccode,procdef.localst);
  887. gen_free_symtable(aktproccode,procdef.parast);
  888. { add code that will load the return value, this is not done
  889. for assembler routines when they didn't reference the result
  890. variable }
  891. gen_load_return_value(templist);
  892. aktproccode.concatlist(templist);
  893. { Already reserve all registers for stack checking code and
  894. generate the call to the helper function }
  895. if not(tf_no_generic_stackcheck in target_info.flags) and
  896. (cs_check_stack in entryswitches) and
  897. not(po_assembler in procdef.procoptions) and
  898. (procdef.proctypeoption<>potype_proginit) then
  899. begin
  900. current_filepos:=entrypos;
  901. gen_stack_check_call(templist);
  902. aktproccode.insertlistafter(stackcheck_asmnode.currenttai,templist)
  903. end;
  904. { this code (got loading) comes before everything which has }
  905. { already been generated, so reset the info about already }
  906. { backwards extended registers (so their live range can be }
  907. { extended backwards even further if needed) }
  908. { This code must be }
  909. { a) generated after do_secondpass has been called }
  910. { (because pi_needs_got may be set there) }
  911. { b) generated before register allocation, because the }
  912. { got/pic register can be a virtual one }
  913. { c) inserted before the entry code, because the entry }
  914. { code may need global symbols such as init rtti }
  915. { d) inserted after the stackframe allocation, because }
  916. { this register may have to be spilled }
  917. cg.set_regalloc_live_range_direction(rad_backwards_reinit);
  918. current_filepos:=entrypos;
  919. { load got if necessary }
  920. cg.g_maybe_got_init(templist);
  921. aktproccode.insertlistafter(headertai,templist);
  922. cg.set_regalloc_live_range_direction(rad_forward);
  923. { The procedure body is finished, we can now
  924. allocate the registers }
  925. cg.do_register_allocation(aktproccode,headertai);
  926. { translate imag. register to their real counter parts
  927. this is necessary for debuginfo and verbose assembler output
  928. when SSA will be implented, this will be more complicated because we've to
  929. maintain location lists }
  930. current_procinfo.procdef.parast.SymList.ForEachCall(@translate_registers,templist);
  931. current_procinfo.procdef.localst.SymList.ForEachCall(@translate_registers,templist);
  932. if (cs_create_pic in current_settings.moduleswitches) and
  933. (pi_needs_got in current_procinfo.flags) and
  934. not(cs_no_regalloc in current_settings.globalswitches) and
  935. (current_procinfo.got<>NR_NO) then
  936. cg.translate_register(current_procinfo.got);
  937. { Add save and restore of used registers }
  938. current_filepos:=entrypos;
  939. gen_save_used_regs(templist);
  940. aktproccode.insertlistafter(headertai,templist);
  941. current_filepos:=exitpos;
  942. gen_restore_used_regs(aktproccode);
  943. { We know the size of the stack, now we can generate the
  944. parameter that is passed to the stack checking code }
  945. if not(tf_no_generic_stackcheck in target_info.flags) and
  946. (cs_check_stack in entryswitches) and
  947. not(po_assembler in procdef.procoptions) and
  948. (procdef.proctypeoption<>potype_proginit) then
  949. begin
  950. current_filepos:=entrypos;
  951. gen_stack_check_size_para(templist);
  952. aktproccode.insertlistafter(stackcheck_asmnode.currenttai,templist)
  953. end;
  954. { Add entry code (stack allocation) after header }
  955. current_filepos:=entrypos;
  956. gen_proc_entry_code(templist);
  957. aktproccode.insertlistafter(headertai,templist);
  958. {$if defined(x86) or defined(arm)}
  959. { Set return value of safecall procedure if implicit try/finally blocks are disabled }
  960. if not (cs_implicit_exceptions in current_settings.moduleswitches) and
  961. (target_info.system in system_all_windows) and
  962. (procdef.proccalloption=pocall_safecall) then
  963. cg.a_load_const_reg(aktproccode,OS_ADDR,0,NR_FUNCTION_RETURN_REG);
  964. {$endif}
  965. { Add exit code at the end }
  966. current_filepos:=exitpos;
  967. gen_proc_exit_code(templist);
  968. aktproccode.concatlist(templist);
  969. { check if the implicit finally has been generated. The flag
  970. should already be set in pass1 }
  971. if (cs_implicit_exceptions in current_settings.moduleswitches) and
  972. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) and
  973. (pi_needs_implicit_finally in flags) and
  974. not(pi_has_implicit_finally in flags) then
  975. internalerror(200405231);
  976. {$ifndef NoOpt}
  977. if not(cs_no_regalloc in current_settings.globalswitches) then
  978. begin
  979. if (cs_opt_level1 in current_settings.optimizerswitches) and
  980. { do not optimize pure assembler procedures }
  981. not(pi_is_assembler in flags) then
  982. optimize(aktproccode);
  983. end;
  984. {$endif NoOpt}
  985. {$ifdef ARM}
  986. { because of the limited constant size of the arm, all data access is done pc relative }
  987. insertpcrelativedata(aktproccode,aktlocaldata);
  988. {$endif ARM}
  989. { Add end symbol and debug info }
  990. { this must be done after the pcrelativedata is appended else the distance calculation of
  991. insertpcrelativedata will be wrong, further the pc indirect data is part of the procedure
  992. so it should be inserted before the end symbol (FK)
  993. }
  994. current_filepos:=exitpos;
  995. gen_proc_symbol_end(templist);
  996. aktproccode.concatlist(templist);
  997. {$if defined(POWERPC) or defined(POWERPC64)}
  998. fixup_jmps(aktproccode);
  999. {$endif}
  1000. { insert line debuginfo }
  1001. if (cs_debuginfo in current_settings.moduleswitches) or
  1002. (cs_use_lineinfo in current_settings.globalswitches) then
  1003. current_debuginfo.insertlineinfo(aktproccode);
  1004. { add the procedure to the al_procedures }
  1005. maybe_new_object_file(current_asmdata.asmlists[al_procedures]);
  1006. new_section(current_asmdata.asmlists[al_procedures],sec_code,lower(procdef.mangledname),getprocalign);
  1007. current_asmdata.asmlists[al_procedures].concatlist(aktproccode);
  1008. { save local data (casetable) also in the same file }
  1009. if assigned(aktlocaldata) and
  1010. (not aktlocaldata.empty) then
  1011. current_asmdata.asmlists[al_procedures].concatlist(aktlocaldata);
  1012. { only now we can remove the temps }
  1013. tg.resettempgen;
  1014. { stop tempgen and ra }
  1015. tg.free;
  1016. cg.done_register_allocators;
  1017. destroy_codegen;
  1018. tg:=nil;
  1019. end;
  1020. dfabuilder.free;
  1021. { restore symtablestack }
  1022. remove_from_symtablestack;
  1023. { restore }
  1024. templist.free;
  1025. current_settings.maxfpuregisters:=oldmaxfpuregisters;
  1026. current_filepos:=oldfilepos;
  1027. current_objectdef:=old_current_objectdef;
  1028. current_procinfo:=old_current_procinfo;
  1029. end;
  1030. procedure tcgprocinfo.add_to_symtablestack;
  1031. var
  1032. _class,hp : tobjectdef;
  1033. begin
  1034. { insert symtables for the class, but only if it is no nested function }
  1035. if assigned(procdef._class) and
  1036. not(assigned(parent) and
  1037. assigned(parent.procdef) and
  1038. assigned(parent.procdef._class)) then
  1039. begin
  1040. { insert them in the reverse order }
  1041. hp:=nil;
  1042. repeat
  1043. _class:=procdef._class;
  1044. while _class.childof<>hp do
  1045. _class:=_class.childof;
  1046. hp:=_class;
  1047. symtablestack.push(_class.symtable);
  1048. until hp=procdef._class;
  1049. end;
  1050. { insert parasymtable in symtablestack when parsing
  1051. a function }
  1052. if procdef.parast.symtablelevel>=normal_function_level then
  1053. symtablestack.push(procdef.parast);
  1054. { insert localsymtable }
  1055. symtablestack.push(procdef.localst);
  1056. end;
  1057. procedure tcgprocinfo.remove_from_symtablestack;
  1058. var
  1059. _class : tobjectdef;
  1060. begin
  1061. { remove localsymtable }
  1062. symtablestack.pop(procdef.localst);
  1063. { remove parasymtable }
  1064. if procdef.parast.symtablelevel>=normal_function_level then
  1065. symtablestack.pop(procdef.parast);
  1066. { remove symtables for the class, but only if it is no nested function }
  1067. if assigned(procdef._class) and
  1068. not(assigned(parent) and
  1069. assigned(parent.procdef) and
  1070. assigned(parent.procdef._class)) then
  1071. begin
  1072. _class:=procdef._class;
  1073. while assigned(_class) do
  1074. begin
  1075. symtablestack.pop(_class.symtable);
  1076. _class:=_class.childof;
  1077. end;
  1078. end;
  1079. end;
  1080. procedure tcgprocinfo.resetprocdef;
  1081. begin
  1082. { remove code tree, if not inline procedure }
  1083. if assigned(code) then
  1084. begin
  1085. { the inline procedure has already got a copy of the tree
  1086. stored in procdef.inlininginfo }
  1087. code.free;
  1088. code:=nil;
  1089. end;
  1090. end;
  1091. function checknodeinlining(procdef: tprocdef): boolean;
  1092. var
  1093. i : integer;
  1094. currpara : tparavarsym;
  1095. begin
  1096. result := false;
  1097. if (pi_has_assembler_block in current_procinfo.flags) then
  1098. begin
  1099. Message1(parser_w_not_supported_for_inline,'assembler');
  1100. Message(parser_w_inlining_disabled);
  1101. exit;
  1102. end;
  1103. for i:=0 to procdef.paras.count-1 do
  1104. begin
  1105. currpara:=tparavarsym(procdef.paras[i]);
  1106. case currpara.vardef.typ of
  1107. formaldef :
  1108. begin
  1109. if (currpara.varspez in [vs_out,vs_var,vs_const]) then
  1110. begin
  1111. Message1(parser_w_not_supported_for_inline,'formal parameter');
  1112. Message(parser_w_inlining_disabled);
  1113. exit;
  1114. end;
  1115. end;
  1116. arraydef :
  1117. begin
  1118. if is_array_of_const(currpara.vardef) or
  1119. is_variant_array(currpara.vardef) then
  1120. begin
  1121. Message1(parser_w_not_supported_for_inline,'array of const');
  1122. Message(parser_w_inlining_disabled);
  1123. exit;
  1124. end;
  1125. { open arrays might need re-basing of the index, i.e. if you pass
  1126. an array[1..10] as open array, you have to add 1 to all index operations
  1127. if you directly inline it }
  1128. if is_open_array(currpara.vardef) then
  1129. begin
  1130. Message1(parser_w_not_supported_for_inline,'open array');
  1131. Message(parser_w_inlining_disabled);
  1132. exit;
  1133. end;
  1134. end;
  1135. end;
  1136. end;
  1137. result:=true;
  1138. end;
  1139. procedure tcgprocinfo.parse_body;
  1140. var
  1141. old_current_procinfo : tprocinfo;
  1142. old_block_type : tblock_type;
  1143. st : TSymtable;
  1144. old_current_objectdef : tobjectdef;
  1145. begin
  1146. old_current_procinfo:=current_procinfo;
  1147. old_block_type:=block_type;
  1148. old_current_objectdef:=current_objectdef;
  1149. current_procinfo:=self;
  1150. current_objectdef:=procdef._class;
  1151. { calculate the lexical level }
  1152. if procdef.parast.symtablelevel>maxnesting then
  1153. Message(parser_e_too_much_lexlevel);
  1154. block_type:=bt_body;
  1155. {$ifdef state_tracking}
  1156. { aktstate:=Tstate_storage.create;}
  1157. {$endif state_tracking}
  1158. { allocate the symbol for this procedure }
  1159. alloc_proc_symbol(procdef);
  1160. { add parast/localst to symtablestack }
  1161. add_to_symtablestack;
  1162. { save entry info }
  1163. entrypos:=current_filepos;
  1164. entryswitches:=current_settings.localswitches;
  1165. if (df_generic in procdef.defoptions) then
  1166. begin
  1167. { start token recorder for generic template }
  1168. procdef.initgeneric;
  1169. current_scanner.startrecordtokens(procdef.generictokenbuf);
  1170. end;
  1171. { parse the code ... }
  1172. code:=block(current_module.islibrary);
  1173. if (df_generic in procdef.defoptions) then
  1174. begin
  1175. { stop token recorder for generic template }
  1176. current_scanner.stoprecordtokens;
  1177. { Give an error for accesses in the static symtable that aren't visible
  1178. outside the current unit }
  1179. st:=procdef.owner;
  1180. while (st.symtabletype=ObjectSymtable) do
  1181. st:=st.defowner.owner;
  1182. if (pi_uses_static_symtable in flags) and
  1183. (st.symtabletype<>staticsymtable) then
  1184. Comment(V_Error,'Global Generic template references static symtable');
  1185. end;
  1186. { save exit info }
  1187. exitswitches:=current_settings.localswitches;
  1188. exitpos:=last_endtoken_filepos;
  1189. { the procedure is now defined }
  1190. procdef.forwarddef:=false;
  1191. if assigned(code) then
  1192. begin
  1193. { get a better entry point }
  1194. entrypos:=code.fileinfo;
  1195. { Finish type checking pass }
  1196. do_typecheckpass(code);
  1197. end;
  1198. { Check for unused labels, forwards, symbols for procedures. Static
  1199. symtable is checked in pmodules.
  1200. The check must be done after the typecheckpass }
  1201. if (Errorcount=0) and
  1202. (tstoredsymtable(procdef.localst).symtabletype<>staticsymtable) then
  1203. begin
  1204. { check if forwards are resolved }
  1205. tstoredsymtable(procdef.localst).check_forwards;
  1206. { check if all labels are used }
  1207. tstoredsymtable(procdef.localst).checklabels;
  1208. { check for unused symbols, but only if there is no asm block }
  1209. if not(pi_has_assembler_block in flags) then
  1210. begin
  1211. tstoredsymtable(procdef.localst).allsymbolsused;
  1212. tstoredsymtable(procdef.parast).allsymbolsused;
  1213. end;
  1214. end;
  1215. if (po_inline in procdef.procoptions) then
  1216. begin
  1217. { Can we inline this procedure? }
  1218. if checknodeinlining(procdef) then
  1219. begin
  1220. new(procdef.inlininginfo);
  1221. include(procdef.procoptions,po_has_inlininginfo);
  1222. procdef.inlininginfo^.code:=code.getcopy;
  1223. procdef.inlininginfo^.flags:=current_procinfo.flags;
  1224. { The blocknode needs to set an exit label }
  1225. if procdef.inlininginfo^.code.nodetype=blockn then
  1226. include(procdef.inlininginfo^.code.flags,nf_block_with_exit);
  1227. end;
  1228. end;
  1229. { Print the node to tree.log }
  1230. if paraprintnodetree=1 then
  1231. printproc;
  1232. { ... remove symbol tables }
  1233. remove_from_symtablestack;
  1234. {$ifdef state_tracking}
  1235. { aktstate.destroy;}
  1236. {$endif state_tracking}
  1237. current_objectdef:=old_current_objectdef;
  1238. current_procinfo:=old_current_procinfo;
  1239. { Restore old state }
  1240. block_type:=old_block_type;
  1241. end;
  1242. {****************************************************************************
  1243. PROCEDURE/FUNCTION PARSING
  1244. ****************************************************************************}
  1245. procedure check_init_paras(p:TObject;arg:pointer);
  1246. begin
  1247. if tsym(p).typ<>paravarsym then
  1248. exit;
  1249. with tparavarsym(p) do
  1250. if (not is_class(vardef) and
  1251. vardef.needs_inittable and
  1252. (varspez in [vs_value,vs_out])) then
  1253. include(current_procinfo.flags,pi_do_call);
  1254. end;
  1255. procedure read_proc_body(old_current_procinfo:tprocinfo;pd:tprocdef);
  1256. {
  1257. Parses the procedure directives, then parses the procedure body, then
  1258. generates the code for it
  1259. }
  1260. procedure do_generate_code(pi:tcgprocinfo);
  1261. var
  1262. hpi : tcgprocinfo;
  1263. begin
  1264. { generate code for this procedure }
  1265. pi.generate_code;
  1266. { process nested procs }
  1267. hpi:=tcgprocinfo(pi.nestedprocs.first);
  1268. while assigned(hpi) do
  1269. begin
  1270. do_generate_code(hpi);
  1271. hpi:=tcgprocinfo(hpi.next);
  1272. end;
  1273. pi.resetprocdef;
  1274. end;
  1275. var
  1276. oldfailtokenmode : tmodeswitch;
  1277. isnestedproc : boolean;
  1278. begin
  1279. Message1(parser_d_procedure_start,pd.fullprocname(false));
  1280. { create a new procedure }
  1281. current_procinfo:=cprocinfo.create(old_current_procinfo);
  1282. current_module.procinfo:=current_procinfo;
  1283. current_procinfo.procdef:=pd;
  1284. isnestedproc:=(current_procinfo.procdef.parast.symtablelevel>normal_function_level);
  1285. { Insert mangledname }
  1286. pd.aliasnames.insert(pd.mangledname);
  1287. { Handle Export of this procedure }
  1288. if (po_exports in pd.procoptions) and
  1289. (target_info.system in [system_i386_os2,system_i386_emx]) then
  1290. begin
  1291. pd.aliasnames.insert(pd.procsym.realname);
  1292. if cs_link_deffile in current_settings.globalswitches then
  1293. deffile.AddExport(pd.mangledname);
  1294. end;
  1295. { Insert result variables in the localst }
  1296. insert_funcret_local(pd);
  1297. { check if there are para's which require initing -> set }
  1298. { pi_do_call (if not yet set) }
  1299. if not(pi_do_call in current_procinfo.flags) then
  1300. pd.parast.SymList.ForEachCall(@check_init_paras,nil);
  1301. { set _FAIL as keyword if constructor }
  1302. if (pd.proctypeoption=potype_constructor) then
  1303. begin
  1304. oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
  1305. tokeninfo^[_FAIL].keyword:=m_all;
  1306. end;
  1307. tcgprocinfo(current_procinfo).parse_body;
  1308. { We can't support inlining for procedures that have nested
  1309. procedures because the nested procedures use a fixed offset
  1310. for accessing locals in the parent procedure (PFV) }
  1311. if (tcgprocinfo(current_procinfo).nestedprocs.count>0) then
  1312. begin
  1313. if (df_generic in current_procinfo.procdef.defoptions) then
  1314. Comment(V_Error,'Generic methods cannot have nested procedures')
  1315. else
  1316. if (po_inline in current_procinfo.procdef.procoptions) then
  1317. begin
  1318. Message1(parser_w_not_supported_for_inline,'nested procedures');
  1319. Message(parser_w_inlining_disabled);
  1320. exclude(current_procinfo.procdef.procoptions,po_inline);
  1321. end;
  1322. end;
  1323. { When it's a nested procedure then defer the code generation,
  1324. when back at normal function level then generate the code
  1325. for all defered nested procedures and the current procedure }
  1326. if isnestedproc then
  1327. tcgprocinfo(current_procinfo.parent).nestedprocs.insert(current_procinfo)
  1328. else
  1329. begin
  1330. if not(df_generic in current_procinfo.procdef.defoptions) then
  1331. do_generate_code(tcgprocinfo(current_procinfo));
  1332. end;
  1333. { reset _FAIL as _SELF normal }
  1334. if (pd.proctypeoption=potype_constructor) then
  1335. tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
  1336. { release procinfo }
  1337. if tprocinfo(current_module.procinfo)<>current_procinfo then
  1338. internalerror(200304274);
  1339. current_module.procinfo:=current_procinfo.parent;
  1340. { For specialization we didn't record the last semicolon. Moving this parsing
  1341. into the parse_body routine is not done because of having better file position
  1342. information available }
  1343. if not(df_specialization in current_procinfo.procdef.defoptions) then
  1344. consume(_SEMICOLON);
  1345. if not isnestedproc then
  1346. { current_procinfo is checked for nil later on }
  1347. freeandnil(current_procinfo);
  1348. end;
  1349. procedure read_proc;
  1350. {
  1351. Parses the procedure directives, then parses the procedure body, then
  1352. generates the code for it
  1353. }
  1354. var
  1355. old_current_procinfo : tprocinfo;
  1356. old_current_objectdef : tobjectdef;
  1357. pdflags : tpdflags;
  1358. pd,firstpd : tprocdef;
  1359. s : string;
  1360. begin
  1361. { save old state }
  1362. old_current_procinfo:=current_procinfo;
  1363. old_current_objectdef:=current_objectdef;
  1364. { reset current_procinfo.procdef to nil to be sure that nothing is writing
  1365. to an other procdef }
  1366. current_procinfo:=nil;
  1367. current_objectdef:=nil;
  1368. { parse procedure declaration }
  1369. pd:=parse_proc_dec(old_current_objectdef);
  1370. { set the default function options }
  1371. if parse_only then
  1372. begin
  1373. pd.forwarddef:=true;
  1374. { set also the interface flag, for better error message when the
  1375. implementation doesn't much this header }
  1376. pd.interfacedef:=true;
  1377. include(pd.procoptions,po_global);
  1378. pdflags:=[pd_interface];
  1379. end
  1380. else
  1381. begin
  1382. pdflags:=[pd_body];
  1383. if (not current_module.in_interface) then
  1384. include(pdflags,pd_implemen);
  1385. if (not current_module.is_unit) or
  1386. create_smartlink or
  1387. {
  1388. taking addresses of static procedures goes wrong
  1389. if they aren't global when pic is used (FK)
  1390. }
  1391. (cs_create_pic in current_settings.moduleswitches) then
  1392. include(pd.procoptions,po_global);
  1393. pd.forwarddef:=false;
  1394. end;
  1395. { parse the directives that may follow }
  1396. parse_proc_directives(pd,pdflags);
  1397. { hint directives, these can be separated by semicolons here,
  1398. that needs to be handled here with a loop (PFV) }
  1399. while try_consume_hintdirective(pd.symoptions,pd.deprecatedmsg) do
  1400. Consume(_SEMICOLON);
  1401. { Set calling convention }
  1402. handle_calling_convention(pd);
  1403. { search for forward declarations }
  1404. if not proc_add_definition(pd) then
  1405. begin
  1406. { A method must be forward defined (in the object declaration) }
  1407. if assigned(pd._class) and
  1408. (not assigned(old_current_objectdef)) then
  1409. begin
  1410. MessagePos1(pd.fileinfo,parser_e_header_dont_match_any_member,pd.fullprocname(false));
  1411. tprocsym(pd.procsym).write_parameter_lists(pd);
  1412. end
  1413. else
  1414. begin
  1415. { Give a better error if there is a forward def in the interface and only
  1416. a single implementation }
  1417. firstpd:=tprocdef(tprocsym(pd.procsym).ProcdefList[0]);
  1418. if (not pd.forwarddef) and
  1419. (not pd.interfacedef) and
  1420. (tprocsym(pd.procsym).ProcdefList.Count>1) and
  1421. firstpd.forwarddef and
  1422. firstpd.interfacedef and
  1423. not(tprocsym(pd.procsym).ProcdefList.Count>2) and
  1424. { don't give an error if it may be an overload }
  1425. not(m_fpc in current_settings.modeswitches) and
  1426. (not(po_overload in pd.procoptions) or
  1427. not(po_overload in firstpd.procoptions)) then
  1428. begin
  1429. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  1430. tprocsym(pd.procsym).write_parameter_lists(pd);
  1431. end;
  1432. end;
  1433. end;
  1434. { Set mangled name }
  1435. proc_set_mangledname(pd);
  1436. { compile procedure when a body is needed }
  1437. if (pd_body in pdflags) then
  1438. begin
  1439. read_proc_body(old_current_procinfo,pd);
  1440. end
  1441. else
  1442. begin
  1443. { Handle imports }
  1444. if (po_external in pd.procoptions) then
  1445. begin
  1446. { External declared in implementation, and there was already a
  1447. forward (or interface) declaration then we need to generate
  1448. a stub that calls the external routine }
  1449. if (not pd.forwarddef) and
  1450. (pd.hasforward) and
  1451. not(
  1452. assigned(pd.import_dll) and
  1453. (target_info.system in [system_i386_wdosx,
  1454. system_arm_wince,system_i386_wince])
  1455. ) then
  1456. begin
  1457. s:=proc_get_importname(pd);
  1458. if s<>'' then
  1459. gen_external_stub(current_asmdata.asmlists[al_procedures],pd,s);
  1460. end;
  1461. { Import DLL specified? }
  1462. if assigned(pd.import_dll) then
  1463. current_module.AddExternalImport(pd.import_dll^,proc_get_importname(pd),pd.import_nr,false,pd.import_name=nil)
  1464. else
  1465. begin
  1466. { add import name to external list for DLL scanning }
  1467. if tf_has_dllscanner in target_info.flags then
  1468. current_module.dllscannerinputlist.Add(proc_get_importname(pd),pd);
  1469. end;
  1470. end;
  1471. end;
  1472. { make sure that references to forward-declared functions are not }
  1473. { treated as references to external symbols, needed for darwin. }
  1474. { make sure we don't change the binding of real external symbols }
  1475. if not(po_external in pd.procoptions) then
  1476. begin
  1477. if (po_global in pd.procoptions) or
  1478. (cs_profile in current_settings.moduleswitches) then
  1479. current_asmdata.DefineAsmSymbol(pd.mangledname,AB_GLOBAL,AT_FUNCTION)
  1480. else
  1481. current_asmdata.DefineAsmSymbol(pd.mangledname,AB_LOCAL,AT_FUNCTION);
  1482. end;
  1483. current_objectdef:=old_current_objectdef;
  1484. current_procinfo:=old_current_procinfo;
  1485. end;
  1486. {****************************************************************************
  1487. DECLARATION PARSING
  1488. ****************************************************************************}
  1489. { search in symtablestack for not complete classes }
  1490. procedure check_forward_class(p:TObject;arg:pointer);
  1491. begin
  1492. if (tsym(p).typ=typesym) and
  1493. (ttypesym(p).typedef.typ=objectdef) and
  1494. (oo_is_forward in tobjectdef(ttypesym(p).typedef).objectoptions) then
  1495. MessagePos1(tsym(p).fileinfo,sym_e_forward_type_not_resolved,tsym(p).realname);
  1496. end;
  1497. procedure read_declarations(islibrary : boolean);
  1498. begin
  1499. repeat
  1500. if not assigned(current_procinfo) then
  1501. internalerror(200304251);
  1502. case token of
  1503. _LABEL:
  1504. label_dec;
  1505. _CONST:
  1506. const_dec;
  1507. _TYPE:
  1508. type_dec;
  1509. _VAR:
  1510. var_dec;
  1511. _THREADVAR:
  1512. threadvar_dec;
  1513. _CONSTRUCTOR,
  1514. _DESTRUCTOR,
  1515. _FUNCTION,
  1516. _PROCEDURE,
  1517. _OPERATOR,
  1518. _CLASS:
  1519. read_proc;
  1520. _EXPORTS:
  1521. begin
  1522. if (current_procinfo.procdef.localst.symtablelevel>main_program_level) then
  1523. begin
  1524. Message(parser_e_syntax_error);
  1525. consume_all_until(_SEMICOLON);
  1526. end
  1527. else if islibrary or
  1528. (target_info.system in system_unit_program_exports) then
  1529. read_exports
  1530. else
  1531. begin
  1532. Message(parser_w_unsupported_feature);
  1533. consume(_BEGIN);
  1534. end;
  1535. end
  1536. else
  1537. begin
  1538. case idtoken of
  1539. _RESOURCESTRING :
  1540. begin
  1541. { m_class is needed, because the resourcestring
  1542. loading is in the ObjPas unit }
  1543. { if (m_class in current_settings.modeswitches) then}
  1544. resourcestring_dec
  1545. { else
  1546. break;}
  1547. end;
  1548. _PROPERTY:
  1549. begin
  1550. if (m_fpc in current_settings.modeswitches) then
  1551. property_dec
  1552. else
  1553. break;
  1554. end;
  1555. else
  1556. break;
  1557. end;
  1558. end;
  1559. end;
  1560. until false;
  1561. { check for incomplete class definitions, this is only required
  1562. for fpc modes }
  1563. if (m_fpc in current_settings.modeswitches) then
  1564. current_procinfo.procdef.localst.SymList.ForEachCall(@check_forward_class,nil);
  1565. end;
  1566. procedure read_interface_declarations;
  1567. begin
  1568. repeat
  1569. case token of
  1570. _CONST :
  1571. const_dec;
  1572. _TYPE :
  1573. type_dec;
  1574. _VAR :
  1575. var_dec;
  1576. _THREADVAR :
  1577. threadvar_dec;
  1578. _FUNCTION,
  1579. _PROCEDURE,
  1580. _OPERATOR :
  1581. read_proc;
  1582. else
  1583. begin
  1584. case idtoken of
  1585. _RESOURCESTRING :
  1586. resourcestring_dec;
  1587. _PROPERTY:
  1588. begin
  1589. if (m_fpc in current_settings.modeswitches) then
  1590. property_dec
  1591. else
  1592. break;
  1593. end;
  1594. else
  1595. break;
  1596. end;
  1597. end;
  1598. end;
  1599. until false;
  1600. { check for incomplete class definitions, this is only required
  1601. for fpc modes }
  1602. if (m_fpc in current_settings.modeswitches) then
  1603. symtablestack.top.SymList.ForEachCall(@check_forward_class,nil);
  1604. end;
  1605. {****************************************************************************
  1606. SPECIALIZATION BODY GENERATION
  1607. ****************************************************************************}
  1608. procedure specialize_objectdefs(p:TObject;arg:pointer);
  1609. var
  1610. i : longint;
  1611. hp : tdef;
  1612. oldcurrent_filepos : tfileposinfo;
  1613. oldsymtablestack : tsymtablestack;
  1614. pu : tused_unit;
  1615. hmodule : tmodule;
  1616. specobj : tobjectdef;
  1617. begin
  1618. if not((tsym(p).typ=typesym) and
  1619. (ttypesym(p).typedef.typesym=tsym(p)) and
  1620. (ttypesym(p).typedef.typ=objectdef) and
  1621. (df_specialization in ttypesym(p).typedef.defoptions)
  1622. ) then
  1623. exit;
  1624. { Setup symtablestack a definition time }
  1625. specobj:=tobjectdef(ttypesym(p).typedef);
  1626. oldsymtablestack:=symtablestack;
  1627. symtablestack:=tsymtablestack.create;
  1628. if not assigned(tobjectdef(ttypesym(p).typedef).genericdef) then
  1629. internalerror(200705151);
  1630. hmodule:=find_module_from_symtable(specobj.genericdef.owner);
  1631. if hmodule=nil then
  1632. internalerror(200705152);
  1633. pu:=tused_unit(hmodule.used_units.first);
  1634. while assigned(pu) do
  1635. begin
  1636. if not assigned(pu.u.globalsymtable) then
  1637. internalerror(200705153);
  1638. symtablestack.push(pu.u.globalsymtable);
  1639. pu:=tused_unit(pu.next);
  1640. end;
  1641. if assigned(hmodule.globalsymtable) then
  1642. symtablestack.push(hmodule.globalsymtable);
  1643. if assigned(hmodule.localsymtable) then
  1644. symtablestack.push(hmodule.localsymtable);
  1645. { procedure definitions for classes or objects }
  1646. if is_class(specobj) or is_object(specobj) then
  1647. begin
  1648. for i:=0 to specobj.symtable.DefList.Count-1 do
  1649. begin
  1650. hp:=tdef(specobj.symtable.DefList[i]);
  1651. if hp.typ=procdef then
  1652. begin
  1653. if assigned(tprocdef(hp).genericdef) and
  1654. (tprocdef(hp).genericdef.typ=procdef) and
  1655. assigned(tprocdef(tprocdef(hp).genericdef).generictokenbuf) then
  1656. begin
  1657. oldcurrent_filepos:=current_filepos;
  1658. current_filepos:=tprocdef(tprocdef(hp).genericdef).fileinfo;
  1659. { use the index the module got from the current compilation process }
  1660. current_filepos.moduleindex:=hmodule.unit_index;
  1661. current_tokenpos:=current_filepos;
  1662. current_scanner.startreplaytokens(tprocdef(tprocdef(hp).genericdef).generictokenbuf);
  1663. read_proc_body(nil,tprocdef(hp));
  1664. current_filepos:=oldcurrent_filepos;
  1665. end
  1666. else
  1667. MessagePos1(tprocdef(hp).fileinfo,sym_e_forward_not_resolved,tprocdef(hp).fullprocname(false));
  1668. end;
  1669. end;
  1670. end;
  1671. { Restore symtablestack }
  1672. symtablestack.free;
  1673. symtablestack:=oldsymtablestack;
  1674. end;
  1675. procedure generate_specialization_procs;
  1676. begin
  1677. if assigned(current_module.globalsymtable) then
  1678. current_module.globalsymtable.SymList.ForEachCall(@specialize_objectdefs,nil);
  1679. if assigned(current_module.localsymtable) then
  1680. current_module.localsymtable.SymList.ForEachCall(@specialize_objectdefs,nil);
  1681. end;
  1682. end.