symtable.pas 90 KB

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