symtable.pas 90 KB

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