symtable.pas 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573
  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 is_managed_type(tabstractvarsym(sym).vardef) then
  647. b_needs_init_final:=true;
  648. end;
  649. end;
  650. end;
  651. { returns true, if p contains data which needs init/final code }
  652. function tstoredsymtable.needs_init_final : boolean;
  653. begin
  654. b_needs_init_final:=false;
  655. SymList.ForEachCall(@_needs_init_final,nil);
  656. needs_init_final:=b_needs_init_final;
  657. end;
  658. {****************************************************************************
  659. TAbstractRecordSymtable
  660. ****************************************************************************}
  661. constructor tabstractrecordsymtable.create(const n:string;usealign:shortint);
  662. begin
  663. inherited create(n);
  664. _datasize:=0;
  665. databitsize:=0;
  666. recordalignment:=1;
  667. usefieldalignment:=usealign;
  668. padalignment:=1;
  669. { recordalign C_alignment means C record packing, that starts
  670. with an alignment of 1 }
  671. case usealign of
  672. C_alignment,
  673. bit_alignment:
  674. fieldalignment:=1;
  675. mac68k_alignment:
  676. fieldalignment:=2;
  677. else
  678. fieldalignment:=usealign;
  679. end;
  680. end;
  681. procedure tabstractrecordsymtable.ppuload(ppufile:tcompilerppufile);
  682. begin
  683. inherited ppuload(ppufile);
  684. end;
  685. procedure tabstractrecordsymtable.ppuwrite(ppufile:tcompilerppufile);
  686. var
  687. oldtyp : byte;
  688. begin
  689. oldtyp:=ppufile.entrytyp;
  690. ppufile.entrytyp:=subentryid;
  691. inherited ppuwrite(ppufile);
  692. ppufile.entrytyp:=oldtyp;
  693. end;
  694. function field2recordalignment(fieldoffs, fieldalign: aint): aint;
  695. begin
  696. { optimal alignment of the record when declaring a variable of this }
  697. { type is independent of the packrecords setting }
  698. if (fieldoffs mod fieldalign) = 0 then
  699. result:=fieldalign
  700. else if (fieldalign >= 16) and
  701. ((fieldoffs mod 16) = 0) and
  702. ((fieldalign mod 16) = 0) then
  703. result:=16
  704. else if (fieldalign >= 8) and
  705. ((fieldoffs mod 8) = 0) and
  706. ((fieldalign mod 8) = 0) then
  707. result:=8
  708. else if (fieldalign >= 4) and
  709. ((fieldoffs mod 4) = 0) and
  710. ((fieldalign mod 4) = 0) then
  711. result:=4
  712. else if (fieldalign >= 2) and
  713. ((fieldoffs mod 2) = 0) and
  714. ((fieldalign mod 2) = 0) then
  715. result:=2
  716. else
  717. result:=1;
  718. end;
  719. procedure tabstractrecordsymtable.alignrecord(fieldoffset:aint;varalign:shortint);
  720. var
  721. varalignrecord: shortint;
  722. begin
  723. case usefieldalignment of
  724. C_alignment:
  725. varalignrecord:=used_align(varalign,current_settings.alignment.recordalignmin,current_settings.alignment.maxCrecordalign);
  726. mac68k_alignment:
  727. varalignrecord:=2;
  728. else
  729. varalignrecord:=field2recordalignment(fieldoffset,varalign);
  730. end;
  731. recordalignment:=max(recordalignment,varalignrecord);
  732. end;
  733. procedure tabstractrecordsymtable.addfield(sym:tfieldvarsym;vis:tvisibility);
  734. var
  735. l : aint;
  736. varalignfield,
  737. varalign : shortint;
  738. vardef : tdef;
  739. begin
  740. if (sym.owner<>self) then
  741. internalerror(200602031);
  742. if sym.fieldoffset<>-1 then
  743. internalerror(200602032);
  744. { set visibility for the symbol }
  745. sym.visibility:=vis;
  746. { this symbol can't be loaded to a register }
  747. sym.varregable:=vr_none;
  748. { Calculate field offset }
  749. l:=sym.getsize;
  750. vardef:=sym.vardef;
  751. varalign:=vardef.alignment;
  752. case usefieldalignment of
  753. bit_alignment:
  754. begin
  755. { bitpacking only happens for ordinals, the rest is aligned at }
  756. { 1 byte (compatible with GPC/GCC) }
  757. if is_ordinal(vardef) then
  758. begin
  759. sym.fieldoffset:=databitsize;
  760. l:=sym.getpackedbitsize;
  761. end
  762. else
  763. begin
  764. databitsize:=_datasize*8;
  765. sym.fieldoffset:=databitsize;
  766. if (l>high(aint) div 8) then
  767. Message(sym_e_segment_too_large);
  768. l:=l*8;
  769. end;
  770. if varalign=0 then
  771. varalign:=size_2_align(l);
  772. recordalignment:=max(recordalignment,field2recordalignment(databitsize mod 8,varalign));
  773. { bit packed records are limited to high(aint) bits }
  774. { instead of bytes to avoid double precision }
  775. { arithmetic in offset calculations }
  776. if int64(l)>high(aint)-sym.fieldoffset then
  777. begin
  778. Message(sym_e_segment_too_large);
  779. _datasize:=high(aint);
  780. databitsize:=high(aint);
  781. end
  782. else
  783. begin
  784. databitsize:=sym.fieldoffset+l;
  785. _datasize:=(databitsize+7) div 8;
  786. end;
  787. { rest is not applicable }
  788. exit;
  789. end;
  790. { Calc the alignment size for C style records }
  791. C_alignment:
  792. begin
  793. if (varalign>4) and
  794. ((varalign mod 4)<>0) and
  795. (vardef.typ=arraydef) then
  796. Message1(sym_w_wrong_C_pack,vardef.typename);
  797. if varalign=0 then
  798. varalign:=l;
  799. if (fieldalignment<current_settings.alignment.maxCrecordalign) then
  800. begin
  801. if (varalign>16) and (fieldalignment<32) then
  802. fieldalignment:=32
  803. else if (varalign>12) and (fieldalignment<16) then
  804. fieldalignment:=16
  805. { 12 is needed for long double }
  806. else if (varalign>8) and (fieldalignment<12) then
  807. fieldalignment:=12
  808. else if (varalign>4) and (fieldalignment<8) then
  809. fieldalignment:=8
  810. else if (varalign>2) and (fieldalignment<4) then
  811. fieldalignment:=4
  812. else if (varalign>1) and (fieldalignment<2) then
  813. fieldalignment:=2;
  814. end;
  815. fieldalignment:=min(fieldalignment,current_settings.alignment.maxCrecordalign);
  816. end;
  817. mac68k_alignment:
  818. begin
  819. { mac68k alignment (C description):
  820. * char is aligned to 1 byte
  821. * everything else (except vector) is aligned to 2 bytes
  822. * vector is aligned to 16 bytes
  823. }
  824. if l>1 then
  825. fieldalignment:=2
  826. else
  827. fieldalignment:=1;
  828. varalign:=2;
  829. end;
  830. end;
  831. if varalign=0 then
  832. varalign:=size_2_align(l);
  833. varalignfield:=used_align(varalign,current_settings.alignment.recordalignmin,fieldalignment);
  834. sym.fieldoffset:=align(_datasize,varalignfield);
  835. if l>high(aint)-sym.fieldoffset then
  836. begin
  837. Message(sym_e_segment_too_large);
  838. _datasize:=high(aint);
  839. end
  840. else
  841. _datasize:=sym.fieldoffset+l;
  842. { Calc alignment needed for this record }
  843. alignrecord(sym.fieldoffset,varalign);
  844. end;
  845. procedure tabstractrecordsymtable.addalignmentpadding;
  846. begin
  847. { make the record size aligned correctly so it can be
  848. used as elements in an array. For C records we
  849. use the fieldalignment, because that is updated with the
  850. used alignment. }
  851. if (padalignment = 1) then
  852. case usefieldalignment of
  853. C_alignment:
  854. padalignment:=fieldalignment;
  855. { bitpacked }
  856. bit_alignment:
  857. padalignment:=1;
  858. { mac68k: always round to multiple of 2 }
  859. mac68k_alignment:
  860. padalignment:=2;
  861. { default/no packrecords specified }
  862. 0:
  863. padalignment:=recordalignment
  864. { specific packrecords setting -> use as upper limit }
  865. else
  866. padalignment:=min(recordalignment,usefieldalignment);
  867. end;
  868. _datasize:=align(_datasize,padalignment);
  869. end;
  870. procedure tabstractrecordsymtable.insertdef(def:TDefEntry);
  871. begin
  872. { Enums must also be available outside the record scope,
  873. insert in the owner of this symtable }
  874. if def.typ=enumdef then
  875. defowner.owner.insertdef(def)
  876. else
  877. inherited insertdef(def);
  878. end;
  879. function tabstractrecordsymtable.is_packed: boolean;
  880. begin
  881. result:=usefieldalignment=bit_alignment;
  882. end;
  883. procedure tabstractrecordsymtable.setdatasize(val: aint);
  884. begin
  885. _datasize:=val;
  886. if (usefieldalignment=bit_alignment) then
  887. { can overflow in non bitpacked records }
  888. databitsize:=val*8;
  889. end;
  890. {****************************************************************************
  891. TRecordSymtable
  892. ****************************************************************************}
  893. constructor trecordsymtable.create(usealign:shortint);
  894. begin
  895. inherited create('',usealign);
  896. symtabletype:=recordsymtable;
  897. end;
  898. { this procedure is reserved for inserting case variant into
  899. a record symtable }
  900. { the offset is the location of the start of the variant
  901. and datasize and dataalignment corresponds to
  902. the complete size (see code in pdecl unit) PM }
  903. procedure trecordsymtable.insertunionst(unionst : trecordsymtable;offset : longint);
  904. var
  905. sym : tsym;
  906. def : tdef;
  907. i : integer;
  908. varalignrecord,varalign,
  909. storesize,storealign : aint;
  910. bitsize: aint;
  911. begin
  912. storesize:=_datasize;
  913. storealign:=fieldalignment;
  914. _datasize:=offset;
  915. if (usefieldalignment=bit_alignment) then
  916. databitsize:=offset*8;
  917. { We move the ownership of the defs and symbols to the new recordsymtable.
  918. The old unionsymtable keeps the references, but doesn't own the
  919. objects anymore }
  920. unionst.DefList.OwnsObjects:=false;
  921. unionst.SymList.OwnsObjects:=false;
  922. { copy symbols }
  923. for i:=0 to unionst.SymList.Count-1 do
  924. begin
  925. sym:=TSym(unionst.SymList[i]);
  926. if sym.typ<>fieldvarsym then
  927. internalerror(200601272);
  928. if tfieldvarsym(sym).fieldoffset=0 then
  929. include(tfieldvarsym(sym).varoptions,vo_is_first_field);
  930. { add to this record symtable }
  931. // unionst.SymList.List.List^[i].Data:=nil;
  932. sym.ChangeOwner(self);
  933. varalign:=tfieldvarsym(sym).vardef.alignment;
  934. if varalign=0 then
  935. varalign:=size_2_align(tfieldvarsym(sym).getsize);
  936. { retrieve size }
  937. if (usefieldalignment=bit_alignment) then
  938. begin
  939. { bit packed records are limited to high(aint) bits }
  940. { instead of bytes to avoid double precision }
  941. { arithmetic in offset calculations }
  942. if is_ordinal(tfieldvarsym(sym).vardef) then
  943. bitsize:=tfieldvarsym(sym).getpackedbitsize
  944. else
  945. begin
  946. bitsize:=tfieldvarsym(sym).getsize;
  947. if (bitsize>high(aint) div 8) then
  948. Message(sym_e_segment_too_large);
  949. bitsize:=bitsize*8;
  950. end;
  951. if bitsize>high(aint)-databitsize then
  952. begin
  953. Message(sym_e_segment_too_large);
  954. _datasize:=high(aint);
  955. databitsize:=high(aint);
  956. end
  957. else
  958. begin
  959. databitsize:=tfieldvarsym(sym).fieldoffset+offset*8;
  960. _datasize:=(databitsize+7) div 8;
  961. end;
  962. tfieldvarsym(sym).fieldoffset:=databitsize;
  963. varalignrecord:=field2recordalignment(tfieldvarsym(sym).fieldoffset div 8,varalign);
  964. end
  965. else
  966. begin
  967. if tfieldvarsym(sym).getsize>high(aint)-_datasize then
  968. begin
  969. Message(sym_e_segment_too_large);
  970. _datasize:=high(aint);
  971. end
  972. else
  973. _datasize:=tfieldvarsym(sym).fieldoffset+offset;
  974. { update address }
  975. tfieldvarsym(sym).fieldoffset:=_datasize;
  976. varalignrecord:=field2recordalignment(tfieldvarsym(sym).fieldoffset,varalign);
  977. end;
  978. { update alignment of this record }
  979. if (usefieldalignment<>C_alignment) and
  980. (usefieldalignment<>mac68k_alignment) then
  981. recordalignment:=max(recordalignment,varalignrecord);
  982. end;
  983. { update alignment for C records }
  984. if (usefieldalignment=C_alignment) and
  985. (usefieldalignment<>mac68k_alignment) then
  986. recordalignment:=max(recordalignment,unionst.recordalignment);
  987. { Register defs in the new record symtable }
  988. for i:=0 to unionst.DefList.Count-1 do
  989. begin
  990. def:=TDef(unionst.DefList[i]);
  991. def.ChangeOwner(self);
  992. end;
  993. _datasize:=storesize;
  994. fieldalignment:=storealign;
  995. end;
  996. {****************************************************************************
  997. TObjectSymtable
  998. ****************************************************************************}
  999. constructor tObjectSymtable.create(adefowner:tdef;const n:string;usealign:shortint);
  1000. begin
  1001. inherited create(n,usealign);
  1002. symtabletype:=ObjectSymtable;
  1003. defowner:=adefowner;
  1004. end;
  1005. function tObjectSymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1006. var
  1007. hsym : tsym;
  1008. begin
  1009. result:=false;
  1010. if not assigned(defowner) then
  1011. internalerror(200602061);
  1012. { procsym and propertysym have special code
  1013. to override values in inherited classes. For other
  1014. symbols check for duplicates }
  1015. if not(sym.typ in [procsym,propertysym]) then
  1016. begin
  1017. { but private ids can be reused }
  1018. hsym:=search_class_member(tobjectdef(defowner),hashedid.id);
  1019. if assigned(hsym) and
  1020. (
  1021. (
  1022. not(m_delphi in current_settings.modeswitches) and
  1023. is_visible_for_object(hsym,tobjectdef(defowner))
  1024. ) or
  1025. (
  1026. { In Delphi, you can repeat members of a parent class. You can't }
  1027. { do this for objects however, and you (obviouly) can't }
  1028. { declare two fields with the same name in a single class }
  1029. (m_delphi in current_settings.modeswitches) and
  1030. (
  1031. is_object(tdef(defowner)) or
  1032. (hsym.owner = self)
  1033. )
  1034. )
  1035. ) then
  1036. begin
  1037. DuplicateSym(hashedid,sym,hsym);
  1038. result:=true;
  1039. end;
  1040. end
  1041. else
  1042. begin
  1043. if not(m_duplicate_names in current_settings.modeswitches) then
  1044. result:=inherited checkduplicate(hashedid,sym);
  1045. end;
  1046. end;
  1047. {****************************************************************************
  1048. TAbstractLocalSymtable
  1049. ****************************************************************************}
  1050. procedure tabstractlocalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1051. var
  1052. oldtyp : byte;
  1053. begin
  1054. oldtyp:=ppufile.entrytyp;
  1055. ppufile.entrytyp:=subentryid;
  1056. { write definitions }
  1057. writedefs(ppufile);
  1058. { write symbols }
  1059. writesyms(ppufile);
  1060. ppufile.entrytyp:=oldtyp;
  1061. end;
  1062. function tabstractlocalsymtable.count_locals:longint;
  1063. var
  1064. i : longint;
  1065. sym : tsym;
  1066. begin
  1067. result:=0;
  1068. for i:=0 to SymList.Count-1 do
  1069. begin
  1070. sym:=tsym(SymList[i]);
  1071. { Count only varsyms, but ignore the funcretsym }
  1072. if (tsym(sym).typ in [localvarsym,paravarsym]) and
  1073. (tsym(sym)<>current_procinfo.procdef.funcretsym) and
  1074. (not(vo_is_parentfp in tabstractvarsym(sym).varoptions) or
  1075. (tstoredsym(sym).refs>0)) then
  1076. inc(result);
  1077. end;
  1078. end;
  1079. {****************************************************************************
  1080. TLocalSymtable
  1081. ****************************************************************************}
  1082. constructor tlocalsymtable.create(adefowner:tdef;level:byte);
  1083. begin
  1084. inherited create('');
  1085. defowner:=adefowner;
  1086. symtabletype:=localsymtable;
  1087. symtablelevel:=level;
  1088. end;
  1089. function tlocalsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1090. var
  1091. hsym : tsym;
  1092. begin
  1093. if not assigned(defowner) or
  1094. (defowner.typ<>procdef) then
  1095. internalerror(200602042);
  1096. result:=false;
  1097. hsym:=tsym(FindWithHash(hashedid));
  1098. if assigned(hsym) then
  1099. begin
  1100. { a local and the function can have the same
  1101. name in TP and Delphi, but RESULT not }
  1102. if (m_duplicate_names in current_settings.modeswitches) and
  1103. (hsym.typ in [absolutevarsym,localvarsym]) and
  1104. (vo_is_funcret in tabstractvarsym(hsym).varoptions) and
  1105. not((m_result in current_settings.modeswitches) and
  1106. (vo_is_result in tabstractvarsym(hsym).varoptions)) then
  1107. HideSym(hsym)
  1108. else
  1109. DuplicateSym(hashedid,sym,hsym);
  1110. result:=true;
  1111. exit;
  1112. end;
  1113. { check also parasymtable, this needs to be done here becuase
  1114. of the special situation with the funcret sym that needs to be
  1115. hidden for tp and delphi modes }
  1116. hsym:=tsym(tabstractprocdef(defowner).parast.FindWithHash(hashedid));
  1117. if assigned(hsym) then
  1118. begin
  1119. { a local and the function can have the same
  1120. name in TP and Delphi, but RESULT not }
  1121. if (m_duplicate_names in current_settings.modeswitches) and
  1122. (sym.typ in [absolutevarsym,localvarsym]) and
  1123. (vo_is_funcret in tabstractvarsym(sym).varoptions) and
  1124. not((m_result in current_settings.modeswitches) and
  1125. (vo_is_result in tabstractvarsym(sym).varoptions)) then
  1126. Hidesym(sym)
  1127. else
  1128. DuplicateSym(hashedid,sym,hsym);
  1129. result:=true;
  1130. exit;
  1131. end;
  1132. { check ObjectSymtable, skip this for funcret sym because
  1133. that will always be positive because it has the same name
  1134. as the procsym }
  1135. if not is_funcret_sym(sym) and
  1136. (defowner.typ=procdef) and
  1137. assigned(tprocdef(defowner)._class) and
  1138. (tprocdef(defowner).owner.defowner=tprocdef(defowner)._class) and
  1139. (
  1140. not(m_delphi in current_settings.modeswitches) or
  1141. is_object(tprocdef(defowner)._class)
  1142. ) then
  1143. result:=tprocdef(defowner)._class.symtable.checkduplicate(hashedid,sym);
  1144. end;
  1145. {****************************************************************************
  1146. TParaSymtable
  1147. ****************************************************************************}
  1148. constructor tparasymtable.create(adefowner:tdef;level:byte);
  1149. begin
  1150. inherited create('');
  1151. defowner:=adefowner;
  1152. symtabletype:=parasymtable;
  1153. symtablelevel:=level;
  1154. end;
  1155. function tparasymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1156. begin
  1157. result:=inherited checkduplicate(hashedid,sym);
  1158. if result then
  1159. exit;
  1160. if not(m_duplicate_names in current_settings.modeswitches) and
  1161. (defowner.typ=procdef) and
  1162. assigned(tprocdef(defowner)._class) and
  1163. (tprocdef(defowner).owner.defowner=tprocdef(defowner)._class) and
  1164. (
  1165. not(m_delphi in current_settings.modeswitches) or
  1166. is_object(tprocdef(defowner)._class)
  1167. ) then
  1168. result:=tprocdef(defowner)._class.symtable.checkduplicate(hashedid,sym);
  1169. end;
  1170. {****************************************************************************
  1171. TAbstractUniTSymtable
  1172. ****************************************************************************}
  1173. constructor tabstractuniTSymtable.create(const n : string;id:word);
  1174. begin
  1175. inherited create(n);
  1176. moduleid:=id;
  1177. end;
  1178. function tabstractuniTSymtable.iscurrentunit:boolean;
  1179. begin
  1180. result:=assigned(current_module) and
  1181. (
  1182. (current_module.globalsymtable=self) or
  1183. (current_module.localsymtable=self)
  1184. );
  1185. end;
  1186. {****************************************************************************
  1187. TStaticSymtable
  1188. ****************************************************************************}
  1189. constructor tstaticsymtable.create(const n : string;id:word);
  1190. begin
  1191. inherited create(n,id);
  1192. symtabletype:=staticsymtable;
  1193. symtablelevel:=main_program_level;
  1194. end;
  1195. procedure tstaticsymtable.ppuload(ppufile:tcompilerppufile);
  1196. begin
  1197. inherited ppuload(ppufile);
  1198. { now we can deref the syms and defs }
  1199. deref;
  1200. end;
  1201. procedure tstaticsymtable.ppuwrite(ppufile:tcompilerppufile);
  1202. begin
  1203. inherited ppuwrite(ppufile);
  1204. end;
  1205. function tstaticsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1206. var
  1207. hsym : tsym;
  1208. begin
  1209. result:=false;
  1210. hsym:=tsym(FindWithHash(hashedid));
  1211. if assigned(hsym) then
  1212. begin
  1213. { Delphi (contrary to TP) you can have a symbol with the same name as the
  1214. unit, the unit can then not be accessed anymore using
  1215. <unit>.<id>, so we can hide the symbol }
  1216. if (m_delphi in current_settings.modeswitches) and
  1217. (hsym.typ=symconst.unitsym) then
  1218. HideSym(hsym)
  1219. else
  1220. DuplicateSym(hashedid,sym,hsym);
  1221. result:=true;
  1222. exit;
  1223. end;
  1224. if (current_module.localsymtable=self) and
  1225. assigned(current_module.globalsymtable) then
  1226. result:=tglobalsymtable(current_module.globalsymtable).checkduplicate(hashedid,sym);
  1227. end;
  1228. {****************************************************************************
  1229. TGlobalSymtable
  1230. ****************************************************************************}
  1231. constructor tglobalsymtable.create(const n : string;id:word);
  1232. begin
  1233. inherited create(n,id);
  1234. symtabletype:=globalsymtable;
  1235. symtablelevel:=main_program_level;
  1236. end;
  1237. procedure tglobalsymtable.ppuload(ppufile:tcompilerppufile);
  1238. begin
  1239. inherited ppuload(ppufile);
  1240. { now we can deref the syms and defs }
  1241. deref;
  1242. end;
  1243. procedure tglobalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1244. begin
  1245. { write the symtable entries }
  1246. inherited ppuwrite(ppufile);
  1247. end;
  1248. function tglobalsymtable.checkduplicate(var hashedid:THashedIDString;sym:TSymEntry):boolean;
  1249. var
  1250. hsym : tsym;
  1251. begin
  1252. result:=false;
  1253. hsym:=tsym(FindWithHash(hashedid));
  1254. if assigned(hsym) then
  1255. begin
  1256. { Delphi (contrary to TP) you can have a symbol with the same name as the
  1257. unit, the unit can then not be accessed anymore using
  1258. <unit>.<id>, so we can hide the symbol }
  1259. if (m_delphi in current_settings.modeswitches) and
  1260. (hsym.typ=symconst.unitsym) then
  1261. HideSym(hsym)
  1262. else
  1263. DuplicateSym(hashedid,sym,hsym);
  1264. result:=true;
  1265. exit;
  1266. end;
  1267. end;
  1268. {****************************************************************************
  1269. TWITHSYMTABLE
  1270. ****************************************************************************}
  1271. constructor twithsymtable.create(aowner:tdef;ASymList:TFPHashObjectList;refnode:tobject{tnode});
  1272. begin
  1273. inherited create('');
  1274. symtabletype:=withsymtable;
  1275. withrefnode:=refnode;
  1276. { Replace SymList with the passed symlist }
  1277. SymList.free;
  1278. SymList:=ASymList;
  1279. defowner:=aowner;
  1280. end;
  1281. destructor twithsymtable.destroy;
  1282. begin
  1283. withrefnode.free;
  1284. { Disable SymList because we don't Own it }
  1285. SymList:=nil;
  1286. inherited destroy;
  1287. end;
  1288. procedure twithsymtable.clear;
  1289. begin
  1290. { remove no entry from a withsymtable as it is only a pointer to the
  1291. recorddef or objectdef symtable }
  1292. end;
  1293. procedure twithsymtable.insertdef(def:TDefEntry);
  1294. begin
  1295. { Definitions can't be registered in the withsymtable
  1296. because the withsymtable is removed after the with block.
  1297. We can't easily solve it here because the next symtable in the
  1298. stack is not known. }
  1299. internalerror(200602046);
  1300. end;
  1301. {****************************************************************************
  1302. TSTT_ExceptionSymtable
  1303. ****************************************************************************}
  1304. constructor tstt_excepTSymtable.create;
  1305. begin
  1306. inherited create('');
  1307. symtabletype:=stt_excepTSymtable;
  1308. end;
  1309. {****************************************************************************
  1310. TMacroSymtable
  1311. ****************************************************************************}
  1312. constructor tmacrosymtable.create(exported: boolean);
  1313. begin
  1314. inherited create('');
  1315. if exported then
  1316. symtabletype:=exportedmacrosymtable
  1317. else
  1318. symtabletype:=localmacrosymtable;
  1319. symtablelevel:=main_program_level;
  1320. end;
  1321. {****************************************************************************
  1322. TEnumSymtable
  1323. ****************************************************************************}
  1324. procedure tenumsymtable.insert(sym: TSymEntry; checkdup: boolean);
  1325. var
  1326. value: longint;
  1327. def: tenumdef;
  1328. begin
  1329. // defowner = nil only when we are loading from ppu
  1330. if defowner<>nil then
  1331. begin
  1332. { First entry? Then we need to set the minval }
  1333. value:=tenumsym(sym).value;
  1334. def:=tenumdef(defowner);
  1335. if SymList.count=0 then
  1336. begin
  1337. if value>0 then
  1338. def.has_jumps:=true;
  1339. def.setmin(value);
  1340. def.setmax(value);
  1341. end
  1342. else
  1343. begin
  1344. { check for jumps }
  1345. if value>def.max+1 then
  1346. def.has_jumps:=true;
  1347. { update low and high }
  1348. if def.min>value then
  1349. def.setmin(value);
  1350. if def.max<value then
  1351. def.setmax(value);
  1352. end;
  1353. end;
  1354. inherited insert(sym, checkdup);
  1355. end;
  1356. constructor tenumsymtable.create(adefowner: tdef);
  1357. begin
  1358. inherited Create('');
  1359. symtabletype:=enumsymtable;
  1360. defowner:=adefowner;
  1361. end;
  1362. {*****************************************************************************
  1363. Helper Routines
  1364. *****************************************************************************}
  1365. function FullTypeName(def,otherdef:tdef):string;
  1366. var
  1367. s1,s2 : string;
  1368. begin
  1369. if def.typ=objectdef then
  1370. s1:=tobjectdef(def).RttiName
  1371. else
  1372. s1:=def.typename;
  1373. { When the names are the same try to include the unit name }
  1374. if assigned(otherdef) and
  1375. (def.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1376. begin
  1377. s2:=otherdef.typename;
  1378. if upper(s1)=upper(s2) then
  1379. s1:=def.owner.realname^+'.'+s1;
  1380. end;
  1381. FullTypeName:=s1;
  1382. end;
  1383. procedure incompatibletypes(def1,def2:tdef);
  1384. begin
  1385. { When there is an errordef there is already an error message show }
  1386. if (def2.typ=errordef) or
  1387. (def1.typ=errordef) then
  1388. exit;
  1389. CGMessage2(type_e_incompatible_types,FullTypeName(def1,def2),FullTypeName(def2,def1));
  1390. end;
  1391. procedure hidesym(sym:TSymEntry);
  1392. begin
  1393. sym.realname:='$hidden'+sym.realname;
  1394. tsym(sym).visibility:=vis_hidden;
  1395. end;
  1396. procedure duplicatesym(var hashedid:THashedIDString;dupsym,origsym:TSymEntry);
  1397. var
  1398. st : TSymtable;
  1399. begin
  1400. Message1(sym_e_duplicate_id,tsym(origsym).realname);
  1401. { Write hint where the original symbol was found }
  1402. st:=finduniTSymtable(origsym.owner);
  1403. with tsym(origsym).fileinfo do
  1404. begin
  1405. if assigned(st) and
  1406. (st.symtabletype=globalsymtable) and
  1407. st.iscurrentunit then
  1408. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line))
  1409. else if assigned(st.name) then
  1410. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line));
  1411. end;
  1412. { Rename duplicate sym to an unreachable name, but it can be
  1413. inserted in the symtable without errors }
  1414. inc(dupnr);
  1415. hashedid.id:='dup'+tostr(dupnr)+hashedid.id;
  1416. if assigned(dupsym) then
  1417. include(tsym(dupsym).symoptions,sp_implicitrename);
  1418. end;
  1419. {*****************************************************************************
  1420. Search
  1421. *****************************************************************************}
  1422. procedure addsymref(sym:tsym);
  1423. begin
  1424. { symbol uses count }
  1425. sym.IncRefCount;
  1426. { unit uses count }
  1427. if assigned(current_module) and
  1428. (sym.owner.symtabletype=globalsymtable) then
  1429. begin
  1430. if tglobalsymtable(sym.owner).moduleid>=current_module.unitmapsize then
  1431. internalerror(200501152);
  1432. inc(current_module.unitmap[tglobalsymtable(sym.owner).moduleid].refs);
  1433. end;
  1434. end;
  1435. function is_visible_for_object(symst:tsymtable;symvisibility:tvisibility;contextobjdef:tobjectdef):boolean;
  1436. var
  1437. symownerdef : tobjectdef;
  1438. begin
  1439. result:=false;
  1440. { Get objdectdef owner of the symtable for the is_related checks }
  1441. if not assigned(symst) or
  1442. (symst.symtabletype<>objectsymtable) then
  1443. internalerror(200810285);
  1444. symownerdef:=tobjectdef(symst.defowner);
  1445. case symvisibility of
  1446. vis_private :
  1447. begin
  1448. { private symbols are allowed when we are in the same
  1449. module as they are defined }
  1450. result:=(
  1451. (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1452. (symownerdef.owner.iscurrentunit)
  1453. ) or
  1454. ( // the case of specialize inside the generic declaration
  1455. (symownerdef.owner.symtabletype = objectsymtable) and
  1456. (
  1457. assigned(current_objectdef) and
  1458. (
  1459. (current_objectdef=symownerdef) or
  1460. (current_objectdef.owner.moduleid=symownerdef.owner.moduleid)
  1461. )
  1462. ) or
  1463. (
  1464. not assigned(current_objectdef) and
  1465. (symownerdef.owner.moduleid=current_module.moduleid)
  1466. )
  1467. );
  1468. end;
  1469. vis_strictprivate :
  1470. begin
  1471. result:=assigned(current_objectdef) and
  1472. (current_objectdef=symownerdef);
  1473. end;
  1474. vis_strictprotected :
  1475. begin
  1476. result:=assigned(current_objectdef) and
  1477. current_objectdef.is_related(symownerdef);
  1478. end;
  1479. vis_protected :
  1480. begin
  1481. { protected symbols are visible in the module that defines them and
  1482. also visible to related objects. The related object must be defined
  1483. in the current module }
  1484. result:=(
  1485. (
  1486. (symownerdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1487. (symownerdef.owner.iscurrentunit)
  1488. ) or
  1489. (
  1490. assigned(contextobjdef) and
  1491. (contextobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1492. (contextobjdef.owner.iscurrentunit) and
  1493. contextobjdef.is_related(symownerdef)
  1494. ) or
  1495. ( // the case of specialize inside the generic declaration
  1496. (symownerdef.owner.symtabletype = objectsymtable) and
  1497. (
  1498. assigned(current_objectdef) and
  1499. (
  1500. (current_objectdef=symownerdef) or
  1501. (current_objectdef.owner.moduleid=symownerdef.owner.moduleid)
  1502. )
  1503. ) or
  1504. (
  1505. not assigned(current_objectdef) and
  1506. (symownerdef.owner.moduleid=current_module.moduleid)
  1507. )
  1508. )
  1509. );
  1510. end;
  1511. vis_public,
  1512. vis_published :
  1513. result:=true;
  1514. end;
  1515. end;
  1516. function is_visible_for_object(pd:tprocdef;contextobjdef:tobjectdef):boolean;
  1517. begin
  1518. result:=is_visible_for_object(pd.owner,pd.visibility,contextobjdef);
  1519. end;
  1520. function is_visible_for_object(sym:tsym;contextobjdef:tobjectdef):boolean;
  1521. var
  1522. i : longint;
  1523. pd : tprocdef;
  1524. begin
  1525. if sym.typ=procsym then
  1526. begin
  1527. { A procsym is visible, when there is at least one of the procdefs visible }
  1528. result:=false;
  1529. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  1530. begin
  1531. pd:=tprocdef(tprocsym(sym).ProcdefList[i]);
  1532. if (pd.owner=sym.owner) and
  1533. is_visible_for_object(pd,contextobjdef) then
  1534. begin
  1535. result:=true;
  1536. exit;
  1537. end;
  1538. end;
  1539. end
  1540. else
  1541. result:=is_visible_for_object(sym.owner,sym.visibility,contextobjdef);
  1542. end;
  1543. function searchsym(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1544. var
  1545. hashedid : THashedIDString;
  1546. contextobjdef : tobjectdef;
  1547. stackitem : psymtablestackitem;
  1548. begin
  1549. result:=false;
  1550. hashedid.id:=s;
  1551. stackitem:=symtablestack.stack;
  1552. while assigned(stackitem) do
  1553. begin
  1554. srsymtable:=stackitem^.symtable;
  1555. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1556. if assigned(srsym) then
  1557. begin
  1558. { use the class from withsymtable only when it is
  1559. defined in this unit }
  1560. if (srsymtable.symtabletype=withsymtable) and
  1561. assigned(srsymtable.defowner) and
  1562. (srsymtable.defowner.typ=objectdef) and
  1563. (srsymtable.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1564. (srsymtable.defowner.owner.iscurrentunit) then
  1565. contextobjdef:=tobjectdef(srsymtable.defowner)
  1566. else
  1567. contextobjdef:=current_objectdef;
  1568. if (srsym.owner.symtabletype<>objectsymtable) or
  1569. is_visible_for_object(srsym,contextobjdef) then
  1570. begin
  1571. { we need to know if a procedure references symbols
  1572. in the static symtable, because then it can't be
  1573. inlined from outside this unit }
  1574. if assigned(current_procinfo) and
  1575. (srsym.owner.symtabletype=staticsymtable) then
  1576. include(current_procinfo.flags,pi_uses_static_symtable);
  1577. addsymref(srsym);
  1578. result:=true;
  1579. exit;
  1580. end;
  1581. end;
  1582. { also search for class helpers }
  1583. if (srsymtable.symtabletype=objectsymtable) and
  1584. is_objcclass(tdef(srsymtable.defowner)) then
  1585. begin
  1586. if search_class_helper(tobjectdef(srsymtable.defowner),s,srsym,srsymtable) then
  1587. begin
  1588. result:=true;
  1589. exit;
  1590. end;
  1591. end;
  1592. stackitem:=stackitem^.next;
  1593. end;
  1594. srsym:=nil;
  1595. srsymtable:=nil;
  1596. end;
  1597. function searchsym_type(const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1598. var
  1599. hashedid : THashedIDString;
  1600. stackitem : psymtablestackitem;
  1601. begin
  1602. result:=false;
  1603. hashedid.id:=s;
  1604. stackitem:=symtablestack.stack;
  1605. while assigned(stackitem) do
  1606. begin
  1607. {
  1608. It is not possible to have type symbols in:
  1609. records
  1610. objects
  1611. parameters
  1612. Exception are classes, objects, generic definitions and specializations
  1613. that have the parameterized types inserted in the symtable.
  1614. }
  1615. srsymtable:=stackitem^.symtable;
  1616. if not(srsymtable.symtabletype in [recordsymtable,ObjectSymtable,parasymtable]) or
  1617. (assigned(srsymtable.defowner) and
  1618. (
  1619. (df_generic in tdef(srsymtable.defowner).defoptions) or
  1620. (df_specialization in tdef(srsymtable.defowner).defoptions) or
  1621. is_class_or_object(tdef(srsymtable.defowner)))
  1622. ) then
  1623. begin
  1624. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1625. if assigned(srsym) and
  1626. not(srsym.typ in [fieldvarsym,paravarsym]) and
  1627. (
  1628. (srsym.owner.symtabletype<>objectsymtable) or
  1629. (is_visible_for_object(srsym,current_objectdef) and
  1630. (srsym.typ=typesym))
  1631. ) then
  1632. begin
  1633. { we need to know if a procedure references symbols
  1634. in the static symtable, because then it can't be
  1635. inlined from outside this unit }
  1636. if assigned(current_procinfo) and
  1637. (srsym.owner.symtabletype=staticsymtable) then
  1638. include(current_procinfo.flags,pi_uses_static_symtable);
  1639. addsymref(srsym);
  1640. result:=true;
  1641. exit;
  1642. end;
  1643. end;
  1644. stackitem:=stackitem^.next;
  1645. end;
  1646. result:=false;
  1647. srsym:=nil;
  1648. srsymtable:=nil;
  1649. end;
  1650. function searchsym_in_module(pm:pointer;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1651. var
  1652. pmod : tmodule;
  1653. begin
  1654. pmod:=tmodule(pm);
  1655. result:=false;
  1656. if assigned(pmod.globalsymtable) then
  1657. begin
  1658. srsym:=tsym(pmod.globalsymtable.Find(s));
  1659. if assigned(srsym) then
  1660. begin
  1661. srsymtable:=pmod.globalsymtable;
  1662. addsymref(srsym);
  1663. result:=true;
  1664. exit;
  1665. end;
  1666. end;
  1667. { If the module is the current unit we also need
  1668. to search the local symtable }
  1669. if (pmod=current_module) and
  1670. assigned(pmod.localsymtable) then
  1671. begin
  1672. srsym:=tsym(pmod.localsymtable.Find(s));
  1673. if assigned(srsym) then
  1674. begin
  1675. srsymtable:=pmod.localsymtable;
  1676. addsymref(srsym);
  1677. result:=true;
  1678. exit;
  1679. end;
  1680. end;
  1681. srsym:=nil;
  1682. srsymtable:=nil;
  1683. end;
  1684. function searchsym_in_named_module(const unitname, symname: TIDString; out srsym: tsym; out srsymtable: tsymtable): boolean;
  1685. var
  1686. stackitem : psymtablestackitem;
  1687. begin
  1688. result:=false;
  1689. stackitem:=symtablestack.stack;
  1690. while assigned(stackitem) do
  1691. begin
  1692. srsymtable:=stackitem^.symtable;
  1693. if (srsymtable.symtabletype=globalsymtable) and
  1694. (srsymtable.name^=unitname) then
  1695. begin
  1696. srsym:=tsym(srsymtable.find(symname));
  1697. if not assigned(srsym) then
  1698. break;
  1699. result:=true;
  1700. exit;
  1701. end;
  1702. stackitem:=stackitem^.next;
  1703. end;
  1704. { If the module is the current unit we also need
  1705. to search the local symtable }
  1706. if (current_module.globalsymtable=srsymtable) and
  1707. assigned(current_module.localsymtable) then
  1708. begin
  1709. srsymtable:=current_module.localsymtable;
  1710. srsym:=tsym(srsymtable.find(symname));
  1711. if assigned(srsym) then
  1712. begin
  1713. result:=true;
  1714. exit;
  1715. end;
  1716. end;
  1717. end;
  1718. function searchsym_in_class(classh,contextclassh:tobjectdef;const s : TIDString;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1719. var
  1720. hashedid : THashedIDString;
  1721. orgclass : tobjectdef;
  1722. begin
  1723. orgclass:=classh;
  1724. { The contextclassh is used for visibility. The classh must be equal to
  1725. or be a parent of contextclassh. E.g. for inherited searches the classh is the
  1726. parent. }
  1727. if assigned(classh) and
  1728. not contextclassh.is_related(classh) then
  1729. internalerror(200811161);
  1730. result:=false;
  1731. hashedid.id:=s;
  1732. while assigned(classh) do
  1733. begin
  1734. srsymtable:=classh.symtable;
  1735. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1736. if assigned(srsym) and
  1737. is_visible_for_object(srsym,contextclassh) then
  1738. begin
  1739. addsymref(srsym);
  1740. result:=true;
  1741. exit;
  1742. end;
  1743. classh:=classh.childof;
  1744. end;
  1745. if is_objcclass(orgclass) then
  1746. result:=search_class_helper(orgclass,s,srsym,srsymtable)
  1747. else
  1748. begin
  1749. srsym:=nil;
  1750. srsymtable:=nil;
  1751. end;
  1752. end;
  1753. function searchsym_in_class_by_msgint(classh:tobjectdef;msgid:longint;out srdef : tdef;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1754. var
  1755. def : tdef;
  1756. i : longint;
  1757. begin
  1758. result:=false;
  1759. def:=nil;
  1760. while assigned(classh) do
  1761. begin
  1762. for i:=0 to classh.symtable.DefList.Count-1 do
  1763. begin
  1764. def:=tstoreddef(classh.symtable.DefList[i]);
  1765. { Find also all hidden private methods to
  1766. be compatible with delphi, see tw6203 (PFV) }
  1767. if (def.typ=procdef) and
  1768. (po_msgint in tprocdef(def).procoptions) and
  1769. (tprocdef(def).messageinf.i=msgid) then
  1770. begin
  1771. srdef:=def;
  1772. srsym:=tprocdef(def).procsym;
  1773. srsymtable:=classh.symtable;
  1774. addsymref(srsym);
  1775. result:=true;
  1776. exit;
  1777. end;
  1778. end;
  1779. classh:=classh.childof;
  1780. end;
  1781. srdef:=nil;
  1782. srsym:=nil;
  1783. srsymtable:=nil;
  1784. end;
  1785. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string;out srsym:tsym;out srsymtable:TSymtable):boolean;
  1786. var
  1787. def : tdef;
  1788. i : longint;
  1789. begin
  1790. result:=false;
  1791. def:=nil;
  1792. while assigned(classh) do
  1793. begin
  1794. for i:=0 to classh.symtable.DefList.Count-1 do
  1795. begin
  1796. def:=tstoreddef(classh.symtable.DefList[i]);
  1797. { Find also all hidden private methods to
  1798. be compatible with delphi, see tw6203 (PFV) }
  1799. if (def.typ=procdef) and
  1800. (po_msgstr in tprocdef(def).procoptions) and
  1801. (tprocdef(def).messageinf.str^=s) then
  1802. begin
  1803. srsym:=tprocdef(def).procsym;
  1804. srsymtable:=classh.symtable;
  1805. addsymref(srsym);
  1806. result:=true;
  1807. exit;
  1808. end;
  1809. end;
  1810. classh:=classh.childof;
  1811. end;
  1812. srsym:=nil;
  1813. srsymtable:=nil;
  1814. end;
  1815. function search_assignment_operator(from_def,to_def:Tdef):Tprocdef;
  1816. var
  1817. sym : Tprocsym;
  1818. hashedid : THashedIDString;
  1819. curreq,
  1820. besteq : tequaltype;
  1821. currpd,
  1822. bestpd : tprocdef;
  1823. stackitem : psymtablestackitem;
  1824. begin
  1825. hashedid.id:='assign';
  1826. besteq:=te_incompatible;
  1827. bestpd:=nil;
  1828. stackitem:=symtablestack.stack;
  1829. while assigned(stackitem) do
  1830. begin
  1831. sym:=Tprocsym(stackitem^.symtable.FindWithHash(hashedid));
  1832. if sym<>nil then
  1833. begin
  1834. if sym.typ<>procsym then
  1835. internalerror(200402031);
  1836. { if the source type is an alias then this is only the second choice,
  1837. if you mess with this code, check tw4093 }
  1838. currpd:=sym.find_procdef_assignment_operator(from_def,to_def,curreq);
  1839. if curreq>besteq then
  1840. begin
  1841. besteq:=curreq;
  1842. bestpd:=currpd;
  1843. if (besteq=te_exact) then
  1844. break;
  1845. end;
  1846. end;
  1847. stackitem:=stackitem^.next;
  1848. end;
  1849. result:=bestpd;
  1850. end;
  1851. function search_enumerator_operator(type_def:Tdef): Tprocdef;
  1852. var
  1853. sym : Tprocsym;
  1854. hashedid : THashedIDString;
  1855. curreq,
  1856. besteq : tequaltype;
  1857. currpd,
  1858. bestpd : tprocdef;
  1859. stackitem : psymtablestackitem;
  1860. begin
  1861. hashedid.id:='enumerator';
  1862. besteq:=te_incompatible;
  1863. bestpd:=nil;
  1864. stackitem:=symtablestack.stack;
  1865. while assigned(stackitem) do
  1866. begin
  1867. sym:=Tprocsym(stackitem^.symtable.FindWithHash(hashedid));
  1868. if sym<>nil then
  1869. begin
  1870. if sym.typ<>procsym then
  1871. internalerror(200910241);
  1872. { if the source type is an alias then this is only the second choice,
  1873. if you mess with this code, check tw4093 }
  1874. currpd:=sym.find_procdef_enumerator_operator(type_def,curreq);
  1875. if curreq>besteq then
  1876. begin
  1877. besteq:=curreq;
  1878. bestpd:=currpd;
  1879. if (besteq=te_exact) then
  1880. break;
  1881. end;
  1882. end;
  1883. stackitem:=stackitem^.next;
  1884. end;
  1885. result:=bestpd;
  1886. end;
  1887. function search_system_type(const s: TIDString): ttypesym;
  1888. var
  1889. sym : tsym;
  1890. begin
  1891. sym:=tsym(systemunit.Find(s));
  1892. if not assigned(sym) or
  1893. (sym.typ<>typesym) then
  1894. cgmessage1(cg_f_unknown_system_type,s);
  1895. result:=ttypesym(sym);
  1896. end;
  1897. function search_named_unit_globaltype(const unitname, typename: TIDString): ttypesym;
  1898. var
  1899. srsymtable: tsymtable;
  1900. sym: tsym;
  1901. begin
  1902. if searchsym_in_named_module(unitname,typename,sym,srsymtable) and
  1903. (sym.typ=typesym) then
  1904. begin
  1905. result:=ttypesym(sym);
  1906. exit;
  1907. end
  1908. else
  1909. begin
  1910. cgmessage2(cg_f_unknown_type_in_unit,typename,unitname);
  1911. result:=nil;
  1912. end;
  1913. end;
  1914. function search_class_helper(pd : tobjectdef;const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  1915. var
  1916. hashedid : THashedIDString;
  1917. stackitem : psymtablestackitem;
  1918. i : longint;
  1919. defowner : tobjectdef;
  1920. begin
  1921. hashedid.id:=class_helper_prefix+s;
  1922. stackitem:=symtablestack.stack;
  1923. while assigned(stackitem) do
  1924. begin
  1925. srsymtable:=stackitem^.symtable;
  1926. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1927. if assigned(srsym) then
  1928. begin
  1929. if not(srsymtable.symtabletype in [globalsymtable,staticsymtable]) or
  1930. not(srsym.owner.symtabletype in [globalsymtable,staticsymtable]) or
  1931. (srsym.typ<>procsym) then
  1932. internalerror(2009111505);
  1933. { check whether this procsym includes a helper for this particular class }
  1934. for i:=0 to tprocsym(srsym).procdeflist.count-1 do
  1935. begin
  1936. { does pd inherit from (or is the same as) the class
  1937. that this method's category extended?
  1938. Warning: this list contains both category and objcclass methods
  1939. (for id.randommethod), so only check category methods here
  1940. }
  1941. defowner:=tobjectdef(tprocdef(tprocsym(srsym).procdeflist[i]).owner.defowner);
  1942. if (oo_is_classhelper in defowner.objectoptions) and
  1943. pd.is_related(defowner.childof) then
  1944. begin
  1945. { we need to know if a procedure references symbols
  1946. in the static symtable, because then it can't be
  1947. inlined from outside this unit }
  1948. if assigned(current_procinfo) and
  1949. (srsym.owner.symtabletype=staticsymtable) then
  1950. include(current_procinfo.flags,pi_uses_static_symtable);
  1951. { no need to keep looking. There might be other
  1952. categories that extend this, a parent or child
  1953. class with a method with the same name (either
  1954. overriding this one, or overridden by this one),
  1955. but that doesn't matter as far as the basic
  1956. procsym is concerned.
  1957. }
  1958. srsym:=tprocdef(tprocsym(srsym).procdeflist[i]).procsym;
  1959. srsymtable:=srsym.owner;
  1960. addsymref(srsym);
  1961. result:=true;
  1962. exit;
  1963. end;
  1964. end;
  1965. end;
  1966. stackitem:=stackitem^.next;
  1967. end;
  1968. srsym:=nil;
  1969. srsymtable:=nil;
  1970. result:=false;
  1971. end;
  1972. function search_objc_method(const s : string; out srsym: tsym; out srsymtable: tsymtable):boolean;
  1973. var
  1974. hashedid : THashedIDString;
  1975. stackitem : psymtablestackitem;
  1976. i : longint;
  1977. begin
  1978. hashedid.id:=class_helper_prefix+s;
  1979. stackitem:=symtablestack.stack;
  1980. while assigned(stackitem) do
  1981. begin
  1982. srsymtable:=stackitem^.symtable;
  1983. srsym:=tsym(srsymtable.FindWithHash(hashedid));
  1984. if assigned(srsym) then
  1985. begin
  1986. if not(srsymtable.symtabletype in [globalsymtable,staticsymtable]) or
  1987. not(srsym.owner.symtabletype in [globalsymtable,staticsymtable]) or
  1988. (srsym.typ<>procsym) then
  1989. internalerror(2009112005);
  1990. { check whether this procsym includes a helper for this particular class }
  1991. for i:=0 to tprocsym(srsym).procdeflist.count-1 do
  1992. begin
  1993. { we need to know if a procedure references symbols
  1994. in the static symtable, because then it can't be
  1995. inlined from outside this unit }
  1996. if assigned(current_procinfo) and
  1997. (srsym.owner.symtabletype=staticsymtable) then
  1998. include(current_procinfo.flags,pi_uses_static_symtable);
  1999. { no need to keep looking. There might be other
  2000. methods with the same name, but that doesn't matter
  2001. as far as the basic procsym is concerned.
  2002. }
  2003. srsym:=tprocdef(tprocsym(srsym).procdeflist[i]).procsym;
  2004. { We need the symtable in which the classhelper-like sym
  2005. is located, not the objectdef. The reason is that the
  2006. callnode will climb the symtablestack until it encounters
  2007. this symtable to start looking for overloads (and it won't
  2008. find the objectsymtable in which this method sym is
  2009. located
  2010. srsymtable:=srsym.owner;
  2011. }
  2012. addsymref(srsym);
  2013. result:=true;
  2014. exit;
  2015. end;
  2016. end;
  2017. stackitem:=stackitem^.next;
  2018. end;
  2019. srsym:=nil;
  2020. srsymtable:=nil;
  2021. result:=false;
  2022. end;
  2023. function search_class_member(pd : tobjectdef;const s : string):tsym;
  2024. { searches n in symtable of pd and all anchestors }
  2025. var
  2026. hashedid : THashedIDString;
  2027. srsym : tsym;
  2028. orgpd : tobjectdef;
  2029. srsymtable : tsymtable;
  2030. begin
  2031. hashedid.id:=s;
  2032. orgpd:=pd;
  2033. while assigned(pd) do
  2034. begin
  2035. srsym:=tsym(pd.symtable.FindWithHash(hashedid));
  2036. if assigned(srsym) then
  2037. begin
  2038. search_class_member:=srsym;
  2039. exit;
  2040. end;
  2041. pd:=pd.childof;
  2042. end;
  2043. { not found, now look for class helpers }
  2044. if is_objcclass(pd) then
  2045. search_class_helper(orgpd,s,result,srsymtable)
  2046. else
  2047. result:=nil;
  2048. end;
  2049. function search_macro(const s : string):tsym;
  2050. var
  2051. stackitem : psymtablestackitem;
  2052. hashedid : THashedIDString;
  2053. srsym : tsym;
  2054. begin
  2055. hashedid.id:=s;
  2056. { First search the localmacrosymtable before searching the
  2057. global macrosymtables from the units }
  2058. if assigned(current_module) then
  2059. begin
  2060. srsym:=tsym(current_module.localmacrosymtable.FindWithHash(hashedid));
  2061. if assigned(srsym) then
  2062. begin
  2063. result:= srsym;
  2064. exit;
  2065. end;
  2066. end;
  2067. stackitem:=macrosymtablestack.stack;
  2068. while assigned(stackitem) do
  2069. begin
  2070. srsym:=tsym(stackitem^.symtable.FindWithHash(hashedid));
  2071. if assigned(srsym) then
  2072. begin
  2073. result:= srsym;
  2074. exit;
  2075. end;
  2076. stackitem:=stackitem^.next;
  2077. end;
  2078. result:= nil;
  2079. end;
  2080. function defined_macro(const s : string):boolean;
  2081. var
  2082. mac: tmacro;
  2083. begin
  2084. mac:=tmacro(search_macro(s));
  2085. if assigned(mac) then
  2086. begin
  2087. mac.is_used:=true;
  2088. defined_macro:=mac.defined;
  2089. end
  2090. else
  2091. defined_macro:=false;
  2092. end;
  2093. {****************************************************************************
  2094. Object Helpers
  2095. ****************************************************************************}
  2096. function search_default_property(pd : tobjectdef) : tpropertysym;
  2097. { returns the default property of a class, searches also anchestors }
  2098. var
  2099. _defaultprop : tpropertysym;
  2100. begin
  2101. _defaultprop:=nil;
  2102. while assigned(pd) do
  2103. begin
  2104. pd.symtable.SymList.ForEachCall(@tstoredsymtable(pd.symtable).testfordefaultproperty,@_defaultprop);
  2105. if assigned(_defaultprop) then
  2106. break;
  2107. pd:=pd.childof;
  2108. end;
  2109. search_default_property:=_defaultprop;
  2110. end;
  2111. {****************************************************************************
  2112. Macro Helpers
  2113. ****************************************************************************}
  2114. procedure def_system_macro(const name : string);
  2115. var
  2116. mac : tmacro;
  2117. s: string;
  2118. begin
  2119. if name = '' then
  2120. internalerror(2004121202);
  2121. s:= upper(name);
  2122. mac:=tmacro(search_macro(s));
  2123. if not assigned(mac) then
  2124. begin
  2125. mac:=tmacro.create(s);
  2126. if assigned(current_module) then
  2127. current_module.localmacrosymtable.insert(mac)
  2128. else
  2129. initialmacrosymtable.insert(mac);
  2130. end;
  2131. if not mac.defined then
  2132. Message1(parser_c_macro_defined,mac.name);
  2133. mac.defined:=true;
  2134. end;
  2135. procedure set_system_macro(const name, value : string);
  2136. var
  2137. mac : tmacro;
  2138. s: string;
  2139. begin
  2140. if name = '' then
  2141. internalerror(2004121203);
  2142. s:= upper(name);
  2143. mac:=tmacro(search_macro(s));
  2144. if not assigned(mac) then
  2145. begin
  2146. mac:=tmacro.create(s);
  2147. if assigned(current_module) then
  2148. current_module.localmacrosymtable.insert(mac)
  2149. else
  2150. initialmacrosymtable.insert(mac);
  2151. end
  2152. else
  2153. begin
  2154. mac.is_compiler_var:=false;
  2155. if assigned(mac.buftext) then
  2156. freemem(mac.buftext,mac.buflen);
  2157. end;
  2158. Message2(parser_c_macro_set_to,mac.name,value);
  2159. mac.buflen:=length(value);
  2160. getmem(mac.buftext,mac.buflen);
  2161. move(value[1],mac.buftext^,mac.buflen);
  2162. mac.defined:=true;
  2163. end;
  2164. procedure set_system_compvar(const name, value : string);
  2165. var
  2166. mac : tmacro;
  2167. s: string;
  2168. begin
  2169. if name = '' then
  2170. internalerror(2004121204);
  2171. s:= upper(name);
  2172. mac:=tmacro(search_macro(s));
  2173. if not assigned(mac) then
  2174. begin
  2175. mac:=tmacro.create(s);
  2176. mac.is_compiler_var:=true;
  2177. if assigned(current_module) then
  2178. current_module.localmacrosymtable.insert(mac)
  2179. else
  2180. initialmacrosymtable.insert(mac);
  2181. end
  2182. else
  2183. begin
  2184. mac.is_compiler_var:=true;
  2185. if assigned(mac.buftext) then
  2186. freemem(mac.buftext,mac.buflen);
  2187. end;
  2188. Message2(parser_c_macro_set_to,mac.name,value);
  2189. mac.buflen:=length(value);
  2190. getmem(mac.buftext,mac.buflen);
  2191. move(value[1],mac.buftext^,mac.buflen);
  2192. mac.defined:=true;
  2193. end;
  2194. procedure undef_system_macro(const name : string);
  2195. var
  2196. mac : tmacro;
  2197. s: string;
  2198. begin
  2199. if name = '' then
  2200. internalerror(2004121205);
  2201. s:= upper(name);
  2202. mac:=tmacro(search_macro(s));
  2203. if not assigned(mac) then
  2204. {If not found, then it's already undefined.}
  2205. else
  2206. begin
  2207. if mac.defined then
  2208. Message1(parser_c_macro_undefined,mac.name);
  2209. mac.defined:=false;
  2210. mac.is_compiler_var:=false;
  2211. { delete old definition }
  2212. if assigned(mac.buftext) then
  2213. begin
  2214. freemem(mac.buftext,mac.buflen);
  2215. mac.buftext:=nil;
  2216. end;
  2217. end;
  2218. end;
  2219. {$ifdef UNITALIASES}
  2220. {****************************************************************************
  2221. TUNIT_ALIAS
  2222. ****************************************************************************}
  2223. constructor tunit_alias.create(const n:string);
  2224. var
  2225. i : longint;
  2226. begin
  2227. i:=pos('=',n);
  2228. if i=0 then
  2229. fail;
  2230. inherited createname(Copy(n,1,i-1));
  2231. newname:=stringdup(Copy(n,i+1,255));
  2232. end;
  2233. destructor tunit_alias.destroy;
  2234. begin
  2235. stringdispose(newname);
  2236. inherited destroy;
  2237. end;
  2238. procedure addunitalias(const n:string);
  2239. begin
  2240. unitaliases^.insert(tunit_alias,init(Upper(n))));
  2241. end;
  2242. function getunitalias(const n:string):string;
  2243. var
  2244. p : punit_alias;
  2245. begin
  2246. p:=punit_alias(unitaliases^.Find(Upper(n)));
  2247. if assigned(p) then
  2248. getunitalias:=punit_alias(p).newname^
  2249. else
  2250. getunitalias:=n;
  2251. end;
  2252. {$endif UNITALIASES}
  2253. {****************************************************************************
  2254. Init/Done Symtable
  2255. ****************************************************************************}
  2256. procedure InitSymtable;
  2257. begin
  2258. { Reset symbolstack }
  2259. symtablestack:=nil;
  2260. systemunit:=nil;
  2261. { create error syms and def }
  2262. generrorsym:=terrorsym.create;
  2263. generrordef:=terrordef.create;
  2264. { macros }
  2265. initialmacrosymtable:=tmacrosymtable.create(false);
  2266. macrosymtablestack:=TSymtablestack.create;
  2267. macrosymtablestack.push(initialmacrosymtable);
  2268. {$ifdef UNITALIASES}
  2269. { unit aliases }
  2270. unitaliases:=TFPHashObjectList.create;
  2271. {$endif}
  2272. { set some global vars to nil, might be important for the ide }
  2273. class_tobject:=nil;
  2274. interface_iunknown:=nil;
  2275. rec_tguid:=nil;
  2276. dupnr:=0;
  2277. end;
  2278. procedure DoneSymtable;
  2279. begin
  2280. generrorsym.owner:=nil;
  2281. generrorsym.free;
  2282. generrordef.owner:=nil;
  2283. generrordef.free;
  2284. initialmacrosymtable.free;
  2285. macrosymtablestack.free;
  2286. {$ifdef UNITALIASES}
  2287. unitaliases.free;
  2288. {$endif}
  2289. end;
  2290. end.