symtable.pas 90 KB

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