symtable.pas 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. This unit handles the symbol tables
  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 symtable;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,cclasses,
  23. { global }
  24. cpuinfo,globtype,tokens,
  25. { symtable }
  26. symconst,symbase,symtype,symdef,symsym,
  27. { ppu }
  28. ppu,
  29. { assembler }
  30. aasmtai,aasmdata
  31. ;
  32. {****************************************************************************
  33. Symtable types
  34. ****************************************************************************}
  35. type
  36. tstoredsymtable = class(TSymtable)
  37. private
  38. b_needs_init_final : boolean;
  39. procedure _needs_init_final(sym:TObject;arg:pointer);
  40. procedure check_forward(sym:TObject;arg:pointer);
  41. procedure labeldefined(sym:TObject;arg:pointer);
  42. procedure varsymbolused(sym:TObject;arg:pointer);
  43. procedure TestPrivate(sym:TObject;arg:pointer);
  44. procedure objectprivatesymbolused(sym:TObject;arg:pointer);
  45. procedure loaddefs(ppufile:tcompilerppufile);
  46. procedure loadsyms(ppufile:tcompilerppufile);
  47. procedure writedefs(ppufile:tcompilerppufile);
  48. procedure writesyms(ppufile:tcompilerppufile);
  49. public
  50. procedure insert(sym:TSymEntry;checkdup:boolean=true);override;
  51. procedure delete(sym:TSymEntry);override;
  52. { load/write }
  53. procedure ppuload(ppufile:tcompilerppufile);virtual;
  54. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  55. procedure buildderef;virtual;
  56. procedure buildderefimpl;virtual;
  57. procedure deref;virtual;
  58. procedure derefimpl;virtual;
  59. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  60. procedure allsymbolsused;
  61. procedure allprivatesused;
  62. procedure check_forwards;
  63. procedure checklabels;
  64. function needs_init_final : boolean;
  65. procedure testfordefaultproperty(sym:TObject;arg:pointer);
  66. end;
  67. tabstractrecordsymtable = class(tstoredsymtable)
  68. public
  69. usefieldalignment, { alignment to use for fields (PACKRECORDS value), C_alignment is C style }
  70. recordalignment, { alignment desired when inserting this record }
  71. fieldalignment, { alignment current alignment used when fields are inserted }
  72. padalignment : shortint; { size to a multiple of which the symtable has to be rounded up }
  73. constructor create(const n:string;usealign:shortint);
  74. procedure ppuload(ppufile:tcompilerppufile);override;
  75. procedure ppuwrite(ppufile:tcompilerppufile);override;
  76. procedure alignrecord(fieldoffset:asizeint;varalign:shortint);
  77. procedure addfield(sym:tfieldvarsym;vis:tvisibility);
  78. procedure addalignmentpadding;
  79. procedure insertdef(def:TDefEntry);override;
  80. function is_packed: boolean;
  81. function has_single_field(out sym:tfieldvarsym): boolean;
  82. function get_unit_symtable: tsymtable;
  83. protected
  84. _datasize : asizeint;
  85. { size in bits of the data in case of bitpacked record. Only important during construction, }
  86. { no need to save in/restore from ppu file. datasize is always (databitsize+7) div 8. }
  87. databitsize : asizeint;
  88. procedure setdatasize(val: asizeint);
  89. public
  90. function iscurrentunit: boolean; override;
  91. property datasize : asizeint read _datasize write setdatasize;
  92. end;
  93. trecordsymtable = class(tabstractrecordsymtable)
  94. public
  95. constructor create(const n:string;usealign:shortint);
  96. procedure insertunionst(unionst : trecordsymtable;offset : longint);
  97. end;
  98. tObjectSymtable = class(tabstractrecordsymtable)
  99. public
  100. constructor create(adefowner:tdef;const n:string;usealign:shortint);
  101. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  102. end;
  103. { tabstractlocalsymtable }
  104. tabstractlocalsymtable = class(tstoredsymtable)
  105. public
  106. procedure ppuwrite(ppufile:tcompilerppufile);override;
  107. function count_locals:longint;
  108. end;
  109. tlocalsymtable = class(tabstractlocalsymtable)
  110. public
  111. constructor create(adefowner:tdef;level:byte);
  112. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  113. end;
  114. { tparasymtable }
  115. tparasymtable = class(tabstractlocalsymtable)
  116. public
  117. readonly: boolean;
  118. constructor create(adefowner:tdef;level:byte);
  119. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  120. procedure insertdef(def:TDefEntry);override;
  121. end;
  122. tabstractuniTSymtable = class(tstoredsymtable)
  123. public
  124. constructor create(const n : string;id:word);
  125. function iscurrentunit:boolean;override;
  126. end;
  127. tglobalsymtable = class(tabstractuniTSymtable)
  128. public
  129. unittypecount : word;
  130. constructor create(const n : string;id:word);
  131. procedure ppuload(ppufile:tcompilerppufile);override;
  132. procedure ppuwrite(ppufile:tcompilerppufile);override;
  133. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  134. end;
  135. tstaticsymtable = class(tabstractuniTSymtable)
  136. public
  137. constructor create(const n : string;id:word);
  138. procedure ppuload(ppufile:tcompilerppufile);override;
  139. procedure ppuwrite(ppufile:tcompilerppufile);override;
  140. function checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;override;
  141. end;
  142. twithsymtable = class(TSymtable)
  143. withrefnode : tobject; { tnode }
  144. constructor create(aowner:tdef;ASymList:TFPHashObjectList;refnode:tobject{tnode});
  145. destructor destroy;override;
  146. procedure clear;override;
  147. procedure insertdef(def:TDefEntry);override;
  148. end;
  149. tstt_excepTSymtable = class(TSymtable)
  150. public
  151. constructor create;
  152. end;
  153. tmacrosymtable = class(tstoredsymtable)
  154. public
  155. constructor create(exported: boolean);
  156. end;
  157. { tenumsymtable }
  158. tenumsymtable = class(tstoredsymtable)
  159. public
  160. procedure insert(sym: TSymEntry; checkdup: boolean = true); override;
  161. constructor create(adefowner:tdef);
  162. end;
  163. { tarraysymtable }
  164. tarraysymtable = class(tstoredsymtable)
  165. public
  166. procedure insertdef(def:TDefEntry);override;
  167. constructor create(adefowner:tdef);
  168. end;
  169. var
  170. systemunit : tglobalsymtable; { pointer to the system unit }
  171. {****************************************************************************
  172. Functions
  173. ****************************************************************************}
  174. {*** Misc ***}
  175. function FullTypeName(def,otherdef:tdef):string;
  176. function generate_nested_name(symtable:tsymtable;delimiter:string):string;
  177. procedure incompatibletypes(def1,def2:tdef);
  178. procedure hidesym(sym:TSymEntry);
  179. procedure duplicatesym(var hashedid:THashedIDString;dupsym,origsym:TSymEntry);
  180. {*** Search ***}
  181. procedure addsymref(sym:tsym);
  182. function is_owned_by(childdef,ownerdef:tabstractrecorddef):boolean;
  183. function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tabstractrecorddef):boolean;
  184. function is_visible_for_object(pd:tprocdef;contextobjdef:tabstractrecorddef):boolean;
  185. function is_visible_for_object(sym:tsym;contextobjdef:tabstractrecorddef):boolean;
  186. function searchsym(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  187. function searchsym_type(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  188. function searchsym_in_module(pm:pointer;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  189. function searchsym_in_named_module(const unitname, symname: TIDString; out srsym: tsym; out srsymtable: tsymtable): boolean;
  190. function searchsym_in_class(classh,contextclassh:tobjectdef;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable;searchhelper:boolean):boolean;
  191. function searchsym_in_record(recordh:tabstractrecorddef;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  192. function searchsym_in_class_by_msgint(classh:tobjectdef;msgid:longint;out srdef : tdef;out srsym:tsym;out srsymtable:TSymtable):boolean;
  193. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string;out srsym:tsym;out srsymtable:TSymtable):boolean;
  194. { searches symbols inside of a helper's implementation }
  195. function searchsym_in_helper(classh,contextclassh:tobjectdef;const s: TIDString;out srsym:tsym;out srsymtable:TSymtable;aHasInherited:boolean):boolean;
  196. function search_system_type(const s: TIDString): ttypesym;
  197. function try_search_system_type(const s: TIDString): ttypesym;
  198. function search_named_unit_globaltype(const unitname, typename: TIDString; throwerror: boolean): ttypesym;
  199. function search_struct_member(pd : tabstractrecorddef;const s : string):tsym;
  200. function search_assignment_operator(from_def,to_def:Tdef;explicit:boolean):Tprocdef;
  201. function search_enumerator_operator(from_def,to_def:Tdef):Tprocdef;
  202. { searches for the helper definition that's currently active for pd }
  203. function search_last_objectpascal_helper(pd,contextclassh : tabstractrecorddef;out odef : tobjectdef):boolean;
  204. { searches whether the symbol s is available in the currently active }
  205. { helper for pd }
  206. function search_objectpascal_helper(pd,contextclassh : tabstractrecorddef;const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  207. function search_objc_helper(pd : tobjectdef;const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  208. function search_objc_method(const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  209. {Looks for macro s (must be given in upper case) in the macrosymbolstack, }
  210. {and returns it if found. Returns nil otherwise.}
  211. function search_macro(const s : string):tsym;
  212. { Additionally to searching for a macro, also checks whether it's still }
  213. { actually defined (could be disable using "undef") }
  214. function defined_macro(const s : string):boolean;
  215. {*** Object Helpers ***}
  216. function search_default_property(pd : tabstractrecorddef) : tpropertysym;
  217. function find_real_objcclass_definition(pd: tobjectdef; erroronfailure: boolean): tobjectdef;
  218. {*** Macro Helpers ***}
  219. {If called initially, the following procedures manipulate macros in }
  220. {initialmacrotable, otherwise they manipulate system macros local to a module.}
  221. {Name can be given in any case (it will be converted to upper case).}
  222. procedure def_system_macro(const name : string);
  223. procedure set_system_macro(const name, value : string);
  224. procedure set_system_compvar(const name, value : string);
  225. procedure undef_system_macro(const name : string);
  226. {*** symtable stack ***}
  227. { $ifdef DEBUG
  228. procedure test_symtablestack;
  229. procedure list_symtablestack;
  230. $endif DEBUG}
  231. {$ifdef UNITALIASES}
  232. type
  233. punit_alias = ^tunit_alias;
  234. tunit_alias = object(TNamedIndexItem)
  235. newname : pshortstring;
  236. constructor init(const n:string);
  237. destructor done;virtual;
  238. end;
  239. var
  240. unitaliases : pdictionary;
  241. procedure addunitalias(const n:string);
  242. function getunitalias(const n:string):string;
  243. {$endif UNITALIASES}
  244. {*** Init / Done ***}
  245. procedure IniTSymtable;
  246. procedure DoneSymtable;
  247. const
  248. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] = (
  249. { NOTOKEN } 'error',
  250. { _PLUS } 'plus',
  251. { _MINUS } 'minus',
  252. { _STAR } 'star',
  253. { _SLASH } 'slash',
  254. { _EQ } 'equal',
  255. { _GT } 'greater',
  256. { _LT } 'lower',
  257. { _GTE } 'greater_or_equal',
  258. { _LTE } 'lower_or_equal',
  259. { _NE } 'not_equal',
  260. { _SYMDIF } 'sym_diff',
  261. { _STARSTAR } 'starstar',
  262. { _OP_AS } 'as',
  263. { _OP_IN } 'in',
  264. { _OP_IS } 'is',
  265. { _OP_OR } 'or',
  266. { _OP_AND } 'and',
  267. { _OP_DIV } 'div',
  268. { _OP_MOD } 'mod',
  269. { _OP_NOT } 'not',
  270. { _OP_SHL } 'shl',
  271. { _OP_SHR } 'shr',
  272. { _OP_XOR } 'xor',
  273. { _ASSIGNMENT } 'assign',
  274. { _OP_EXPLICIT } 'explicit',
  275. { _OP_ENUMERATOR } 'enumerator',
  276. { _OP_INC } 'inc',
  277. { _OP_DEC } 'dec');
  278. implementation
  279. uses
  280. { global }
  281. verbose,globals,
  282. { target }
  283. systems,
  284. { symtable }
  285. symutil,defcmp,defutil,
  286. { module }
  287. fmodule,
  288. { codegen }
  289. procinfo
  290. ;
  291. var
  292. dupnr : longint; { unique number for duplicate symbols }
  293. {*****************************************************************************
  294. TStoredSymtable
  295. *****************************************************************************}
  296. procedure tstoredsymtable.insert(sym:TSymEntry;checkdup:boolean=true);
  297. begin
  298. inherited insert(sym,checkdup);
  299. end;
  300. procedure tstoredsymtable.delete(sym:TSymEntry);
  301. begin
  302. inherited delete(sym);
  303. end;
  304. procedure tstoredsymtable.ppuload(ppufile:tcompilerppufile);
  305. begin
  306. { load the table's flags }
  307. if ppufile.readentry<>ibsymtableoptions then
  308. Message(unit_f_ppu_read_error);
  309. ppufile.getsmallset(tableoptions);
  310. { load definitions }
  311. loaddefs(ppufile);
  312. { load symbols }
  313. loadsyms(ppufile);
  314. end;
  315. procedure tstoredsymtable.ppuwrite(ppufile:tcompilerppufile);
  316. begin
  317. { write the table's flags }
  318. ppufile.putsmallset(tableoptions);
  319. ppufile.writeentry(ibsymtableoptions);
  320. { write definitions }
  321. writedefs(ppufile);
  322. { write symbols }
  323. writesyms(ppufile);
  324. end;
  325. procedure tstoredsymtable.loaddefs(ppufile:tcompilerppufile);
  326. var
  327. def : tdef;
  328. b : byte;
  329. begin
  330. { load start of definition section, which holds the amount of defs }
  331. if ppufile.readentry<>ibstartdefs then
  332. Message(unit_f_ppu_read_error);
  333. { read definitions }
  334. repeat
  335. b:=ppufile.readentry;
  336. case b of
  337. ibpointerdef : def:=tpointerdef.ppuload(ppufile);
  338. ibarraydef : def:=tarraydef.ppuload(ppufile);
  339. iborddef : def:=torddef.ppuload(ppufile);
  340. ibfloatdef : def:=tfloatdef.ppuload(ppufile);
  341. ibprocdef : def:=tprocdef.ppuload(ppufile);
  342. ibshortstringdef : def:=tstringdef.loadshort(ppufile);
  343. iblongstringdef : def:=tstringdef.loadlong(ppufile);
  344. ibansistringdef : def:=tstringdef.loadansi(ppufile);
  345. ibwidestringdef : def:=tstringdef.loadwide(ppufile);
  346. ibunicodestringdef : def:=tstringdef.loadunicode(ppufile);
  347. ibrecorddef : def:=trecorddef.ppuload(ppufile);
  348. ibobjectdef : def:=tobjectdef.ppuload(ppufile);
  349. ibenumdef : def:=tenumdef.ppuload(ppufile);
  350. ibsetdef : def:=tsetdef.ppuload(ppufile);
  351. ibprocvardef : def:=tprocvardef.ppuload(ppufile);
  352. ibfiledef : def:=tfiledef.ppuload(ppufile);
  353. ibclassrefdef : def:=tclassrefdef.ppuload(ppufile);
  354. ibformaldef : def:=tformaldef.ppuload(ppufile);
  355. ibvariantdef : def:=tvariantdef.ppuload(ppufile);
  356. ibundefineddef : def:=tundefineddef.ppuload(ppufile);
  357. ibenddefs : break;
  358. ibend : Message(unit_f_ppu_read_error);
  359. else
  360. Message1(unit_f_ppu_invalid_entry,tostr(b));
  361. end;
  362. InsertDef(def);
  363. until false;
  364. end;
  365. procedure tstoredsymtable.loadsyms(ppufile:tcompilerppufile);
  366. var
  367. b : byte;
  368. sym : tsym;
  369. begin
  370. { load start of definition section, which holds the amount of defs }
  371. if ppufile.readentry<>ibstartsyms then
  372. Message(unit_f_ppu_read_error);
  373. { now read the symbols }
  374. repeat
  375. b:=ppufile.readentry;
  376. case b of
  377. ibtypesym : sym:=ttypesym.ppuload(ppufile);
  378. ibprocsym : sym:=tprocsym.ppuload(ppufile);
  379. ibconstsym : sym:=tconstsym.ppuload(ppufile);
  380. ibstaticvarsym : sym:=tstaticvarsym.ppuload(ppufile);
  381. iblocalvarsym : sym:=tlocalvarsym.ppuload(ppufile);
  382. ibparavarsym : sym:=tparavarsym.ppuload(ppufile);
  383. ibfieldvarsym : sym:=tfieldvarsym.ppuload(ppufile);
  384. ibabsolutevarsym : sym:=tabsolutevarsym.ppuload(ppufile);
  385. ibenumsym : sym:=tenumsym.ppuload(ppufile);
  386. ibpropertysym : sym:=tpropertysym.ppuload(ppufile);
  387. ibunitsym : sym:=tunitsym.ppuload(ppufile);
  388. iblabelsym : sym:=tlabelsym.ppuload(ppufile);
  389. ibsyssym : sym:=tsyssym.ppuload(ppufile);
  390. ibmacrosym : sym:=tmacro.ppuload(ppufile);
  391. ibendsyms : break;
  392. ibend : Message(unit_f_ppu_read_error);
  393. else
  394. Message1(unit_f_ppu_invalid_entry,tostr(b));
  395. end;
  396. Insert(sym,false);
  397. until false;
  398. end;
  399. procedure tstoredsymtable.writedefs(ppufile:tcompilerppufile);
  400. var
  401. i : longint;
  402. def : tstoreddef;
  403. begin
  404. { each definition get a number, write then the amount of defs to the
  405. ibstartdef entry }
  406. ppufile.putlongint(DefList.count);
  407. ppufile.writeentry(ibstartdefs);
  408. { now write the definition }
  409. for i:=0 to DefList.Count-1 do
  410. begin
  411. def:=tstoreddef(DefList[i]);
  412. def.ppuwrite(ppufile);
  413. end;
  414. { write end of definitions }
  415. ppufile.writeentry(ibenddefs);
  416. end;
  417. procedure tstoredsymtable.writesyms(ppufile:tcompilerppufile);
  418. var
  419. i : longint;
  420. sym : Tstoredsym;
  421. begin
  422. { each definition get a number, write then the amount of syms and the
  423. datasize to the ibsymdef entry }
  424. ppufile.putlongint(SymList.count);
  425. ppufile.writeentry(ibstartsyms);
  426. { foreach is used to write all symbols }
  427. for i:=0 to SymList.Count-1 do
  428. begin
  429. sym:=tstoredsym(SymList[i]);
  430. sym.ppuwrite(ppufile);
  431. end;
  432. { end of symbols }
  433. ppufile.writeentry(ibendsyms);
  434. end;
  435. procedure tstoredsymtable.buildderef;
  436. var
  437. i : longint;
  438. def : tstoreddef;
  439. sym : tstoredsym;
  440. begin
  441. { interface definitions }
  442. for i:=0 to DefList.Count-1 do
  443. begin
  444. def:=tstoreddef(DefList[i]);
  445. def.buildderef;
  446. end;
  447. { interface symbols }
  448. for i:=0 to SymList.Count-1 do
  449. begin
  450. sym:=tstoredsym(SymList[i]);
  451. sym.buildderef;
  452. end;
  453. end;
  454. procedure tstoredsymtable.buildderefimpl;
  455. var
  456. i : longint;
  457. def : tstoreddef;
  458. begin
  459. { implementation definitions }
  460. for i:=0 to DefList.Count-1 do
  461. begin
  462. def:=tstoreddef(DefList[i]);
  463. def.buildderefimpl;
  464. end;
  465. end;
  466. procedure tstoredsymtable.deref;
  467. var
  468. i : longint;
  469. def : tstoreddef;
  470. sym : tstoredsym;
  471. begin
  472. { first deref the interface ttype symbols. This is needs
  473. to be done before the interface defs are derefed, because
  474. the interface defs can contain references to the type symbols
  475. which then already need to contain a resolved typedef field (PFV) }
  476. for i:=0 to SymList.Count-1 do
  477. begin
  478. sym:=tstoredsym(SymList[i]);
  479. if sym.typ=typesym then
  480. sym.deref;
  481. end;
  482. { interface definitions }
  483. for i:=0 to DefList.Count-1 do
  484. begin
  485. def:=tstoreddef(DefList[i]);
  486. def.deref;
  487. end;
  488. { interface symbols }
  489. for i:=0 to SymList.Count-1 do
  490. begin
  491. sym:=tstoredsym(SymList[i]);
  492. if sym.typ<>typesym then
  493. sym.deref;
  494. end;
  495. end;
  496. procedure tstoredsymtable.derefimpl;
  497. var
  498. i : longint;
  499. def : tstoreddef;
  500. begin
  501. { implementation definitions }
  502. for i:=0 to DefList.Count-1 do
  503. begin
  504. def:=tstoreddef(DefList[i]);
  505. def.derefimpl;
  506. end;
  507. end;
  508. function tstoredsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  509. var
  510. hsym : tsym;
  511. begin
  512. hsym:=tsym(FindWithHash(hashedid));
  513. if assigned(hsym) then
  514. DuplicateSym(hashedid,sym,hsym);
  515. result:=assigned(hsym);
  516. end;
  517. {**************************************
  518. Callbacks
  519. **************************************}
  520. procedure TStoredSymtable.check_forward(sym:TObject;arg:pointer);
  521. begin
  522. if tsym(sym).typ=procsym then
  523. tprocsym(sym).check_forward
  524. { check also object method table }
  525. { we needn't to test the def list }
  526. { because each object has to have a type sym,
  527. only test objects declarations, not type renamings }
  528. else
  529. if (tsym(sym).typ=typesym) and
  530. assigned(ttypesym(sym).typedef) and
  531. (ttypesym(sym).typedef.typesym=ttypesym(sym)) and
  532. (ttypesym(sym).typedef.typ in [objectdef,recorddef]) then
  533. tabstractrecorddef(ttypesym(sym).typedef).check_forwards;
  534. end;
  535. procedure TStoredSymtable.labeldefined(sym:TObject;arg:pointer);
  536. begin
  537. if (tsym(sym).typ=labelsym) and
  538. not(tlabelsym(sym).defined) then
  539. begin
  540. if tlabelsym(sym).used then
  541. Message1(sym_e_label_used_and_not_defined,tlabelsym(sym).realname)
  542. else
  543. Message1(sym_w_label_not_defined,tlabelsym(sym).realname);
  544. end;
  545. end;
  546. procedure TStoredSymtable.varsymbolused(sym:TObject;arg:pointer);
  547. begin
  548. if (tsym(sym).typ in [staticvarsym,localvarsym,paravarsym,fieldvarsym]) and
  549. ((tsym(sym).owner.symtabletype in
  550. [parasymtable,localsymtable,ObjectSymtable,recordsymtable,staticsymtable])) then
  551. begin
  552. { unused symbol should be reported only if no }
  553. { error is reported }
  554. { if the symbol is in a register it is used }
  555. { also don't count the value parameters which have local copies }
  556. { also don't claim for high param of open parameters (PM) }
  557. if (Errorcount<>0) or
  558. ([vo_is_hidden_para,vo_is_funcret] * tabstractvarsym(sym).varoptions = [vo_is_hidden_para]) or
  559. (sp_internal in tsym(sym).symoptions) then
  560. exit;
  561. if (tstoredsym(sym).refs=0) then
  562. begin
  563. if (vo_is_funcret in tabstractvarsym(sym).varoptions) then
  564. begin
  565. { don't warn about the result of constructors }
  566. if ((tsym(sym).owner.symtabletype<>localsymtable) or
  567. (tprocdef(tsym(sym).owner.defowner).proctypeoption<>potype_constructor)) and
  568. not(cs_opt_nodedfa in current_settings.optimizerswitches) then
  569. MessagePos(tsym(sym).fileinfo,sym_w_function_result_not_set)
  570. end
  571. else if (tsym(sym).owner.symtabletype=parasymtable) then
  572. MessagePos1(tsym(sym).fileinfo,sym_h_para_identifier_not_used,tsym(sym).prettyname)
  573. else if (tsym(sym).owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  574. MessagePos2(tsym(sym).fileinfo,sym_n_private_identifier_not_used,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname)
  575. else
  576. MessagePos1(tsym(sym).fileinfo,sym_n_local_identifier_not_used,tsym(sym).prettyname);
  577. end
  578. else if tabstractvarsym(sym).varstate in [vs_written,vs_initialised] then
  579. begin
  580. if (tsym(sym).owner.symtabletype=parasymtable) then
  581. begin
  582. if not(tabstractvarsym(sym).varspez in [vs_var,vs_out,vs_constref]) and
  583. not(vo_is_funcret in tabstractvarsym(sym).varoptions) then
  584. MessagePos1(tsym(sym).fileinfo,sym_h_para_identifier_only_set,tsym(sym).prettyname)
  585. end
  586. else if (tsym(sym).owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  587. MessagePos2(tsym(sym).fileinfo,sym_n_private_identifier_only_set,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname)
  588. else if tabstractvarsym(sym).varoptions*[vo_is_funcret,vo_is_public,vo_is_external]=[] then
  589. MessagePos1(tsym(sym).fileinfo,sym_n_local_identifier_only_set,tsym(sym).prettyname);
  590. end
  591. else if (tabstractvarsym(sym).varstate = vs_read_not_warned) and
  592. ([vo_is_public,vo_is_external] * tabstractvarsym(sym).varoptions = []) then
  593. MessagePos1(tsym(sym).fileinfo,sym_w_identifier_only_read,tsym(sym).prettyname)
  594. end
  595. else if ((tsym(sym).owner.symtabletype in
  596. [ObjectSymtable,parasymtable,localsymtable,staticsymtable,recordsymtable])) then
  597. begin
  598. if (Errorcount<>0) or
  599. (sp_internal in tsym(sym).symoptions) then
  600. exit;
  601. { do not claim for inherited private fields !! }
  602. if (tsym(sym).refs=0) and (tsym(sym).owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  603. case tsym(sym).typ of
  604. typesym:
  605. MessagePos2(tsym(sym).fileinfo,sym_n_private_type_not_used,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname);
  606. constsym:
  607. MessagePos2(tsym(sym).fileinfo,sym_n_private_const_not_used,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname);
  608. propertysym:
  609. MessagePos2(tsym(sym).fileinfo,sym_n_private_property_not_used,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname);
  610. else
  611. MessagePos2(tsym(sym).fileinfo,sym_n_private_method_not_used,tabstractrecorddef(tsym(sym).owner.defowner).RttiName,tsym(sym).prettyname);
  612. end
  613. { units references are problematic }
  614. else
  615. begin
  616. if (tsym(sym).refs=0) and
  617. not(tsym(sym).typ in [enumsym,unitsym]) and
  618. not(is_funcret_sym(tsym(sym))) and
  619. { don't complain about compiler generated syms for specializations, see also #13405 }
  620. not((tsym(sym).typ=typesym) and (df_specialization in ttypesym(sym).typedef.defoptions) and
  621. (pos('$',ttypesym(sym).Realname)<>0)) and
  622. (
  623. (tsym(sym).typ<>procsym) or
  624. ((tsym(sym).owner.symtabletype=staticsymtable) and
  625. not current_module.is_unit)
  626. ) and
  627. { don't complain about alias for hidden _cmd parameter to
  628. obj-c methods }
  629. not((tsym(sym).typ in [localvarsym,paravarsym,absolutevarsym]) and
  630. (vo_is_msgsel in tabstractvarsym(sym).varoptions)) then
  631. MessagePos2(tsym(sym).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(sym).typ],tsym(sym).prettyname);
  632. end;
  633. end;
  634. end;
  635. procedure TStoredSymtable.TestPrivate(sym:TObject;arg:pointer);
  636. begin
  637. if tsym(sym).visibility in [vis_private,vis_strictprivate] then
  638. varsymbolused(sym,arg);
  639. end;
  640. procedure TStoredSymtable.objectprivatesymbolused(sym:TObject;arg:pointer);
  641. begin
  642. {
  643. Don't test simple object aliases PM
  644. }
  645. if (tsym(sym).typ=typesym) and
  646. (ttypesym(sym).typedef.typ in [objectdef,recorddef]) and
  647. (ttypesym(sym).typedef.typesym=tsym(sym)) then
  648. tabstractrecorddef(ttypesym(sym).typedef).symtable.SymList.ForEachCall(@TestPrivate,nil);
  649. end;
  650. procedure tstoredsymtable.testfordefaultproperty(sym:TObject;arg:pointer);
  651. begin
  652. if (tsym(sym).typ=propertysym) and
  653. (ppo_defaultproperty in tpropertysym(sym).propoptions) then
  654. ppointer(arg)^:=sym;
  655. end;
  656. {***********************************************
  657. Process all entries
  658. ***********************************************}
  659. { checks, if all procsyms and methods are defined }
  660. procedure tstoredsymtable.check_forwards;
  661. begin
  662. SymList.ForEachCall(@check_forward,nil);
  663. end;
  664. procedure tstoredsymtable.checklabels;
  665. begin
  666. SymList.ForEachCall(@labeldefined,nil);
  667. end;
  668. procedure tstoredsymtable.allsymbolsused;
  669. begin
  670. SymList.ForEachCall(@varsymbolused,nil);
  671. end;
  672. procedure tstoredsymtable.allprivatesused;
  673. begin
  674. SymList.ForEachCall(@objectprivatesymbolused,nil);
  675. end;
  676. procedure TStoredSymtable._needs_init_final(sym:TObject;arg:pointer);
  677. begin
  678. if b_needs_init_final then
  679. exit;
  680. { don't check static symbols - they can be present in structures only and
  681. always have a reference to a symbol defined on unit level }
  682. if sp_static in tsym(sym).symoptions then
  683. exit;
  684. case tsym(sym).typ of
  685. fieldvarsym,
  686. staticvarsym,
  687. localvarsym,
  688. paravarsym :
  689. begin
  690. if is_managed_type(tabstractvarsym(sym).vardef) then
  691. b_needs_init_final:=true;
  692. end;
  693. end;
  694. end;
  695. { returns true, if p contains data which needs init/final code }
  696. function tstoredsymtable.needs_init_final : boolean;
  697. begin
  698. b_needs_init_final:=false;
  699. SymList.ForEachCall(@_needs_init_final,nil);
  700. needs_init_final:=b_needs_init_final;
  701. end;
  702. {****************************************************************************
  703. TAbstractRecordSymtable
  704. ****************************************************************************}
  705. constructor tabstractrecordsymtable.create(const n:string;usealign:shortint);
  706. begin
  707. inherited create(n);
  708. moduleid:=current_module.moduleid;
  709. _datasize:=0;
  710. databitsize:=0;
  711. recordalignment:=1;
  712. usefieldalignment:=usealign;
  713. padalignment:=1;
  714. { recordalign C_alignment means C record packing, that starts
  715. with an alignment of 1 }
  716. case usealign of
  717. C_alignment,
  718. bit_alignment:
  719. fieldalignment:=1;
  720. mac68k_alignment:
  721. fieldalignment:=2;
  722. else
  723. fieldalignment:=usealign;
  724. end;
  725. end;
  726. procedure tabstractrecordsymtable.ppuload(ppufile:tcompilerppufile);
  727. begin
  728. inherited ppuload(ppufile);
  729. end;
  730. procedure tabstractrecordsymtable.ppuwrite(ppufile:tcompilerppufile);
  731. var
  732. oldtyp : byte;
  733. begin
  734. oldtyp:=ppufile.entrytyp;
  735. ppufile.entrytyp:=subentryid;
  736. inherited ppuwrite(ppufile);
  737. ppufile.entrytyp:=oldtyp;
  738. end;
  739. function field2recordalignment(fieldoffs, fieldalign: asizeint): asizeint;
  740. begin
  741. { optimal alignment of the record when declaring a variable of this }
  742. { type is independent of the packrecords setting }
  743. if (fieldoffs mod fieldalign) = 0 then
  744. result:=fieldalign
  745. else if (fieldalign >= 16) and
  746. ((fieldoffs mod 16) = 0) and
  747. ((fieldalign mod 16) = 0) then
  748. result:=16
  749. else if (fieldalign >= 8) and
  750. ((fieldoffs mod 8) = 0) and
  751. ((fieldalign mod 8) = 0) then
  752. result:=8
  753. else if (fieldalign >= 4) and
  754. ((fieldoffs mod 4) = 0) and
  755. ((fieldalign mod 4) = 0) then
  756. result:=4
  757. else if (fieldalign >= 2) and
  758. ((fieldoffs mod 2) = 0) and
  759. ((fieldalign mod 2) = 0) then
  760. result:=2
  761. else
  762. result:=1;
  763. end;
  764. procedure tabstractrecordsymtable.alignrecord(fieldoffset:asizeint;varalign:shortint);
  765. var
  766. varalignrecord: shortint;
  767. begin
  768. case usefieldalignment of
  769. C_alignment:
  770. varalignrecord:=used_align(varalign,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  771. mac68k_alignment:
  772. varalignrecord:=2;
  773. else
  774. varalignrecord:=field2recordalignment(fieldoffset,varalign);
  775. end;
  776. recordalignment:=max(recordalignment,varalignrecord);
  777. end;
  778. procedure tabstractrecordsymtable.addfield(sym:tfieldvarsym;vis:tvisibility);
  779. var
  780. l : asizeint;
  781. varalignfield,
  782. varalign : shortint;
  783. vardef : tdef;
  784. begin
  785. if (sym.owner<>self) then
  786. internalerror(200602031);
  787. if sym.fieldoffset<>-1 then
  788. internalerror(200602032);
  789. { set visibility for the symbol }
  790. sym.visibility:=vis;
  791. { this symbol can't be loaded to a register }
  792. sym.varregable:=vr_none;
  793. { Calculate field offset }
  794. l:=sym.getsize;
  795. vardef:=sym.vardef;
  796. varalign:=vardef.alignment;
  797. case usefieldalignment of
  798. bit_alignment:
  799. begin
  800. { bitpacking only happens for ordinals, the rest is aligned at }
  801. { 1 byte (compatible with GPC/GCC) }
  802. if is_ordinal(vardef) then
  803. begin
  804. sym.fieldoffset:=databitsize;
  805. l:=sym.getpackedbitsize;
  806. end
  807. else
  808. begin
  809. databitsize:=_datasize*8;
  810. sym.fieldoffset:=databitsize;
  811. if (l>high(asizeint) div 8) then
  812. Message(sym_e_segment_too_large);
  813. l:=l*8;
  814. end;
  815. if varalign=0 then
  816. varalign:=size_2_align(l);
  817. recordalignment:=max(recordalignment,field2recordalignment(databitsize mod 8,varalign));
  818. { bit packed records are limited to high(aint) bits }
  819. { instead of bytes to avoid double precision }
  820. { arithmetic in offset calculations }
  821. if int64(l)>high(asizeint)-sym.fieldoffset then
  822. begin
  823. Message(sym_e_segment_too_large);
  824. _datasize:=high(asizeint);
  825. databitsize:=high(asizeint);
  826. end
  827. else
  828. begin
  829. databitsize:=sym.fieldoffset+l;
  830. _datasize:=(databitsize+7) div 8;
  831. end;
  832. { rest is not applicable }
  833. exit;
  834. end;
  835. { Calc the alignment size for C style records }
  836. C_alignment:
  837. begin
  838. if (varalign>4) and
  839. ((varalign mod 4)<>0) and
  840. (vardef.typ=arraydef) then
  841. Message1(sym_w_wrong_C_pack,vardef.typename);
  842. if varalign=0 then
  843. varalign:=l;
  844. if (fieldalignment<current_settings.alignment.maxCrecordalign) then
  845. begin
  846. if (varalign>16) and (fieldalignment<32) then
  847. fieldalignment:=32
  848. else if (varalign>12) and (fieldalignment<16) then
  849. fieldalignment:=16
  850. { 12 is needed for long double }
  851. else if (varalign>8) and (fieldalignment<12) then
  852. fieldalignment:=12
  853. else if (varalign>4) and (fieldalignment<8) then
  854. fieldalignment:=8
  855. else if (varalign>2) and (fieldalignment<4) then
  856. fieldalignment:=4
  857. else if (varalign>1) and (fieldalignment<2) then
  858. fieldalignment:=2;
  859. end;
  860. fieldalignment:=min(fieldalignment,current_settings.alignment.maxCrecordalign);
  861. end;
  862. mac68k_alignment:
  863. begin
  864. { mac68k alignment (C description):
  865. * char is aligned to 1 byte
  866. * everything else (except vector) is aligned to 2 bytes
  867. * vector is aligned to 16 bytes
  868. }
  869. if l>1 then
  870. fieldalignment:=2
  871. else
  872. fieldalignment:=1;
  873. varalign:=2;
  874. end;
  875. end;
  876. if varalign=0 then
  877. varalign:=size_2_align(l);
  878. varalignfield:=used_align(varalign,current_settings.alignment.recordalignmin,fieldalignment);
  879. sym.fieldoffset:=align(_datasize,varalignfield);
  880. if l>high(asizeint)-sym.fieldoffset then
  881. begin
  882. Message(sym_e_segment_too_large);
  883. _datasize:=high(aint);
  884. end
  885. else
  886. _datasize:=sym.fieldoffset+l;
  887. { Calc alignment needed for this record }
  888. alignrecord(sym.fieldoffset,varalign);
  889. end;
  890. procedure tabstractrecordsymtable.addalignmentpadding;
  891. begin
  892. { make the record size aligned correctly so it can be
  893. used as elements in an array. For C records we
  894. use the fieldalignment, because that is updated with the
  895. used alignment. }
  896. if (padalignment = 1) then
  897. case usefieldalignment of
  898. C_alignment:
  899. padalignment:=fieldalignment;
  900. { bitpacked }
  901. bit_alignment:
  902. padalignment:=1;
  903. { mac68k: always round to multiple of 2 }
  904. mac68k_alignment:
  905. padalignment:=2;
  906. { default/no packrecords specified }
  907. 0:
  908. padalignment:=recordalignment
  909. { specific packrecords setting -> use as upper limit }
  910. else
  911. padalignment:=min(recordalignment,usefieldalignment);
  912. end;
  913. _datasize:=align(_datasize,padalignment);
  914. end;
  915. procedure tabstractrecordsymtable.insertdef(def:TDefEntry);
  916. begin
  917. { Enums must also be available outside the record scope,
  918. insert in the owner of this symtable }
  919. if def.typ=enumdef then
  920. defowner.owner.insertdef(def)
  921. else
  922. inherited insertdef(def);
  923. end;
  924. function tabstractrecordsymtable.is_packed: boolean;
  925. begin
  926. result:=usefieldalignment=bit_alignment;
  927. end;
  928. function tabstractrecordsymtable.has_single_field(out sym: tfieldvarsym): boolean;
  929. var
  930. i: longint;
  931. begin
  932. result:=false;
  933. { If a record contains a union, it does not contain a "single
  934. non-composite field" in the context of certain ABIs requiring
  935. special treatment for such records }
  936. if (defowner.typ=recorddef) and
  937. trecorddef(defowner).isunion then
  938. exit;
  939. { a record/object can contain other things than fields }
  940. for i:=0 to SymList.Count-1 do
  941. begin
  942. if tsym(symlist[i]).typ=fieldvarsym then
  943. begin
  944. if result then
  945. begin
  946. result:=false;
  947. exit;
  948. end;
  949. result:=true;
  950. sym:=tfieldvarsym(symlist[i])
  951. end;
  952. end;
  953. end;
  954. function tabstractrecordsymtable.get_unit_symtable: tsymtable;
  955. begin
  956. result:=defowner.owner;
  957. while assigned(result) and (result.symtabletype in [ObjectSymtable,recordsymtable]) do
  958. result:=result.defowner.owner;
  959. end;
  960. procedure tabstractrecordsymtable.setdatasize(val: asizeint);
  961. begin
  962. _datasize:=val;
  963. if (usefieldalignment=bit_alignment) then
  964. { can overflow in non bitpacked records }
  965. databitsize:=val*8;
  966. end;
  967. function tabstractrecordsymtable.iscurrentunit: boolean;
  968. begin
  969. Result := Assigned(current_module) and (current_module.moduleid=moduleid);
  970. end;
  971. {****************************************************************************
  972. TRecordSymtable
  973. ****************************************************************************}
  974. constructor trecordsymtable.create(const n:string;usealign:shortint);
  975. begin
  976. inherited create(n,usealign);
  977. symtabletype:=recordsymtable;
  978. end;
  979. { this procedure is reserved for inserting case variant into
  980. a record symtable }
  981. { the offset is the location of the start of the variant
  982. and datasize and dataalignment corresponds to
  983. the complete size (see code in pdecl unit) PM }
  984. procedure trecordsymtable.insertunionst(unionst : trecordsymtable;offset : longint);
  985. var
  986. sym : tsym;
  987. def : tdef;
  988. i : integer;
  989. varalignrecord,varalign,
  990. storesize,storealign : aint;
  991. bitsize: aint;
  992. begin
  993. storesize:=_datasize;
  994. storealign:=fieldalignment;
  995. _datasize:=offset;
  996. if (usefieldalignment=bit_alignment) then
  997. databitsize:=offset*8;
  998. { We move the ownership of the defs and symbols to the new recordsymtable.
  999. The old unionsymtable keeps the references, but doesn't own the
  1000. objects anymore }
  1001. unionst.DefList.OwnsObjects:=false;
  1002. unionst.SymList.OwnsObjects:=false;
  1003. { copy symbols }
  1004. for i:=0 to unionst.SymList.Count-1 do
  1005. begin
  1006. sym:=TSym(unionst.SymList[i]);
  1007. if sym.typ<>fieldvarsym then
  1008. internalerror(200601272);
  1009. if tfieldvarsym(sym).fieldoffset=0 then
  1010. include(tfieldvarsym(sym).varoptions,vo_is_first_field);
  1011. { add to this record symtable }
  1012. // unionst.SymList.List.List^[i].Data:=nil;
  1013. sym.ChangeOwner(self);
  1014. varalign:=tfieldvarsym(sym).vardef.alignment;
  1015. if varalign=0 then
  1016. varalign:=size_2_align(tfieldvarsym(sym).getsize);
  1017. { retrieve size }
  1018. if (usefieldalignment=bit_alignment) then
  1019. begin
  1020. { bit packed records are limited to high(aint) bits }
  1021. { instead of bytes to avoid double precision }
  1022. { arithmetic in offset calculations }
  1023. if is_ordinal(tfieldvarsym(sym).vardef) then
  1024. bitsize:=tfieldvarsym(sym).getpackedbitsize
  1025. else
  1026. begin
  1027. bitsize:=tfieldvarsym(sym).getsize;
  1028. if (bitsize>high(asizeint) div 8) then
  1029. Message(sym_e_segment_too_large);
  1030. bitsize:=bitsize*8;
  1031. end;
  1032. if bitsize>high(asizeint)-databitsize then
  1033. begin
  1034. Message(sym_e_segment_too_large);
  1035. _datasize:=high(aint);
  1036. databitsize:=high(aint);
  1037. end
  1038. else
  1039. begin
  1040. databitsize:=tfieldvarsym(sym).fieldoffset+offset*8;
  1041. _datasize:=(databitsize+7) div 8;
  1042. end;
  1043. tfieldvarsym(sym).fieldoffset:=databitsize;
  1044. varalignrecord:=field2recordalignment(tfieldvarsym(sym).fieldoffset div 8,varalign);
  1045. end
  1046. else
  1047. begin
  1048. if tfieldvarsym(sym).getsize>high(asizeint)-_datasize then
  1049. begin
  1050. Message(sym_e_segment_too_large);
  1051. _datasize:=high(aint);
  1052. end
  1053. else
  1054. _datasize:=tfieldvarsym(sym).fieldoffset+offset;
  1055. { update address }
  1056. tfieldvarsym(sym).fieldoffset:=_datasize;
  1057. varalignrecord:=field2recordalignment(tfieldvarsym(sym).fieldoffset,varalign);
  1058. end;
  1059. { update alignment of this record }
  1060. if (usefieldalignment<>C_alignment) and
  1061. (usefieldalignment<>mac68k_alignment) then
  1062. recordalignment:=max(recordalignment,varalignrecord);
  1063. end;
  1064. { update alignment for C records }
  1065. if (usefieldalignment=C_alignment) and
  1066. (usefieldalignment<>mac68k_alignment) then
  1067. recordalignment:=max(recordalignment,unionst.recordalignment);
  1068. { Register defs in the new record symtable }
  1069. for i:=0 to unionst.DefList.Count-1 do
  1070. begin
  1071. def:=TDef(unionst.DefList[i]);
  1072. def.ChangeOwner(self);
  1073. end;
  1074. _datasize:=storesize;
  1075. fieldalignment:=storealign;
  1076. { If a record contains a union, it does not contain a "single
  1077. non-composite field" in the context of certain ABIs requiring
  1078. special treatment for such records }
  1079. if defowner.typ=recorddef then
  1080. trecorddef(defowner).isunion:=true;
  1081. end;
  1082. {****************************************************************************
  1083. TObjectSymtable
  1084. ****************************************************************************}
  1085. constructor tObjectSymtable.create(adefowner:tdef;const n:string;usealign:shortint);
  1086. begin
  1087. inherited create(n,usealign);
  1088. symtabletype:=ObjectSymtable;
  1089. defowner:=adefowner;
  1090. end;
  1091. function tObjectSymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1092. var
  1093. hsym : tsym;
  1094. begin
  1095. result:=false;
  1096. if not assigned(defowner) then
  1097. internalerror(200602061);
  1098. { procsym and propertysym have special code
  1099. to override values in inherited classes. For other
  1100. symbols check for duplicates }
  1101. if not(sym.typ in [procsym,propertysym]) then
  1102. begin
  1103. { but private ids can be reused }
  1104. hsym:=search_struct_member(tobjectdef(defowner),hashedid.id);
  1105. if assigned(hsym) and
  1106. (
  1107. (
  1108. not(m_delphi in current_settings.modeswitches) and
  1109. is_visible_for_object(hsym,tobjectdef(defowner))
  1110. ) or
  1111. (
  1112. { In Delphi, you can repeat members of a parent class. You can't }
  1113. { do this for objects however, and you (obviouly) can't }
  1114. { declare two fields with the same name in a single class }
  1115. (m_delphi in current_settings.modeswitches) and
  1116. (
  1117. is_object(tdef(defowner)) or
  1118. (hsym.owner = self)
  1119. )
  1120. )
  1121. ) then
  1122. begin
  1123. DuplicateSym(hashedid,sym,hsym);
  1124. result:=true;
  1125. end;
  1126. end
  1127. else
  1128. begin
  1129. if not(m_duplicate_names in current_settings.modeswitches) then
  1130. result:=inherited checkduplicate(hashedid,sym);
  1131. end;
  1132. end;
  1133. {****************************************************************************
  1134. TAbstractLocalSymtable
  1135. ****************************************************************************}
  1136. procedure tabstractlocalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1137. var
  1138. oldtyp : byte;
  1139. begin
  1140. oldtyp:=ppufile.entrytyp;
  1141. ppufile.entrytyp:=subentryid;
  1142. inherited ppuwrite(ppufile);
  1143. ppufile.entrytyp:=oldtyp;
  1144. end;
  1145. function tabstractlocalsymtable.count_locals:longint;
  1146. var
  1147. i : longint;
  1148. sym : tsym;
  1149. begin
  1150. result:=0;
  1151. for i:=0 to SymList.Count-1 do
  1152. begin
  1153. sym:=tsym(SymList[i]);
  1154. { Count only varsyms, but ignore the funcretsym }
  1155. if (tsym(sym).typ in [localvarsym,paravarsym]) and
  1156. (tsym(sym)<>current_procinfo.procdef.funcretsym) and
  1157. (not(vo_is_parentfp in tabstractvarsym(sym).varoptions) or
  1158. (tstoredsym(sym).refs>0)) then
  1159. inc(result);
  1160. end;
  1161. end;
  1162. {****************************************************************************
  1163. TLocalSymtable
  1164. ****************************************************************************}
  1165. constructor tlocalsymtable.create(adefowner:tdef;level:byte);
  1166. begin
  1167. inherited create('');
  1168. defowner:=adefowner;
  1169. symtabletype:=localsymtable;
  1170. symtablelevel:=level;
  1171. end;
  1172. function tlocalsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1173. var
  1174. hsym : tsym;
  1175. begin
  1176. if not assigned(defowner) or
  1177. (defowner.typ<>procdef) then
  1178. internalerror(200602042);
  1179. result:=false;
  1180. hsym:=tsym(FindWithHash(hashedid));
  1181. if assigned(hsym) then
  1182. begin
  1183. { a local and the function can have the same
  1184. name in TP and Delphi, but RESULT not }
  1185. if (m_duplicate_names in current_settings.modeswitches) and
  1186. (hsym.typ in [absolutevarsym,localvarsym]) and
  1187. (vo_is_funcret in tabstractvarsym(hsym).varoptions) and
  1188. not((m_result in current_settings.modeswitches) and
  1189. (vo_is_result in tabstractvarsym(hsym).varoptions)) then
  1190. HideSym(hsym)
  1191. else
  1192. DuplicateSym(hashedid,sym,hsym);
  1193. result:=true;
  1194. exit;
  1195. end;
  1196. { check also parasymtable, this needs to be done here because
  1197. of the special situation with the funcret sym that needs to be
  1198. hidden for tp and delphi modes }
  1199. hsym:=tsym(tabstractprocdef(defowner).parast.FindWithHash(hashedid));
  1200. if assigned(hsym) then
  1201. begin
  1202. { a local and the function can have the same
  1203. name in TP and Delphi, but RESULT not }
  1204. if (m_duplicate_names in current_settings.modeswitches) and
  1205. (sym.typ in [absolutevarsym,localvarsym]) and
  1206. (vo_is_funcret in tabstractvarsym(sym).varoptions) and
  1207. not((m_result in current_settings.modeswitches) and
  1208. (vo_is_result in tabstractvarsym(sym).varoptions)) then
  1209. Hidesym(sym)
  1210. else
  1211. DuplicateSym(hashedid,sym,hsym);
  1212. result:=true;
  1213. exit;
  1214. end;
  1215. { check ObjectSymtable, skip this for funcret sym because
  1216. that will always be positive because it has the same name
  1217. as the procsym }
  1218. if not is_funcret_sym(sym) and
  1219. (defowner.typ=procdef) and
  1220. assigned(tprocdef(defowner).struct) and
  1221. (tprocdef(defowner).owner.defowner=tprocdef(defowner).struct) and
  1222. (
  1223. not(m_delphi in current_settings.modeswitches) or
  1224. is_object(tprocdef(defowner).struct)
  1225. ) then
  1226. result:=tprocdef(defowner).struct.symtable.checkduplicate(hashedid,sym);
  1227. end;
  1228. {****************************************************************************
  1229. TParaSymtable
  1230. ****************************************************************************}
  1231. constructor tparasymtable.create(adefowner:tdef;level:byte);
  1232. begin
  1233. inherited create('');
  1234. readonly:=false;
  1235. defowner:=adefowner;
  1236. symtabletype:=parasymtable;
  1237. symtablelevel:=level;
  1238. end;
  1239. function tparasymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1240. begin
  1241. result:=inherited checkduplicate(hashedid,sym);
  1242. if result then
  1243. exit;
  1244. if not(m_duplicate_names in current_settings.modeswitches) and
  1245. (defowner.typ=procdef) and
  1246. assigned(tprocdef(defowner).struct) and
  1247. (tprocdef(defowner).owner.defowner=tprocdef(defowner).struct) and
  1248. (
  1249. not(m_delphi in current_settings.modeswitches) or
  1250. is_object(tprocdef(defowner).struct)
  1251. ) then
  1252. result:=tprocdef(defowner).struct.symtable.checkduplicate(hashedid,sym);
  1253. end;
  1254. procedure tparasymtable.insertdef(def: TDefEntry);
  1255. begin
  1256. if readonly then
  1257. defowner.owner.insertdef(def)
  1258. else
  1259. inherited insertdef(def);
  1260. end;
  1261. {****************************************************************************
  1262. TAbstractUniTSymtable
  1263. ****************************************************************************}
  1264. constructor tabstractuniTSymtable.create(const n : string;id:word);
  1265. begin
  1266. inherited create(n);
  1267. moduleid:=id;
  1268. end;
  1269. function tabstractuniTSymtable.iscurrentunit:boolean;
  1270. begin
  1271. result:=assigned(current_module) and
  1272. (
  1273. (current_module.globalsymtable=self) or
  1274. (current_module.localsymtable=self)
  1275. );
  1276. end;
  1277. {****************************************************************************
  1278. TStaticSymtable
  1279. ****************************************************************************}
  1280. constructor tstaticsymtable.create(const n : string;id:word);
  1281. begin
  1282. inherited create(n,id);
  1283. symtabletype:=staticsymtable;
  1284. symtablelevel:=main_program_level;
  1285. end;
  1286. procedure tstaticsymtable.ppuload(ppufile:tcompilerppufile);
  1287. begin
  1288. inherited ppuload(ppufile);
  1289. { now we can deref the syms and defs }
  1290. deref;
  1291. end;
  1292. procedure tstaticsymtable.ppuwrite(ppufile:tcompilerppufile);
  1293. begin
  1294. inherited ppuwrite(ppufile);
  1295. end;
  1296. function tstaticsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1297. var
  1298. hsym : tsym;
  1299. begin
  1300. result:=false;
  1301. hsym:=tsym(FindWithHash(hashedid));
  1302. if assigned(hsym) then
  1303. begin
  1304. { Delphi (contrary to TP) you can have a symbol with the same name as the
  1305. unit, the unit can then not be accessed anymore using
  1306. <unit>.<id>, so we can hide the symbol }
  1307. if (m_delphi in current_settings.modeswitches) and
  1308. (hsym.typ=symconst.unitsym) then
  1309. HideSym(hsym)
  1310. else
  1311. DuplicateSym(hashedid,sym,hsym);
  1312. result:=true;
  1313. exit;
  1314. end;
  1315. if (current_module.localsymtable=self) and
  1316. assigned(current_module.globalsymtable) then
  1317. result:=tglobalsymtable(current_module.globalsymtable).checkduplicate(hashedid,sym);
  1318. end;
  1319. {****************************************************************************
  1320. TGlobalSymtable
  1321. ****************************************************************************}
  1322. constructor tglobalsymtable.create(const n : string;id:word);
  1323. begin
  1324. inherited create(n,id);
  1325. symtabletype:=globalsymtable;
  1326. symtablelevel:=main_program_level;
  1327. end;
  1328. procedure tglobalsymtable.ppuload(ppufile:tcompilerppufile);
  1329. begin
  1330. inherited ppuload(ppufile);
  1331. { now we can deref the syms and defs }
  1332. deref;
  1333. end;
  1334. procedure tglobalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1335. begin
  1336. { write the symtable entries }
  1337. inherited ppuwrite(ppufile);
  1338. end;
  1339. function tglobalsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1340. var
  1341. hsym : tsym;
  1342. begin
  1343. result:=false;
  1344. hsym:=tsym(FindWithHash(hashedid));
  1345. if assigned(hsym) then
  1346. begin
  1347. { Delphi (contrary to TP) you can have a symbol with the same name as the
  1348. unit, the unit can then not be accessed anymore using
  1349. <unit>.<id>, so we can hide the symbol }
  1350. if (m_delphi in current_settings.modeswitches) and
  1351. (hsym.typ=symconst.unitsym) then
  1352. HideSym(hsym)
  1353. else
  1354. DuplicateSym(hashedid,sym,hsym);
  1355. result:=true;
  1356. exit;
  1357. end;
  1358. end;
  1359. {****************************************************************************
  1360. TWITHSYMTABLE
  1361. ****************************************************************************}
  1362. constructor twithsymtable.create(aowner:tdef;ASymList:TFPHashObjectList;refnode:tobject{tnode});
  1363. begin
  1364. inherited create('');
  1365. symtabletype:=withsymtable;
  1366. withrefnode:=refnode;
  1367. { Replace SymList with the passed symlist }
  1368. SymList.free;
  1369. SymList:=ASymList;
  1370. defowner:=aowner;
  1371. end;
  1372. destructor twithsymtable.destroy;
  1373. begin
  1374. withrefnode.free;
  1375. { Disable SymList because we don't Own it }
  1376. SymList:=nil;
  1377. inherited destroy;
  1378. end;
  1379. procedure twithsymtable.clear;
  1380. begin
  1381. { remove no entry from a withsymtable as it is only a pointer to the
  1382. recorddef or objectdef symtable }
  1383. end;
  1384. procedure twithsymtable.insertdef(def:TDefEntry);
  1385. begin
  1386. { Definitions can't be registered in the withsymtable
  1387. because the withsymtable is removed after the with block.
  1388. We can't easily solve it here because the next symtable in the
  1389. stack is not known. }
  1390. internalerror(200602046);
  1391. end;
  1392. {****************************************************************************
  1393. TSTT_ExceptionSymtable
  1394. ****************************************************************************}
  1395. constructor tstt_excepTSymtable.create;
  1396. begin
  1397. inherited create('');
  1398. symtabletype:=stt_excepTSymtable;
  1399. end;
  1400. {****************************************************************************
  1401. TMacroSymtable
  1402. ****************************************************************************}
  1403. constructor tmacrosymtable.create(exported: boolean);
  1404. begin
  1405. inherited create('');
  1406. if exported then
  1407. symtabletype:=exportedmacrosymtable
  1408. else
  1409. symtabletype:=localmacrosymtable;
  1410. symtablelevel:=main_program_level;
  1411. end;
  1412. {****************************************************************************
  1413. TEnumSymtable
  1414. ****************************************************************************}
  1415. procedure tenumsymtable.insert(sym: TSymEntry; checkdup: boolean);
  1416. var
  1417. value: longint;
  1418. def: tenumdef;
  1419. begin
  1420. // defowner = nil only when we are loading from ppu
  1421. if defowner<>nil then
  1422. begin
  1423. { First entry? Then we need to set the minval }
  1424. value:=tenumsym(sym).value;
  1425. def:=tenumdef(defowner);
  1426. if SymList.count=0 then
  1427. begin
  1428. if value>0 then
  1429. def.has_jumps:=true;
  1430. def.setmin(value);
  1431. def.setmax(value);
  1432. end
  1433. else
  1434. begin
  1435. { check for jumps }
  1436. if value>def.max+1 then
  1437. def.has_jumps:=true;
  1438. { update low and high }
  1439. if def.min>value then
  1440. def.setmin(value);
  1441. if def.max<value then
  1442. def.setmax(value);
  1443. end;
  1444. end;
  1445. inherited insert(sym, checkdup);
  1446. end;
  1447. constructor tenumsymtable.create(adefowner: tdef);
  1448. begin
  1449. inherited Create('');
  1450. symtabletype:=enumsymtable;
  1451. defowner:=adefowner;
  1452. end;
  1453. {****************************************************************************
  1454. TArraySymtable
  1455. ****************************************************************************}
  1456. procedure tarraysymtable.insertdef(def: TDefEntry);
  1457. begin
  1458. { Enums must also be available outside the record scope,
  1459. insert in the owner of this symtable }
  1460. if def.typ=enumdef then
  1461. defowner.owner.insertdef(def)
  1462. else
  1463. inherited insertdef(def);
  1464. end;
  1465. constructor tarraysymtable.create(adefowner: tdef);
  1466. begin
  1467. inherited Create('');
  1468. symtabletype:=arraysymtable;
  1469. defowner:=adefowner;
  1470. end;
  1471. {*****************************************************************************
  1472. Helper Routines
  1473. *****************************************************************************}
  1474. function FullTypeName(def,otherdef:tdef):string;
  1475. var
  1476. s1,s2 : string;
  1477. begin
  1478. if def.typ in [objectdef,recorddef] then
  1479. s1:=tabstractrecorddef(def).RttiName
  1480. else
  1481. s1:=def.typename;
  1482. { When the names are the same try to include the unit name }
  1483. if assigned(otherdef) and
  1484. (def.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1485. begin
  1486. s2:=otherdef.typename;
  1487. if upper(s1)=upper(s2) then
  1488. s1:=def.owner.realname^+'.'+s1;
  1489. end;
  1490. FullTypeName:=s1;
  1491. end;
  1492. function generate_nested_name(symtable:tsymtable;delimiter:string):string;
  1493. begin
  1494. result:='';
  1495. while assigned(symtable) and (symtable.symtabletype in [ObjectSymtable,recordsymtable]) do
  1496. begin
  1497. if (result='') then
  1498. result:=symtable.name^
  1499. else
  1500. result:=symtable.name^+delimiter+result;
  1501. symtable:=symtable.defowner.owner;
  1502. end;
  1503. end;
  1504. procedure incompatibletypes(def1,def2:tdef);
  1505. begin
  1506. { When there is an errordef there is already an error message show }
  1507. if (def2.typ=errordef) or
  1508. (def1.typ=errordef) then
  1509. exit;
  1510. CGMessage2(type_e_incompatible_types,FullTypeName(def1,def2),FullTypeName(def2,def1));
  1511. end;
  1512. procedure hidesym(sym:TSymEntry);
  1513. begin
  1514. sym.realname:='$hidden'+sym.realname;
  1515. tsym(sym).visibility:=vis_hidden;
  1516. end;
  1517. procedure duplicatesym(var hashedid:THashedIDString;dupsym,origsym:TSymEntry);
  1518. var
  1519. st : TSymtable;
  1520. begin
  1521. Message1(sym_e_duplicate_id,tsym(origsym).realname);
  1522. { Write hint where the original symbol was found }
  1523. st:=finduniTSymtable(origsym.owner);
  1524. with tsym(origsym).fileinfo do
  1525. begin
  1526. if assigned(st) and
  1527. (st.symtabletype=globalsymtable) and
  1528. st.iscurrentunit then
  1529. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line))
  1530. else if assigned(st.name) then
  1531. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line));
  1532. end;
  1533. { Rename duplicate sym to an unreachable name, but it can be
  1534. inserted in the symtable without errors }
  1535. inc(dupnr);
  1536. hashedid.id:='dup'+tostr(dupnr)+hashedid.id;
  1537. if assigned(dupsym) then
  1538. include(tsym(dupsym).symoptions,sp_implicitrename);
  1539. end;
  1540. {*****************************************************************************
  1541. Search
  1542. *****************************************************************************}
  1543. procedure addsymref(sym:tsym);
  1544. begin
  1545. { symbol uses count }
  1546. sym.IncRefCount;
  1547. { unit uses count }
  1548. if assigned(current_module) and
  1549. (sym.owner.symtabletype=globalsymtable) then
  1550. begin
  1551. if tglobalsymtable(sym.owner).moduleid>=current_module.unitmapsize then
  1552. internalerror(200501152);
  1553. inc(current_module.unitmap[tglobalsymtable(sym.owner).moduleid].refs);
  1554. end;
  1555. end;
  1556. function is_owned_by(childdef,ownerdef:tabstractrecorddef):boolean;
  1557. begin
  1558. result:=childdef=ownerdef;
  1559. if not result and (childdef.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  1560. result:=is_owned_by(tabstractrecorddef(childdef.owner.defowner),ownerdef);
  1561. end;
  1562. function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tabstractrecorddef):boolean;
  1563. var
  1564. symownerdef : tabstractrecorddef;
  1565. begin
  1566. result:=false;
  1567. { Get objdectdef owner of the symtable for the is_related checks }
  1568. if not assigned(symst) or
  1569. not (symst.symtabletype in [objectsymtable,recordsymtable]) then
  1570. internalerror(200810285);
  1571. symownerdef:=tabstractrecorddef(symst.defowner);
  1572. case symvisibility of
  1573. vis_private :
  1574. begin
  1575. { private symbols are allowed when we are in the same
  1576. module as they are defined }
  1577. result:=(
  1578. (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1579. (symownerdef.owner.iscurrentunit)
  1580. ) or
  1581. ( // the case of specialize inside the generic declaration
  1582. (symownerdef.owner.symtabletype = objectsymtable) and
  1583. (
  1584. assigned(current_structdef) and
  1585. (
  1586. (current_structdef=symownerdef) or
  1587. (current_structdef.owner.iscurrentunit)
  1588. )
  1589. ) or
  1590. (
  1591. not assigned(current_structdef) and
  1592. (symownerdef.owner.iscurrentunit)
  1593. )
  1594. );
  1595. end;
  1596. vis_strictprivate :
  1597. begin
  1598. result:=assigned(current_structdef) and
  1599. is_owned_by(current_structdef,symownerdef);
  1600. end;
  1601. vis_strictprotected :
  1602. begin
  1603. result:=(
  1604. assigned(current_structdef) and
  1605. (current_structdef.is_related(symownerdef) or
  1606. is_owned_by(current_structdef,symownerdef))
  1607. ) or
  1608. (
  1609. { helpers can access strict protected symbols }
  1610. is_objectpascal_helper(contextobjdef) and
  1611. tobjectdef(contextobjdef).extendeddef.is_related(symownerdef)
  1612. );
  1613. end;
  1614. vis_protected :
  1615. begin
  1616. { protected symbols are visible in the module that defines them and
  1617. also visible to related objects. The related object must be defined
  1618. in the current module }
  1619. result:=(
  1620. (
  1621. (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1622. (symownerdef.owner.iscurrentunit)
  1623. ) or
  1624. (
  1625. assigned(contextobjdef) and
  1626. (contextobjdef.owner.symtabletype in [globalsymtable,staticsymtable,ObjectSymtable]) and
  1627. (contextobjdef.owner.iscurrentunit) and
  1628. contextobjdef.is_related(symownerdef)
  1629. ) or
  1630. ( // the case of specialize inside the generic declaration
  1631. (symownerdef.owner.symtabletype = objectsymtable) and
  1632. (
  1633. assigned(current_structdef) and
  1634. (
  1635. (current_structdef=symownerdef) or
  1636. (current_structdef.owner.iscurrentunit)
  1637. )
  1638. ) or
  1639. (
  1640. not assigned(current_structdef) and
  1641. (symownerdef.owner.iscurrentunit)
  1642. ) or
  1643. (
  1644. { helpers can access protected symbols }
  1645. is_objectpascal_helper(contextobjdef) and
  1646. tobjectdef(contextobjdef).extendeddef.is_related(symownerdef)
  1647. )
  1648. )
  1649. );
  1650. end;
  1651. vis_public,
  1652. vis_published :
  1653. result:=true;
  1654. end;
  1655. end;
  1656. function is_visible_for_object(pd:tprocdef;contextobjdef:tabstractrecorddef):boolean;
  1657. begin
  1658. result:=is_visible_for_object(pd.owner,pd.visibility,contextobjdef);
  1659. end;
  1660. function is_visible_for_object(sym:tsym;contextobjdef:tabstractrecorddef):boolean;
  1661. var
  1662. i : longint;
  1663. pd : tprocdef;
  1664. begin
  1665. if sym.typ=procsym then
  1666. begin
  1667. { A procsym is visible, when there is at least one of the procdefs visible }
  1668. result:=false;
  1669. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  1670. begin
  1671. pd:=tprocdef(tprocsym(sym).ProcdefList[i]);
  1672. if (pd.owner=sym.owner) and
  1673. is_visible_for_object(pd,contextobjdef) then
  1674. begin
  1675. result:=true;
  1676. exit;
  1677. end;
  1678. end;
  1679. end
  1680. else
  1681. result:=is_visible_for_object(sym.owner,sym.visibility,contextobjdef);
  1682. end;
  1683. function searchsym(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1684. var
  1685. hashedid : THashedIDString;
  1686. contextstructdef : tabstractrecorddef;
  1687. stackitem : psymtablestackitem;
  1688. begin
  1689. result:=false;
  1690. hashedid.id:=s;
  1691. stackitem:=symtablestack.stack;
  1692. while assigned(stackitem) do
  1693. begin
  1694. srsymtable:=stackitem^.symtable;
  1695. if (srsymtable.symtabletype=objectsymtable) then
  1696. begin
  1697. if searchsym_in_class(tobjectdef(srsymtable.defowner),tobjectdef(srsymtable.defowner),s,srsym,srsymtable,true) then
  1698. begin
  1699. result:=true;
  1700. exit;
  1701. end;
  1702. end
  1703. else
  1704. begin
  1705. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1706. if assigned(srsym) then
  1707. begin
  1708. { use the class from withsymtable only when it is
  1709. defined in this unit }
  1710. if (srsymtable.symtabletype=withsymtable) and
  1711. assigned(srsymtable.defowner) and
  1712. (srsymtable.defowner.typ in [recorddef,objectdef]) and
  1713. (srsymtable.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1714. (srsymtable.defowner.owner.iscurrentunit) then
  1715. contextstructdef:=tabstractrecorddef(srsymtable.defowner)
  1716. else
  1717. contextstructdef:=current_structdef;
  1718. if not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or
  1719. is_visible_for_object(srsym,contextstructdef) then
  1720. begin
  1721. { we need to know if a procedure references symbols
  1722. in the static symtable, because then it can't be
  1723. inlined from outside this unit }
  1724. if assigned(current_procinfo) and
  1725. (srsym.owner.symtabletype=staticsymtable) then
  1726. include(current_procinfo.flags,pi_uses_static_symtable);
  1727. addsymref(srsym);
  1728. result:=true;
  1729. exit;
  1730. end;
  1731. end;
  1732. end;
  1733. stackitem:=stackitem^.next;
  1734. end;
  1735. srsym:=nil;
  1736. srsymtable:=nil;
  1737. end;
  1738. function searchsym_type(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1739. var
  1740. hashedid : THashedIDString;
  1741. stackitem : psymtablestackitem;
  1742. classh : tobjectdef;
  1743. begin
  1744. result:=false;
  1745. hashedid.id:=s;
  1746. stackitem:=symtablestack.stack;
  1747. while assigned(stackitem) do
  1748. begin
  1749. {
  1750. It is not possible to have type symbols in:
  1751. parameters
  1752. Exception are classes, objects, records, generic definitions and specializations
  1753. that have the parameterized types inserted in the symtable.
  1754. }
  1755. srsymtable:=stackitem^.symtable;
  1756. if (srsymtable.symtabletype=ObjectSymtable) then
  1757. begin
  1758. classh:=tobjectdef(srsymtable.defowner);
  1759. while assigned(classh) do
  1760. begin
  1761. srsymtable:=classh.symtable;
  1762. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1763. if assigned(srsym) and
  1764. not(srsym.typ in [fieldvarsym,paravarsym,propertysym,procsym,labelsym]) and
  1765. is_visible_for_object(srsym,current_structdef) then
  1766. begin
  1767. addsymref(srsym);
  1768. result:=true;
  1769. exit;
  1770. end;
  1771. classh:=classh.childof;
  1772. end;
  1773. end
  1774. else
  1775. begin
  1776. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1777. if assigned(srsym) and
  1778. not(srsym.typ in [fieldvarsym,paravarsym,propertysym,procsym,labelsym]) and
  1779. (not (srsym.owner.symtabletype in [objectsymtable,recordsymtable]) or is_visible_for_object(srsym,current_structdef)) then
  1780. begin
  1781. { we need to know if a procedure references symbols
  1782. in the static symtable, because then it can't be
  1783. inlined from outside this unit }
  1784. if assigned(current_procinfo) and
  1785. (srsym.owner.symtabletype=staticsymtable) then
  1786. include(current_procinfo.flags,pi_uses_static_symtable);
  1787. addsymref(srsym);
  1788. result:=true;
  1789. exit;
  1790. end;
  1791. end;
  1792. stackitem:=stackitem^.next;
  1793. end;
  1794. result:=false;
  1795. srsym:=nil;
  1796. srsymtable:=nil;
  1797. end;
  1798. function searchsym_in_module(pm:pointer;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1799. var
  1800. pmod : tmodule;
  1801. begin
  1802. pmod:=tmodule(pm);
  1803. result:=false;
  1804. if assigned(pmod.globalsymtable) then
  1805. begin
  1806. srsym:=tsym(pmod.globalsymtable.Find(s));
  1807. if assigned(srsym) then
  1808. begin
  1809. srsymtable:=pmod.globalsymtable;
  1810. addsymref(srsym);
  1811. result:=true;
  1812. exit;
  1813. end;
  1814. end;
  1815. { If the module is the current unit we also need
  1816. to search the local symtable }
  1817. if (pmod=current_module) and
  1818. assigned(pmod.localsymtable) then
  1819. begin
  1820. srsym:=tsym(pmod.localsymtable.Find(s));
  1821. if assigned(srsym) then
  1822. begin
  1823. srsymtable:=pmod.localsymtable;
  1824. addsymref(srsym);
  1825. result:=true;
  1826. exit;
  1827. end;
  1828. end;
  1829. srsym:=nil;
  1830. srsymtable:=nil;
  1831. end;
  1832. function searchsym_in_named_module(const unitname, symname: TIDString; out srsym: tsym; out srsymtable: tsymtable): boolean;
  1833. var
  1834. stackitem : psymtablestackitem;
  1835. begin
  1836. result:=false;
  1837. stackitem:=symtablestack.stack;
  1838. while assigned(stackitem) do
  1839. begin
  1840. srsymtable:=stackitem^.symtable;
  1841. if (srsymtable.symtabletype=globalsymtable) and
  1842. (srsymtable.name^=unitname) then
  1843. begin
  1844. srsym:=tsym(srsymtable.find(symname));
  1845. if not assigned(srsym) then
  1846. break;
  1847. result:=true;
  1848. exit;
  1849. end;
  1850. stackitem:=stackitem^.next;
  1851. end;
  1852. { If the module is the current unit we also need
  1853. to search the local symtable }
  1854. if (current_module.globalsymtable=srsymtable) and
  1855. assigned(current_module.localsymtable) then
  1856. begin
  1857. srsymtable:=current_module.localsymtable;
  1858. srsym:=tsym(srsymtable.find(symname));
  1859. if assigned(srsym) then
  1860. begin
  1861. result:=true;
  1862. exit;
  1863. end;
  1864. end;
  1865. end;
  1866. function find_real_objcclass_definition(pd: tobjectdef; erroronfailure: boolean): tobjectdef;
  1867. var
  1868. hashedid : THashedIDString;
  1869. stackitem : psymtablestackitem;
  1870. srsymtable : tsymtable;
  1871. srsym : tsym;
  1872. begin
  1873. { not a formal definition -> return it }
  1874. if not(oo_is_formal in pd.objectoptions) then
  1875. begin
  1876. result:=pd;
  1877. exit;
  1878. end;
  1879. hashedid.id:=pd.typesym.name;
  1880. stackitem:=symtablestack.stack;
  1881. while assigned(stackitem) do
  1882. begin
  1883. srsymtable:=stackitem^.symtable;
  1884. { ObjC classes can't appear in generics or as nested class
  1885. definitions }
  1886. if not(srsymtable.symtabletype in [recordsymtable,ObjectSymtable,parasymtable]) then
  1887. begin
  1888. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1889. if assigned(srsym) and
  1890. (srsym.typ=typesym) and
  1891. is_objcclass(ttypesym(srsym).typedef) and
  1892. not(oo_is_formal in tobjectdef(ttypesym(srsym).typedef).objectoptions) then
  1893. begin
  1894. { the external name for the formal and the real definition must match }
  1895. if tobjectdef(ttypesym(srsym).typedef).objextname^<>pd.objextname^ then
  1896. begin
  1897. Message2(sym_e_external_class_name_mismatch1,pd.objextname^,pd.typename);
  1898. MessagePos1(srsym.fileinfo,sym_e_external_class_name_mismatch2,tobjectdef(ttypesym(srsym).typedef).objextname^);
  1899. end;
  1900. result:=tobjectdef(ttypesym(srsym).typedef);
  1901. if assigned(current_procinfo) and
  1902. (srsym.owner.symtabletype=staticsymtable) then
  1903. include(current_procinfo.flags,pi_uses_static_symtable);
  1904. addsymref(srsym);
  1905. exit;
  1906. end;
  1907. end;
  1908. stackitem:=stackitem^.next;
  1909. end;
  1910. { nothing found: optionally give an error and return the original
  1911. (empty) one }
  1912. if erroronfailure then
  1913. Message1(sym_e_objc_formal_class_not_resolved,pd.objrealname^);
  1914. result:=pd;
  1915. end;
  1916. function searchsym_in_class(classh,contextclassh:tobjectdef;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable;searchhelper:boolean):boolean;
  1917. var
  1918. hashedid : THashedIDString;
  1919. orgclass : tobjectdef;
  1920. i : longint;
  1921. begin
  1922. orgclass:=classh;
  1923. { in case this is a formal objcclass, first find the real definition }
  1924. if assigned(classh) then
  1925. begin
  1926. if (oo_is_formal in classh.objectoptions) then
  1927. classh:=find_real_objcclass_definition(classh,true);
  1928. { The contextclassh is used for visibility. The classh must be equal to
  1929. or be a parent of contextclassh. E.g. for inherited searches the classh is the
  1930. parent or a class helper. }
  1931. if not (contextclassh.is_related(classh) or
  1932. (assigned(contextclassh.extendeddef) and
  1933. (contextclassh.extendeddef.typ=objectdef) and
  1934. contextclassh.extendeddef.is_related(classh))) then
  1935. internalerror(200811161);
  1936. end;
  1937. result:=false;
  1938. hashedid.id:=s;
  1939. { an Objective-C protocol can inherit from multiple other protocols
  1940. -> uses ImplementedInterfaces instead }
  1941. if is_objcprotocol(classh) then
  1942. begin
  1943. srsymtable:=classh.symtable;
  1944. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1945. if assigned(srsym) and
  1946. is_visible_for_object(srsym,contextclassh) then
  1947. begin
  1948. addsymref(srsym);
  1949. result:=true;
  1950. exit;
  1951. end;
  1952. for i:=0 to classh.ImplementedInterfaces.count-1 do
  1953. begin
  1954. if searchsym_in_class(TImplementedInterface(classh.ImplementedInterfaces[i]).intfdef,contextclassh,s,srsym,srsymtable,false) then
  1955. begin
  1956. result:=true;
  1957. exit;
  1958. end;
  1959. end;
  1960. end
  1961. else
  1962. if is_objectpascal_helper(classh) then
  1963. begin
  1964. { helpers have their own obscure search logic... }
  1965. result:=searchsym_in_helper(classh,contextclassh,s,srsym,srsymtable,false);
  1966. if result then
  1967. exit;
  1968. end
  1969. else
  1970. begin
  1971. while assigned(classh) do
  1972. begin
  1973. { search for a class helper method first if this is an Object
  1974. Pascal class }
  1975. if is_class(classh) and searchhelper then
  1976. begin
  1977. result:=search_objectpascal_helper(classh,contextclassh,s,srsym,srsymtable);
  1978. if result then
  1979. { if the procsym is overloaded we need to use the
  1980. "original" symbol; the helper symbol will be found when
  1981. searching for overloads }
  1982. if (srsym.typ<>procsym) or
  1983. not (sp_has_overloaded in tprocsym(srsym).symoptions) then
  1984. exit;
  1985. end;
  1986. srsymtable:=classh.symtable;
  1987. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1988. if assigned(srsym) and
  1989. is_visible_for_object(srsym,contextclassh) then
  1990. begin
  1991. addsymref(srsym);
  1992. result:=true;
  1993. exit;
  1994. end;
  1995. classh:=classh.childof;
  1996. end;
  1997. end;
  1998. if is_objcclass(orgclass) then
  1999. result:=search_objc_helper(orgclass,s,srsym,srsymtable)
  2000. else
  2001. begin
  2002. srsym:=nil;
  2003. srsymtable:=nil;
  2004. end;
  2005. end;
  2006. function searchsym_in_record(recordh:tabstractrecorddef;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  2007. var
  2008. hashedid : THashedIDString;
  2009. begin
  2010. result:=false;
  2011. hashedid.id:=s;
  2012. { search for a record helper method first }
  2013. result:=search_objectpascal_helper(recordh,recordh,s,srsym,srsymtable);
  2014. if result then
  2015. { if the procsym is overloaded we need to use the
  2016. "original" symbol; the helper symbol will be found when
  2017. searching for overloads }
  2018. if (srsym.typ<>procsym) or
  2019. not (sp_has_overloaded in tprocsym(srsym).symoptions) then
  2020. exit;
  2021. srsymtable:=recordh.symtable;
  2022. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2023. if assigned(srsym) and is_visible_for_object(srsym,recordh) then
  2024. begin
  2025. addsymref(srsym);
  2026. result:=true;
  2027. exit;
  2028. end;
  2029. srsym:=nil;
  2030. srsymtable:=nil;
  2031. end;
  2032. function searchsym_in_class_by_msgint(classh:tobjectdef;msgid:longint;out srdef : tdef;out srsym:tsym;out srsymtable:TSymtable):boolean;
  2033. var
  2034. def : tdef;
  2035. i : longint;
  2036. begin
  2037. { in case this is a formal objcclass, first find the real definition }
  2038. if assigned(classh) and
  2039. (oo_is_formal in classh.objectoptions) then
  2040. classh:=find_real_objcclass_definition(classh,true);
  2041. result:=false;
  2042. def:=nil;
  2043. while assigned(classh) do
  2044. begin
  2045. for i:=0 to classh.symtable.DefList.Count-1 do
  2046. begin
  2047. def:=tstoreddef(classh.symtable.DefList[i]);
  2048. { Find also all hidden private methods to
  2049. be compatible with delphi, see tw6203 (PFV) }
  2050. if (def.typ=procdef) and
  2051. (po_msgint in tprocdef(def).procoptions) and
  2052. (tprocdef(def).messageinf.i=msgid) then
  2053. begin
  2054. srdef:=def;
  2055. srsym:=tprocdef(def).procsym;
  2056. srsymtable:=classh.symtable;
  2057. addsymref(srsym);
  2058. result:=true;
  2059. exit;
  2060. end;
  2061. end;
  2062. classh:=classh.childof;
  2063. end;
  2064. srdef:=nil;
  2065. srsym:=nil;
  2066. srsymtable:=nil;
  2067. end;
  2068. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string;out srsym:tsym;out srsymtable:TSymtable):boolean;
  2069. var
  2070. def : tdef;
  2071. i : longint;
  2072. begin
  2073. { in case this is a formal objcclass, first find the real definition }
  2074. if assigned(classh) and
  2075. (oo_is_formal in classh.objectoptions) then
  2076. classh:=find_real_objcclass_definition(classh,true);
  2077. result:=false;
  2078. def:=nil;
  2079. while assigned(classh) do
  2080. begin
  2081. for i:=0 to classh.symtable.DefList.Count-1 do
  2082. begin
  2083. def:=tstoreddef(classh.symtable.DefList[i]);
  2084. { Find also all hidden private methods to
  2085. be compatible with delphi, see tw6203 (PFV) }
  2086. if (def.typ=procdef) and
  2087. (po_msgstr in tprocdef(def).procoptions) and
  2088. (tprocdef(def).messageinf.str^=s) then
  2089. begin
  2090. srsym:=tprocdef(def).procsym;
  2091. srsymtable:=classh.symtable;
  2092. addsymref(srsym);
  2093. result:=true;
  2094. exit;
  2095. end;
  2096. end;
  2097. classh:=classh.childof;
  2098. end;
  2099. srsym:=nil;
  2100. srsymtable:=nil;
  2101. end;
  2102. function searchsym_in_helper(classh,contextclassh:tobjectdef;const s: TIDString;out srsym:tsym;out srsymtable:TSymtable;aHasInherited:boolean):boolean;
  2103. var
  2104. hashedid : THashedIDString;
  2105. parentclassh : tobjectdef;
  2106. begin
  2107. result:=false;
  2108. if not is_objectpascal_helper(classh) then
  2109. Internalerror(2011030101);
  2110. hashedid.id:=s;
  2111. { in a helper things are a bit more complex:
  2112. 1. search the symbol in the helper (if not "inherited")
  2113. 2. search the symbol in the extended type
  2114. 3. search the symbol in the parent helpers
  2115. 4. only classes: search the symbol in the parents of the extended type
  2116. }
  2117. if not aHasInherited then
  2118. begin
  2119. { search in the helper itself }
  2120. srsymtable:=classh.symtable;
  2121. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2122. if assigned(srsym) and
  2123. is_visible_for_object(srsym,contextclassh) then
  2124. begin
  2125. addsymref(srsym);
  2126. result:=true;
  2127. exit;
  2128. end;
  2129. end;
  2130. { now search in the extended type itself }
  2131. srsymtable:=classh.extendeddef.symtable;
  2132. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2133. if assigned(srsym) and
  2134. is_visible_for_object(srsym,contextclassh) then
  2135. begin
  2136. addsymref(srsym);
  2137. result:=true;
  2138. exit;
  2139. end;
  2140. { now search in the parent helpers }
  2141. parentclassh:=classh.childof;
  2142. while assigned(parentclassh) do
  2143. begin
  2144. srsymtable:=parentclassh.symtable;
  2145. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2146. if assigned(srsym) and
  2147. is_visible_for_object(srsym,contextclassh) then
  2148. begin
  2149. addsymref(srsym);
  2150. result:=true;
  2151. exit;
  2152. end;
  2153. parentclassh:=parentclassh.childof;
  2154. end;
  2155. if is_class(classh.extendeddef) then
  2156. { now search in the parents of the extended class (with helpers!) }
  2157. result:=searchsym_in_class(tobjectdef(classh.extendeddef).childof,contextclassh,s,srsym,srsymtable,true);
  2158. { addsymref is already called by searchsym_in_class }
  2159. end;
  2160. function search_specific_assignment_operator(assignment_type:ttoken;from_def,to_def:Tdef):Tprocdef;
  2161. var
  2162. sym : Tprocsym;
  2163. hashedid : THashedIDString;
  2164. curreq,
  2165. besteq : tequaltype;
  2166. currpd,
  2167. bestpd : tprocdef;
  2168. stackitem : psymtablestackitem;
  2169. begin
  2170. hashedid.id:=overloaded_names[assignment_type];
  2171. besteq:=te_incompatible;
  2172. bestpd:=nil;
  2173. stackitem:=symtablestack.stack;
  2174. while assigned(stackitem) do
  2175. begin
  2176. sym:=Tprocsym(stackitem^.symtable.FindWithHash(hashedid));
  2177. if sym<>nil then
  2178. begin
  2179. if sym.typ<>procsym then
  2180. internalerror(200402031);
  2181. { if the source type is an alias then this is only the second choice,
  2182. if you mess with this code, check tw4093 }
  2183. currpd:=sym.find_procdef_assignment_operator(from_def,to_def,curreq);
  2184. if curreq>besteq then
  2185. begin
  2186. besteq:=curreq;
  2187. bestpd:=currpd;
  2188. if (besteq=te_exact) then
  2189. break;
  2190. end;
  2191. end;
  2192. stackitem:=stackitem^.next;
  2193. end;
  2194. result:=bestpd;
  2195. end;
  2196. function search_assignment_operator(from_def,to_def:Tdef;explicit:boolean):Tprocdef;
  2197. begin
  2198. { search record/object symtable first for a suitable operator }
  2199. if from_def.typ in [recorddef,objectdef] then
  2200. symtablestack.push(tabstractrecorddef(from_def).symtable);
  2201. if to_def.typ in [recorddef,objectdef] then
  2202. symtablestack.push(tabstractrecorddef(to_def).symtable);
  2203. { if type conversion is explicit then search first for explicit
  2204. operator overload and if not found then use implicit operator }
  2205. if explicit then
  2206. result:=search_specific_assignment_operator(_OP_EXPLICIT,from_def,to_def)
  2207. else
  2208. result:=nil;
  2209. if result=nil then
  2210. result:=search_specific_assignment_operator(_ASSIGNMENT,from_def,to_def);
  2211. { restore symtable stack }
  2212. if to_def.typ in [recorddef,objectdef] then
  2213. symtablestack.pop(tabstractrecorddef(to_def).symtable);
  2214. if from_def.typ in [recorddef,objectdef] then
  2215. symtablestack.pop(tabstractrecorddef(from_def).symtable);
  2216. end;
  2217. function search_enumerator_operator(from_def,to_def:Tdef): Tprocdef;
  2218. var
  2219. sym : Tprocsym;
  2220. hashedid : THashedIDString;
  2221. curreq,
  2222. besteq : tequaltype;
  2223. currpd,
  2224. bestpd : tprocdef;
  2225. stackitem : psymtablestackitem;
  2226. begin
  2227. hashedid.id:='enumerator';
  2228. besteq:=te_incompatible;
  2229. bestpd:=nil;
  2230. stackitem:=symtablestack.stack;
  2231. while assigned(stackitem) do
  2232. begin
  2233. sym:=Tprocsym(stackitem^.symtable.FindWithHash(hashedid));
  2234. if sym<>nil then
  2235. begin
  2236. if sym.typ<>procsym then
  2237. internalerror(200910241);
  2238. { if the source type is an alias then this is only the second choice,
  2239. if you mess with this code, check tw4093 }
  2240. currpd:=sym.find_procdef_enumerator_operator(from_def,to_def,curreq);
  2241. if curreq>besteq then
  2242. begin
  2243. besteq:=curreq;
  2244. bestpd:=currpd;
  2245. if (besteq=te_exact) then
  2246. break;
  2247. end;
  2248. end;
  2249. stackitem:=stackitem^.next;
  2250. end;
  2251. result:=bestpd;
  2252. end;
  2253. function search_system_type(const s: TIDString): ttypesym;
  2254. var
  2255. sym : tsym;
  2256. begin
  2257. sym:=tsym(systemunit.Find(s));
  2258. if not assigned(sym) or
  2259. (sym.typ<>typesym) then
  2260. cgmessage1(cg_f_unknown_system_type,s);
  2261. result:=ttypesym(sym);
  2262. end;
  2263. function try_search_system_type(const s: TIDString): ttypesym;
  2264. var
  2265. sym : tsym;
  2266. begin
  2267. sym:=tsym(systemunit.Find(s));
  2268. if not assigned(sym) then
  2269. result:=nil
  2270. else
  2271. begin
  2272. if sym.typ<>typesym then
  2273. cgmessage1(cg_f_unknown_system_type,s);
  2274. result:=ttypesym(sym);
  2275. end;
  2276. end;
  2277. function search_named_unit_globaltype(const unitname, typename: TIDString; throwerror: boolean): ttypesym;
  2278. var
  2279. srsymtable: tsymtable;
  2280. sym: tsym;
  2281. begin
  2282. if searchsym_in_named_module(unitname,typename,sym,srsymtable) and
  2283. (sym.typ=typesym) then
  2284. begin
  2285. result:=ttypesym(sym);
  2286. exit;
  2287. end
  2288. else
  2289. begin
  2290. if throwerror then
  2291. cgmessage2(cg_f_unknown_type_in_unit,typename,unitname);
  2292. result:=nil;
  2293. end;
  2294. end;
  2295. function search_last_objectpascal_helper(pd,contextclassh : tabstractrecorddef;out odef : tobjectdef):boolean;
  2296. var
  2297. s: string;
  2298. list: TFPObjectList;
  2299. i: integer;
  2300. st: tsymtable;
  2301. begin
  2302. result:=false;
  2303. odef:=nil;
  2304. { when there are no helpers active currently then we don't need to do
  2305. anything }
  2306. if current_module.extendeddefs.count=0 then
  2307. exit;
  2308. { no helpers for anonymous types }
  2309. if not assigned(pd.objrealname) or (pd.objrealname^='') then
  2310. exit;
  2311. { if pd is defined inside a procedure we must not use make_mangledname
  2312. (as a helper may not be defined in a procedure this is no problem...)}
  2313. st:=pd.owner;
  2314. while st.symtabletype in [objectsymtable,recordsymtable] do
  2315. st:=st.defowner.owner;
  2316. if st.symtabletype=localsymtable then
  2317. exit;
  2318. { the mangled name is used as the key for tmodule.extendeddefs }
  2319. s:=make_mangledname('',pd.symtable,'');
  2320. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  2321. if assigned(list) and (list.count>0) then
  2322. begin
  2323. i:=list.count-1;
  2324. repeat
  2325. odef:=tobjectdef(list[list.count-1]);
  2326. result:=(odef.owner.symtabletype in [staticsymtable,globalsymtable]) or
  2327. is_visible_for_object(tobjectdef(list[i]).typesym,contextclassh);
  2328. dec(i);
  2329. until result or (i<0);
  2330. if not result then
  2331. { just to be sure that noone uses odef }
  2332. odef:=nil;
  2333. end;
  2334. end;
  2335. function search_objectpascal_helper(pd,contextclassh : tabstractrecorddef;const s: string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  2336. var
  2337. hashedid : THashedIDString;
  2338. classh : tobjectdef;
  2339. i : integer;
  2340. pdef : tprocdef;
  2341. begin
  2342. result:=false;
  2343. { if there is no class helper for the class then there is no need to
  2344. search further }
  2345. if not search_last_objectpascal_helper(pd,contextclassh,classh) then
  2346. exit;
  2347. hashedid.id:=s;
  2348. repeat
  2349. srsymtable:=classh.symtable;
  2350. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2351. if srsym<>nil then
  2352. begin
  2353. if srsym.typ=propertysym then
  2354. begin
  2355. result:=true;
  2356. exit;
  2357. end;
  2358. for i:=0 to tprocsym(srsym).procdeflist.count-1 do
  2359. begin
  2360. pdef:=tprocdef(tprocsym(srsym).procdeflist[i]);
  2361. if not is_visible_for_object(pdef.owner,pdef.visibility,contextclassh) then
  2362. continue;
  2363. { we need to know if a procedure references symbols
  2364. in the static symtable, because then it can't be
  2365. inlined from outside this unit }
  2366. if assigned(current_procinfo) and
  2367. (srsym.owner.symtabletype=staticsymtable) then
  2368. include(current_procinfo.flags,pi_uses_static_symtable);
  2369. { the first found method wins }
  2370. srsym:=tprocdef(tprocsym(srsym).procdeflist[i]).procsym;
  2371. srsymtable:=srsym.owner;
  2372. addsymref(srsym);
  2373. result:=true;
  2374. exit;
  2375. end;
  2376. end;
  2377. { try the helper parent if available }
  2378. classh:=classh.childof;
  2379. until classh=nil;
  2380. srsym:=nil;
  2381. srsymtable:=nil;
  2382. end;
  2383. function search_objc_helper(pd : tobjectdef;const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  2384. var
  2385. hashedid : THashedIDString;
  2386. stackitem : psymtablestackitem;
  2387. i : longint;
  2388. defowner : tobjectdef;
  2389. begin
  2390. hashedid.id:=class_helper_prefix+s;
  2391. stackitem:=symtablestack.stack;
  2392. while assigned(stackitem) do
  2393. begin
  2394. srsymtable:=stackitem^.symtable;
  2395. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2396. if assigned(srsym) then
  2397. begin
  2398. if not(srsymtable.symtabletype in [globalsymtable,staticsymtable]) or
  2399. not(srsym.owner.symtabletype in [globalsymtable,staticsymtable]) or
  2400. (srsym.typ<>procsym) then
  2401. internalerror(2009111505);
  2402. { check whether this procsym includes a helper for this particular class }
  2403. for i:=0 to tprocsym(srsym).procdeflist.count-1 do
  2404. begin
  2405. { does pd inherit from (or is the same as) the class
  2406. that this method's category extended?
  2407. Warning: this list contains both category and objcclass methods
  2408. (for id.randommethod), so only check category methods here
  2409. }
  2410. defowner:=tobjectdef(tprocdef(tprocsym(srsym).procdeflist[i]).owner.defowner);
  2411. if (oo_is_classhelper in defowner.objectoptions) and
  2412. pd.is_related(defowner.childof) then
  2413. begin
  2414. { we need to know if a procedure references symbols
  2415. in the static symtable, because then it can't be
  2416. inlined from outside this unit }
  2417. if assigned(current_procinfo) and
  2418. (srsym.owner.symtabletype=staticsymtable) then
  2419. include(current_procinfo.flags,pi_uses_static_symtable);
  2420. { no need to keep looking. There might be other
  2421. categories that extend this, a parent or child
  2422. class with a method with the same name (either
  2423. overriding this one, or overridden by this one),
  2424. but that doesn't matter as far as the basic
  2425. procsym is concerned.
  2426. }
  2427. srsym:=tprocdef(tprocsym(srsym).procdeflist[i]).procsym;
  2428. srsymtable:=srsym.owner;
  2429. addsymref(srsym);
  2430. result:=true;
  2431. exit;
  2432. end;
  2433. end;
  2434. end;
  2435. stackitem:=stackitem^.next;
  2436. end;
  2437. srsym:=nil;
  2438. srsymtable:=nil;
  2439. result:=false;
  2440. end;
  2441. function search_objc_method(const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  2442. var
  2443. hashedid : THashedIDString;
  2444. stackitem : psymtablestackitem;
  2445. i : longint;
  2446. begin
  2447. hashedid.id:=class_helper_prefix+s;
  2448. stackitem:=symtablestack.stack;
  2449. while assigned(stackitem) do
  2450. begin
  2451. srsymtable:=stackitem^.symtable;
  2452. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  2453. if assigned(srsym) then
  2454. begin
  2455. if not(srsymtable.symtabletype in [globalsymtable,staticsymtable]) or
  2456. not(srsym.owner.symtabletype in [globalsymtable,staticsymtable]) or
  2457. (srsym.typ<>procsym) then
  2458. internalerror(2009112005);
  2459. { check whether this procsym includes a helper for this particular class }
  2460. for i:=0 to tprocsym(srsym).procdeflist.count-1 do
  2461. begin
  2462. { we need to know if a procedure references symbols
  2463. in the static symtable, because then it can't be
  2464. inlined from outside this unit }
  2465. if assigned(current_procinfo) and
  2466. (srsym.owner.symtabletype=staticsymtable) then
  2467. include(current_procinfo.flags,pi_uses_static_symtable);
  2468. { no need to keep looking. There might be other
  2469. methods with the same name, but that doesn't matter
  2470. as far as the basic procsym is concerned.
  2471. }
  2472. srsym:=tprocdef(tprocsym(srsym).procdeflist[i]).procsym;
  2473. { We need the symtable in which the classhelper-like sym
  2474. is located, not the objectdef. The reason is that the
  2475. callnode will climb the symtablestack until it encounters
  2476. this symtable to start looking for overloads (and it won't
  2477. find the objectsymtable in which this method sym is
  2478. located
  2479. srsymtable:=srsym.owner;
  2480. }
  2481. addsymref(srsym);
  2482. result:=true;
  2483. exit;
  2484. end;
  2485. end;
  2486. stackitem:=stackitem^.next;
  2487. end;
  2488. srsym:=nil;
  2489. srsymtable:=nil;
  2490. result:=false;
  2491. end;
  2492. function search_struct_member(pd : tabstractrecorddef;const s : string):tsym;
  2493. { searches n in symtable of pd and all anchestors }
  2494. var
  2495. hashedid : THashedIDString;
  2496. srsym : tsym;
  2497. orgpd : tabstractrecorddef;
  2498. srsymtable : tsymtable;
  2499. begin
  2500. { in case this is a formal objcclass, first find the real definition }
  2501. if (oo_is_formal in pd.objectoptions) then
  2502. pd:=find_real_objcclass_definition(tobjectdef(pd),true);
  2503. if search_objectpascal_helper(pd, pd, s, result, srsymtable) then
  2504. exit;
  2505. hashedid.id:=s;
  2506. orgpd:=pd;
  2507. while assigned(pd) do
  2508. begin
  2509. srsym:=tsym(pd.symtable.FindWithHash(hashedid));
  2510. if assigned(srsym) then
  2511. begin
  2512. search_struct_member:=srsym;
  2513. exit;
  2514. end;
  2515. if pd.typ=objectdef then
  2516. pd:=tobjectdef(pd).childof
  2517. else
  2518. pd:=nil;
  2519. end;
  2520. { not found, now look for class helpers }
  2521. if is_objcclass(pd) then
  2522. search_objc_helper(tobjectdef(orgpd),s,result,srsymtable)
  2523. else
  2524. result:=nil;
  2525. end;
  2526. function search_macro(const s : string):tsym;
  2527. var
  2528. stackitem : psymtablestackitem;
  2529. hashedid : THashedIDString;
  2530. srsym : tsym;
  2531. begin
  2532. hashedid.id:=s;
  2533. { First search the localmacrosymtable before searching the
  2534. global macrosymtables from the units }
  2535. if assigned(current_module) then
  2536. begin
  2537. srsym:=tsym(current_module.localmacrosymtable.FindWithHash(hashedid));
  2538. if assigned(srsym) then
  2539. begin
  2540. result:= srsym;
  2541. exit;
  2542. end;
  2543. end;
  2544. stackitem:=macrosymtablestack.stack;
  2545. while assigned(stackitem) do
  2546. begin
  2547. srsym:=tsym(stackitem^.symtable.FindWithHash(hashedid));
  2548. if assigned(srsym) then
  2549. begin
  2550. result:= srsym;
  2551. exit;
  2552. end;
  2553. stackitem:=stackitem^.next;
  2554. end;
  2555. result:= nil;
  2556. end;
  2557. function defined_macro(const s : string):boolean;
  2558. var
  2559. mac: tmacro;
  2560. begin
  2561. mac:=tmacro(search_macro(s));
  2562. if assigned(mac) then
  2563. begin
  2564. mac.is_used:=true;
  2565. defined_macro:=mac.defined;
  2566. end
  2567. else
  2568. defined_macro:=false;
  2569. end;
  2570. {****************************************************************************
  2571. Object Helpers
  2572. ****************************************************************************}
  2573. function search_default_property(pd : tabstractrecorddef) : tpropertysym;
  2574. { returns the default property of a class, searches also anchestors }
  2575. var
  2576. _defaultprop : tpropertysym;
  2577. helperpd : tobjectdef;
  2578. begin
  2579. _defaultprop:=nil;
  2580. { first search in helper's hierarchy }
  2581. if search_last_objectpascal_helper(pd,nil,helperpd) then
  2582. while assigned(helperpd) do
  2583. begin
  2584. helperpd.symtable.SymList.ForEachCall(@tstoredsymtable(helperpd.symtable).testfordefaultproperty,@_defaultprop);
  2585. if assigned(_defaultprop) then
  2586. break;
  2587. helperpd:=helperpd.childof;
  2588. end;
  2589. if assigned(_defaultprop) then
  2590. begin
  2591. search_default_property:=_defaultprop;
  2592. exit;
  2593. end;
  2594. { now search in the type's hierarchy itself }
  2595. while assigned(pd) do
  2596. begin
  2597. pd.symtable.SymList.ForEachCall(@tstoredsymtable(pd.symtable).testfordefaultproperty,@_defaultprop);
  2598. if assigned(_defaultprop) then
  2599. break;
  2600. if (pd.typ=objectdef) then
  2601. pd:=tobjectdef(pd).childof
  2602. else
  2603. break;
  2604. end;
  2605. search_default_property:=_defaultprop;
  2606. end;
  2607. {****************************************************************************
  2608. Macro Helpers
  2609. ****************************************************************************}
  2610. procedure def_system_macro(const name : string);
  2611. var
  2612. mac : tmacro;
  2613. s: string;
  2614. begin
  2615. if name = '' then
  2616. internalerror(2004121202);
  2617. s:= upper(name);
  2618. mac:=tmacro(search_macro(s));
  2619. if not assigned(mac) then
  2620. begin
  2621. mac:=tmacro.create(s);
  2622. if assigned(current_module) then
  2623. current_module.localmacrosymtable.insert(mac)
  2624. else
  2625. initialmacrosymtable.insert(mac);
  2626. end;
  2627. Message1(parser_c_macro_defined,mac.name);
  2628. mac.defined:=true;
  2629. end;
  2630. procedure set_system_macro(const name, value : string);
  2631. var
  2632. mac : tmacro;
  2633. s: string;
  2634. begin
  2635. if name = '' then
  2636. internalerror(2004121203);
  2637. s:= upper(name);
  2638. mac:=tmacro(search_macro(s));
  2639. if not assigned(mac) then
  2640. begin
  2641. mac:=tmacro.create(s);
  2642. if assigned(current_module) then
  2643. current_module.localmacrosymtable.insert(mac)
  2644. else
  2645. initialmacrosymtable.insert(mac);
  2646. end
  2647. else
  2648. begin
  2649. mac.is_compiler_var:=false;
  2650. if assigned(mac.buftext) then
  2651. freemem(mac.buftext,mac.buflen);
  2652. end;
  2653. Message2(parser_c_macro_set_to,mac.name,value);
  2654. mac.buflen:=length(value);
  2655. getmem(mac.buftext,mac.buflen);
  2656. move(value[1],mac.buftext^,mac.buflen);
  2657. mac.defined:=true;
  2658. end;
  2659. procedure set_system_compvar(const name, value : string);
  2660. var
  2661. mac : tmacro;
  2662. s: string;
  2663. begin
  2664. if name = '' then
  2665. internalerror(2004121204);
  2666. s:= upper(name);
  2667. mac:=tmacro(search_macro(s));
  2668. if not assigned(mac) then
  2669. begin
  2670. mac:=tmacro.create(s);
  2671. mac.is_compiler_var:=true;
  2672. if assigned(current_module) then
  2673. current_module.localmacrosymtable.insert(mac)
  2674. else
  2675. initialmacrosymtable.insert(mac);
  2676. end
  2677. else
  2678. begin
  2679. mac.is_compiler_var:=true;
  2680. if assigned(mac.buftext) then
  2681. freemem(mac.buftext,mac.buflen);
  2682. end;
  2683. Message2(parser_c_macro_set_to,mac.name,value);
  2684. mac.buflen:=length(value);
  2685. getmem(mac.buftext,mac.buflen);
  2686. move(value[1],mac.buftext^,mac.buflen);
  2687. mac.defined:=true;
  2688. end;
  2689. procedure undef_system_macro(const name : string);
  2690. var
  2691. mac : tmacro;
  2692. s: string;
  2693. begin
  2694. if name = '' then
  2695. internalerror(2004121205);
  2696. s:= upper(name);
  2697. mac:=tmacro(search_macro(s));
  2698. if not assigned(mac) then
  2699. {If not found, then it's already undefined.}
  2700. else
  2701. begin
  2702. Message1(parser_c_macro_undefined,mac.name);
  2703. mac.defined:=false;
  2704. mac.is_compiler_var:=false;
  2705. { delete old definition }
  2706. if assigned(mac.buftext) then
  2707. begin
  2708. freemem(mac.buftext,mac.buflen);
  2709. mac.buftext:=nil;
  2710. end;
  2711. end;
  2712. end;
  2713. {$ifdef UNITALIASES}
  2714. {****************************************************************************
  2715. TUNIT_ALIAS
  2716. ****************************************************************************}
  2717. constructor tunit_alias.create(const n:string);
  2718. var
  2719. i : longint;
  2720. begin
  2721. i:=pos('=',n);
  2722. if i=0 then
  2723. fail;
  2724. inherited createname(Copy(n,1,i-1));
  2725. newname:=stringdup(Copy(n,i+1,255));
  2726. end;
  2727. destructor tunit_alias.destroy;
  2728. begin
  2729. stringdispose(newname);
  2730. inherited destroy;
  2731. end;
  2732. procedure addunitalias(const n:string);
  2733. begin
  2734. unitaliases^.insert(tunit_alias,init(Upper(n))));
  2735. end;
  2736. function getunitalias(const n:string):string;
  2737. var
  2738. p : punit_alias;
  2739. begin
  2740. p:=punit_alias(unitaliases^.Find(Upper(n)));
  2741. if assigned(p) then
  2742. getunitalias:=punit_alias(p).newname^
  2743. else
  2744. getunitalias:=n;
  2745. end;
  2746. {$endif UNITALIASES}
  2747. {****************************************************************************
  2748. Init/Done Symtable
  2749. ****************************************************************************}
  2750. procedure InitSymtable;
  2751. begin
  2752. { Reset symbolstack }
  2753. symtablestack:=nil;
  2754. systemunit:=nil;
  2755. { create error syms and def }
  2756. generrorsym:=terrorsym.create;
  2757. generrordef:=terrordef.create;
  2758. { macros }
  2759. initialmacrosymtable:=tmacrosymtable.create(false);
  2760. macrosymtablestack:=TSymtablestack.create;
  2761. macrosymtablestack.push(initialmacrosymtable);
  2762. {$ifdef UNITALIASES}
  2763. { unit aliases }
  2764. unitaliases:=TFPHashObjectList.create;
  2765. {$endif}
  2766. { set some global vars to nil, might be important for the ide }
  2767. class_tobject:=nil;
  2768. interface_iunknown:=nil;
  2769. interface_idispatch:=nil;
  2770. rec_tguid:=nil;
  2771. dupnr:=0;
  2772. end;
  2773. procedure DoneSymtable;
  2774. begin
  2775. generrorsym.owner:=nil;
  2776. generrorsym.free;
  2777. generrordef.owner:=nil;
  2778. generrordef.free;
  2779. initialmacrosymtable.free;
  2780. macrosymtablestack.free;
  2781. {$ifdef UNITALIASES}
  2782. unitaliases.free;
  2783. {$endif}
  2784. end;
  2785. end.