symtable.pas 112 KB

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