symtable.pas 111 KB

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