symtable.pas 90 KB

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