symtable.pas 111 KB

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