symtable.pas 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. This unit handles the symbol tables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symtable;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. cpuinfo,globtype,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,symsym,
  28. { ppu }
  29. ppu,
  30. { assembler }
  31. aasmtai
  32. ;
  33. {****************************************************************************
  34. Symtable types
  35. ****************************************************************************}
  36. type
  37. tstoredsymtable = class(tsymtable)
  38. private
  39. b_needs_init_final : boolean;
  40. procedure _needs_init_final(p : tnamedindexitem;arg:pointer);
  41. procedure check_forward(sym : TNamedIndexItem;arg:pointer);
  42. procedure labeldefined(p : TNamedIndexItem;arg:pointer);
  43. procedure varsymbolused(p : TNamedIndexItem;arg:pointer);
  44. procedure TestPrivate(p : TNamedIndexItem;arg:pointer);
  45. procedure objectprivatesymbolused(p : TNamedIndexItem;arg:pointer);
  46. {$ifdef GDB}
  47. private
  48. procedure concatstab(p : TNamedIndexItem;arg:pointer);
  49. procedure resetstab(p : TNamedIndexItem;arg:pointer);
  50. procedure concattypestab(p : TNamedIndexItem;arg:pointer);
  51. {$endif}
  52. procedure unchain_overloads(p : TNamedIndexItem;arg:pointer);
  53. procedure loaddefs(ppufile:tcompilerppufile);
  54. procedure loadsyms(ppufile:tcompilerppufile);
  55. procedure reset_def(def:Tnamedindexitem;arg:pointer);
  56. procedure writedefs(ppufile:tcompilerppufile);
  57. procedure writesyms(ppufile:tcompilerppufile);
  58. public
  59. { load/write }
  60. procedure ppuload(ppufile:tcompilerppufile);virtual;
  61. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  62. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  63. procedure write_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  64. procedure buildderef;virtual;
  65. procedure buildderefimpl;virtual;
  66. procedure deref;virtual;
  67. procedure derefimpl;virtual;
  68. procedure insert(sym : tsymentry);override;
  69. procedure reset_all_defs;virtual;
  70. function speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;override;
  71. procedure allsymbolsused;
  72. procedure allprivatesused;
  73. procedure check_forwards;
  74. procedure checklabels;
  75. function needs_init_final : boolean;
  76. procedure unchain_overloaded;
  77. {$ifdef GDB}
  78. procedure concatstabto(asmlist : taasmoutput);virtual;
  79. function getnewtypecount : word; override;
  80. {$endif GDB}
  81. procedure testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  82. end;
  83. tabstractrecordsymtable = class(tstoredsymtable)
  84. public
  85. datasize : longint;
  86. usefieldalignment, { alignment to use for fields (PACKRECORDS value), -1 is C style }
  87. recordalignment, { alignment required when inserting this record }
  88. fieldalignment : shortint; { alignment current alignment used when fields are inserted }
  89. constructor create(const n:string;usealign:shortint);
  90. procedure ppuload(ppufile:tcompilerppufile);override;
  91. procedure ppuwrite(ppufile:tcompilerppufile);override;
  92. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  93. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  94. procedure insertfield(sym:tvarsym;addsym:boolean);
  95. procedure addalignmentpadding;
  96. end;
  97. trecordsymtable = class(tabstractrecordsymtable)
  98. public
  99. constructor create(usealign:shortint);
  100. procedure insertunionst(unionst : trecordsymtable;offset : longint);
  101. end;
  102. tobjectsymtable = class(tabstractrecordsymtable)
  103. public
  104. constructor create(const n:string;usealign:shortint);
  105. procedure insert(sym : tsymentry);override;
  106. end;
  107. tabstractlocalsymtable = class(tstoredsymtable)
  108. public
  109. procedure ppuwrite(ppufile:tcompilerppufile);override;
  110. end;
  111. tlocalsymtable = class(tabstractlocalsymtable)
  112. public
  113. constructor create(level:byte);
  114. procedure insert(sym : tsymentry);override;
  115. end;
  116. tparasymtable = class(tabstractlocalsymtable)
  117. public
  118. constructor create(level:byte);
  119. procedure insert(sym : tsymentry);override;
  120. end;
  121. tabstractunitsymtable = class(tstoredsymtable)
  122. public
  123. {$ifdef GDB}
  124. dbx_count : longint;
  125. prev_dbx_counter : plongint;
  126. dbx_count_ok : boolean;
  127. is_stab_written : boolean;
  128. {$endif GDB}
  129. constructor create(const n : string);
  130. {$ifdef GDB}
  131. procedure concattypestabto(asmlist : taasmoutput);
  132. {$endif GDB}
  133. end;
  134. tglobalsymtable = class(tabstractunitsymtable)
  135. public
  136. unittypecount : word;
  137. constructor create(const n : string);
  138. procedure ppuload(ppufile:tcompilerppufile);override;
  139. procedure ppuwrite(ppufile:tcompilerppufile);override;
  140. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  141. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  142. procedure insert(sym : tsymentry);override;
  143. {$ifdef GDB}
  144. function getnewtypecount : word; override;
  145. {$endif}
  146. end;
  147. tstaticsymtable = class(tabstractunitsymtable)
  148. public
  149. constructor create(const n : string);
  150. procedure ppuload(ppufile:tcompilerppufile);override;
  151. procedure ppuwrite(ppufile:tcompilerppufile);override;
  152. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  153. procedure write_references(ppufile:tcompilerppufile;locals:boolean);override;
  154. procedure insert(sym : tsymentry);override;
  155. end;
  156. twithsymtable = class(tsymtable)
  157. withrefnode : pointer; { tnode }
  158. constructor create(aowner:tdef;asymsearch:TDictionary;refnode:pointer{tnode});
  159. destructor destroy;override;
  160. procedure clear;override;
  161. end;
  162. tstt_exceptsymtable = class(tsymtable)
  163. public
  164. constructor create;
  165. end;
  166. var
  167. constsymtable : tsymtable; { symtable were the constants can be inserted }
  168. systemunit : tglobalsymtable; { pointer to the system unit }
  169. {****************************************************************************
  170. Functions
  171. ****************************************************************************}
  172. {*** Misc ***}
  173. procedure globaldef(const s : string;var t:ttype);
  174. function findunitsymtable(st:tsymtable):tsymtable;
  175. procedure duplicatesym(sym:tsym);
  176. procedure incompatibletypes(def1,def2:tdef);
  177. {*** Search ***}
  178. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  179. function searchsym_type(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  180. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  181. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  182. function searchsym_in_class_by_msgint(classh:tobjectdef;i:longint):tsym;
  183. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string):tsym;
  184. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  185. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  186. function search_class_member(pd : tobjectdef;const s : string):tsym;
  187. function search_assignment_operator(from_def,to_def:Tdef):Tprocdef;
  188. {*** Object Helpers ***}
  189. procedure search_class_overloads(aprocsym : tprocsym);
  190. function search_default_property(pd : tobjectdef) : tpropertysym;
  191. procedure reset_all_defs;
  192. {*** symtable stack ***}
  193. {$ifdef DEBUG}
  194. procedure test_symtablestack;
  195. procedure list_symtablestack;
  196. {$endif DEBUG}
  197. {$ifdef UNITALIASES}
  198. type
  199. punit_alias = ^tunit_alias;
  200. tunit_alias = object(TNamedIndexItem)
  201. newname : pstring;
  202. constructor init(const n:string);
  203. destructor done;virtual;
  204. end;
  205. var
  206. unitaliases : pdictionary;
  207. procedure addunitalias(const n:string);
  208. function getunitalias(const n:string):string;
  209. {$endif UNITALIASES}
  210. {*** Init / Done ***}
  211. procedure InitSymtable;
  212. procedure DoneSymtable;
  213. const
  214. overloaded_names : array [NOTOKEN..last_overloaded] of string[16] =
  215. ('error',
  216. 'plus','minus','star','slash','equal',
  217. 'greater','lower','greater_or_equal',
  218. 'lower_or_equal',
  219. 'sym_diff','starstar',
  220. 'as','is','in','or',
  221. 'and','div','mod','not','shl','shr','xor',
  222. 'assign');
  223. implementation
  224. uses
  225. { global }
  226. verbose,globals,
  227. { target }
  228. systems,
  229. { symtable }
  230. symutil,defcmp,
  231. { module }
  232. fmodule,
  233. {$ifdef GDB}
  234. gdb,
  235. {$endif GDB}
  236. { codegen }
  237. procinfo
  238. ;
  239. {*****************************************************************************
  240. TStoredSymtable
  241. *****************************************************************************}
  242. procedure tstoredsymtable.ppuload(ppufile:tcompilerppufile);
  243. begin
  244. { load definitions }
  245. loaddefs(ppufile);
  246. { load symbols }
  247. loadsyms(ppufile);
  248. end;
  249. procedure tstoredsymtable.ppuwrite(ppufile:tcompilerppufile);
  250. begin
  251. { write definitions }
  252. writedefs(ppufile);
  253. { write symbols }
  254. writesyms(ppufile);
  255. end;
  256. procedure tstoredsymtable.loaddefs(ppufile:tcompilerppufile);
  257. var
  258. hp : tdef;
  259. b : byte;
  260. begin
  261. { load start of definition section, which holds the amount of defs }
  262. if ppufile.readentry<>ibstartdefs then
  263. Message(unit_f_ppu_read_error);
  264. ppufile.getlongint;
  265. { read definitions }
  266. repeat
  267. b:=ppufile.readentry;
  268. case b of
  269. ibpointerdef : hp:=tpointerdef.ppuload(ppufile);
  270. ibarraydef : hp:=tarraydef.ppuload(ppufile);
  271. iborddef : hp:=torddef.ppuload(ppufile);
  272. ibfloatdef : hp:=tfloatdef.ppuload(ppufile);
  273. ibprocdef : hp:=tprocdef.ppuload(ppufile);
  274. ibshortstringdef : hp:=tstringdef.loadshort(ppufile);
  275. iblongstringdef : hp:=tstringdef.loadlong(ppufile);
  276. ibansistringdef : hp:=tstringdef.loadansi(ppufile);
  277. ibwidestringdef : hp:=tstringdef.loadwide(ppufile);
  278. ibrecorddef : hp:=trecorddef.ppuload(ppufile);
  279. ibobjectdef : hp:=tobjectdef.ppuload(ppufile);
  280. ibenumdef : hp:=tenumdef.ppuload(ppufile);
  281. ibsetdef : hp:=tsetdef.ppuload(ppufile);
  282. ibprocvardef : hp:=tprocvardef.ppuload(ppufile);
  283. ibfiledef : hp:=tfiledef.ppuload(ppufile);
  284. ibclassrefdef : hp:=tclassrefdef.ppuload(ppufile);
  285. ibformaldef : hp:=tformaldef.ppuload(ppufile);
  286. ibvariantdef : hp:=tvariantdef.ppuload(ppufile);
  287. ibenddefs : break;
  288. ibend : Message(unit_f_ppu_read_error);
  289. else
  290. Message1(unit_f_ppu_invalid_entry,tostr(b));
  291. end;
  292. hp.owner:=self;
  293. defindex.insert(hp);
  294. until false;
  295. end;
  296. procedure tstoredsymtable.loadsyms(ppufile:tcompilerppufile);
  297. var
  298. b : byte;
  299. sym : tsym;
  300. begin
  301. { load start of definition section, which holds the amount of defs }
  302. if ppufile.readentry<>ibstartsyms then
  303. Message(unit_f_ppu_read_error);
  304. { skip amount of symbols, not used currently }
  305. ppufile.getlongint;
  306. { now read the symbols }
  307. repeat
  308. b:=ppufile.readentry;
  309. case b of
  310. ibtypesym : sym:=ttypesym.ppuload(ppufile);
  311. ibprocsym : sym:=tprocsym.ppuload(ppufile);
  312. ibconstsym : sym:=tconstsym.ppuload(ppufile);
  313. ibvarsym : sym:=tvarsym.ppuload(ppufile);
  314. ibabsolutesym : sym:=tabsolutesym.ppuload(ppufile);
  315. ibenumsym : sym:=tenumsym.ppuload(ppufile);
  316. ibtypedconstsym : sym:=ttypedconstsym.ppuload(ppufile);
  317. ibpropertysym : sym:=tpropertysym.ppuload(ppufile);
  318. ibunitsym : sym:=tunitsym.ppuload(ppufile);
  319. iblabelsym : sym:=tlabelsym.ppuload(ppufile);
  320. ibsyssym : sym:=tsyssym.ppuload(ppufile);
  321. ibrttisym : sym:=trttisym.ppuload(ppufile);
  322. ibendsyms : break;
  323. ibend : Message(unit_f_ppu_read_error);
  324. else
  325. Message1(unit_f_ppu_invalid_entry,tostr(b));
  326. end;
  327. sym.owner:=self;
  328. symindex.insert(sym);
  329. symsearch.insert(sym);
  330. until false;
  331. end;
  332. procedure tstoredsymtable.writedefs(ppufile:tcompilerppufile);
  333. var
  334. pd : tstoreddef;
  335. begin
  336. { each definition get a number, write then the amount of defs to the
  337. ibstartdef entry }
  338. ppufile.putlongint(defindex.count);
  339. ppufile.writeentry(ibstartdefs);
  340. { now write the definition }
  341. pd:=tstoreddef(defindex.first);
  342. while assigned(pd) do
  343. begin
  344. pd.ppuwrite(ppufile);
  345. pd:=tstoreddef(pd.indexnext);
  346. end;
  347. { write end of definitions }
  348. ppufile.writeentry(ibenddefs);
  349. end;
  350. procedure tstoredsymtable.writesyms(ppufile:tcompilerppufile);
  351. var
  352. pd : Tsym;
  353. begin
  354. { each definition get a number, write then the amount of syms and the
  355. datasize to the ibsymdef entry }
  356. ppufile.putlongint(symindex.count);
  357. ppufile.writeentry(ibstartsyms);
  358. { foreach is used to write all symbols }
  359. pd:=Tsym(symindex.first);
  360. while assigned(pd) do
  361. begin
  362. pd.ppuwrite(ppufile);
  363. pd:=Tsym(pd.indexnext);
  364. end;
  365. { end of symbols }
  366. ppufile.writeentry(ibendsyms);
  367. end;
  368. procedure tstoredsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  369. var
  370. b : byte;
  371. d : tderef;
  372. sym : Tsym;
  373. prdef : tstoreddef;
  374. begin
  375. b:=ppufile.readentry;
  376. if b <> ibbeginsymtablebrowser then
  377. Message1(unit_f_ppu_invalid_entry,tostr(b));
  378. repeat
  379. b:=ppufile.readentry;
  380. case b of
  381. ibsymref :
  382. begin
  383. ppufile.getderef(d);
  384. sym:=Tsym(d.resolve);
  385. if assigned(sym) then
  386. sym.load_references(ppufile,locals);
  387. end;
  388. ibdefref :
  389. begin
  390. ppufile.getderef(d);
  391. prdef:=tstoreddef(d.resolve);
  392. if assigned(prdef) then
  393. begin
  394. if prdef.deftype<>procdef then
  395. Message(unit_f_ppu_read_error);
  396. tprocdef(prdef).load_references(ppufile,locals);
  397. end;
  398. end;
  399. ibendsymtablebrowser :
  400. break;
  401. else
  402. Message1(unit_f_ppu_invalid_entry,tostr(b));
  403. end;
  404. until false;
  405. end;
  406. procedure tstoredsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  407. var
  408. pd : Tsym;
  409. begin
  410. ppufile.writeentry(ibbeginsymtablebrowser);
  411. { write all symbols }
  412. pd:=Tsym(symindex.first);
  413. while assigned(pd) do
  414. begin
  415. pd.write_references(ppufile,locals);
  416. pd:=Tsym(pd.indexnext);
  417. end;
  418. ppufile.writeentry(ibendsymtablebrowser);
  419. end;
  420. procedure tstoredsymtable.buildderef;
  421. var
  422. hp : tdef;
  423. hs : tsym;
  424. begin
  425. { interface definitions }
  426. hp:=tdef(defindex.first);
  427. while assigned(hp) do
  428. begin
  429. hp.buildderef;
  430. hp:=tdef(hp.indexnext);
  431. end;
  432. { interface symbols }
  433. hs:=tsym(symindex.first);
  434. while assigned(hs) do
  435. begin
  436. hs.buildderef;
  437. hs:=tsym(hs.indexnext);
  438. end;
  439. end;
  440. procedure tstoredsymtable.buildderefimpl;
  441. var
  442. hp : tdef;
  443. begin
  444. { definitions }
  445. hp:=tdef(defindex.first);
  446. while assigned(hp) do
  447. begin
  448. hp.buildderefimpl;
  449. hp:=tdef(hp.indexnext);
  450. end;
  451. end;
  452. procedure tstoredsymtable.deref;
  453. var
  454. hp : tdef;
  455. hs : tsym;
  456. begin
  457. { first deref the interface ttype symbols. This is needs
  458. to be done before the interface defs are derefed, because
  459. the interface defs can contain references to the type symbols
  460. which then already need to contain a resolved restype field (PFV) }
  461. hs:=tsym(symindex.first);
  462. while assigned(hs) do
  463. begin
  464. if hs.typ=typesym then
  465. hs.deref;
  466. hs:=tsym(hs.indexnext);
  467. end;
  468. { deref the interface definitions }
  469. hp:=tdef(defindex.first);
  470. while assigned(hp) do
  471. begin
  472. hp.deref;
  473. hp:=tdef(hp.indexnext);
  474. end;
  475. { deref the interface symbols }
  476. hs:=tsym(symindex.first);
  477. while assigned(hs) do
  478. begin
  479. if hs.typ<>typesym then
  480. hs.deref;
  481. hs:=tsym(hs.indexnext);
  482. end;
  483. end;
  484. procedure tstoredsymtable.derefimpl;
  485. var
  486. hp : tdef;
  487. begin
  488. { definitions }
  489. hp:=tdef(defindex.first);
  490. while assigned(hp) do
  491. begin
  492. hp.derefimpl;
  493. hp:=tdef(hp.indexnext);
  494. end;
  495. end;
  496. procedure tstoredsymtable.insert(sym:tsymentry);
  497. var
  498. hsym : tsym;
  499. begin
  500. { set owner and sym indexnb }
  501. sym.owner:=self;
  502. { check the current symtable }
  503. hsym:=tsym(search(sym.name));
  504. if assigned(hsym) then
  505. begin
  506. { in TP and Delphi you can have a local with the
  507. same name as the function, the function is then hidden for
  508. the user. (Under delphi it can still be accessed using result),
  509. but don't allow hiding of RESULT }
  510. if (m_duplicate_names in aktmodeswitches) and
  511. (sym.typ in [varsym,absolutesym]) and
  512. (vo_is_funcret in tvarsym(sym).varoptions) and
  513. not((m_result in aktmodeswitches) and
  514. (vo_is_result in tvarsym(sym).varoptions)) then
  515. sym.name:='hidden'+sym.name
  516. else
  517. begin
  518. DuplicateSym(hsym);
  519. exit;
  520. end;
  521. end;
  522. { register definition of typesym }
  523. if (sym.typ = typesym) and
  524. assigned(ttypesym(sym).restype.def) then
  525. begin
  526. if not(assigned(ttypesym(sym).restype.def.owner)) and
  527. (ttypesym(sym).restype.def.deftype<>errordef) then
  528. registerdef(ttypesym(sym).restype.def);
  529. {$ifdef GDB}
  530. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  531. (symtabletype in [globalsymtable,staticsymtable]) then
  532. begin
  533. ttypesym(sym).isusedinstab := true;
  534. {sym.concatstabto(debuglist);}
  535. end;
  536. {$endif GDB}
  537. end;
  538. { insert in index and search hash }
  539. symindex.insert(sym);
  540. symsearch.insert(sym);
  541. end;
  542. function tstoredsymtable.speedsearch(const s : stringid;speedvalue : cardinal) : tsymentry;
  543. var
  544. hp : Tsym;
  545. newref : tref;
  546. begin
  547. hp:=Tsym(inherited speedsearch(s,speedvalue));
  548. if assigned(hp) then
  549. begin
  550. { reject non static members in static procedures }
  551. if (symtabletype=objectsymtable) and
  552. not(sp_static in hp.symoptions) and
  553. allow_only_static then
  554. Message(sym_e_only_static_in_static);
  555. { unit uses count }
  556. if (unitid<>0) and
  557. (symtabletype = globalsymtable) and
  558. assigned(current_module) and
  559. (unitid<current_module.mapsize) and
  560. assigned(current_module.map[unitid].unitsym) then
  561. inc(current_module.map[unitid].unitsym.refs);
  562. {$ifdef GDB}
  563. { if it is a type, we need the stabs of this type
  564. this might be the cause of the class debug problems
  565. as TCHILDCLASS.Create did not generate appropriate
  566. stabs debug info if TCHILDCLASS wasn't used anywhere else PM }
  567. if (cs_debuginfo in aktmoduleswitches) and
  568. (hp.typ=typesym) and make_ref then
  569. begin
  570. if assigned(ttypesym(hp).restype.def) then
  571. tstoreddef(ttypesym(hp).restype.def).numberstring
  572. else
  573. ttypesym(hp).isusedinstab:=true;
  574. end;
  575. {$endif GDB}
  576. { unitsym are only loaded for browsing PM }
  577. { this was buggy anyway because we could use }
  578. { unitsyms from other units in _USES !! }
  579. {if (symtabletype=unitsymtable) and (hp.typ=unitsym) and
  580. assigned(current_module) and (current_module.globalsymtable<>.load) then
  581. hp:=nil;}
  582. if make_ref and (cs_browser in aktmoduleswitches) then
  583. begin
  584. newref:=tref.create(hp.lastref,@akttokenpos);
  585. { for symbols that are in tables without browser info or syssyms }
  586. if hp.refcount=0 then
  587. begin
  588. hp.defref:=newref;
  589. hp.lastref:=newref;
  590. end
  591. else
  592. if resolving_forward and assigned(hp.defref) then
  593. { put it as second reference }
  594. begin
  595. newref.nextref:=hp.defref.nextref;
  596. hp.defref.nextref:=newref;
  597. hp.lastref.nextref:=nil;
  598. end
  599. else
  600. hp.lastref:=newref;
  601. inc(hp.refcount);
  602. end;
  603. if make_ref then
  604. inc(hp.refs);
  605. end; { value was not found }
  606. speedsearch:=hp;
  607. end;
  608. {**************************************
  609. Callbacks
  610. **************************************}
  611. procedure TStoredSymtable.check_forward(sym : TNamedIndexItem;arg:pointer);
  612. begin
  613. if tsym(sym).typ=procsym then
  614. tprocsym(sym).check_forward
  615. { check also object method table }
  616. { we needn't to test the def list }
  617. { because each object has to have a type sym }
  618. else
  619. if (tsym(sym).typ=typesym) and
  620. assigned(ttypesym(sym).restype.def) and
  621. (ttypesym(sym).restype.def.deftype=objectdef) then
  622. tobjectdef(ttypesym(sym).restype.def).check_forwards;
  623. end;
  624. procedure TStoredSymtable.labeldefined(p : TNamedIndexItem;arg:pointer);
  625. begin
  626. if (tsym(p).typ=labelsym) and
  627. not(tlabelsym(p).defined) then
  628. begin
  629. if tlabelsym(p).used then
  630. Message1(sym_e_label_used_and_not_defined,tlabelsym(p).realname)
  631. else
  632. Message1(sym_w_label_not_defined,tlabelsym(p).realname);
  633. end;
  634. end;
  635. procedure TStoredSymtable.varsymbolused(p : TNamedIndexItem;arg:pointer);
  636. begin
  637. if (tsym(p).typ=varsym) and
  638. ((tsym(p).owner.symtabletype in
  639. [parasymtable,localsymtable,objectsymtable,staticsymtable])) then
  640. begin
  641. { unused symbol should be reported only if no }
  642. { error is reported }
  643. { if the symbol is in a register it is used }
  644. { also don't count the value parameters which have local copies }
  645. { also don't claim for high param of open parameters (PM) }
  646. if (Errorcount<>0) or
  647. (assigned(tvarsym(p).paraitem) and
  648. tvarsym(p).paraitem.is_hidden) then
  649. exit;
  650. if (tvarsym(p).refs=0) then
  651. begin
  652. if (vo_is_funcret in tvarsym(p).varoptions) then
  653. begin
  654. { don't warn about the result of constructors }
  655. if (tsym(p).owner.symtabletype<>localsymtable) or
  656. (tprocdef(tsym(p).owner.defowner).proctypeoption<>potype_constructor) then
  657. MessagePos(tsym(p).fileinfo,sym_w_function_result_not_set)
  658. end
  659. else if (tsym(p).owner.symtabletype=parasymtable) then
  660. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_not_used,tsym(p).realname)
  661. else if (tsym(p).owner.symtabletype=objectsymtable) then
  662. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_not_used,tsym(p).owner.realname^,tsym(p).realname)
  663. else
  664. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_not_used,tsym(p).realname);
  665. end
  666. else if tvarsym(p).varstate=vs_assigned then
  667. begin
  668. if (tsym(p).owner.symtabletype=parasymtable) then
  669. begin
  670. if not(tvarsym(p).varspez in [vs_var,vs_out]) and
  671. not(vo_is_funcret in tvarsym(p).varoptions) then
  672. MessagePos1(tsym(p).fileinfo,sym_h_para_identifier_only_set,tsym(p).realname)
  673. end
  674. else if (tsym(p).owner.symtabletype=objectsymtable) then
  675. MessagePos2(tsym(p).fileinfo,sym_n_private_identifier_only_set,tsym(p).owner.realname^,tsym(p).realname)
  676. else if not(vo_is_exported in tvarsym(p).varoptions) and
  677. not(vo_is_funcret in tvarsym(p).varoptions) then
  678. MessagePos1(tsym(p).fileinfo,sym_n_local_identifier_only_set,tsym(p).realname);
  679. end;
  680. end
  681. else if ((tsym(p).owner.symtabletype in
  682. [objectsymtable,parasymtable,localsymtable,staticsymtable])) then
  683. begin
  684. if (Errorcount<>0) or
  685. (sp_internal in tsym(p).symoptions) then
  686. exit;
  687. { do not claim for inherited private fields !! }
  688. if (Tsym(p).refs=0) and (tsym(p).owner.symtabletype=objectsymtable) then
  689. MessagePos2(tsym(p).fileinfo,sym_n_private_method_not_used,tsym(p).owner.realname^,tsym(p).realname)
  690. { units references are problematic }
  691. else
  692. begin
  693. if (Tsym(p).refs=0) and
  694. not(tsym(p).typ in [enumsym,unitsym]) and
  695. not(is_funcret_sym(tsym(p))) and
  696. (
  697. (tsym(p).typ<>procsym) or
  698. {$ifdef GDB}
  699. not (tprocsym(p).is_global) or
  700. {$endif GDB}
  701. { all program functions are declared global
  702. but unused should still be signaled PM }
  703. ((tsym(p).owner.symtabletype=staticsymtable) and
  704. not current_module.is_unit)
  705. ) then
  706. MessagePos2(tsym(p).fileinfo,sym_h_local_symbol_not_used,SymTypeName[tsym(p).typ],tsym(p).realname);
  707. end;
  708. end;
  709. end;
  710. procedure TStoredSymtable.TestPrivate(p : TNamedIndexItem;arg:pointer);
  711. begin
  712. if sp_private in tsym(p).symoptions then
  713. varsymbolused(p,arg);
  714. end;
  715. procedure TStoredSymtable.objectprivatesymbolused(p : TNamedIndexItem;arg:pointer);
  716. begin
  717. {
  718. Don't test simple object aliases PM
  719. }
  720. if (tsym(p).typ=typesym) and
  721. (ttypesym(p).restype.def.deftype=objectdef) and
  722. (ttypesym(p).restype.def.typesym=tsym(p)) then
  723. tobjectdef(ttypesym(p).restype.def).symtable.foreach({$ifdef FPCPROCVAR}@{$endif}TestPrivate,nil);
  724. end;
  725. procedure tstoredsymtable.unchain_overloads(p : TNamedIndexItem;arg:pointer);
  726. begin
  727. if tsym(p).typ=procsym then
  728. tprocsym(p).unchain_overload;
  729. end;
  730. procedure Tstoredsymtable.reset_def(def:Tnamedindexitem;arg:pointer);
  731. begin
  732. Tstoreddef(def).reset;
  733. end;
  734. {$ifdef GDB}
  735. procedure TStoredSymtable.concatstab(p : TNamedIndexItem;arg:pointer);
  736. var stabstr:Pchar;
  737. ao:Taasmoutput;
  738. begin
  739. if Tsym(p).typ<>procsym then
  740. begin
  741. ao:=Taasmoutput(arg);
  742. if not Tsym(p).isstabwritten then
  743. begin
  744. stabstr:=Tsym(p).stabstring;
  745. if stabstr<>nil then
  746. ao.concat(Tai_stabs.create(stabstr));
  747. Tsym(p).isstabwritten:=true;
  748. end;
  749. end;
  750. end;
  751. procedure TStoredSymtable.resetstab(p : TNamedIndexItem;arg:pointer);
  752. begin
  753. if tsym(p).typ <> procsym then
  754. Tstoredsym(p).isstabwritten:=false;
  755. end;
  756. procedure TStoredSymtable.concattypestab(p : TNamedIndexItem;arg:pointer);
  757. var stabstr:Pchar;
  758. ao:Taasmoutput;
  759. begin
  760. if Tsym(p).typ=typesym then
  761. begin
  762. ao:=Taasmoutput(arg);
  763. if Ttypesym(p).restype.def.typesym=p then
  764. Tstoreddef(Ttypesym(p).restype.def).concatstabto(ao)
  765. else
  766. begin
  767. Tsym(p).isstabwritten:=false;
  768. stabstr:=Tsym(p).stabstring;
  769. if stabstr<>nil then
  770. ao.concat(Tai_stabs.create(stabstr));
  771. Tsym(p).isstabwritten:=true;
  772. end;
  773. end;
  774. end;
  775. function tstoredsymtable.getnewtypecount : word;
  776. begin
  777. getnewtypecount:=pglobaltypecount^;
  778. inc(pglobaltypecount^);
  779. end;
  780. {$endif GDB}
  781. {***********************************************
  782. Process all entries
  783. ***********************************************}
  784. procedure Tstoredsymtable.reset_all_defs;
  785. begin
  786. defindex.foreach(@reset_def,nil);
  787. end;
  788. { checks, if all procsyms and methods are defined }
  789. procedure tstoredsymtable.check_forwards;
  790. begin
  791. foreach({$ifdef FPCPROCVAR}@{$endif}check_forward,nil);
  792. end;
  793. procedure tstoredsymtable.checklabels;
  794. begin
  795. foreach({$ifdef FPCPROCVAR}@{$endif}labeldefined,nil);
  796. end;
  797. procedure tstoredsymtable.allsymbolsused;
  798. begin
  799. foreach({$ifdef FPCPROCVAR}@{$endif}varsymbolused,nil);
  800. end;
  801. procedure tstoredsymtable.allprivatesused;
  802. begin
  803. foreach({$ifdef FPCPROCVAR}@{$endif}objectprivatesymbolused,nil);
  804. end;
  805. procedure tstoredsymtable.unchain_overloaded;
  806. begin
  807. foreach({$ifdef FPCPROCVAR}@{$endif}unchain_overloads,nil);
  808. end;
  809. {$ifdef GDB}
  810. procedure tstoredsymtable.concatstabto(asmlist : taasmoutput);
  811. begin
  812. foreach({$ifdef FPCPROCVAR}@{$endif}concatstab,asmlist);
  813. end;
  814. {$endif}
  815. procedure TStoredSymtable._needs_init_final(p : tnamedindexitem;arg:pointer);
  816. begin
  817. if b_needs_init_final then
  818. exit;
  819. case tsym(p).typ of
  820. varsym :
  821. begin
  822. if not(is_class(tvarsym(p).vartype.def)) and
  823. tstoreddef(tvarsym(p).vartype.def).needs_inittable then
  824. b_needs_init_final:=true;
  825. end;
  826. typedconstsym :
  827. begin
  828. if ttypedconstsym(p).is_writable and
  829. tstoreddef(ttypedconstsym(p).typedconsttype.def).needs_inittable then
  830. b_needs_init_final:=true;
  831. end;
  832. end;
  833. end;
  834. { returns true, if p contains data which needs init/final code }
  835. function tstoredsymtable.needs_init_final : boolean;
  836. begin
  837. b_needs_init_final:=false;
  838. foreach({$ifdef FPCPROCVAR}@{$endif}_needs_init_final,nil);
  839. needs_init_final:=b_needs_init_final;
  840. end;
  841. {****************************************************************************
  842. TAbstractRecordSymtable
  843. ****************************************************************************}
  844. constructor tabstractrecordsymtable.create(const n:string;usealign:shortint);
  845. begin
  846. inherited create(n);
  847. datasize:=0;
  848. recordalignment:=1;
  849. usefieldalignment:=usealign;
  850. { recordalign -1 means C record packing, that starts
  851. with an alignment of 1 }
  852. if usealign=-1 then
  853. fieldalignment:=1
  854. else
  855. fieldalignment:=usealign;
  856. end;
  857. procedure tabstractrecordsymtable.ppuload(ppufile:tcompilerppufile);
  858. var
  859. storesymtable : tsymtable;
  860. begin
  861. storesymtable:=aktrecordsymtable;
  862. aktrecordsymtable:=self;
  863. inherited ppuload(ppufile);
  864. aktrecordsymtable:=storesymtable;
  865. end;
  866. procedure tabstractrecordsymtable.ppuwrite(ppufile:tcompilerppufile);
  867. var
  868. oldtyp : byte;
  869. storesymtable : tsymtable;
  870. begin
  871. storesymtable:=aktrecordsymtable;
  872. aktrecordsymtable:=self;
  873. oldtyp:=ppufile.entrytyp;
  874. ppufile.entrytyp:=subentryid;
  875. inherited ppuwrite(ppufile);
  876. ppufile.entrytyp:=oldtyp;
  877. aktrecordsymtable:=storesymtable;
  878. end;
  879. procedure tabstractrecordsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  880. var
  881. storesymtable : tsymtable;
  882. begin
  883. storesymtable:=aktrecordsymtable;
  884. aktrecordsymtable:=self;
  885. inherited load_references(ppufile,locals);
  886. aktrecordsymtable:=storesymtable;
  887. end;
  888. procedure tabstractrecordsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  889. var
  890. storesymtable : tsymtable;
  891. begin
  892. storesymtable:=aktrecordsymtable;
  893. aktrecordsymtable:=self;
  894. inherited write_references(ppufile,locals);
  895. aktrecordsymtable:=storesymtable;
  896. end;
  897. procedure tabstractrecordsymtable.insertfield(sym : tvarsym;addsym:boolean);
  898. var
  899. l,
  900. varalignrecord,
  901. varalignfield,
  902. varalign : longint;
  903. vardef : tdef;
  904. begin
  905. if addsym then
  906. insert(sym);
  907. { this symbol can't be loaded to a register }
  908. exclude(tvarsym(sym).varoptions,vo_regable);
  909. exclude(tvarsym(sym).varoptions,vo_fpuregable);
  910. { Calculate field offset }
  911. l:=tvarsym(sym).getvaluesize;
  912. vardef:=tvarsym(sym).vartype.def;
  913. varalign:=vardef.alignment;
  914. { Calc the alignment size for C style records }
  915. if (usefieldalignment=-1) then
  916. begin
  917. if (varalign>4) and
  918. ((varalign mod 4)<>0) and
  919. (vardef.deftype=arraydef) then
  920. Message1(sym_w_wrong_C_pack,vardef.typename);
  921. if varalign=0 then
  922. varalign:=l;
  923. if (fieldalignment<aktalignment.maxCrecordalign) then
  924. begin
  925. if (varalign>16) and (fieldalignment<32) then
  926. fieldalignment:=32
  927. else if (varalign>12) and (fieldalignment<16) then
  928. fieldalignment:=16
  929. { 12 is needed for long double }
  930. else if (varalign>8) and (fieldalignment<12) then
  931. fieldalignment:=12
  932. else if (varalign>4) and (fieldalignment<8) then
  933. fieldalignment:=8
  934. else if (varalign>2) and (fieldalignment<4) then
  935. fieldalignment:=4
  936. else if (varalign>1) and (fieldalignment<2) then
  937. fieldalignment:=2;
  938. end;
  939. fieldalignment:=min(fieldalignment,aktalignment.maxCrecordalign);
  940. end;
  941. if varalign=0 then
  942. varalign:=size_2_align(l);
  943. varalignfield:=used_align(varalign,aktalignment.recordalignmin,fieldalignment);
  944. tvarsym(sym).fieldoffset:=align(datasize,varalignfield);
  945. datasize:=tvarsym(sym).fieldoffset+l;
  946. { Calc alignment needed for this record }
  947. if (usefieldalignment=-1) then
  948. varalignrecord:=used_align(varalign,aktalignment.recordalignmin,aktalignment.maxCrecordalign)
  949. else
  950. varalignrecord:=used_align(varalign,aktalignment.recordalignmin,aktalignment.recordalignmax);
  951. recordalignment:=max(recordalignment,varalignrecord);
  952. end;
  953. procedure tabstractrecordsymtable.addalignmentpadding;
  954. var
  955. padalign : shortint;
  956. begin
  957. { make the record size aligned correctly so it can be
  958. used as elements in an array. For C records we
  959. use the fieldalignment, because that is updated with the
  960. used alignment. For normal records we use minimum from
  961. recordalginment or fieldalignment. This is required to
  962. be able to override the natural alignment with 'packed' }
  963. if usefieldalignment=-1 then
  964. padalign:=fieldalignment
  965. else
  966. padalign:=min(fieldalignment,recordalignment);
  967. datasize:=align(datasize,padalign);
  968. end;
  969. {****************************************************************************
  970. TRecordSymtable
  971. ****************************************************************************}
  972. constructor trecordsymtable.create(usealign:shortint);
  973. begin
  974. inherited create('',usealign);
  975. symtabletype:=recordsymtable;
  976. end;
  977. { this procedure is reserved for inserting case variant into
  978. a record symtable }
  979. { the offset is the location of the start of the variant
  980. and datasize and dataalignment corresponds to
  981. the complete size (see code in pdecl unit) PM }
  982. procedure trecordsymtable.insertunionst(unionst : trecordsymtable;offset : longint);
  983. var
  984. ps,nps : tvarsym;
  985. pd,npd : tdef;
  986. varalignrecord,varalign,
  987. storesize,storealign : longint;
  988. begin
  989. storesize:=datasize;
  990. storealign:=fieldalignment;
  991. datasize:=offset;
  992. ps:=tvarsym(unionst.symindex.first);
  993. while assigned(ps) do
  994. begin
  995. nps:=tvarsym(ps.indexnext);
  996. { remove from current symtable }
  997. unionst.symindex.deleteindex(ps);
  998. ps.left:=nil;
  999. ps.right:=nil;
  1000. { add to this record }
  1001. ps.owner:=self;
  1002. datasize:=ps.fieldoffset+offset;
  1003. symindex.insert(ps);
  1004. symsearch.insert(ps);
  1005. { update address }
  1006. ps.fieldoffset:=datasize;
  1007. { update alignment of this record }
  1008. varalign:=ps.vartype.def.alignment;
  1009. if varalign=0 then
  1010. varalign:=size_2_align(ps.getvaluesize);
  1011. varalignrecord:=used_align(varalign,aktalignment.recordalignmin,aktalignment.recordalignmax);
  1012. recordalignment:=max(recordalignment,varalignrecord);
  1013. { next }
  1014. ps:=nps;
  1015. end;
  1016. pd:=tdef(unionst.defindex.first);
  1017. while assigned(pd) do
  1018. begin
  1019. npd:=tdef(pd.indexnext);
  1020. unionst.defindex.deleteindex(pd);
  1021. pd.left:=nil;
  1022. pd.right:=nil;
  1023. registerdef(pd);
  1024. pd:=npd;
  1025. end;
  1026. datasize:=storesize;
  1027. fieldalignment:=storealign;
  1028. end;
  1029. {****************************************************************************
  1030. TObjectSymtable
  1031. ****************************************************************************}
  1032. constructor tobjectsymtable.create(const n:string;usealign:shortint);
  1033. begin
  1034. inherited create(n,usealign);
  1035. symtabletype:=objectsymtable;
  1036. end;
  1037. procedure tobjectsymtable.insert(sym:tsymentry);
  1038. var
  1039. hsym : tsym;
  1040. begin
  1041. { check for duplicate field id in inherited classes }
  1042. if (sym.typ=varsym) and
  1043. assigned(defowner) and
  1044. (
  1045. not(m_delphi in aktmodeswitches) or
  1046. is_object(tdef(defowner))
  1047. ) then
  1048. begin
  1049. { but private ids can be reused }
  1050. hsym:=search_class_member(tobjectdef(defowner),sym.name);
  1051. if assigned(hsym) and
  1052. Tsym(hsym).is_visible_for_object(tobjectdef(defowner)) then
  1053. begin
  1054. DuplicateSym(hsym);
  1055. exit;
  1056. end;
  1057. end;
  1058. inherited insert(sym);
  1059. end;
  1060. {****************************************************************************
  1061. TAbstractLocalSymtable
  1062. ****************************************************************************}
  1063. procedure tabstractlocalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1064. var
  1065. oldtyp : byte;
  1066. begin
  1067. oldtyp:=ppufile.entrytyp;
  1068. ppufile.entrytyp:=subentryid;
  1069. { write definitions }
  1070. writedefs(ppufile);
  1071. { write symbols }
  1072. writesyms(ppufile);
  1073. ppufile.entrytyp:=oldtyp;
  1074. end;
  1075. {****************************************************************************
  1076. TLocalSymtable
  1077. ****************************************************************************}
  1078. constructor tlocalsymtable.create(level:byte);
  1079. begin
  1080. inherited create('');
  1081. symtabletype:=localsymtable;
  1082. symtablelevel:=level;
  1083. end;
  1084. procedure tlocalsymtable.insert(sym:tsymentry);
  1085. var
  1086. hsym : tsym;
  1087. begin
  1088. { need to hide function result? }
  1089. hsym:=tsym(search(sym.name));
  1090. if assigned(hsym) then
  1091. begin
  1092. { a local and the function can have the same
  1093. name in TP and Delphi, but RESULT not }
  1094. if (m_duplicate_names in aktmodeswitches) and
  1095. (hsym.typ in [absolutesym,varsym]) and
  1096. (vo_is_funcret in tvarsym(hsym).varoptions) and
  1097. not((m_result in aktmodeswitches) and
  1098. (vo_is_result in tvarsym(hsym).varoptions)) then
  1099. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1100. else
  1101. begin
  1102. DuplicateSym(hsym);
  1103. exit;
  1104. end;
  1105. end;
  1106. if assigned(next) and
  1107. (next.symtabletype=parasymtable) then
  1108. begin
  1109. { check para symtable }
  1110. hsym:=tsym(next.search(sym.name));
  1111. if assigned(hsym) then
  1112. begin
  1113. { a local and the function can have the same
  1114. name in TP and Delphi, but RESULT not }
  1115. if (m_duplicate_names in aktmodeswitches) and
  1116. (sym.typ in [absolutesym,varsym]) and
  1117. (vo_is_funcret in tvarsym(sym).varoptions) and
  1118. not((m_result in aktmodeswitches) and
  1119. (vo_is_result in tvarsym(sym).varoptions)) then
  1120. sym.name:='hidden'+sym.name
  1121. else
  1122. begin
  1123. DuplicateSym(hsym);
  1124. exit;
  1125. end;
  1126. end;
  1127. { check for duplicate id in local symtable of methods }
  1128. if assigned(next.next) and
  1129. { funcretsym is allowed !! }
  1130. (not is_funcret_sym(sym)) and
  1131. (next.next.symtabletype=objectsymtable) then
  1132. begin
  1133. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1134. if assigned(hsym) and
  1135. { private ids can be reused }
  1136. (not(sp_private in hsym.symoptions) or
  1137. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1138. begin
  1139. { delphi allows to reuse the names in a class, but not
  1140. in object (tp7 compatible) }
  1141. if not((m_delphi in aktmodeswitches) and
  1142. is_class(tdef(next.next.defowner))) then
  1143. begin
  1144. DuplicateSym(hsym);
  1145. exit;
  1146. end;
  1147. end;
  1148. end;
  1149. end;
  1150. inherited insert(sym);
  1151. end;
  1152. {****************************************************************************
  1153. TParaSymtable
  1154. ****************************************************************************}
  1155. constructor tparasymtable.create(level:byte);
  1156. begin
  1157. inherited create('');
  1158. symtabletype:=parasymtable;
  1159. symtablelevel:=level;
  1160. end;
  1161. procedure tparasymtable.insert(sym:tsymentry);
  1162. var
  1163. hsym : tsym;
  1164. begin
  1165. { check for duplicate id in para symtable of methods }
  1166. if assigned(next) and
  1167. (next.symtabletype=objectsymtable) and
  1168. { funcretsym is allowed }
  1169. (not is_funcret_sym(sym)) then
  1170. begin
  1171. hsym:=search_class_member(tobjectdef(next.defowner),sym.name);
  1172. { private ids can be reused }
  1173. if assigned(hsym) and
  1174. Tsym(hsym).is_visible_for_object(tobjectdef(next.defowner)) then
  1175. begin
  1176. { delphi allows to reuse the names in a class, but not
  1177. in object (tp7 compatible) }
  1178. if not((m_delphi in aktmodeswitches) and
  1179. is_class_or_interface(tobjectdef(next.defowner))) then
  1180. begin
  1181. DuplicateSym(hsym);
  1182. exit;
  1183. end;
  1184. end;
  1185. end;
  1186. inherited insert(sym);
  1187. end;
  1188. {****************************************************************************
  1189. TAbstractUnitSymtable
  1190. ****************************************************************************}
  1191. constructor tabstractunitsymtable.create(const n : string);
  1192. begin
  1193. inherited create(n);
  1194. symsearch.usehash;
  1195. {$ifdef GDB}
  1196. { reset GDB things }
  1197. prev_dbx_counter := dbx_counter;
  1198. dbx_counter := nil;
  1199. is_stab_written:=false;
  1200. dbx_count := -1;
  1201. {$endif GDB}
  1202. end;
  1203. {$ifdef GDB}
  1204. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1205. var prev_dbx_count : plongint;
  1206. begin
  1207. if is_stab_written then
  1208. exit;
  1209. if not assigned(name) then
  1210. name := stringdup('Main_program');
  1211. {if (symtabletype = globalsymtable) and
  1212. (current_module.globalsymtable<>self) then
  1213. begin
  1214. unitid:=current_module.unitcount;
  1215. inc(current_module.unitcount);
  1216. end;}
  1217. asmList.concat(tai_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1218. if cs_gdb_dbx in aktglobalswitches then
  1219. begin
  1220. if dbx_count_ok then
  1221. begin
  1222. asmList.concat(tai_comment.Create(strpnew('"repeated" unit '+name^
  1223. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1224. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1225. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1226. exit;
  1227. end
  1228. else if (current_module.globalsymtable<>self) then
  1229. begin
  1230. prev_dbx_count := dbx_counter;
  1231. dbx_counter := nil;
  1232. do_count_dbx:=false;
  1233. if (symtabletype = globalsymtable) and (unitid<>0) then
  1234. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1235. dbx_counter := @dbx_count;
  1236. dbx_count:=0;
  1237. do_count_dbx:=assigned(dbx_counter);
  1238. end;
  1239. end;
  1240. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1241. if cs_gdb_dbx in aktglobalswitches then
  1242. begin
  1243. if (current_module.globalsymtable<>self) then
  1244. begin
  1245. dbx_counter := prev_dbx_count;
  1246. do_count_dbx:=false;
  1247. asmList.concat(tai_comment.Create(strpnew('End unit '+name^
  1248. +' has index '+tostr(unitid))));
  1249. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1250. +tostr(N_EINCL)+',0,0,0')));
  1251. do_count_dbx:=assigned(dbx_counter);
  1252. dbx_count_ok := {true}false;
  1253. end;
  1254. end;
  1255. is_stab_written:=true;
  1256. end;
  1257. {$endif GDB}
  1258. {****************************************************************************
  1259. TStaticSymtable
  1260. ****************************************************************************}
  1261. constructor tstaticsymtable.create(const n : string);
  1262. begin
  1263. inherited create(n);
  1264. symtabletype:=staticsymtable;
  1265. symtablelevel:=main_program_level;
  1266. end;
  1267. procedure tstaticsymtable.ppuload(ppufile:tcompilerppufile);
  1268. begin
  1269. aktstaticsymtable:=self;
  1270. next:=symtablestack;
  1271. symtablestack:=self;
  1272. inherited ppuload(ppufile);
  1273. { now we can deref the syms and defs }
  1274. deref;
  1275. { restore symtablestack }
  1276. symtablestack:=next;
  1277. end;
  1278. procedure tstaticsymtable.ppuwrite(ppufile:tcompilerppufile);
  1279. begin
  1280. aktstaticsymtable:=self;
  1281. inherited ppuwrite(ppufile);
  1282. end;
  1283. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1284. begin
  1285. aktstaticsymtable:=self;
  1286. inherited load_references(ppufile,locals);
  1287. end;
  1288. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1289. begin
  1290. aktstaticsymtable:=self;
  1291. inherited write_references(ppufile,locals);
  1292. end;
  1293. procedure tstaticsymtable.insert(sym:tsymentry);
  1294. var
  1295. hsym : tsym;
  1296. begin
  1297. { also check the global symtable }
  1298. if assigned(next) and
  1299. (next.unitid=0) then
  1300. begin
  1301. hsym:=tsym(next.search(sym.name));
  1302. if assigned(hsym) then
  1303. begin
  1304. { Delphi you can have a symbol with the same name as the
  1305. unit, the unit can then not be accessed anymore using
  1306. <unit>.<id>, so we can hide the symbol }
  1307. if (m_duplicate_names in aktmodeswitches) and
  1308. (hsym.typ=symconst.unitsym) then
  1309. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1310. else
  1311. begin
  1312. DuplicateSym(hsym);
  1313. exit;
  1314. end;
  1315. end;
  1316. end;
  1317. inherited insert(sym);
  1318. end;
  1319. {****************************************************************************
  1320. TGlobalSymtable
  1321. ****************************************************************************}
  1322. constructor tglobalsymtable.create(const n : string);
  1323. begin
  1324. inherited create(n);
  1325. symtabletype:=globalsymtable;
  1326. symtablelevel:=main_program_level;
  1327. unitid:=0;
  1328. {$ifdef GDB}
  1329. if cs_gdb_dbx in aktglobalswitches then
  1330. begin
  1331. dbx_count := 0;
  1332. unittypecount:=1;
  1333. pglobaltypecount := @unittypecount;
  1334. {unitid:=current_module.unitcount;}
  1335. debugList.concat(tai_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1336. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1337. {inc(current_module.unitcount);}
  1338. { we can't use dbx_vcount, because we don't know
  1339. if the object file will be loaded before or afeter PM }
  1340. dbx_count_ok:=false;
  1341. dbx_counter:=@dbx_count;
  1342. do_count_dbx:=true;
  1343. end;
  1344. {$endif GDB}
  1345. end;
  1346. procedure tglobalsymtable.ppuload(ppufile:tcompilerppufile);
  1347. {$ifdef GDB}
  1348. var
  1349. b : byte;
  1350. {$endif GDB}
  1351. begin
  1352. {$ifdef GDB}
  1353. if cs_gdb_dbx in aktglobalswitches then
  1354. begin
  1355. UnitTypeCount:=1;
  1356. PglobalTypeCount:=@UnitTypeCount;
  1357. end;
  1358. {$endif GDB}
  1359. aktglobalsymtable:=self;
  1360. next:=symtablestack;
  1361. symtablestack:=self;
  1362. inherited ppuload(ppufile);
  1363. { now we can deref the syms and defs }
  1364. deref;
  1365. { restore symtablestack }
  1366. symtablestack:=next;
  1367. { read dbx count }
  1368. {$ifdef GDB}
  1369. if (current_module.flags and uf_has_dbx)<>0 then
  1370. begin
  1371. b:=ppufile.readentry;
  1372. if b<>ibdbxcount then
  1373. Message(unit_f_ppu_dbx_count_problem)
  1374. else
  1375. dbx_count:=ppufile.getlongint;
  1376. {$IfDef EXTDEBUG}
  1377. writeln('Read dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1378. {$ENDIF EXTDEBUG}
  1379. { we can't use dbx_vcount, because we don't know
  1380. if the object file will be loaded before or afeter PM }
  1381. dbx_count_ok := {true}false;
  1382. end
  1383. else
  1384. begin
  1385. dbx_count:=-1;
  1386. dbx_count_ok:=false;
  1387. end;
  1388. {$endif GDB}
  1389. end;
  1390. procedure tglobalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1391. begin
  1392. aktglobalsymtable:=self;
  1393. { write the symtable entries }
  1394. inherited ppuwrite(ppufile);
  1395. { write dbx count }
  1396. {$ifdef GDB}
  1397. if cs_gdb_dbx in aktglobalswitches then
  1398. begin
  1399. {$IfDef EXTDEBUG}
  1400. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1401. {$ENDIF EXTDEBUG}
  1402. ppufile.do_crc:=false;
  1403. ppufile.putlongint(dbx_count);
  1404. ppufile.writeentry(ibdbxcount);
  1405. ppufile.do_crc:=true;
  1406. end;
  1407. {$endif GDB}
  1408. end;
  1409. procedure tglobalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1410. begin
  1411. aktglobalsymtable:=self;
  1412. inherited load_references(ppufile,locals);
  1413. end;
  1414. procedure tglobalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1415. begin
  1416. aktglobalsymtable:=self;
  1417. inherited write_references(ppufile,locals);
  1418. end;
  1419. procedure tglobalsymtable.insert(sym:tsymentry);
  1420. var
  1421. hsym : tsym;
  1422. begin
  1423. { also check the global symtable }
  1424. if assigned(next) and
  1425. (next.unitid=0) then
  1426. begin
  1427. hsym:=tsym(next.search(sym.name));
  1428. if assigned(hsym) then
  1429. begin
  1430. { Delphi you can have a symbol with the same name as the
  1431. unit, the unit can then not be accessed anymore using
  1432. <unit>.<id>, so we can hide the symbol }
  1433. if (m_duplicate_names in aktmodeswitches) and
  1434. (hsym.typ=symconst.unitsym) then
  1435. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1436. else
  1437. begin
  1438. DuplicateSym(hsym);
  1439. exit;
  1440. end;
  1441. end;
  1442. end;
  1443. hsym:=tsym(search(sym.name));
  1444. if assigned(hsym) then
  1445. begin
  1446. { Delphi you can have a symbol with the same name as the
  1447. unit, the unit can then not be accessed anymore using
  1448. <unit>.<id>, so we can hide the symbol }
  1449. if (m_duplicate_names in aktmodeswitches) and
  1450. (hsym.typ=symconst.unitsym) then
  1451. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1452. else
  1453. begin
  1454. DuplicateSym(hsym);
  1455. exit;
  1456. end;
  1457. end;
  1458. inherited insert(sym);
  1459. end;
  1460. {$ifdef GDB}
  1461. function tglobalsymtable.getnewtypecount : word;
  1462. begin
  1463. if not (cs_gdb_dbx in aktglobalswitches) then
  1464. getnewtypecount:=inherited getnewtypecount
  1465. else
  1466. begin
  1467. getnewtypecount:=unittypecount;
  1468. inc(unittypecount);
  1469. end;
  1470. end;
  1471. {$endif}
  1472. {****************************************************************************
  1473. TWITHSYMTABLE
  1474. ****************************************************************************}
  1475. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary;refnode:pointer{tnode});
  1476. begin
  1477. inherited create('');
  1478. symtabletype:=withsymtable;
  1479. withrefnode:=refnode;
  1480. { we don't need the symsearch }
  1481. symsearch.free;
  1482. { set the defaults }
  1483. symsearch:=asymsearch;
  1484. defowner:=aowner;
  1485. end;
  1486. destructor twithsymtable.destroy;
  1487. begin
  1488. tobject(withrefnode).free;
  1489. symsearch:=nil;
  1490. inherited destroy;
  1491. end;
  1492. procedure twithsymtable.clear;
  1493. begin
  1494. { remove no entry from a withsymtable as it is only a pointer to the
  1495. recorddef or objectdef symtable }
  1496. end;
  1497. {****************************************************************************
  1498. TSTT_ExceptionSymtable
  1499. ****************************************************************************}
  1500. constructor tstt_exceptsymtable.create;
  1501. begin
  1502. inherited create('');
  1503. symtabletype:=stt_exceptsymtable;
  1504. end;
  1505. {*****************************************************************************
  1506. Helper Routines
  1507. *****************************************************************************}
  1508. function findunitsymtable(st:tsymtable):tsymtable;
  1509. begin
  1510. findunitsymtable:=nil;
  1511. repeat
  1512. if not assigned(st) then
  1513. internalerror(5566561);
  1514. case st.symtabletype of
  1515. localsymtable,
  1516. parasymtable,
  1517. staticsymtable :
  1518. exit;
  1519. globalsymtable :
  1520. begin
  1521. findunitsymtable:=st;
  1522. exit;
  1523. end;
  1524. objectsymtable :
  1525. st:=st.defowner.owner;
  1526. recordsymtable :
  1527. begin
  1528. { don't continue when the current
  1529. symtable is used for variant records }
  1530. if trecorddef(st.defowner).isunion then
  1531. begin
  1532. findunitsymtable:=nil;
  1533. exit;
  1534. end
  1535. else
  1536. st:=st.defowner.owner;
  1537. end;
  1538. else
  1539. internalerror(5566562);
  1540. end;
  1541. until false;
  1542. end;
  1543. procedure duplicatesym(sym:tsym);
  1544. var
  1545. st : tsymtable;
  1546. begin
  1547. Message1(sym_e_duplicate_id,sym.realname);
  1548. st:=findunitsymtable(sym.owner);
  1549. with sym.fileinfo do
  1550. begin
  1551. if assigned(st) and (st.unitid<>0) then
  1552. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1553. else
  1554. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1555. end;
  1556. end;
  1557. procedure incompatibletypes(def1,def2:tdef);
  1558. var
  1559. s1,s2 : string;
  1560. begin
  1561. s1:=def1.typename;
  1562. s2:=def2.typename;
  1563. { When the names are the same try to include the unit name }
  1564. if upper(s1)=upper(s2) then
  1565. begin
  1566. if (def1.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1567. s1:=def1.owner.realname^+'.'+s1;
  1568. if (def2.owner.symtabletype in [globalsymtable,staticsymtable]) then
  1569. s2:=def2.owner.realname^+'.'+s2;
  1570. end;
  1571. if def2.deftype<>errordef then
  1572. CGMessage2(type_e_incompatible_types,s1,s2);
  1573. end;
  1574. {*****************************************************************************
  1575. Search
  1576. *****************************************************************************}
  1577. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1578. var
  1579. speedvalue : cardinal;
  1580. topclass : tobjectdef;
  1581. begin
  1582. speedvalue:=getspeedvalue(s);
  1583. srsymtable:=symtablestack;
  1584. while assigned(srsymtable) do
  1585. begin
  1586. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1587. if assigned(srsym) then
  1588. begin
  1589. topclass:=nil;
  1590. if (srsymtable.symtabletype=withsymtable) and
  1591. assigned(srsymtable.defowner) and
  1592. (srsymtable.defowner.deftype=objectdef) then
  1593. topclass:=tobjectdef(srsymtable.defowner)
  1594. else
  1595. begin
  1596. if assigned(current_procinfo) then
  1597. topclass:=current_procinfo.procdef._class;
  1598. end;
  1599. if (not assigned(topclass)) or
  1600. Tsym(srsym).is_visible_for_object(topclass) then
  1601. begin
  1602. searchsym:=true;
  1603. exit;
  1604. end;
  1605. end;
  1606. srsymtable:=srsymtable.next;
  1607. end;
  1608. searchsym:=false;
  1609. end;
  1610. function searchsym_type(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1611. var
  1612. speedvalue : cardinal;
  1613. begin
  1614. speedvalue:=getspeedvalue(s);
  1615. srsymtable:=symtablestack;
  1616. while assigned(srsymtable) do
  1617. begin
  1618. {
  1619. It is not possible to have type defintions in:
  1620. records
  1621. objects
  1622. parameters
  1623. }
  1624. if not(srsymtable.symtabletype in [recordsymtable,objectsymtable,parasymtable]) then
  1625. begin
  1626. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1627. if assigned(srsym) and
  1628. (not assigned(current_procinfo) or
  1629. Tsym(srsym).is_visible_for_object(current_procinfo.procdef._class)) then
  1630. begin
  1631. result:=true;
  1632. exit;
  1633. end
  1634. end;
  1635. srsymtable:=srsymtable.next;
  1636. end;
  1637. result:=false;
  1638. end;
  1639. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1640. var
  1641. srsym : tsym;
  1642. begin
  1643. { the caller have to take care if srsym=nil }
  1644. if assigned(p) then
  1645. begin
  1646. srsym:=tsym(p.search(s));
  1647. if assigned(srsym) then
  1648. begin
  1649. searchsymonlyin:=srsym;
  1650. exit;
  1651. end;
  1652. { also check in the local symtbale if it exists }
  1653. if (p=tsymtable(current_module.globalsymtable)) then
  1654. begin
  1655. srsym:=tsym(current_module.localsymtable.search(s));
  1656. if assigned(srsym) then
  1657. begin
  1658. searchsymonlyin:=srsym;
  1659. exit;
  1660. end;
  1661. end
  1662. end;
  1663. searchsymonlyin:=nil;
  1664. end;
  1665. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1666. var
  1667. speedvalue : cardinal;
  1668. topclassh : tobjectdef;
  1669. sym : tsym;
  1670. begin
  1671. speedvalue:=getspeedvalue(s);
  1672. { when the class passed is defined in this unit we
  1673. need to use the scope of that class. This is a trick
  1674. that can be used to access protected members in other
  1675. units. At least kylix supports it this way (PFV) }
  1676. if assigned(classh) and
  1677. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1678. (classh.owner.unitid=0) then
  1679. topclassh:=classh
  1680. else
  1681. begin
  1682. if assigned(current_procinfo) then
  1683. topclassh:=current_procinfo.procdef._class
  1684. else
  1685. topclassh:=nil;
  1686. end;
  1687. sym:=nil;
  1688. while assigned(classh) do
  1689. begin
  1690. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1691. if assigned(sym) and
  1692. Tsym(sym).is_visible_for_object(topclassh) then
  1693. break;
  1694. classh:=classh.childof;
  1695. end;
  1696. searchsym_in_class:=sym;
  1697. end;
  1698. function searchsym_in_class_by_msgint(classh:tobjectdef;i:longint):tsym;
  1699. var
  1700. topclassh : tobjectdef;
  1701. def : tdef;
  1702. sym : tsym;
  1703. begin
  1704. { when the class passed is defined in this unit we
  1705. need to use the scope of that class. This is a trick
  1706. that can be used to access protected members in other
  1707. units. At least kylix supports it this way (PFV) }
  1708. if assigned(classh) and
  1709. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1710. (classh.owner.unitid=0) then
  1711. topclassh:=classh
  1712. else
  1713. begin
  1714. if assigned(current_procinfo) then
  1715. topclassh:=current_procinfo.procdef._class
  1716. else
  1717. topclassh:=nil;
  1718. end;
  1719. sym:=nil;
  1720. def:=nil;
  1721. while assigned(classh) do
  1722. begin
  1723. def:=tdef(classh.symtable.defindex.first);
  1724. while assigned(def) do
  1725. begin
  1726. if (def.deftype=procdef) and
  1727. (po_msgint in tprocdef(def).procoptions) and
  1728. (tprocdef(def).messageinf.i=i) then
  1729. begin
  1730. sym:=tprocdef(def).procsym;
  1731. if assigned(topclassh) then
  1732. begin
  1733. if tprocdef(def).is_visible_for_object(topclassh) then
  1734. break;
  1735. end
  1736. else
  1737. break;
  1738. end;
  1739. def:=tdef(def.indexnext);
  1740. end;
  1741. if assigned(sym) then
  1742. break;
  1743. classh:=classh.childof;
  1744. end;
  1745. searchsym_in_class_by_msgint:=sym;
  1746. end;
  1747. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string):tsym;
  1748. var
  1749. topclassh : tobjectdef;
  1750. def : tdef;
  1751. sym : tsym;
  1752. begin
  1753. { when the class passed is defined in this unit we
  1754. need to use the scope of that class. This is a trick
  1755. that can be used to access protected members in other
  1756. units. At least kylix supports it this way (PFV) }
  1757. if assigned(classh) and
  1758. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1759. (classh.owner.unitid=0) then
  1760. topclassh:=classh
  1761. else
  1762. begin
  1763. if assigned(current_procinfo) then
  1764. topclassh:=current_procinfo.procdef._class
  1765. else
  1766. topclassh:=nil;
  1767. end;
  1768. sym:=nil;
  1769. def:=nil;
  1770. while assigned(classh) do
  1771. begin
  1772. def:=tdef(classh.symtable.defindex.first);
  1773. while assigned(def) do
  1774. begin
  1775. if (def.deftype=procdef) and
  1776. (po_msgstr in tprocdef(def).procoptions) and
  1777. (tprocdef(def).messageinf.str=s) then
  1778. begin
  1779. sym:=tprocdef(def).procsym;
  1780. if assigned(topclassh) then
  1781. begin
  1782. if tprocdef(def).is_visible_for_object(topclassh) then
  1783. break;
  1784. end
  1785. else
  1786. break;
  1787. end;
  1788. def:=tdef(def.indexnext);
  1789. end;
  1790. if assigned(sym) then
  1791. break;
  1792. classh:=classh.childof;
  1793. end;
  1794. searchsym_in_class_by_msgstr:=sym;
  1795. end;
  1796. function search_assignment_operator(from_def,to_def:Tdef):Tprocdef;
  1797. var st:Tsymtable;
  1798. sym:Tprocsym;
  1799. sv:cardinal;
  1800. begin
  1801. st:=symtablestack;
  1802. sv:=getspeedvalue('assign');
  1803. while st<>nil do
  1804. begin
  1805. sym:=Tprocsym(st.speedsearch('assign',sv));
  1806. if sym<>nil then
  1807. begin
  1808. if sym.typ<>procsym then
  1809. internalerror(200402031);
  1810. search_assignment_operator:=sym.search_procdef_assignment_operator(from_def,to_def);
  1811. if search_assignment_operator<>nil then
  1812. break;
  1813. end;
  1814. st:=st.next;
  1815. end;
  1816. end;
  1817. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1818. var
  1819. symowner: tsymtable;
  1820. begin
  1821. if not(cs_compilesystem in aktmoduleswitches) then
  1822. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1823. else
  1824. searchsym(s,tsym(srsym),symowner);
  1825. searchsystype :=
  1826. assigned(srsym) and
  1827. (srsym.typ = typesym);
  1828. end;
  1829. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1830. begin
  1831. if not(cs_compilesystem in aktmoduleswitches) then
  1832. begin
  1833. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1834. symowner := systemunit;
  1835. end
  1836. else
  1837. searchsym(s,tsym(srsym),symowner);
  1838. searchsysvar :=
  1839. assigned(srsym) and
  1840. (srsym.typ = varsym);
  1841. end;
  1842. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1843. { searches n in symtable of pd and all anchestors }
  1844. var
  1845. speedvalue : cardinal;
  1846. srsym : tsym;
  1847. begin
  1848. speedvalue:=getspeedvalue(s);
  1849. while assigned(pd) do
  1850. begin
  1851. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1852. if assigned(srsym) then
  1853. begin
  1854. search_class_member:=srsym;
  1855. exit;
  1856. end;
  1857. pd:=pd.childof;
  1858. end;
  1859. search_class_member:=nil;
  1860. end;
  1861. procedure reset_all_defs;
  1862. var st:Tsymtable;
  1863. begin
  1864. st:=symtablestack;
  1865. while st<>nil do
  1866. begin
  1867. Tstoredsymtable(st).reset_all_defs;
  1868. st:=st.next;
  1869. end;
  1870. end;
  1871. {*****************************************************************************
  1872. Definition Helpers
  1873. *****************************************************************************}
  1874. procedure globaldef(const s : string;var t:ttype);
  1875. var st : string;
  1876. symt : tsymtable;
  1877. srsym : tsym;
  1878. srsymtable : tsymtable;
  1879. begin
  1880. srsym := nil;
  1881. if pos('.',s) > 0 then
  1882. begin
  1883. st := copy(s,1,pos('.',s)-1);
  1884. searchsym(st,srsym,srsymtable);
  1885. st := copy(s,pos('.',s)+1,255);
  1886. if assigned(srsym) then
  1887. begin
  1888. if srsym.typ = unitsym then
  1889. begin
  1890. symt := tunitsym(srsym).unitsymtable;
  1891. srsym := tsym(symt.search(st));
  1892. end else srsym := nil;
  1893. end;
  1894. end else st := s;
  1895. if srsym = nil then
  1896. searchsym(st,srsym,srsymtable);
  1897. if srsym = nil then
  1898. srsym:=searchsymonlyin(systemunit,st);
  1899. if (not assigned(srsym)) or
  1900. (srsym.typ<>typesym) then
  1901. begin
  1902. Message(type_e_type_id_expected);
  1903. t:=generrortype;
  1904. exit;
  1905. end;
  1906. t := ttypesym(srsym).restype;
  1907. end;
  1908. {****************************************************************************
  1909. Object Helpers
  1910. ****************************************************************************}
  1911. procedure search_class_overloads(aprocsym : tprocsym);
  1912. { searches n in symtable of pd and all anchestors }
  1913. var
  1914. speedvalue : cardinal;
  1915. srsym : tprocsym;
  1916. s : string;
  1917. objdef : tobjectdef;
  1918. begin
  1919. if aprocsym.overloadchecked then
  1920. exit;
  1921. aprocsym.overloadchecked:=true;
  1922. if (aprocsym.owner.symtabletype<>objectsymtable) then
  1923. internalerror(200111021);
  1924. objdef:=tobjectdef(aprocsym.owner.defowner);
  1925. { we start in the parent }
  1926. if not assigned(objdef.childof) then
  1927. exit;
  1928. objdef:=objdef.childof;
  1929. s:=aprocsym.name;
  1930. speedvalue:=getspeedvalue(s);
  1931. while assigned(objdef) do
  1932. begin
  1933. srsym:=tprocsym(objdef.symtable.speedsearch(s,speedvalue));
  1934. if assigned(srsym) then
  1935. begin
  1936. if (srsym.typ<>procsym) then
  1937. internalerror(200111022);
  1938. if srsym.is_visible_for_object(tobjectdef(aprocsym.owner.defowner)) then
  1939. begin
  1940. srsym.add_para_match_to(Aprocsym,[cpo_ignorehidden,cpo_allowdefaults]);
  1941. { we can stop if the overloads were already added
  1942. for the found symbol }
  1943. if srsym.overloadchecked then
  1944. break;
  1945. end;
  1946. end;
  1947. { next parent }
  1948. objdef:=objdef.childof;
  1949. end;
  1950. end;
  1951. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  1952. begin
  1953. if (tsym(p).typ=propertysym) and
  1954. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  1955. ppointer(arg)^:=p;
  1956. end;
  1957. function search_default_property(pd : tobjectdef) : tpropertysym;
  1958. { returns the default property of a class, searches also anchestors }
  1959. var
  1960. _defaultprop : tpropertysym;
  1961. begin
  1962. _defaultprop:=nil;
  1963. while assigned(pd) do
  1964. begin
  1965. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,@_defaultprop);
  1966. if assigned(_defaultprop) then
  1967. break;
  1968. pd:=pd.childof;
  1969. end;
  1970. search_default_property:=_defaultprop;
  1971. end;
  1972. {$ifdef UNITALIASES}
  1973. {****************************************************************************
  1974. TUNIT_ALIAS
  1975. ****************************************************************************}
  1976. constructor tunit_alias.create(const n:string);
  1977. var
  1978. i : longint;
  1979. begin
  1980. i:=pos('=',n);
  1981. if i=0 then
  1982. fail;
  1983. inherited createname(Copy(n,1,i-1));
  1984. newname:=stringdup(Copy(n,i+1,255));
  1985. end;
  1986. destructor tunit_alias.destroy;
  1987. begin
  1988. stringdispose(newname);
  1989. inherited destroy;
  1990. end;
  1991. procedure addunitalias(const n:string);
  1992. begin
  1993. unitaliases^.insert(tunit_alias,init(Upper(n))));
  1994. end;
  1995. function getunitalias(const n:string):string;
  1996. var
  1997. p : punit_alias;
  1998. begin
  1999. p:=punit_alias(unitaliases^.search(Upper(n)));
  2000. if assigned(p) then
  2001. getunitalias:=punit_alias(p).newname^
  2002. else
  2003. getunitalias:=n;
  2004. end;
  2005. {$endif UNITALIASES}
  2006. {****************************************************************************
  2007. Symtable Stack
  2008. ****************************************************************************}
  2009. {$ifdef DEBUG}
  2010. procedure test_symtablestack;
  2011. var
  2012. p : tsymtable;
  2013. i : longint;
  2014. begin
  2015. p:=symtablestack;
  2016. i:=0;
  2017. while assigned(p) do
  2018. begin
  2019. inc(i);
  2020. p:=p.next;
  2021. if i>500 then
  2022. Message(sym_f_internal_error_in_symtablestack);
  2023. end;
  2024. end;
  2025. procedure list_symtablestack;
  2026. var
  2027. p : tsymtable;
  2028. i : longint;
  2029. begin
  2030. p:=symtablestack;
  2031. i:=0;
  2032. while assigned(p) do
  2033. begin
  2034. inc(i);
  2035. writeln(i,' ',p.name^);
  2036. p:=p.next;
  2037. if i>500 then
  2038. Message(sym_f_internal_error_in_symtablestack);
  2039. end;
  2040. end;
  2041. {$endif DEBUG}
  2042. {****************************************************************************
  2043. Init/Done Symtable
  2044. ****************************************************************************}
  2045. procedure InitSymtable;
  2046. var
  2047. token : ttoken;
  2048. begin
  2049. { Reset symbolstack }
  2050. registerdef:=false;
  2051. symtablestack:=nil;
  2052. systemunit:=nil;
  2053. {$ifdef GDB}
  2054. globaltypecount:=1;
  2055. pglobaltypecount:=@globaltypecount;
  2056. {$endif GDB}
  2057. { defs for internal use }
  2058. voidprocdef:=tprocdef.create(unknown_level);
  2059. { create error syms and def }
  2060. generrorsym:=terrorsym.create;
  2061. generrortype.setdef(terrordef.create);
  2062. {$ifdef UNITALIASES}
  2063. { unit aliases }
  2064. unitaliases:=tdictionary.create;
  2065. {$endif}
  2066. end;
  2067. procedure DoneSymtable;
  2068. begin
  2069. voidprocdef.free;
  2070. generrorsym.free;
  2071. generrortype.def.free;
  2072. {$ifdef UNITALIASES}
  2073. unitaliases.free;
  2074. {$endif}
  2075. end;
  2076. end.
  2077. {
  2078. $Log$
  2079. Revision 1.140 2004-02-24 16:12:39 peter
  2080. * operator overload chooses rewrite
  2081. * overload choosing is now generic and moved to htypechk
  2082. Revision 1.139 2004/02/20 21:55:59 peter
  2083. * procvar cleanup
  2084. Revision 1.138 2004/02/17 15:57:49 peter
  2085. - fix rtti generation for properties containing sl_vec
  2086. - fix crash when overloaded operator is not available
  2087. - fix record alignment for C style variant records
  2088. Revision 1.137 2004/02/13 15:40:58 peter
  2089. * fixed protected checking in withsymtable
  2090. Revision 1.136 2004/02/11 19:59:06 peter
  2091. * fix compilation without GDB
  2092. Revision 1.135 2004/02/06 22:37:00 daniel
  2093. * Removed not very usefull nextglobal & previousglobal fields from
  2094. Tstoreddef, saving 78 kb of memory
  2095. Revision 1.134 2004/02/04 22:15:16 daniel
  2096. * Rtti generation moved to ncgutil
  2097. * Assmtai usage of symsym removed
  2098. * operator overloading cleanup up
  2099. Revision 1.133 2004/01/31 22:48:31 daniel
  2100. * Fix stabs generation problem reported by Jonas
  2101. Revision 1.132 2004/01/31 18:40:15 daniel
  2102. * Last steps before removal of aasmtai dependency in symsym can be
  2103. accomplished.
  2104. Revision 1.131 2004/01/30 14:33:06 florian
  2105. * fixed more alignment issues
  2106. Revision 1.130 2004/01/30 13:42:03 florian
  2107. * fixed more alignment issues
  2108. Revision 1.129 2004/01/29 16:51:29 peter
  2109. * fixed alignment calculation for variant records
  2110. * fixed alignment padding of records
  2111. Revision 1.128 2004/01/28 22:16:31 peter
  2112. * more record alignment fixes
  2113. Revision 1.127 2004/01/28 20:30:18 peter
  2114. * record alignment splitted in fieldalignment and recordalignment,
  2115. the latter is used when this record is inserted in another record.
  2116. Revision 1.126 2004/01/26 16:12:28 daniel
  2117. * reginfo now also only allocated during register allocation
  2118. * third round of gdb cleanups: kick out most of concatstabto
  2119. Revision 1.125 2004/01/15 15:16:18 daniel
  2120. * Some minor stuff
  2121. * Managed to eliminate speed effects of string compression
  2122. Revision 1.124 2004/01/11 23:56:20 daniel
  2123. * Experiment: Compress strings to save memory
  2124. Did not save a single byte of mem; clearly the core size is boosted by
  2125. temporary memory usage...
  2126. Revision 1.123 2003/11/10 22:02:52 peter
  2127. * cross unit inlining fixed
  2128. Revision 1.122 2003/11/08 17:08:44 florian
  2129. * fixed strange error message about expecting erroneous types,
  2130. usually this is caused by other errors so it isn't important
  2131. Revision 1.121 2003/10/30 16:23:13 peter
  2132. * don't search for overloads in parents for constructors
  2133. Revision 1.120 2003/10/23 14:44:07 peter
  2134. * splitted buildderef and buildderefimpl to fix interface crc
  2135. calculation
  2136. Revision 1.119 2003/10/22 20:40:00 peter
  2137. * write derefdata in a separate ppu entry
  2138. Revision 1.118 2003/10/22 15:22:33 peter
  2139. * fixed unitsym-globalsymtable relation so the uses of a unit
  2140. is counted correctly
  2141. Revision 1.117 2003/10/21 18:16:13 peter
  2142. * IncompatibleTypes() added that will include unit names when
  2143. the typenames are the same
  2144. Revision 1.116 2003/10/17 14:38:32 peter
  2145. * 64k registers supported
  2146. * fixed some memory leaks
  2147. Revision 1.115 2003/10/13 14:05:12 peter
  2148. * removed is_visible_for_proc
  2149. * search also for class overloads when finding interface
  2150. implementations
  2151. Revision 1.114 2003/10/07 15:17:07 peter
  2152. * inline supported again, LOC_REFERENCEs are used to pass the
  2153. parameters
  2154. * inlineparasymtable,inlinelocalsymtable removed
  2155. * exitlabel inserting fixed
  2156. Revision 1.113 2003/10/03 14:43:29 peter
  2157. * don't report unused hidden parameters
  2158. Revision 1.112 2003/10/02 21:13:46 peter
  2159. * protected visibility fixes
  2160. Revision 1.111 2003/10/01 19:05:33 peter
  2161. * searchsym_type to search for type definitions. It ignores
  2162. records,objects and parameters
  2163. Revision 1.110 2003/09/23 17:56:06 peter
  2164. * locals and paras are allocated in the code generation
  2165. * tvarsym.localloc contains the location of para/local when
  2166. generating code for the current procedure
  2167. Revision 1.109 2003/08/23 22:31:08 peter
  2168. * unchain operators before adding to overloaded list
  2169. Revision 1.108 2003/06/25 18:31:23 peter
  2170. * sym,def resolving partly rewritten to support also parent objects
  2171. not directly available through the uses clause
  2172. Revision 1.107 2003/06/13 21:19:31 peter
  2173. * current_procdef removed, use current_procinfo.procdef instead
  2174. Revision 1.106 2003/06/09 18:26:27 peter
  2175. * para can be the same as function name in delphi
  2176. Revision 1.105 2003/06/08 11:40:00 peter
  2177. * check parast when inserting in localst
  2178. Revision 1.104 2003/06/07 20:26:32 peter
  2179. * re-resolving added instead of reloading from ppu
  2180. * tderef object added to store deref info for resolving
  2181. Revision 1.103 2003/05/25 11:34:17 peter
  2182. * methodpointer self pushing fixed
  2183. Revision 1.102 2003/05/23 14:27:35 peter
  2184. * remove some unit dependencies
  2185. * current_procinfo changes to store more info
  2186. Revision 1.101 2003/05/16 14:32:58 peter
  2187. * fix dup check for hiding the result varsym in localst, the result
  2188. sym was already in the localst when adding the locals
  2189. Revision 1.100 2003/05/15 18:58:53 peter
  2190. * removed selfpointer_offset, vmtpointer_offset
  2191. * tvarsym.adjusted_address
  2192. * address in localsymtable is now in the real direction
  2193. * removed some obsolete globals
  2194. Revision 1.99 2003/05/13 15:17:13 peter
  2195. * fix crash with hiding function result. The function result is now
  2196. inserted as last so the symbol that we are going to insert is the
  2197. result and needs to be renamed instead of the already existing
  2198. symbol
  2199. Revision 1.98 2003/05/11 14:45:12 peter
  2200. * tloadnode does not support objectsymtable,withsymtable anymore
  2201. * withnode cleanup
  2202. * direct with rewritten to use temprefnode
  2203. Revision 1.97 2003/04/27 11:21:34 peter
  2204. * aktprocdef renamed to current_procinfo.procdef
  2205. * procinfo renamed to current_procinfo
  2206. * procinfo will now be stored in current_module so it can be
  2207. cleaned up properly
  2208. * gen_main_procsym changed to create_main_proc and release_main_proc
  2209. to also generate a tprocinfo structure
  2210. * fixed unit implicit initfinal
  2211. Revision 1.96 2003/04/27 07:29:51 peter
  2212. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2213. a new procdef declaration
  2214. * aktprocsym removed
  2215. * lexlevel removed, use symtable.symtablelevel instead
  2216. * implicit init/final code uses the normal genentry/genexit
  2217. * funcret state checking updated for new funcret handling
  2218. Revision 1.95 2003/04/26 00:33:07 peter
  2219. * vo_is_result flag added for the special RESULT symbol
  2220. Revision 1.94 2003/04/25 20:59:35 peter
  2221. * removed funcretn,funcretsym, function result is now in varsym
  2222. and aliases for result and function name are added using absolutesym
  2223. * vs_hidden parameter for funcret passed in parameter
  2224. * vs_hidden fixes
  2225. * writenode changed to printnode and released from extdebug
  2226. * -vp option added to generate a tree.log with the nodetree
  2227. * nicer printnode for statements, callnode
  2228. Revision 1.93 2003/04/16 07:53:11 jonas
  2229. * calculation of parameter and resultlocation offsets now depends on
  2230. tg.direction instead of if(n)def powerpc
  2231. Revision 1.92 2003/04/05 21:09:32 jonas
  2232. * several ppc/generic result offset related fixes. The "normal" result
  2233. offset seems now to be calculated correctly and a lot of duplicate
  2234. calculations have been removed. Nested functions accessing the parent's
  2235. function result don't work at all though :(
  2236. Revision 1.91 2003/03/17 18:56:49 peter
  2237. * ignore hints for default parameter values
  2238. Revision 1.90 2003/03/17 16:54:41 peter
  2239. * support DefaultHandler and anonymous inheritance fixed
  2240. for message methods
  2241. Revision 1.89 2002/12/29 14:57:50 peter
  2242. * unit loading changed to first register units and load them
  2243. afterwards. This is needed to support uses xxx in yyy correctly
  2244. * unit dependency check fixed
  2245. Revision 1.88 2002/12/27 18:07:45 peter
  2246. * fix crashes when searching symbols
  2247. Revision 1.87 2002/12/25 01:26:56 peter
  2248. * duplicate procsym-unitsym fix
  2249. Revision 1.86 2002/12/21 13:07:34 peter
  2250. * type redefine fix for tb0437
  2251. Revision 1.85 2002/12/07 14:27:10 carl
  2252. * 3% memory optimization
  2253. * changed some types
  2254. + added type checking with different size for call node and for
  2255. parameters
  2256. Revision 1.84 2002/12/06 17:51:11 peter
  2257. * merged cdecl and array fixes
  2258. Revision 1.83 2002/11/30 11:12:48 carl
  2259. + checking for symbols used with hint directives is done mostly in pexpr
  2260. only now
  2261. Revision 1.82 2002/11/29 22:31:20 carl
  2262. + unimplemented hint directive added
  2263. * hint directive parsing implemented
  2264. * warning on these directives
  2265. Revision 1.81 2002/11/27 20:04:09 peter
  2266. * tvarsym.get_push_size replaced by paramanager.push_size
  2267. Revision 1.80 2002/11/22 22:45:49 carl
  2268. + small optimization for speed
  2269. Revision 1.79 2002/11/19 16:26:33 pierre
  2270. * correct a stabs generation problem that lead to use errordef in stabs
  2271. Revision 1.78 2002/11/18 17:32:00 peter
  2272. * pass proccalloption to ret_in_xxx and push_xxx functions
  2273. Revision 1.77 2002/11/15 01:58:54 peter
  2274. * merged changes from 1.0.7 up to 04-11
  2275. - -V option for generating bug report tracing
  2276. - more tracing for option parsing
  2277. - errors for cdecl and high()
  2278. - win32 import stabs
  2279. - win32 records<=8 are returned in eax:edx (turned off by default)
  2280. - heaptrc update
  2281. - more info for temp management in .s file with EXTDEBUG
  2282. Revision 1.76 2002/11/09 15:29:28 carl
  2283. + bss / constant alignment fixes
  2284. * avoid incrementing address/datasize in local symtable for const's
  2285. Revision 1.75 2002/10/14 19:44:43 peter
  2286. * threadvars need 4 bytes extra for storing the threadvar index
  2287. Revision 1.74 2002/10/06 19:41:31 peter
  2288. * Add finalization of typed consts
  2289. * Finalization of globals in the main program
  2290. Revision 1.73 2002/10/05 12:43:29 carl
  2291. * fixes for Delphi 6 compilation
  2292. (warning : Some features do not work under Delphi)
  2293. Revision 1.72 2002/09/09 19:41:46 peter
  2294. * real fix internalerror for dup ids in union sym
  2295. Revision 1.71 2002/09/09 17:34:16 peter
  2296. * tdicationary.replace added to replace and item in a dictionary. This
  2297. is only allowed for the same name
  2298. * varsyms are inserted in symtable before the types are parsed. This
  2299. fixes the long standing "var longint : longint" bug
  2300. - consume_idlist and idstringlist removed. The loops are inserted
  2301. at the callers place and uses the symtable for duplicate id checking
  2302. Revision 1.70 2002/09/05 19:29:45 peter
  2303. * memdebug enhancements
  2304. Revision 1.69 2002/08/25 19:25:21 peter
  2305. * sym.insert_in_data removed
  2306. * symtable.insertvardata/insertconstdata added
  2307. * removed insert_in_data call from symtable.insert, it needs to be
  2308. called separatly. This allows to deref the address calculation
  2309. * procedures now calculate the parast addresses after the procedure
  2310. directives are parsed. This fixes the cdecl parast problem
  2311. * push_addr_param has an extra argument that specifies if cdecl is used
  2312. or not
  2313. Revision 1.68 2002/08/18 20:06:27 peter
  2314. * inlining is now also allowed in interface
  2315. * renamed write/load to ppuwrite/ppuload
  2316. * tnode storing in ppu
  2317. * nld,ncon,nbas are already updated for storing in ppu
  2318. Revision 1.67 2002/08/17 09:23:43 florian
  2319. * first part of procinfo rewrite
  2320. Revision 1.66 2002/08/11 13:24:15 peter
  2321. * saving of asmsymbols in ppu supported
  2322. * asmsymbollist global is removed and moved into a new class
  2323. tasmlibrarydata that will hold the info of a .a file which
  2324. corresponds with a single module. Added librarydata to tmodule
  2325. to keep the library info stored for the module. In the future the
  2326. objectfiles will also be stored to the tasmlibrarydata class
  2327. * all getlabel/newasmsymbol and friends are moved to the new class
  2328. Revision 1.65 2002/07/23 09:51:27 daniel
  2329. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2330. are worth comitting.
  2331. Revision 1.64 2002/07/16 15:34:21 florian
  2332. * exit is now a syssym instead of a keyword
  2333. Revision 1.63 2002/07/15 19:44:53 florian
  2334. * fixed crash with default parameters and stdcall calling convention
  2335. Revision 1.62 2002/07/01 18:46:28 peter
  2336. * internal linker
  2337. * reorganized aasm layer
  2338. Revision 1.61 2002/05/18 13:34:19 peter
  2339. * readded missing revisions
  2340. Revision 1.60 2002/05/16 19:46:45 carl
  2341. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2342. + try to fix temp allocation (still in ifdef)
  2343. + generic constructor calls
  2344. + start of tassembler / tmodulebase class cleanup
  2345. Revision 1.58 2002/05/12 16:53:15 peter
  2346. * moved entry and exitcode to ncgutil and cgobj
  2347. * foreach gets extra argument for passing local data to the
  2348. iterator function
  2349. * -CR checks also class typecasts at runtime by changing them
  2350. into as
  2351. * fixed compiler to cycle with the -CR option
  2352. * fixed stabs with elf writer, finally the global variables can
  2353. be watched
  2354. * removed a lot of routines from cga unit and replaced them by
  2355. calls to cgobj
  2356. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2357. u32bit then the other is typecasted also to u32bit without giving
  2358. a rangecheck warning/error.
  2359. * fixed pascal calling method with reversing also the high tree in
  2360. the parast, detected by tcalcst3 test
  2361. Revision 1.57 2002/04/04 19:06:05 peter
  2362. * removed unused units
  2363. * use tlocation.size in cg.a_*loc*() routines
  2364. Revision 1.56 2002/03/04 19:10:11 peter
  2365. * removed compiler warnings
  2366. Revision 1.55 2002/02/03 09:30:07 peter
  2367. * more fixes for protected handling
  2368. Revision 1.54 2002/01/29 21:30:25 peter
  2369. * allow also dup id in delphi mode in interfaces
  2370. Revision 1.53 2002/01/29 19:46:00 peter
  2371. * fixed recordsymtable.insert_in() for inserting variant record fields
  2372. to not used symtable.insert() because that also updates alignmentinfo
  2373. which was already set
  2374. Revision 1.52 2002/01/24 18:25:50 peter
  2375. * implicit result variable generation for assembler routines
  2376. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2377. }