2
0

symtable.pas 90 KB

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