psub.pas 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440
  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. globals,
  22. node,nbas,
  23. symdef,procinfo,optdfa;
  24. type
  25. { tcgprocinfo }
  26. tcgprocinfo = class(tprocinfo)
  27. private
  28. procedure CreateInlineInfo;
  29. { returns the node which is the start of the user code, this is needed by the dfa }
  30. function GetUserCode: tnode;
  31. procedure maybe_add_constructor_wrapper(var tocode: tnode; withexceptblock: boolean);
  32. procedure add_entry_exit_code;
  33. procedure setup_tempgen;
  34. public
  35. { code for the subroutine as tree }
  36. code : tnode;
  37. { positions in the tree for init/final }
  38. entry_asmnode,
  39. loadpara_asmnode,
  40. exitlabel_asmnode,
  41. stackcheck_asmnode,
  42. init_asmnode,
  43. final_asmnode : tasmnode;
  44. final_used : boolean;
  45. dfabuilder : TDFABuilder;
  46. destructor destroy;override;
  47. procedure printproc(pass:string);
  48. procedure generate_code;
  49. procedure generate_code_tree;
  50. procedure generate_exceptfilter(nestedpi: tcgprocinfo);
  51. procedure resetprocdef;
  52. procedure add_to_symtablestack;
  53. procedure remove_from_symtablestack;
  54. procedure parse_body;
  55. function has_assembler_child : boolean;
  56. end;
  57. procedure printnode_reset;
  58. { reads the declaration blocks }
  59. procedure read_declarations(islibrary : boolean);
  60. { reads declarations in the interface part of a unit }
  61. procedure read_interface_declarations;
  62. { reads any routine in the implementation, or a non-method routine
  63. declaration in the interface (depending on whether or not parse_only is
  64. true) }
  65. procedure read_proc(isclassmethod:boolean; usefwpd: tprocdef);
  66. procedure generate_specialization_procs;
  67. implementation
  68. uses
  69. sysutils,
  70. { common }
  71. cutils,
  72. { global }
  73. globtype,tokens,verbose,comphook,constexp,
  74. systems,cpubase,aasmbase,aasmtai,aasmdata,
  75. { symtable }
  76. symconst,symbase,symsym,symtype,symtable,defutil,symcreat,
  77. paramgr,
  78. ppu,fmodule,
  79. { pass 1 }
  80. nutils,ngenutil,nld,ncal,ncon,nflw,nadd,ncnv,nmem,
  81. pass_1,
  82. {$ifdef state_tracking}
  83. nstate,
  84. {$endif state_tracking}
  85. { pass 2 }
  86. {$ifndef NOPASS2}
  87. pass_2,
  88. {$endif}
  89. { parser }
  90. scanner,gendef,
  91. pbase,pstatmnt,pdecl,pdecsub,pexports,pgenutil,pparautl,
  92. { codegen }
  93. tgobj,cgbase,cgobj,cgutils,hlcgobj,hlcgcpu,dbgbase,
  94. ncgutil,regvars,
  95. optbase,
  96. opttail,
  97. optcse,
  98. optloop,
  99. optconstprop,
  100. optdeadstore
  101. {$if defined(arm)}
  102. ,cpuinfo
  103. {$endif arm}
  104. {$ifndef NOOPT}
  105. {$ifdef i386}
  106. ,aopt386
  107. {$else i386}
  108. ,aopt
  109. {$endif i386}
  110. {$endif}
  111. ;
  112. function checknodeinlining(procdef: tprocdef): boolean;
  113. var
  114. i : integer;
  115. currpara : tparavarsym;
  116. begin
  117. result := false;
  118. if pi_has_assembler_block in current_procinfo.flags then
  119. begin
  120. Message1(parser_h_not_supported_for_inline,'assembler');
  121. Message(parser_h_inlining_disabled);
  122. exit;
  123. end;
  124. if pi_has_global_goto in current_procinfo.flags then
  125. begin
  126. Message1(parser_h_not_supported_for_inline,'global goto');
  127. Message(parser_h_inlining_disabled);
  128. exit;
  129. end;
  130. if pi_has_nested_exit in current_procinfo.flags then
  131. begin
  132. Message1(parser_h_not_supported_for_inline,'nested exit');
  133. Message(parser_h_inlining_disabled);
  134. exit;
  135. end;
  136. if pi_calls_c_varargs in current_procinfo.flags then
  137. begin
  138. Message1(parser_h_not_supported_for_inline,'called C-style varargs functions');
  139. Message(parser_h_inlining_disabled);
  140. exit;
  141. end;
  142. { the compiler cannot handle inherited in inlined subroutines because
  143. it tries to search for self in the symtable, however, the symtable
  144. is not available }
  145. if pi_has_inherited in current_procinfo.flags then
  146. begin
  147. Message1(parser_h_not_supported_for_inline,'inherited');
  148. Message(parser_h_inlining_disabled);
  149. exit;
  150. end;
  151. for i:=0 to procdef.paras.count-1 do
  152. begin
  153. currpara:=tparavarsym(procdef.paras[i]);
  154. case currpara.vardef.typ of
  155. formaldef :
  156. begin
  157. if (currpara.varspez in [vs_out,vs_var,vs_const,vs_constref]) then
  158. begin
  159. Message1(parser_h_not_supported_for_inline,'formal parameter');
  160. Message(parser_h_inlining_disabled);
  161. exit;
  162. end;
  163. end;
  164. arraydef :
  165. begin
  166. if is_array_of_const(currpara.vardef) or
  167. is_variant_array(currpara.vardef) then
  168. begin
  169. Message1(parser_h_not_supported_for_inline,'array of const');
  170. Message(parser_h_inlining_disabled);
  171. exit;
  172. end;
  173. { open arrays might need re-basing of the index, i.e. if you pass
  174. an array[1..10] as open array, you have to add 1 to all index operations
  175. if you directly inline it }
  176. if is_open_array(currpara.vardef) then
  177. begin
  178. Message1(parser_h_not_supported_for_inline,'open array');
  179. Message(parser_h_inlining_disabled);
  180. exit;
  181. end;
  182. end;
  183. end;
  184. end;
  185. result:=true;
  186. end;
  187. {****************************************************************************
  188. PROCEDURE/FUNCTION BODY PARSING
  189. ****************************************************************************}
  190. procedure initializedefaultvars(p:TObject;arg:pointer);
  191. var
  192. b : tblocknode;
  193. begin
  194. if tsym(p).typ<>localvarsym then
  195. exit;
  196. with tabstractnormalvarsym(p) do
  197. begin
  198. if (vo_is_default_var in varoptions) and (vardef.size>0) then
  199. begin
  200. b:=tblocknode(arg);
  201. b.left:=cstatementnode.create(
  202. ccallnode.createintern('fpc_zeromem',
  203. ccallparanode.create(
  204. cordconstnode.create(vardef.size,ptruinttype,false),
  205. ccallparanode.create(
  206. caddrnode.create_internal(
  207. cloadnode.create(tsym(p),tsym(p).owner)),
  208. nil
  209. )
  210. )
  211. ),
  212. b.left);
  213. end;
  214. end;
  215. end;
  216. procedure initializevars(p:TObject;arg:pointer);
  217. var
  218. b : tblocknode;
  219. begin
  220. if not (tsym(p).typ in [localvarsym,staticvarsym]) then
  221. exit;
  222. with tabstractnormalvarsym(p) do
  223. begin
  224. if assigned(defaultconstsym) then
  225. begin
  226. b:=tblocknode(arg);
  227. b.left:=cstatementnode.create(
  228. cassignmentnode.create(
  229. cloadnode.create(tsym(p),tsym(p).owner),
  230. cloadnode.create(defaultconstsym,defaultconstsym.owner)),
  231. b.left);
  232. end
  233. else
  234. initializedefaultvars(p,arg);
  235. end;
  236. end;
  237. procedure check_finalize_paras(p:TObject;arg:pointer);
  238. begin
  239. if (tsym(p).typ=paravarsym) then
  240. begin
  241. if tparavarsym(p).needs_finalization then
  242. begin
  243. include(current_procinfo.flags,pi_needs_implicit_finally);
  244. include(current_procinfo.flags,pi_do_call);
  245. end;
  246. if (tparavarsym(p).varspez in [vs_value,vs_out]) and
  247. (cs_create_pic in current_settings.moduleswitches) and
  248. (tf_pic_uses_got in target_info.flags) and
  249. is_rtti_managed_type(tparavarsym(p).vardef) then
  250. include(current_procinfo.flags,pi_needs_got);
  251. end;
  252. end;
  253. procedure check_finalize_locals(p:TObject;arg:pointer);
  254. begin
  255. { include the result: it needs to be finalized in case an exception }
  256. { occurs }
  257. if (tsym(p).typ=localvarsym) and
  258. (tlocalvarsym(p).refs>0) and
  259. is_managed_type(tlocalvarsym(p).vardef) then
  260. begin
  261. include(current_procinfo.flags,pi_needs_implicit_finally);
  262. include(current_procinfo.flags,pi_do_call);
  263. if is_rtti_managed_type(tlocalvarsym(p).vardef) and
  264. (cs_create_pic in current_settings.moduleswitches) and
  265. (tf_pic_uses_got in target_info.flags) then
  266. include(current_procinfo.flags,pi_needs_got);
  267. end;
  268. end;
  269. function block(islibrary : boolean) : tnode;
  270. var
  271. oldfilepos: tfileposinfo;
  272. begin
  273. { parse const,types and vars }
  274. read_declarations(islibrary);
  275. { do we have an assembler block without the po_assembler?
  276. we should allow this for Delphi compatibility (PFV) }
  277. if (token=_ASM) and (m_delphi in current_settings.modeswitches) then
  278. include(current_procinfo.procdef.procoptions,po_assembler);
  279. { Handle assembler block different }
  280. if (po_assembler in current_procinfo.procdef.procoptions) then
  281. begin
  282. block:=assembler_block;
  283. exit;
  284. end;
  285. {Unit initialization?.}
  286. if (
  287. assigned(current_procinfo.procdef.localst) and
  288. (current_procinfo.procdef.localst.symtablelevel=main_program_level) and
  289. (current_module.is_unit or islibrary)
  290. ) then
  291. begin
  292. if (token=_END) then
  293. begin
  294. consume(_END);
  295. { We need at least a node, else the entry/exit code is not
  296. generated and thus no PASCALMAIN symbol which we need (PFV) }
  297. if islibrary then
  298. block:=cnothingnode.create
  299. else
  300. block:=nil;
  301. end
  302. else
  303. begin
  304. if token=_INITIALIZATION then
  305. begin
  306. { The library init code is already called and does not
  307. need to be in the initfinal table (PFV) }
  308. block:=statement_block(_INITIALIZATION);
  309. end
  310. else if token=_FINALIZATION then
  311. begin
  312. { when a unit has only a finalization section, we can come to this
  313. point when we try to read the nonh existing initalization section
  314. so we've to check if we are really try to parse the finalization }
  315. if current_procinfo.procdef.proctypeoption=potype_unitfinalize then
  316. block:=statement_block(_FINALIZATION)
  317. else
  318. block:=nil;
  319. end
  320. else
  321. block:=statement_block(_BEGIN);
  322. end;
  323. end
  324. else
  325. begin
  326. { parse routine body }
  327. block:=statement_block(_BEGIN);
  328. { initialized variables }
  329. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  330. begin
  331. { initialization of local variables with their initial
  332. values: part of function entry }
  333. oldfilepos:=current_filepos;
  334. current_filepos:=current_procinfo.entrypos;
  335. current_procinfo.procdef.localst.SymList.ForEachCall(@initializevars,block);
  336. current_filepos:=oldfilepos;
  337. end
  338. else if current_procinfo.procdef.localst.symtabletype=staticsymtable then
  339. begin
  340. { for program and unit initialization code we also need to
  341. initialize the local variables used of Default() }
  342. oldfilepos:=current_filepos;
  343. current_filepos:=current_procinfo.entrypos;
  344. current_procinfo.procdef.localst.SymList.ForEachCall(@initializedefaultvars,block);
  345. current_filepos:=oldfilepos;
  346. end;
  347. if assigned(current_procinfo.procdef.parentfpstruct) then
  348. begin
  349. { we only do this after the code has been parsed because
  350. otherwise for-loop counters moved to the struct cause
  351. errors; we still do it nevertheless to prevent false
  352. "unused" symbols warnings and to assist debug info
  353. generation }
  354. redirect_parentfpstruct_local_syms(current_procinfo.procdef);
  355. { finish the parentfpstruct (add padding, ...) }
  356. finish_parentfpstruct(current_procinfo.procdef);
  357. end;
  358. end;
  359. end;
  360. {****************************************************************************
  361. PROCEDURE/FUNCTION COMPILING
  362. ****************************************************************************}
  363. procedure printnode_reset;
  364. begin
  365. assign(printnodefile,treelogfilename);
  366. {$push}{$I-}
  367. rewrite(printnodefile);
  368. {$pop}
  369. if ioresult<>0 then
  370. begin
  371. Comment(V_Error,'Error creating '+treelogfilename);
  372. exit;
  373. end;
  374. close(printnodefile);
  375. end;
  376. procedure add_label_init(p:TObject;arg:pointer);
  377. begin
  378. if tstoredsym(p).typ=labelsym then
  379. begin
  380. addstatement(tstatementnode(arg^),
  381. cifnode.create(caddnode.create(equaln,
  382. ccallnode.createintern('fpc_setjmp',
  383. ccallparanode.create(cloadnode.create(tlabelsym(p).jumpbuf,tlabelsym(p).jumpbuf.owner),nil)),
  384. cordconstnode.create(1,sinttype,true))
  385. ,cgotonode.create(tlabelsym(p)),nil)
  386. );
  387. end;
  388. end;
  389. function generate_bodyentry_block:tnode;
  390. var
  391. srsym : tsym;
  392. para : tcallparanode;
  393. call : tcallnode;
  394. newstatement : tstatementnode;
  395. def : tabstractrecorddef;
  396. begin
  397. result:=internalstatements(newstatement);
  398. if assigned(current_structdef) then
  399. begin
  400. { a constructor needs a help procedure }
  401. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  402. begin
  403. if is_class(current_structdef) or
  404. (
  405. is_objectpascal_helper(current_structdef) and
  406. is_class(tobjectdef(current_structdef).extendeddef)
  407. ) then
  408. begin
  409. if is_objectpascal_helper(current_structdef) then
  410. def:=tabstractrecorddef(tobjectdef(current_structdef).extendeddef)
  411. else
  412. def:=current_structdef;
  413. srsym:=search_struct_member(def,'NEWINSTANCE');
  414. if assigned(srsym) and
  415. (srsym.typ=procsym) then
  416. begin
  417. { if vmt=1 then newinstance }
  418. addstatement(newstatement,cifnode.create(
  419. caddnode.create_internal(equaln,
  420. ctypeconvnode.create_internal(
  421. load_vmt_pointer_node,
  422. voidpointertype),
  423. cpointerconstnode.create(1,voidpointertype)),
  424. cassignmentnode.create(
  425. ctypeconvnode.create_internal(
  426. load_self_pointer_node,
  427. voidpointertype),
  428. ccallnode.create(nil,tprocsym(srsym),srsym.owner,
  429. ctypeconvnode.create_internal(load_self_pointer_node,cclassrefdef.create(current_structdef)),
  430. [])),
  431. nil));
  432. end
  433. else
  434. internalerror(200305108);
  435. end
  436. else
  437. if is_object(current_structdef) then
  438. begin
  439. { parameter 3 : vmt_offset }
  440. { parameter 2 : address of pointer to vmt,
  441. this is required to allow setting the vmt to -1 to indicate
  442. that memory was allocated }
  443. { parameter 1 : self pointer }
  444. para:=ccallparanode.create(
  445. cordconstnode.create(tobjectdef(current_structdef).vmt_offset,s32inttype,false),
  446. ccallparanode.create(
  447. ctypeconvnode.create_internal(
  448. load_vmt_pointer_node,
  449. voidpointertype),
  450. ccallparanode.create(
  451. ctypeconvnode.create_internal(
  452. load_self_pointer_node,
  453. voidpointertype),
  454. nil)));
  455. addstatement(newstatement,cassignmentnode.create(
  456. ctypeconvnode.create_internal(
  457. load_self_pointer_node,
  458. voidpointertype),
  459. ccallnode.createintern('fpc_help_constructor',para)));
  460. end
  461. else
  462. if is_javaclass(current_structdef) or
  463. ((target_info.system in systems_jvm) and
  464. is_record(current_structdef)) then
  465. begin
  466. if (current_procinfo.procdef.proctypeoption=potype_constructor) and
  467. not current_procinfo.ConstructorCallingConstructor then
  468. begin
  469. { call inherited constructor }
  470. if is_javaclass(current_structdef) then
  471. srsym:=search_struct_member_no_helper(tobjectdef(current_structdef).childof,'CREATE')
  472. else
  473. srsym:=search_struct_member_no_helper(java_fpcbaserecordtype,'CREATE');
  474. if assigned(srsym) and
  475. (srsym.typ=procsym) then
  476. begin
  477. call:=ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[cnf_inherited]);
  478. exclude(tcallnode(call).callnodeflags,cnf_return_value_used);
  479. addstatement(newstatement,call);
  480. end
  481. else
  482. internalerror(2011010312);
  483. end;
  484. end
  485. else
  486. if not is_record(current_structdef) and
  487. not (
  488. is_objectpascal_helper(current_structdef) and
  489. (tobjectdef(current_structdef).extendeddef.typ<>objectdef)
  490. ) then
  491. internalerror(200305103);
  492. { if self=nil then exit
  493. calling fail instead of exit is useless because
  494. there is nothing to dispose (PFV) }
  495. if is_class_or_object(current_structdef) then
  496. addstatement(newstatement,cifnode.create(
  497. caddnode.create(equaln,
  498. load_self_pointer_node,
  499. cnilnode.create),
  500. cexitnode.create(nil),
  501. nil));
  502. end;
  503. { maybe call BeforeDestruction for classes }
  504. if (current_procinfo.procdef.proctypeoption=potype_destructor) and
  505. is_class(current_structdef) then
  506. begin
  507. srsym:=search_struct_member(current_structdef,'BEFOREDESTRUCTION');
  508. if assigned(srsym) and
  509. (srsym.typ=procsym) then
  510. begin
  511. { if vmt>0 then beforedestruction }
  512. addstatement(newstatement,cifnode.create(
  513. caddnode.create(gtn,
  514. ctypeconvnode.create_internal(
  515. load_vmt_pointer_node,ptrsinttype),
  516. ctypeconvnode.create_internal(
  517. cnilnode.create,ptrsinttype)),
  518. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  519. nil));
  520. end
  521. else
  522. internalerror(200305104);
  523. end;
  524. end;
  525. if m_non_local_goto in current_settings.modeswitches then
  526. tsymtable(current_procinfo.procdef.localst).SymList.ForEachCall(@add_label_init,@newstatement);
  527. end;
  528. function generate_bodyexit_block:tnode;
  529. var
  530. srsym : tsym;
  531. para : tcallparanode;
  532. newstatement : tstatementnode;
  533. oldlocalswitches: tlocalswitches;
  534. begin
  535. result:=internalstatements(newstatement);
  536. if assigned(current_structdef) then
  537. begin
  538. { Don't test self and the vmt here. The reason is that }
  539. { a constructor already checks whether these are valid }
  540. { before. Further, in case of TThread the thread may }
  541. { free the class instance right after AfterConstruction }
  542. { has been called, so it may no longer be valid (JM) }
  543. oldlocalswitches:=current_settings.localswitches;
  544. current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];
  545. { a destructor needs a help procedure }
  546. if (current_procinfo.procdef.proctypeoption=potype_destructor) then
  547. begin
  548. if is_class(current_structdef) then
  549. begin
  550. srsym:=search_struct_member(current_structdef,'FREEINSTANCE');
  551. if assigned(srsym) and
  552. (srsym.typ=procsym) then
  553. begin
  554. { if self<>0 and vmt<>0 then freeinstance }
  555. addstatement(newstatement,cifnode.create(
  556. caddnode.create(andn,
  557. caddnode.create(unequaln,
  558. load_self_pointer_node,
  559. cnilnode.create),
  560. caddnode.create(unequaln,
  561. ctypeconvnode.create(
  562. load_vmt_pointer_node,
  563. voidpointertype),
  564. cpointerconstnode.create(0,voidpointertype))),
  565. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  566. nil));
  567. end
  568. else
  569. internalerror(200305108);
  570. end
  571. else
  572. if is_object(current_structdef) then
  573. begin
  574. { finalize object data, but only if not in inherited call }
  575. if is_managed_type(current_structdef) then
  576. begin
  577. addstatement(newstatement,cifnode.create(
  578. caddnode.create(unequaln,
  579. ctypeconvnode.create_internal(load_vmt_pointer_node,voidpointertype),
  580. cnilnode.create),
  581. cnodeutils.finalize_data_node(load_self_node),
  582. nil));
  583. end;
  584. { parameter 3 : vmt_offset }
  585. { parameter 2 : pointer to vmt }
  586. { parameter 1 : self pointer }
  587. para:=ccallparanode.create(
  588. cordconstnode.create(tobjectdef(current_structdef).vmt_offset,s32inttype,false),
  589. ccallparanode.create(
  590. ctypeconvnode.create_internal(
  591. load_vmt_pointer_node,
  592. voidpointertype),
  593. ccallparanode.create(
  594. ctypeconvnode.create_internal(
  595. load_self_pointer_node,
  596. voidpointertype),
  597. nil)));
  598. addstatement(newstatement,
  599. ccallnode.createintern('fpc_help_destructor',para));
  600. end
  601. else if is_javaclass(current_structdef) then
  602. begin
  603. { nothing to do }
  604. end
  605. else
  606. internalerror(200305105);
  607. end;
  608. current_settings.localswitches:=oldlocalswitches;
  609. end;
  610. end;
  611. {****************************************************************************
  612. TCGProcInfo
  613. ****************************************************************************}
  614. destructor tcgprocinfo.destroy;
  615. begin
  616. if assigned(code) then
  617. code.free;
  618. if not final_used then
  619. final_asmnode.free;
  620. inherited destroy;
  621. end;
  622. procedure tcgprocinfo.printproc(pass:string);
  623. begin
  624. assign(printnodefile,treelogfilename);
  625. {$push}{$I-}
  626. append(printnodefile);
  627. if ioresult<>0 then
  628. rewrite(printnodefile);
  629. {$pop}
  630. if ioresult<>0 then
  631. begin
  632. Comment(V_Error,'Error creating '+treelogfilename);
  633. exit;
  634. end;
  635. writeln(printnodefile);
  636. writeln(printnodefile,'*******************************************************************************');
  637. writeln(printnodefile, pass);
  638. writeln(printnodefile,procdef.fullprocname(false));
  639. writeln(printnodefile,'*******************************************************************************');
  640. printnode(printnodefile,code);
  641. close(printnodefile);
  642. end;
  643. procedure tcgprocinfo.maybe_add_constructor_wrapper(var tocode: tnode; withexceptblock: boolean);
  644. var
  645. oldlocalswitches: tlocalswitches;
  646. srsym: tsym;
  647. afterconstructionblock,
  648. exceptblock,
  649. newblock: tblocknode;
  650. newstatement: tstatementnode;
  651. pd: tprocdef;
  652. begin
  653. if assigned(procdef.struct) and
  654. (procdef.proctypeoption=potype_constructor) then
  655. begin
  656. withexceptblock:=
  657. withexceptblock and
  658. not(target_info.system in systems_garbage_collected_managed_types);
  659. { Don't test self and the vmt here. See generate_bodyexit_block }
  660. { why (JM) }
  661. oldlocalswitches:=current_settings.localswitches;
  662. current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];
  663. { call AfterConstruction for classes }
  664. if is_class(procdef.struct) then
  665. begin
  666. srsym:=search_struct_member(procdef.struct,'AFTERCONSTRUCTION');
  667. if assigned(srsym) and
  668. (srsym.typ=procsym) then
  669. begin
  670. current_filepos:=exitpos;
  671. afterconstructionblock:=internalstatements(newstatement);
  672. { first execute all constructor code. If no exception
  673. occurred then we will execute afterconstruction,
  674. otherwise we won't (the exception will jump over us) }
  675. addstatement(newstatement,tocode);
  676. { if implicit finally node wasn't created, then exit label and
  677. finalization code must be handled here and placed before
  678. afterconstruction }
  679. if not ((pi_needs_implicit_finally in flags) and
  680. (cs_implicit_exceptions in current_settings.moduleswitches)) then
  681. begin
  682. include(tocode.flags,nf_block_with_exit);
  683. addstatement(newstatement,final_asmnode);
  684. final_used:=true;
  685. end;
  686. { Self can be nil when fail is called }
  687. { if self<>nil and vmt<>nil then afterconstruction }
  688. addstatement(newstatement,cifnode.create(
  689. caddnode.create(andn,
  690. caddnode.create(unequaln,
  691. load_self_node,
  692. cnilnode.create),
  693. caddnode.create(unequaln,
  694. load_vmt_pointer_node,
  695. cnilnode.create)),
  696. ccallnode.create(nil,tprocsym(srsym),srsym.owner,load_self_node,[]),
  697. nil));
  698. tocode:=afterconstructionblock;
  699. end
  700. else
  701. internalerror(200305106);
  702. end;
  703. if withexceptblock and (procdef.struct.typ=objectdef) then
  704. begin
  705. { Generate the implicit "fail" code for a constructor (destroy
  706. in case an exception happened) }
  707. pd:=tobjectdef(procdef.struct).find_destructor;
  708. { this will always be the case for classes, since tobject has
  709. a destructor }
  710. if assigned(pd) or is_object(procdef.struct) then
  711. begin
  712. current_filepos:=exitpos;
  713. exceptblock:=internalstatements(newstatement);
  714. { first free the instance if non-nil }
  715. if assigned(pd) then
  716. { if vmt<>0 then call destructor }
  717. addstatement(newstatement,
  718. cifnode.create(
  719. caddnode.create(unequaln,
  720. load_vmt_pointer_node,
  721. cnilnode.create),
  722. { cnf_create_failed -> don't call BeforeDestruction }
  723. ccallnode.create(nil,tprocsym(pd.procsym),pd.procsym.owner,load_self_node,[cnf_create_failed]),
  724. nil))
  725. else
  726. { object without destructor, call 'fail' helper }
  727. addstatement(newstatement,
  728. ccallnode.createintern('fpc_help_fail',
  729. ccallparanode.create(
  730. cordconstnode.create(tobjectdef(procdef.struct).vmt_offset,s32inttype,false),
  731. ccallparanode.create(
  732. ctypeconvnode.create_internal(
  733. load_vmt_pointer_node,
  734. voidpointertype),
  735. ccallparanode.create(
  736. ctypeconvnode.create_internal(
  737. load_self_pointer_node,
  738. voidpointertype),
  739. nil))))
  740. );
  741. { then re-raise the exception }
  742. addstatement(newstatement,craisenode.create(nil,nil,nil));
  743. current_filepos:=entrypos;
  744. newblock:=internalstatements(newstatement);
  745. { try
  746. tocode
  747. except
  748. exceptblock
  749. end
  750. }
  751. addstatement(newstatement,ctryexceptnode.create(
  752. tocode,
  753. nil,
  754. exceptblock));
  755. tocode:=newblock;
  756. end;
  757. end;
  758. current_settings.localswitches:=oldlocalswitches;
  759. end;
  760. end;
  761. procedure tcgprocinfo.add_entry_exit_code;
  762. var
  763. finalcode,
  764. bodyentrycode,
  765. bodyexitcode,
  766. wrappedbody,
  767. newblock : tnode;
  768. codestatement,
  769. newstatement : tstatementnode;
  770. oldfilepos : tfileposinfo;
  771. is_constructor: boolean;
  772. begin
  773. is_constructor:=assigned(procdef.struct) and
  774. (procdef.proctypeoption=potype_constructor);
  775. oldfilepos:=current_filepos;
  776. { Generate code/locations used at start of proc }
  777. current_filepos:=entrypos;
  778. entry_asmnode:=casmnode.create_get_position;
  779. loadpara_asmnode:=casmnode.create_get_position;
  780. stackcheck_asmnode:=casmnode.create_get_position;
  781. init_asmnode:=casmnode.create_get_position;
  782. bodyentrycode:=generate_bodyentry_block;
  783. { Generate code/locations used at end of proc }
  784. current_filepos:=exitpos;
  785. exitlabel_asmnode:=casmnode.create_get_position;
  786. final_asmnode:=casmnode.create_get_position;
  787. final_used:=false;
  788. bodyexitcode:=generate_bodyexit_block;
  789. { Generate procedure by combining init+body+final,
  790. depending on the implicit finally we need to add
  791. an try...finally...end wrapper }
  792. newblock:=internalstatements(newstatement);
  793. { initialization is common for all cases }
  794. addstatement(newstatement,loadpara_asmnode);
  795. addstatement(newstatement,stackcheck_asmnode);
  796. addstatement(newstatement,entry_asmnode);
  797. addstatement(newstatement,init_asmnode);
  798. addstatement(newstatement,bodyentrycode);
  799. if (cs_implicit_exceptions in current_settings.moduleswitches) and
  800. (pi_needs_implicit_finally in flags) and
  801. { but it's useless in init/final code of units }
  802. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) and
  803. not(po_assembler in procdef.procoptions) and
  804. not(target_info.system in systems_garbage_collected_managed_types) then
  805. begin
  806. { Any result of managed type must be returned in parameter }
  807. if is_managed_type(procdef.returndef) and
  808. (not paramanager.ret_in_param(procdef.returndef,procdef)) and
  809. (not is_class(procdef.returndef)) then
  810. InternalError(2013121301);
  811. { Generate special exception block only needed when
  812. implicit finaly is used }
  813. current_filepos:=exitpos;
  814. { Generate code that will be in the try...finally }
  815. finalcode:=internalstatements(codestatement);
  816. addstatement(codestatement,final_asmnode);
  817. final_used:=true;
  818. current_filepos:=entrypos;
  819. wrappedbody:=ctryfinallynode.create_implicit(
  820. code,
  821. finalcode,
  822. cnothingnode.create);
  823. { afterconstruction must be called after final_asmnode, because it
  824. has to execute after the temps have been finalised in case of a
  825. refcounted class (afterconstruction decreases the refcount
  826. without freeing the instance if the count becomes nil, while
  827. the finalising of the temps can free the instance) }
  828. maybe_add_constructor_wrapper(wrappedbody,true);
  829. addstatement(newstatement,wrappedbody);
  830. addstatement(newstatement,exitlabel_asmnode);
  831. addstatement(newstatement,bodyexitcode);
  832. { set flag the implicit finally has been generated }
  833. include(flags,pi_has_implicit_finally);
  834. end
  835. else
  836. begin
  837. { constructors need destroy-on-exception code even if they don't
  838. have managed variables/temps }
  839. maybe_add_constructor_wrapper(code,
  840. cs_implicit_exceptions in current_settings.moduleswitches);
  841. addstatement(newstatement,code);
  842. if assigned(nestedexitlabel) then
  843. addstatement(newstatement,clabelnode.create(cnothingnode.create,nestedexitlabel));
  844. addstatement(newstatement,exitlabel_asmnode);
  845. addstatement(newstatement,bodyexitcode);
  846. if not is_constructor then
  847. begin
  848. addstatement(newstatement,final_asmnode);
  849. final_used:=true;
  850. end;
  851. end;
  852. do_firstpass(newblock);
  853. code:=newblock;
  854. current_filepos:=oldfilepos;
  855. end;
  856. procedure clearrefs(p:TObject;arg:pointer);
  857. begin
  858. if (tsym(p).typ in [localvarsym,paravarsym,staticvarsym]) then
  859. if tabstractvarsym(p).refs>1 then
  860. tabstractvarsym(p).refs:=1;
  861. end;
  862. procedure translate_registers(p:TObject;list:pointer);
  863. begin
  864. if (tsym(p).typ in [localvarsym,paravarsym,staticvarsym]) and
  865. (tabstractnormalvarsym(p).localloc.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_MMREGISTER,
  866. LOC_CMMREGISTER,LOC_FPUREGISTER,LOC_CFPUREGISTER]) then
  867. begin
  868. if not(cs_no_regalloc in current_settings.globalswitches) then
  869. begin
  870. cg.translate_register(tabstractnormalvarsym(p).localloc.register);
  871. if (tabstractnormalvarsym(p).localloc.registerhi<>NR_NO) then
  872. cg.translate_register(tabstractnormalvarsym(p).localloc.registerhi);
  873. end;
  874. if cs_asm_source in current_settings.globalswitches then
  875. begin
  876. TAsmList(list).concat(Tai_comment.Create(strpnew('Var '+tabstractnormalvarsym(p).realname+' located in register '+
  877. location_reg2string(tabstractnormalvarsym(p).localloc))));
  878. end;
  879. end;
  880. end;
  881. const
  882. exception_flags: array[boolean] of tprocinfoflags = (
  883. [],
  884. [pi_uses_exceptions,pi_needs_implicit_finally,pi_has_implicit_finally]
  885. );
  886. procedure tcgprocinfo.setup_tempgen;
  887. begin
  888. tg:=tgobjclass.create;
  889. {$if defined(i386) or defined(x86_64) or defined(arm)}
  890. {$if defined(arm)}
  891. { frame and stack pointer must be always the same on arm thumb so it makes no
  892. sense to fiddle with a frame pointer }
  893. if GenerateThumbCode then
  894. begin
  895. framepointer:=NR_STACK_POINTER_REG;
  896. tg.direction:=1;
  897. end
  898. else
  899. {$endif defined(arm)}
  900. begin
  901. { try to strip the stack frame }
  902. { set the framepointer to esp if:
  903. - no assembler directive, those are handled in assembler_block
  904. in pstatment.pas (for cases not caught by the Delphi
  905. exception below)
  906. - no exceptions are used
  907. - no pushes are used/esp modifications, could be:
  908. * outgoing parameters on the stack on non-fixed stack target
  909. * incoming parameters on the stack
  910. * open arrays
  911. - no inline assembler
  912. or
  913. - Delphi mode
  914. - assembler directive
  915. - no pushes are used/esp modifications, could be:
  916. * outgoing parameters on the stack
  917. * incoming parameters on the stack
  918. * open arrays
  919. - no local variables
  920. - stack frame cannot be optimized if using Win64 SEH
  921. (at least with the current state of our codegenerator).
  922. }
  923. if ((po_assembler in procdef.procoptions) and
  924. (m_delphi in current_settings.modeswitches) and
  925. { localst at main_program_level is a staticsymtable }
  926. (procdef.localst.symtablelevel<>main_program_level) and
  927. (tabstractlocalsymtable(procdef.localst).count_locals = 0)) or
  928. ((cs_opt_stackframe in current_settings.optimizerswitches) and
  929. not(cs_generate_stackframes in current_settings.localswitches) and
  930. not(cs_profile in current_settings.moduleswitches) and
  931. not(po_assembler in procdef.procoptions) and
  932. not ((pi_has_stackparameter in flags)
  933. {$ifndef arm} { Outgoing parameter(s) on stack do not need stackframe on x86 targets
  934. with fixed stack. On ARM it fails, see bug #25050 }
  935. and (not paramanager.use_fixed_stack)
  936. {$endif arm}
  937. ) and
  938. ((flags*([pi_has_assembler_block,pi_is_assembler,
  939. pi_needs_stackframe]+
  940. exception_flags[(target_info.cpu=cpu_i386)
  941. {$ifndef DISABLE_WIN64_SEH}
  942. or (target_info.system=system_x86_64_win64)
  943. {$endif DISABLE_WIN64_SEH}
  944. ]))=[])
  945. )
  946. then
  947. begin
  948. { we need the parameter info here to determine if the procedure gets
  949. parameters on the stack
  950. calling generate_parameter_info doesn't hurt but it costs time
  951. (necessary to init para_stack_size)
  952. }
  953. generate_parameter_info;
  954. if not(procdef.stack_tainting_parameter(calleeside)) and
  955. not(has_assembler_child) and (para_stack_size=0) then
  956. begin
  957. { Only need to set the framepointer }
  958. framepointer:=NR_STACK_POINTER_REG;
  959. tg.direction:=1;
  960. end
  961. {$if defined(arm)}
  962. { On arm, the stack frame size can be estimated to avoid using an extra frame pointer,
  963. in case parameters are passed on the stack.
  964. However, the draw back is, if the estimation fails, compilation will break later on
  965. with an internal error, so this switch is not enabled by default yet. To overcome this,
  966. multipass compilation of subroutines must be supported
  967. }
  968. else if (cs_opt_forcenostackframe in current_settings.optimizerswitches) and
  969. not(has_assembler_child) then
  970. begin
  971. { Only need to set the framepointer }
  972. framepointer:=NR_STACK_POINTER_REG;
  973. tg.direction:=1;
  974. include(flags,pi_estimatestacksize);
  975. set_first_temp_offset;
  976. procdef.has_paraloc_info:=callnoside;
  977. generate_parameter_info;
  978. exit;
  979. end;
  980. {$endif defined(arm)}
  981. end;
  982. end;
  983. {$endif defined(x86) or defined(arm)}
  984. { set the start offset to the start of the temp area in the stack }
  985. set_first_temp_offset;
  986. end;
  987. function tcgprocinfo.has_assembler_child : boolean;
  988. var
  989. hp : tprocinfo;
  990. begin
  991. result:=false;
  992. hp:=get_first_nestedproc;
  993. while assigned(hp) do
  994. begin
  995. if (hp.flags*[pi_has_assembler_block,pi_is_assembler])<>[] then
  996. begin
  997. result:=true;
  998. exit;
  999. end;
  1000. hp:=tprocinfo(hp.next);
  1001. end;
  1002. end;
  1003. procedure tcgprocinfo.generate_code_tree;
  1004. var
  1005. hpi : tcgprocinfo;
  1006. begin
  1007. { generate code for this procedure }
  1008. generate_code;
  1009. { process nested procedures }
  1010. hpi:=tcgprocinfo(get_first_nestedproc);
  1011. while assigned(hpi) do
  1012. begin
  1013. hpi.generate_code_tree;
  1014. hpi:=tcgprocinfo(hpi.next);
  1015. end;
  1016. resetprocdef;
  1017. end;
  1018. { For SEH, the code from 'finally' blocks must be put into a separate procedures,
  1019. which can be called by OS during stack unwind. This resembles nested procedures,
  1020. but finalizer procedures do not have their own local variables and work directly
  1021. with the stack frame of parent. In particular, the tempgen must be shared, so
  1022. 1) finalizer procedure is able to finalize temps of the parent,
  1023. 2) if the finalizer procedure is complex enough to need its own temps, they are
  1024. allocated in stack frame of parent, so second-level finalizer procedures are
  1025. not needed.
  1026. Due to requirement of shared tempgen we cannot process finalizer as a regular nested
  1027. procedure (after the parent) and have to do it inline.
  1028. This is called by platform-specific tryfinallynodes during pass2.
  1029. Here we put away the codegen (which carries the register allocator state), process
  1030. the 'nested' procedure, then restore previous cg and continue processing the parent
  1031. procedure. generate_code() will create another cg, but not another tempgen because
  1032. setup_tempgen() is not called for potype_exceptfilter procedures. }
  1033. procedure tcgprocinfo.generate_exceptfilter(nestedpi: tcgprocinfo);
  1034. var
  1035. saved_cg: tcg;
  1036. saved_hlcg: thlcgobj;
  1037. {$ifdef cpu64bitalu}
  1038. saved_cg128 : tcg128;
  1039. {$else cpu64bitalu}
  1040. saved_cg64 : tcg64;
  1041. {$endif cpu64bitalu}
  1042. begin
  1043. if nestedpi.procdef.proctypeoption<>potype_exceptfilter then
  1044. InternalError(201201141);
  1045. { flush code generated this far }
  1046. aktproccode.concatlist(current_asmdata.CurrAsmList);
  1047. { save the codegen }
  1048. saved_cg:=cg;
  1049. saved_hlcg:=hlcg;
  1050. cg:=nil;
  1051. hlcg:=nil;
  1052. {$ifdef cpu64bitalu}
  1053. saved_cg128:=cg128;
  1054. cg128:=nil;
  1055. {$else cpu64bitalu}
  1056. saved_cg64:=cg64;
  1057. cg64:=nil;
  1058. {$endif cpu64bitalu}
  1059. nestedpi.generate_code;
  1060. { prevents generating code the second time when processing nested procedures }
  1061. nestedpi.resetprocdef;
  1062. cg:=saved_cg;
  1063. hlcg:=saved_hlcg;
  1064. {$ifdef cpu64bitalu}
  1065. cg128:=saved_cg128;
  1066. {$else cpu64bitalu}
  1067. cg64:=saved_cg64;
  1068. {$endif cpu64bitalu}
  1069. add_reg_instruction_hook:[email protected]_reg_instruction;
  1070. end;
  1071. procedure TCGProcinfo.CreateInlineInfo;
  1072. begin
  1073. new(procdef.inlininginfo);
  1074. procdef.inlininginfo^.code:=code.getcopy;
  1075. procdef.inlininginfo^.flags:=flags;
  1076. { The blocknode needs to set an exit label }
  1077. if procdef.inlininginfo^.code.nodetype=blockn then
  1078. include(procdef.inlininginfo^.code.flags,nf_block_with_exit);
  1079. procdef.has_inlininginfo:=true;
  1080. end;
  1081. function searchusercode(var n: tnode; arg: pointer): foreachnoderesult;
  1082. begin
  1083. if nf_usercode_entry in n.flags then
  1084. begin
  1085. pnode(arg)^:=n;
  1086. result:=fen_norecurse_true
  1087. end
  1088. else
  1089. result:=fen_false;
  1090. end;
  1091. function TCGProcinfo.GetUserCode : tnode;
  1092. var
  1093. n : tnode;
  1094. begin
  1095. n:=nil;
  1096. foreachnodestatic(code,@searchusercode,@n);
  1097. if not(assigned(n)) then
  1098. internalerror(2013111004);
  1099. result:=n;
  1100. end;
  1101. procedure tcgprocinfo.generate_code;
  1102. var
  1103. old_current_procinfo : tprocinfo;
  1104. oldmaxfpuregisters : longint;
  1105. oldfilepos : tfileposinfo;
  1106. old_current_structdef : tabstractrecorddef;
  1107. templist : TAsmList;
  1108. headertai : tai;
  1109. i : integer;
  1110. varsym : tabstractnormalvarsym;
  1111. {RedoDFA : boolean;}
  1112. procedure delete_marker(anode: tasmnode);
  1113. var
  1114. ai: tai;
  1115. begin
  1116. if assigned(anode) then
  1117. begin
  1118. ai:=anode.currenttai;
  1119. if assigned(ai) then
  1120. begin
  1121. aktproccode.remove(ai);
  1122. ai.free;
  1123. anode.currenttai:=nil;
  1124. end;
  1125. end;
  1126. end;
  1127. begin
  1128. { the initialization procedure can be empty, then we
  1129. don't need to generate anything. When it was an empty
  1130. procedure there would be at least a blocknode }
  1131. if not assigned(code) then
  1132. exit;
  1133. { We need valid code }
  1134. if Errorcount<>0 then
  1135. exit;
  1136. { No code can be generated for generic template }
  1137. if (df_generic in procdef.defoptions) then
  1138. internalerror(200511152);
  1139. { For regular procedures the RA and Tempgen shall not be available yet,
  1140. but exception filters reuse Tempgen of parent }
  1141. if assigned(tg)<>(procdef.proctypeoption=potype_exceptfilter) then
  1142. internalerror(200309201);
  1143. old_current_procinfo:=current_procinfo;
  1144. oldfilepos:=current_filepos;
  1145. old_current_structdef:=current_structdef;
  1146. oldmaxfpuregisters:=current_settings.maxfpuregisters;
  1147. current_procinfo:=self;
  1148. current_filepos:=entrypos;
  1149. current_structdef:=procdef.struct;
  1150. { store start of user code, it must be a block node, it will be used later one to
  1151. check variable lifeness }
  1152. include(code.flags,nf_usercode_entry);
  1153. { add wrapping code if necessary (initialization of typed constants on
  1154. some platforms, initing of local variables and out parameters with
  1155. trashing values, ...) }
  1156. { init/final code must be wrapped later (after code for main proc body
  1157. has been generated) }
  1158. if not(current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  1159. code:=cnodeutils.wrap_proc_body(procdef,code);
  1160. { automatic inlining? }
  1161. if (cs_opt_autoinline in current_settings.optimizerswitches) and
  1162. { inlining not turned off? }
  1163. (cs_do_inline in current_settings.localswitches) and
  1164. { no inlining yet? }
  1165. not(procdef.has_inlininginfo) and not(has_nestedprocs) and
  1166. not(procdef.proctypeoption in [potype_proginit,potype_unitinit,potype_unitfinalize,potype_constructor,
  1167. potype_destructor,potype_class_constructor,potype_class_destructor]) and
  1168. ((procdef.procoptions*[po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck])=[]) and
  1169. (not(procdef.proccalloption in [pocall_safecall])) and
  1170. { rough approximation if we should auto inline }
  1171. (node_count(code)<=10) then
  1172. begin
  1173. { Can we inline this procedure? }
  1174. if checknodeinlining(procdef) then
  1175. begin
  1176. Message1(cg_d_autoinlining,procdef.GetTypeName);
  1177. include(procdef.procoptions,po_inline);
  1178. CreateInlineInfo;
  1179. end;
  1180. end;
  1181. templist:=TAsmList.create;
  1182. { add parast/localst to symtablestack }
  1183. add_to_symtablestack;
  1184. { clear register count }
  1185. procdef.localst.SymList.ForEachCall(@clearrefs,nil);
  1186. procdef.parast.SymList.ForEachCall(@clearrefs,nil);
  1187. { there's always a call to FPC_INITIALIZEUNITS/FPC_DO_EXIT in the main program }
  1188. if (procdef.localst.symtablelevel=main_program_level) and
  1189. (not current_module.is_unit) then
  1190. include(flags,pi_do_call);
  1191. { set implicit_finally flag when there are locals/paras to be finalized }
  1192. procdef.parast.SymList.ForEachCall(@check_finalize_paras,nil);
  1193. procdef.localst.SymList.ForEachCall(@check_finalize_locals,nil);
  1194. {$ifdef SUPPORT_SAFECALL}
  1195. { set implicit_finally flag for if procedure is safecall }
  1196. if (tf_safecall_exceptions in target_info.flags) and
  1197. (procdef.proccalloption=pocall_safecall) then
  1198. include(flags, pi_needs_implicit_finally);
  1199. {$endif}
  1200. { firstpass everything }
  1201. flowcontrol:=[];
  1202. do_firstpass(code);
  1203. {$if defined(i386) or defined(i8086)}
  1204. if node_resources_fpu(code)>0 then
  1205. include(flags,pi_uses_fpu);
  1206. {$endif i386 or i8086}
  1207. { Print the node to tree.log }
  1208. if paraprintnodetree=1 then
  1209. printproc( 'after the firstpass');
  1210. { do this before adding the entry code else the tail recursion recognition won't work,
  1211. if this causes troubles, it must be if'ed
  1212. }
  1213. if (cs_opt_tailrecursion in current_settings.optimizerswitches) and
  1214. (pi_is_recursive in flags) then
  1215. do_opttail(code,procdef);
  1216. if cs_opt_constant_propagate in current_settings.optimizerswitches then
  1217. do_optconstpropagate(code);
  1218. if (cs_opt_nodedfa in current_settings.optimizerswitches) and
  1219. { creating dfa is not always possible }
  1220. ((flags*[pi_has_assembler_block,pi_uses_exceptions,pi_is_assembler])=[]) then
  1221. begin
  1222. dfabuilder:=TDFABuilder.Create;
  1223. dfabuilder.createdfainfo(code);
  1224. include(flags,pi_dfaavailable);
  1225. { when life info is available, we can give more sophisticated warning about uninitialized
  1226. variables ...
  1227. ... but not for the finalization section of a unit, we would need global dfa to handle
  1228. it properly }
  1229. if potype_unitfinalize<>procdef.proctypeoption then
  1230. { iterate through life info of the first node }
  1231. for i:=0 to dfabuilder.nodemap.count-1 do
  1232. begin
  1233. if DFASetIn(GetUserCode.optinfo^.life,i) then
  1234. begin
  1235. { do not warn for certain parameters: }
  1236. if not((tnode(dfabuilder.nodemap[i]).nodetype=loadn) and (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ=paravarsym) and
  1237. { do not warn about parameters passed by var }
  1238. (((tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varspez=vs_var) and
  1239. { function result is passed by var but it must be initialized }
  1240. not(vo_is_funcret in tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions)) or
  1241. { do not warn about initialized hidden parameters }
  1242. ((tparavarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).varoptions*[vo_is_high_para,vo_is_parentfp,vo_is_result,vo_is_self])<>[]))) then
  1243. CheckAndWarn(GetUserCode,tnode(dfabuilder.nodemap[i]));
  1244. end
  1245. else
  1246. begin
  1247. if (tnode(dfabuilder.nodemap[i]).nodetype=loadn) and
  1248. (tloadnode(dfabuilder.nodemap[i]).symtableentry.typ in [staticvarsym,localvarsym]) then
  1249. tabstractnormalvarsym(tloadnode(dfabuilder.nodemap[i]).symtableentry).noregvarinitneeded:=true
  1250. end;
  1251. end;
  1252. end;
  1253. if (pi_dfaavailable in flags) and (cs_opt_dead_store_eliminate in current_settings.optimizerswitches) then
  1254. do_optdeadstoreelim(code);
  1255. if (cs_opt_loopstrength in current_settings.optimizerswitches)
  1256. { our induction variable strength reduction doesn't like
  1257. for loops with more than one entry }
  1258. and not(pi_has_label in flags) then
  1259. begin
  1260. {RedoDFA:=}OptimizeInductionVariables(code);
  1261. end;
  1262. if (cs_opt_remove_emtpy_proc in current_settings.optimizerswitches) and
  1263. (procdef.proctypeoption in [potype_operator,potype_procedure,potype_function]) and
  1264. (code.nodetype=blockn) and (tblocknode(code).statements=nil) then
  1265. procdef.isempty:=true;
  1266. { add implicit entry and exit code }
  1267. add_entry_exit_code;
  1268. if cs_opt_nodecse in current_settings.optimizerswitches then
  1269. do_optcse(code);
  1270. { only do secondpass if there are no errors }
  1271. if (ErrorCount=0) then
  1272. begin
  1273. create_hlcodegen;
  1274. if (procdef.proctypeoption<>potype_exceptfilter) then
  1275. setup_tempgen;
  1276. { Create register allocator, must come after framepointer is known }
  1277. hlcg.init_register_allocators;
  1278. generate_parameter_info;
  1279. { allocate got register if needed }
  1280. allocate_got_register(aktproccode);
  1281. { Allocate space in temp/registers for parast and localst }
  1282. current_filepos:=entrypos;
  1283. gen_alloc_symtable(aktproccode,procdef,procdef.parast);
  1284. gen_alloc_symtable(aktproccode,procdef,procdef.localst);
  1285. { Store temp offset for information about 'real' temps }
  1286. tempstart:=tg.lasttemp;
  1287. { Generate code to load register parameters in temps and insert local
  1288. copies for values parameters. This must be done before the code for the
  1289. body is generated because the localloc is updated.
  1290. Note: The generated code will be inserted after the code generation of
  1291. the body is finished, because only then the position is known }
  1292. {$ifdef oldregvars}
  1293. assign_regvars(code);
  1294. {$endif oldreg}
  1295. current_filepos:=entrypos;
  1296. hlcg.gen_load_para_value(templist);
  1297. { caller paraloc info is also necessary in the stackframe_entry
  1298. code of the ppc (and possibly other processors) }
  1299. procdef.init_paraloc_info(callerside);
  1300. { generate code for the node tree }
  1301. do_secondpass(code);
  1302. aktproccode.concatlist(current_asmdata.CurrAsmList);
  1303. { The position of the loadpara_asmnode is now known }
  1304. aktproccode.insertlistafter(loadpara_asmnode.currenttai,templist);
  1305. { first generate entry and initialize code with the correct
  1306. position and switches }
  1307. current_filepos:=entrypos;
  1308. current_settings.localswitches:=entryswitches;
  1309. cg.set_regalloc_live_range_direction(rad_backwards);
  1310. hlcg.gen_entry_code(templist);
  1311. aktproccode.insertlistafter(entry_asmnode.currenttai,templist);
  1312. hlcg.gen_initialize_code(templist);
  1313. aktproccode.insertlistafter(init_asmnode.currenttai,templist);
  1314. { now generate finalize and exit code with the correct position
  1315. and switches }
  1316. current_filepos:=exitpos;
  1317. current_settings.localswitches:=exitswitches;
  1318. cg.set_regalloc_live_range_direction(rad_forward);
  1319. if assigned(finalize_procinfo) then
  1320. generate_exceptfilter(tcgprocinfo(finalize_procinfo))
  1321. else
  1322. begin
  1323. hlcg.gen_finalize_code(templist);
  1324. { the finalcode must be concated if there was no position available,
  1325. using insertlistafter will result in an insert at the start
  1326. when currentai=nil }
  1327. if assigned(final_asmnode) and assigned(final_asmnode.currenttai) then
  1328. aktproccode.insertlistafter(final_asmnode.currenttai,templist)
  1329. else
  1330. aktproccode.concatlist(templist);
  1331. end;
  1332. { insert exit label at the correct position }
  1333. hlcg.a_label(templist,CurrExitLabel);
  1334. if assigned(exitlabel_asmnode.currenttai) then
  1335. aktproccode.insertlistafter(exitlabel_asmnode.currenttai,templist)
  1336. else
  1337. aktproccode.concatlist(templist);
  1338. { exit code }
  1339. hlcg.gen_exit_code(templist);
  1340. aktproccode.concatlist(templist);
  1341. {$ifdef OLDREGVARS}
  1342. { note: this must be done only after as much code as possible has }
  1343. { been generated. The result is that when you ungetregister() a }
  1344. { regvar, it will actually free the regvar (and alse free the }
  1345. { the regvars at the same time). Doing this too early will }
  1346. { confuse the register allocator, as the regvars will still be }
  1347. { used. It should be done before loading the result regs (so }
  1348. { they don't conflict with the regvars) and before }
  1349. { gen_entry_code (that one has to be able to allocate the }
  1350. { regvars again) (JM) }
  1351. free_regvars(aktproccode);
  1352. {$endif OLDREGVARS}
  1353. { generate symbol and save end of header position }
  1354. current_filepos:=entrypos;
  1355. hlcg.gen_proc_symbol(templist);
  1356. headertai:=tai(templist.last);
  1357. { insert symbol }
  1358. aktproccode.insertlist(templist);
  1359. { Free space in temp/registers for parast and localst, must be
  1360. done after gen_entry_code }
  1361. current_filepos:=exitpos;
  1362. { make sure the got/pic register doesn't get freed in the }
  1363. { middle of a loop }
  1364. if (cs_create_pic in current_settings.moduleswitches) and
  1365. (pi_needs_got in flags) and
  1366. (got<>NR_NO) then
  1367. cg.a_reg_sync(aktproccode,got);
  1368. gen_free_symtable(aktproccode,procdef.localst);
  1369. gen_free_symtable(aktproccode,procdef.parast);
  1370. { add code that will load the return value, this is not done
  1371. for assembler routines when they didn't reference the result
  1372. variable }
  1373. hlcg.gen_load_return_value(templist);
  1374. aktproccode.concatlist(templist);
  1375. { Already reserve all registers for stack checking code and
  1376. generate the call to the helper function }
  1377. if not(tf_no_generic_stackcheck in target_info.flags) and
  1378. (cs_check_stack in entryswitches) and
  1379. not(po_assembler in procdef.procoptions) and
  1380. (procdef.proctypeoption<>potype_proginit) then
  1381. begin
  1382. current_filepos:=entrypos;
  1383. gen_stack_check_call(templist);
  1384. aktproccode.insertlistafter(stackcheck_asmnode.currenttai,templist)
  1385. end;
  1386. { this code (got loading) comes before everything which has }
  1387. { already been generated, so reset the info about already }
  1388. { backwards extended registers (so their live range can be }
  1389. { extended backwards even further if needed) }
  1390. { This code must be }
  1391. { a) generated after do_secondpass has been called }
  1392. { (because pi_needs_got may be set there) }
  1393. { b) generated before register allocation, because the }
  1394. { got/pic register can be a virtual one }
  1395. { c) inserted before the entry code, because the entry }
  1396. { code may need global symbols such as init rtti }
  1397. { d) inserted after the stackframe allocation, because }
  1398. { this register may have to be spilled }
  1399. cg.set_regalloc_live_range_direction(rad_backwards_reinit);
  1400. current_filepos:=entrypos;
  1401. { load got if necessary }
  1402. cg.g_maybe_got_init(templist);
  1403. aktproccode.insertlistafter(headertai,templist);
  1404. { re-enable if more code at the end is ever generated here
  1405. cg.set_regalloc_live_range_direction(rad_forward);
  1406. }
  1407. {$ifndef NoOpt}
  1408. {$ifndef i386}
  1409. if (cs_opt_scheduler in current_settings.optimizerswitches) and
  1410. { do not optimize pure assembler procedures }
  1411. not(pi_is_assembler in flags) then
  1412. preregallocschedule(aktproccode);
  1413. {$endif i386}
  1414. {$endif NoOpt}
  1415. { The procedure body is finished, we can now
  1416. allocate the registers }
  1417. cg.do_register_allocation(aktproccode,headertai);
  1418. { translate imag. register to their real counter parts
  1419. this is necessary for debuginfo and verbose assembler output
  1420. when SSA will be implented, this will be more complicated because we've to
  1421. maintain location lists }
  1422. procdef.parast.SymList.ForEachCall(@translate_registers,templist);
  1423. procdef.localst.SymList.ForEachCall(@translate_registers,templist);
  1424. if (cs_create_pic in current_settings.moduleswitches) and
  1425. (pi_needs_got in flags) and
  1426. not(cs_no_regalloc in current_settings.globalswitches) and
  1427. (got<>NR_NO) then
  1428. cg.translate_register(got);
  1429. { Add save and restore of used registers }
  1430. current_filepos:=entrypos;
  1431. gen_save_used_regs(templist);
  1432. { Remember the last instruction of register saving block
  1433. (may be =nil for e.g. assembler procedures) }
  1434. endprologue_ai:=templist.last;
  1435. aktproccode.insertlistafter(headertai,templist);
  1436. current_filepos:=exitpos;
  1437. gen_restore_used_regs(aktproccode);
  1438. { We know the size of the stack, now we can generate the
  1439. parameter that is passed to the stack checking code }
  1440. if not(tf_no_generic_stackcheck in target_info.flags) and
  1441. (cs_check_stack in entryswitches) and
  1442. not(po_assembler in procdef.procoptions) and
  1443. (procdef.proctypeoption<>potype_proginit) then
  1444. begin
  1445. current_filepos:=entrypos;
  1446. gen_stack_check_size_para(templist);
  1447. aktproccode.insertlistafter(stackcheck_asmnode.currenttai,templist)
  1448. end;
  1449. { Add entry code (stack allocation) after header }
  1450. current_filepos:=entrypos;
  1451. gen_proc_entry_code(templist);
  1452. aktproccode.insertlistafter(headertai,templist);
  1453. {$ifdef SUPPORT_SAFECALL}
  1454. { Set return value of safecall procedure if implicit try/finally blocks are disabled }
  1455. if not (cs_implicit_exceptions in current_settings.moduleswitches) and
  1456. (tf_safecall_exceptions in target_info.flags) and
  1457. (procdef.proccalloption=pocall_safecall) then
  1458. cg.a_load_const_reg(aktproccode,OS_ADDR,0,NR_FUNCTION_RETURN_REG);
  1459. {$endif}
  1460. { Add exit code at the end }
  1461. current_filepos:=exitpos;
  1462. gen_proc_exit_code(templist);
  1463. aktproccode.concatlist(templist);
  1464. { check if the implicit finally has been generated. The flag
  1465. should already be set in pass1 }
  1466. if (cs_implicit_exceptions in current_settings.moduleswitches) and
  1467. not(procdef.proctypeoption in [potype_unitfinalize,potype_unitinit]) and
  1468. (pi_needs_implicit_finally in flags) and
  1469. not(po_assembler in procdef.procoptions) and
  1470. not(pi_has_implicit_finally in flags) and
  1471. not(target_info.system in systems_garbage_collected_managed_types) then
  1472. internalerror(200405231);
  1473. { Position markers are only used to insert additional code after the secondpass
  1474. and before this point. They are of no use in optimizer. Instead of checking and
  1475. ignoring all over the optimizer, just remove them here. }
  1476. delete_marker(entry_asmnode);
  1477. delete_marker(loadpara_asmnode);
  1478. delete_marker(exitlabel_asmnode);
  1479. delete_marker(stackcheck_asmnode);
  1480. delete_marker(init_asmnode);
  1481. delete_marker(final_asmnode);
  1482. {$ifndef NoOpt}
  1483. if not(cs_no_regalloc in current_settings.globalswitches) then
  1484. begin
  1485. if (cs_opt_level1 in current_settings.optimizerswitches) and
  1486. { do not optimize pure assembler procedures }
  1487. not(pi_is_assembler in flags) then
  1488. optimize(aktproccode);
  1489. {$ifndef i386}
  1490. { schedule after assembler optimization, it could have brought up
  1491. new schedule possibilities }
  1492. if (cs_opt_scheduler in current_settings.optimizerswitches) and
  1493. { do not optimize pure assembler procedures }
  1494. not(pi_is_assembler in flags) then
  1495. preregallocschedule(aktproccode);
  1496. {$endif i386}
  1497. end;
  1498. {$endif NoOpt}
  1499. { Perform target-specific processing if necessary }
  1500. postprocess_code;
  1501. { Add end symbol and debug info }
  1502. { this must be done after the pcrelativedata is appended else the distance calculation of
  1503. insertpcrelativedata will be wrong, further the pc indirect data is part of the procedure
  1504. so it should be inserted before the end symbol (FK)
  1505. }
  1506. current_filepos:=exitpos;
  1507. hlcg.gen_proc_symbol_end(templist);
  1508. aktproccode.concatlist(templist);
  1509. { insert line debuginfo }
  1510. if (cs_debuginfo in current_settings.moduleswitches) or
  1511. (cs_use_lineinfo in current_settings.globalswitches) then
  1512. current_debuginfo.insertlineinfo(aktproccode);
  1513. hlcg.record_generated_code_for_procdef(current_procinfo.procdef,aktproccode,aktlocaldata);
  1514. { only now we can remove the temps }
  1515. if (procdef.proctypeoption<>potype_exceptfilter) then
  1516. begin
  1517. tg.resettempgen;
  1518. tg.free;
  1519. tg:=nil;
  1520. end;
  1521. { stop tempgen and ra }
  1522. hlcg.done_register_allocators;
  1523. destroy_hlcodegen;
  1524. end;
  1525. dfabuilder.free;
  1526. { restore symtablestack }
  1527. remove_from_symtablestack;
  1528. { restore }
  1529. templist.free;
  1530. current_settings.maxfpuregisters:=oldmaxfpuregisters;
  1531. current_filepos:=oldfilepos;
  1532. current_structdef:=old_current_structdef;
  1533. current_procinfo:=old_current_procinfo;
  1534. end;
  1535. procedure tcgprocinfo.add_to_symtablestack;
  1536. begin
  1537. { insert symtables for the class, but only if it is no nested function }
  1538. if assigned(procdef.struct) and
  1539. not(assigned(parent) and
  1540. assigned(parent.procdef) and
  1541. assigned(parent.procdef.struct)) then
  1542. push_nested_hierarchy(procdef.struct);
  1543. { insert parasymtable in symtablestack when parsing
  1544. a function }
  1545. if procdef.parast.symtablelevel>=normal_function_level then
  1546. symtablestack.push(procdef.parast);
  1547. { insert localsymtable, except for the main procedure
  1548. (in that case the localst is the unit's static symtable,
  1549. which is already on the stack) }
  1550. if procdef.localst.symtablelevel>=normal_function_level then
  1551. symtablestack.push(procdef.localst);
  1552. end;
  1553. procedure tcgprocinfo.remove_from_symtablestack;
  1554. begin
  1555. { remove localsymtable }
  1556. if procdef.localst.symtablelevel>=normal_function_level then
  1557. symtablestack.pop(procdef.localst);
  1558. { remove parasymtable }
  1559. if procdef.parast.symtablelevel>=normal_function_level then
  1560. symtablestack.pop(procdef.parast);
  1561. { remove symtables for the class, but only if it is no nested function }
  1562. if assigned(procdef.struct) and
  1563. not(assigned(parent) and
  1564. assigned(parent.procdef) and
  1565. assigned(parent.procdef.struct)) then
  1566. pop_nested_hierarchy(procdef.struct);
  1567. end;
  1568. procedure tcgprocinfo.resetprocdef;
  1569. begin
  1570. { remove code tree, if not inline procedure }
  1571. if assigned(code) then
  1572. begin
  1573. { the inline procedure has already got a copy of the tree
  1574. stored in procdef.inlininginfo }
  1575. code.free;
  1576. code:=nil;
  1577. end;
  1578. end;
  1579. procedure tcgprocinfo.parse_body;
  1580. var
  1581. old_current_procinfo : tprocinfo;
  1582. old_block_type : tblock_type;
  1583. st : TSymtable;
  1584. old_current_structdef: tabstractrecorddef;
  1585. old_current_genericdef,
  1586. old_current_specializedef: tstoreddef;
  1587. old_parse_generic: boolean;
  1588. begin
  1589. old_current_procinfo:=current_procinfo;
  1590. old_block_type:=block_type;
  1591. old_current_structdef:=current_structdef;
  1592. old_current_genericdef:=current_genericdef;
  1593. old_current_specializedef:=current_specializedef;
  1594. old_parse_generic:=parse_generic;
  1595. current_procinfo:=self;
  1596. current_structdef:=procdef.struct;
  1597. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  1598. begin
  1599. current_genericdef:=current_structdef;
  1600. parse_generic:=true;
  1601. end;
  1602. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  1603. current_specializedef:=current_structdef;
  1604. { calculate the lexical level }
  1605. if procdef.parast.symtablelevel>maxnesting then
  1606. Message(parser_e_too_much_lexlevel);
  1607. block_type:=bt_body;
  1608. {$ifdef state_tracking}
  1609. { aktstate:=Tstate_storage.create;}
  1610. {$endif state_tracking}
  1611. { allocate the symbol for this procedure }
  1612. alloc_proc_symbol(procdef);
  1613. { add parast/localst to symtablestack }
  1614. add_to_symtablestack;
  1615. { save entry info }
  1616. entrypos:=current_filepos;
  1617. entryswitches:=current_settings.localswitches;
  1618. if (df_generic in procdef.defoptions) then
  1619. begin
  1620. { start token recorder for generic template }
  1621. procdef.initgeneric;
  1622. current_scanner.startrecordtokens(procdef.generictokenbuf);
  1623. end;
  1624. { parse the code ... }
  1625. code:=block(current_module.islibrary);
  1626. if (df_generic in procdef.defoptions) then
  1627. begin
  1628. { stop token recorder for generic template }
  1629. current_scanner.stoprecordtokens;
  1630. { Give an error for accesses in the static symtable that aren't visible
  1631. outside the current unit }
  1632. st:=procdef.owner;
  1633. while (st.symtabletype in [ObjectSymtable,recordsymtable]) do
  1634. st:=st.defowner.owner;
  1635. if (pi_uses_static_symtable in flags) and
  1636. (st.symtabletype<>staticsymtable) then
  1637. Message(parser_e_global_generic_references_static);
  1638. end;
  1639. { save exit info }
  1640. exitswitches:=current_settings.localswitches;
  1641. exitpos:=last_endtoken_filepos;
  1642. { the procedure is now defined }
  1643. procdef.forwarddef:=false;
  1644. if assigned(code) then
  1645. begin
  1646. { get a better entry point }
  1647. entrypos:=code.fileinfo;
  1648. { Finish type checking pass }
  1649. do_typecheckpass(code);
  1650. if assigned(procdef.parentfpinitblock) then
  1651. begin
  1652. tblocknode(code).left:=cstatementnode.create(procdef.parentfpinitblock,tblocknode(code).left);
  1653. do_typecheckpass(tblocknode(code).left);
  1654. procdef.parentfpinitblock:=nil;
  1655. end;
  1656. end;
  1657. { Check for unused labels, forwards, symbols for procedures. Static
  1658. symtable is checked in pmodules.
  1659. The check must be done after the typecheckpass }
  1660. if (Errorcount=0) and
  1661. (tstoredsymtable(procdef.localst).symtabletype<>staticsymtable) then
  1662. begin
  1663. { check if forwards are resolved }
  1664. tstoredsymtable(procdef.localst).check_forwards;
  1665. { check if all labels are used }
  1666. tstoredsymtable(procdef.localst).checklabels;
  1667. { check for unused symbols, but only if there is no asm block }
  1668. if not(pi_has_assembler_block in flags) then
  1669. begin
  1670. tstoredsymtable(procdef.localst).allsymbolsused;
  1671. tstoredsymtable(procdef.parast).allsymbolsused;
  1672. end;
  1673. end;
  1674. if (po_inline in procdef.procoptions) and
  1675. { Can we inline this procedure? }
  1676. checknodeinlining(procdef) then
  1677. CreateInlineInfo;
  1678. { Print the node to tree.log }
  1679. if paraprintnodetree=1 then
  1680. printproc( 'after parsing');
  1681. { ... remove symbol tables }
  1682. remove_from_symtablestack;
  1683. {$ifdef state_tracking}
  1684. { aktstate.destroy;}
  1685. {$endif state_tracking}
  1686. current_structdef:=old_current_structdef;
  1687. current_genericdef:=old_current_genericdef;
  1688. current_specializedef:=old_current_specializedef;
  1689. current_procinfo:=old_current_procinfo;
  1690. parse_generic:=old_parse_generic;
  1691. { Restore old state }
  1692. block_type:=old_block_type;
  1693. end;
  1694. {****************************************************************************
  1695. PROCEDURE/FUNCTION PARSING
  1696. ****************************************************************************}
  1697. procedure check_init_paras(p:TObject;arg:pointer);
  1698. begin
  1699. if tsym(p).typ<>paravarsym then
  1700. exit;
  1701. with tparavarsym(p) do
  1702. if (is_managed_type(vardef) and
  1703. (varspez in [vs_value,vs_out])) or
  1704. (is_shortstring(vardef) and
  1705. (varspez=vs_value)) then
  1706. include(current_procinfo.flags,pi_do_call);
  1707. end;
  1708. procedure read_proc_body(old_current_procinfo:tprocinfo;pd:tprocdef);
  1709. {
  1710. Parses the procedure directives, then parses the procedure body, then
  1711. generates the code for it
  1712. }
  1713. var
  1714. oldfailtokenmode : tmodeswitches;
  1715. isnestedproc : boolean;
  1716. begin
  1717. Message1(parser_d_procedure_start,pd.fullprocname(false));
  1718. oldfailtokenmode:=[];
  1719. { create a new procedure }
  1720. current_procinfo:=cprocinfo.create(old_current_procinfo);
  1721. current_module.procinfo:=current_procinfo;
  1722. current_procinfo.procdef:=pd;
  1723. isnestedproc:=(current_procinfo.procdef.parast.symtablelevel>normal_function_level);
  1724. { Insert mangledname }
  1725. pd.aliasnames.insert(pd.mangledname);
  1726. { Handle Export of this procedure }
  1727. if (po_exports in pd.procoptions) and
  1728. (target_info.system in [system_i386_os2,system_i386_emx]) then
  1729. begin
  1730. pd.aliasnames.insert(pd.procsym.realname);
  1731. if cs_link_deffile in current_settings.globalswitches then
  1732. deffile.AddExport(pd.mangledname);
  1733. end;
  1734. { Insert result variables in the localst }
  1735. insert_funcret_local(pd);
  1736. { check if there are para's which require initing -> set }
  1737. { pi_do_call (if not yet set) }
  1738. if not(pi_do_call in current_procinfo.flags) then
  1739. pd.parast.SymList.ForEachCall(@check_init_paras,nil);
  1740. { set _FAIL as keyword if constructor }
  1741. if (pd.proctypeoption=potype_constructor) then
  1742. begin
  1743. oldfailtokenmode:=tokeninfo^[_FAIL].keyword;
  1744. tokeninfo^[_FAIL].keyword:=alllanguagemodes;
  1745. end;
  1746. tcgprocinfo(current_procinfo).parse_body;
  1747. { We can't support inlining for procedures that have nested
  1748. procedures because the nested procedures use a fixed offset
  1749. for accessing locals in the parent procedure (PFV) }
  1750. if current_procinfo.has_nestedprocs then
  1751. begin
  1752. if (df_generic in current_procinfo.procdef.defoptions) then
  1753. Comment(V_Error,'Generic methods cannot have nested procedures')
  1754. else
  1755. if (po_inline in current_procinfo.procdef.procoptions) then
  1756. begin
  1757. Message1(parser_h_not_supported_for_inline,'nested procedures');
  1758. Message(parser_h_inlining_disabled);
  1759. exclude(current_procinfo.procdef.procoptions,po_inline);
  1760. end;
  1761. end;
  1762. { When it's a nested procedure then defer the code generation,
  1763. when back at normal function level then generate the code
  1764. for all defered nested procedures and the current procedure }
  1765. if not isnestedproc then
  1766. begin
  1767. if not(df_generic in current_procinfo.procdef.defoptions) then
  1768. tcgprocinfo(current_procinfo).generate_code_tree;
  1769. end;
  1770. { reset _FAIL as _SELF normal }
  1771. if (pd.proctypeoption=potype_constructor) then
  1772. tokeninfo^[_FAIL].keyword:=oldfailtokenmode;
  1773. { release procinfo }
  1774. if tprocinfo(current_module.procinfo)<>current_procinfo then
  1775. internalerror(200304274);
  1776. current_module.procinfo:=current_procinfo.parent;
  1777. { For specialization we didn't record the last semicolon. Moving this parsing
  1778. into the parse_body routine is not done because of having better file position
  1779. information available }
  1780. if not(df_specialization in current_procinfo.procdef.defoptions) then
  1781. consume(_SEMICOLON);
  1782. if not isnestedproc then
  1783. { current_procinfo is checked for nil later on }
  1784. freeandnil(current_procinfo);
  1785. end;
  1786. procedure read_proc(isclassmethod:boolean; usefwpd: tprocdef);
  1787. {
  1788. Parses the procedure directives, then parses the procedure body, then
  1789. generates the code for it
  1790. }
  1791. var
  1792. old_current_procinfo : tprocinfo;
  1793. old_current_structdef: tabstractrecorddef;
  1794. old_current_genericdef,
  1795. old_current_specializedef: tstoreddef;
  1796. pdflags : tpdflags;
  1797. pd,firstpd : tprocdef;
  1798. s : string;
  1799. begin
  1800. { save old state }
  1801. old_current_procinfo:=current_procinfo;
  1802. old_current_structdef:=current_structdef;
  1803. old_current_genericdef:=current_genericdef;
  1804. old_current_specializedef:=current_specializedef;
  1805. { reset current_procinfo.procdef to nil to be sure that nothing is writing
  1806. to another procdef }
  1807. current_procinfo:=nil;
  1808. current_structdef:=nil;
  1809. current_genericdef:=nil;
  1810. current_specializedef:=nil;
  1811. if not assigned(usefwpd) then
  1812. { parse procedure declaration }
  1813. pd:=parse_proc_dec(isclassmethod,old_current_structdef)
  1814. else
  1815. pd:=usefwpd;
  1816. { set the default function options }
  1817. if parse_only then
  1818. begin
  1819. pd.forwarddef:=true;
  1820. { set also the interface flag, for better error message when the
  1821. implementation doesn't much this header }
  1822. pd.interfacedef:=true;
  1823. include(pd.procoptions,po_global);
  1824. pdflags:=[pd_interface];
  1825. end
  1826. else
  1827. begin
  1828. pdflags:=[pd_body];
  1829. if (not current_module.in_interface) then
  1830. include(pdflags,pd_implemen);
  1831. if (not current_module.is_unit) or
  1832. create_smartlink then
  1833. include(pd.procoptions,po_global);
  1834. pd.forwarddef:=false;
  1835. end;
  1836. if not assigned(usefwpd) then
  1837. begin
  1838. { parse the directives that may follow }
  1839. parse_proc_directives(pd,pdflags);
  1840. { hint directives, these can be separated by semicolons here,
  1841. that needs to be handled here with a loop (PFV) }
  1842. while try_consume_hintdirective(pd.symoptions,pd.deprecatedmsg) do
  1843. Consume(_SEMICOLON);
  1844. { Set calling convention }
  1845. handle_calling_convention(pd);
  1846. end;
  1847. { search for forward declarations }
  1848. if not proc_add_definition(pd) then
  1849. begin
  1850. { A method must be forward defined (in the object declaration) }
  1851. if assigned(pd.struct) and
  1852. (not assigned(old_current_structdef)) then
  1853. begin
  1854. MessagePos1(pd.fileinfo,parser_e_header_dont_match_any_member,pd.fullprocname(false));
  1855. tprocsym(pd.procsym).write_parameter_lists(pd);
  1856. end
  1857. else
  1858. begin
  1859. { Give a better error if there is a forward def in the interface and only
  1860. a single implementation }
  1861. firstpd:=tprocdef(tprocsym(pd.procsym).ProcdefList[0]);
  1862. if (not pd.forwarddef) and
  1863. (not pd.interfacedef) and
  1864. (tprocsym(pd.procsym).ProcdefList.Count>1) and
  1865. firstpd.forwarddef and
  1866. firstpd.interfacedef and
  1867. not(tprocsym(pd.procsym).ProcdefList.Count>2) and
  1868. { don't give an error if it may be an overload }
  1869. not(m_fpc in current_settings.modeswitches) and
  1870. (not(po_overload in pd.procoptions) or
  1871. not(po_overload in firstpd.procoptions)) then
  1872. begin
  1873. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,pd.fullprocname(false));
  1874. tprocsym(pd.procsym).write_parameter_lists(pd);
  1875. end;
  1876. end;
  1877. end;
  1878. { Set mangled name }
  1879. proc_set_mangledname(pd);
  1880. { compile procedure when a body is needed }
  1881. if (pd_body in pdflags) then
  1882. begin
  1883. read_proc_body(old_current_procinfo,pd);
  1884. end
  1885. else
  1886. begin
  1887. { Handle imports }
  1888. if (po_external in pd.procoptions) then
  1889. begin
  1890. { Import DLL specified? }
  1891. if assigned(pd.import_dll) then
  1892. begin
  1893. if assigned (pd.import_name) then
  1894. current_module.AddExternalImport(pd.import_dll^,
  1895. pd.import_name^,proc_get_importname(pd),
  1896. pd.import_nr,false,false)
  1897. else
  1898. current_module.AddExternalImport(pd.import_dll^,
  1899. proc_get_importname(pd),proc_get_importname(pd),
  1900. pd.import_nr,false,true);
  1901. end
  1902. else
  1903. begin
  1904. { add import name to external list for DLL scanning }
  1905. if tf_has_dllscanner in target_info.flags then
  1906. current_module.dllscannerinputlist.Add(proc_get_importname(pd),pd);
  1907. end;
  1908. { External declared in implementation, and there was already a
  1909. forward (or interface) declaration then we need to generate
  1910. a stub that calls the external routine }
  1911. if (not pd.forwarddef) and
  1912. (pd.hasforward)
  1913. { it is unclear to me what's the use of the following condition,
  1914. so commented out, see also issue #18371 (FK)
  1915. and
  1916. not(
  1917. assigned(pd.import_dll) and
  1918. (target_info.system in [system_i386_wdosx,
  1919. system_arm_wince,system_i386_wince])
  1920. ) } then
  1921. begin
  1922. s:=proc_get_importname(pd);
  1923. if s<>'' then
  1924. gen_external_stub(current_asmdata.asmlists[al_procedures],pd,s);
  1925. { remove the external stuff, so that the interface crc
  1926. doesn't change. This makes the function calls less
  1927. efficient, but it means that the interface doesn't
  1928. change if the function is ever redirected to another
  1929. function or implemented in the unit. }
  1930. pd.procoptions:=pd.procoptions-[po_external,po_has_importname,po_has_importdll];
  1931. stringdispose(pd.import_name);
  1932. stringdispose(pd.import_dll);
  1933. pd.import_nr:=0;
  1934. end;
  1935. end;
  1936. end;
  1937. { make sure that references to forward-declared functions are not }
  1938. { treated as references to external symbols, needed for darwin. }
  1939. { make sure we don't change the binding of real external symbols }
  1940. if not(po_external in pd.procoptions) then
  1941. begin
  1942. if (po_global in pd.procoptions) or
  1943. (cs_profile in current_settings.moduleswitches) then
  1944. current_asmdata.DefineAsmSymbol(pd.mangledname,AB_GLOBAL,AT_FUNCTION)
  1945. else
  1946. current_asmdata.DefineAsmSymbol(pd.mangledname,AB_LOCAL,AT_FUNCTION);
  1947. end;
  1948. current_structdef:=old_current_structdef;
  1949. current_genericdef:=old_current_genericdef;
  1950. current_specializedef:=old_current_specializedef;
  1951. current_procinfo:=old_current_procinfo;
  1952. end;
  1953. {****************************************************************************
  1954. DECLARATION PARSING
  1955. ****************************************************************************}
  1956. { search in symtablestack for not complete classes }
  1957. procedure check_forward_class(p:TObject;arg:pointer);
  1958. begin
  1959. if (tsym(p).typ=typesym) and
  1960. (ttypesym(p).typedef.typ=objectdef) and
  1961. (oo_is_forward in tobjectdef(ttypesym(p).typedef).objectoptions) then
  1962. MessagePos1(tsym(p).fileinfo,sym_e_forward_type_not_resolved,tsym(p).realname);
  1963. end;
  1964. procedure read_declarations(islibrary : boolean);
  1965. var
  1966. is_classdef:boolean;
  1967. begin
  1968. is_classdef:=false;
  1969. repeat
  1970. if not assigned(current_procinfo) then
  1971. internalerror(200304251);
  1972. case token of
  1973. _LABEL:
  1974. label_dec;
  1975. _CONST:
  1976. const_dec;
  1977. _TYPE:
  1978. type_dec;
  1979. _VAR:
  1980. var_dec;
  1981. _THREADVAR:
  1982. threadvar_dec;
  1983. _CLASS:
  1984. begin
  1985. is_classdef:=false;
  1986. if try_to_consume(_CLASS) then
  1987. begin
  1988. { class modifier is only allowed for procedures, functions, }
  1989. { constructors, destructors }
  1990. if not(token in [_FUNCTION,_PROCEDURE,_CONSTRUCTOR,_DESTRUCTOR,_OPERATOR]) and
  1991. not((token=_ID) and (idtoken=_OPERATOR)) then
  1992. Message(parser_e_procedure_or_function_expected);
  1993. if is_interface(current_structdef) then
  1994. Message(parser_e_no_static_method_in_interfaces)
  1995. else
  1996. { class methods are also allowed for Objective-C protocols }
  1997. is_classdef:=true;
  1998. end;
  1999. end;
  2000. _CONSTRUCTOR,
  2001. _DESTRUCTOR,
  2002. _FUNCTION,
  2003. _PROCEDURE,
  2004. _OPERATOR:
  2005. begin
  2006. read_proc(is_classdef,nil);
  2007. is_classdef:=false;
  2008. end;
  2009. _EXPORTS:
  2010. begin
  2011. if (current_procinfo.procdef.localst.symtablelevel>main_program_level) then
  2012. begin
  2013. Message(parser_e_syntax_error);
  2014. consume_all_until(_SEMICOLON);
  2015. end
  2016. else if islibrary or
  2017. (target_info.system in systems_unit_program_exports) then
  2018. read_exports
  2019. else
  2020. begin
  2021. Message(parser_w_unsupported_feature);
  2022. consume(_BEGIN);
  2023. end;
  2024. end;
  2025. _PROPERTY:
  2026. begin
  2027. if (m_fpc in current_settings.modeswitches) then
  2028. property_dec
  2029. else
  2030. break;
  2031. end;
  2032. else
  2033. begin
  2034. case idtoken of
  2035. _RESOURCESTRING:
  2036. begin
  2037. { m_class is needed, because the resourcestring
  2038. loading is in the ObjPas unit }
  2039. { if (m_class in current_settings.modeswitches) then}
  2040. resourcestring_dec
  2041. { else
  2042. break;}
  2043. end;
  2044. _OPERATOR:
  2045. begin
  2046. if is_classdef then
  2047. begin
  2048. read_proc(is_classdef,nil);
  2049. is_classdef:=false;
  2050. end
  2051. else
  2052. break;
  2053. end;
  2054. else
  2055. break;
  2056. end;
  2057. end;
  2058. end;
  2059. until false;
  2060. { add implementations for synthetic method declarations added by
  2061. the compiler (not for unit/program init functions, their localst
  2062. is the staticst -> would duplicate the work done in pmodules) }
  2063. if current_procinfo.procdef.localst.symtabletype=localsymtable then
  2064. add_synthetic_method_implementations(current_procinfo.procdef.localst);
  2065. { check for incomplete class definitions, this is only required
  2066. for fpc modes }
  2067. if (m_fpc in current_settings.modeswitches) then
  2068. current_procinfo.procdef.localst.SymList.ForEachCall(@check_forward_class,nil);
  2069. end;
  2070. procedure read_interface_declarations;
  2071. begin
  2072. repeat
  2073. case token of
  2074. _CONST :
  2075. const_dec;
  2076. _TYPE :
  2077. type_dec;
  2078. _VAR :
  2079. var_dec;
  2080. _THREADVAR :
  2081. threadvar_dec;
  2082. _FUNCTION,
  2083. _PROCEDURE,
  2084. _OPERATOR :
  2085. read_proc(false,nil);
  2086. else
  2087. begin
  2088. case idtoken of
  2089. _RESOURCESTRING :
  2090. resourcestring_dec;
  2091. _PROPERTY:
  2092. begin
  2093. if (m_fpc in current_settings.modeswitches) then
  2094. property_dec
  2095. else
  2096. break;
  2097. end;
  2098. else
  2099. break;
  2100. end;
  2101. end;
  2102. end;
  2103. until false;
  2104. { check for incomplete class definitions, this is only required
  2105. for fpc modes }
  2106. if (m_fpc in current_settings.modeswitches) then
  2107. symtablestack.top.SymList.ForEachCall(@check_forward_class,nil);
  2108. end;
  2109. {****************************************************************************
  2110. SPECIALIZATION BODY GENERATION
  2111. ****************************************************************************}
  2112. procedure specialize_objectdefs(p:TObject;arg:pointer);
  2113. var
  2114. oldcurrent_filepos : tfileposinfo;
  2115. specobj : tabstractrecorddef;
  2116. state : tspecializationstate;
  2117. procedure process_abstractrecorddef(def:tabstractrecorddef);
  2118. var
  2119. i : longint;
  2120. hp : tdef;
  2121. hmodule : tmodule;
  2122. begin
  2123. hmodule:=find_module_from_symtable(def.genericdef.owner);
  2124. if hmodule=nil then
  2125. internalerror(201202041);
  2126. for i:=0 to def.symtable.DefList.Count-1 do
  2127. begin
  2128. hp:=tdef(def.symtable.DefList[i]);
  2129. if hp.typ=procdef then
  2130. begin
  2131. { only generate the code if we need a body }
  2132. if assigned(tprocdef(hp).struct) and not tprocdef(hp).forwarddef then
  2133. continue;
  2134. if assigned(tprocdef(hp).genericdef) and
  2135. (tprocdef(hp).genericdef.typ=procdef) and
  2136. assigned(tprocdef(tprocdef(hp).genericdef).generictokenbuf) then
  2137. begin
  2138. oldcurrent_filepos:=current_filepos;
  2139. current_filepos:=tprocdef(tprocdef(hp).genericdef).fileinfo;
  2140. { use the index the module got from the current compilation process }
  2141. current_filepos.moduleindex:=hmodule.unit_index;
  2142. current_tokenpos:=current_filepos;
  2143. current_scanner.startreplaytokens(tprocdef(tprocdef(hp).genericdef).generictokenbuf);
  2144. read_proc_body(nil,tprocdef(hp));
  2145. current_filepos:=oldcurrent_filepos;
  2146. end
  2147. { synthetic routines will be implemented afterwards }
  2148. else if tprocdef(hp).synthetickind=tsk_none then
  2149. MessagePos1(tprocdef(hp).fileinfo,sym_e_forward_not_resolved,tprocdef(hp).fullprocname(false));
  2150. end
  2151. else
  2152. if hp.typ in [objectdef,recorddef] then
  2153. { generate code for subtypes as well }
  2154. process_abstractrecorddef(tabstractrecorddef(hp));
  2155. end;
  2156. end;
  2157. begin
  2158. if not((tsym(p).typ=typesym) and
  2159. (ttypesym(p).typedef.typesym=tsym(p)) and
  2160. (ttypesym(p).typedef.typ in [objectdef,recorddef]) and
  2161. (df_specialization in ttypesym(p).typedef.defoptions)
  2162. ) then
  2163. exit;
  2164. { Setup symtablestack a definition time }
  2165. specobj:=tabstractrecorddef(ttypesym(p).typedef);
  2166. if not (is_class_or_object(specobj) or is_record(specobj) or is_javaclass(specobj)) then
  2167. exit;
  2168. specialization_init(specobj.genericdef,state);
  2169. { procedure definitions for classes or objects }
  2170. process_abstractrecorddef(specobj);
  2171. specialization_done(state);
  2172. end;
  2173. procedure generate_specialization_procs;
  2174. begin
  2175. if assigned(current_module.globalsymtable) then
  2176. current_module.globalsymtable.SymList.WhileEachCall(@specialize_objectdefs,nil);
  2177. if assigned(current_module.localsymtable) then
  2178. current_module.localsymtable.SymList.WhileEachCall(@specialize_objectdefs,nil);
  2179. end;
  2180. end.