symtable.pas 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706
  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 for duplicate id in local symtable of methods }
  1121. if assigned(next.next) and
  1122. { funcretsym is allowed !! }
  1123. (not is_funcret_sym(sym)) and
  1124. (next.next.symtabletype=objectsymtable) then
  1125. begin
  1126. hsym:=search_class_member(tobjectdef(next.next.defowner),sym.name);
  1127. if assigned(hsym) and
  1128. { private ids can be reused }
  1129. (not(sp_private in hsym.symoptions) or
  1130. (hsym.owner.defowner.owner.symtabletype<>globalsymtable)) then
  1131. begin
  1132. { delphi allows to reuse the names in a class, but not
  1133. in object (tp7 compatible) }
  1134. if not((m_delphi in aktmodeswitches) and
  1135. is_class(tdef(next.next.defowner))) then
  1136. begin
  1137. DuplicateSym(hsym);
  1138. exit;
  1139. end;
  1140. end;
  1141. end;
  1142. end;
  1143. inherited insert(sym);
  1144. end;
  1145. procedure tlocalsymtable.insertvardata(sym : tsymentry);
  1146. var
  1147. l,varalign : longint;
  1148. begin
  1149. if not(sym.typ in [varsym]) then
  1150. internalerror(200208255);
  1151. case sym.typ of
  1152. varsym :
  1153. begin
  1154. tvarsym(sym).varstate:=vs_declared;
  1155. l:=tvarsym(sym).getvaluesize;
  1156. varalign:=size_2_align(l);
  1157. varalign:=used_align(varalign,aktalignment.localalignmin,aktalignment.localalignmax);
  1158. if (tg.direction>0) then
  1159. begin
  1160. { on the powerpc, the local variables are accessed with a positiv offset }
  1161. tvarsym(sym).address:=align(datasize,varalign);
  1162. datasize:=tvarsym(sym).address+l;
  1163. end
  1164. else
  1165. begin
  1166. datasize:=align(datasize+l,varalign);
  1167. tvarsym(sym).address:=-datasize;
  1168. end;
  1169. end;
  1170. end;
  1171. end;
  1172. procedure tlocalsymtable.insertconstdata(sym : tsymentry);
  1173. { this does not affect the local stack space, since all
  1174. typed constansts and initialized variables are always
  1175. put in the .data / .rodata section
  1176. }
  1177. var
  1178. storefilepos : tfileposinfo;
  1179. curconstsegment : taasmoutput;
  1180. l : longint;
  1181. begin
  1182. { Note: this is the same code as tabstractunitsymtable.insertconstdata }
  1183. if sym.typ<>typedconstsym then
  1184. internalerror(200208254);
  1185. storefilepos:=aktfilepos;
  1186. aktfilepos:=tsym(sym).fileinfo;
  1187. if ttypedconstsym(sym).is_writable then
  1188. curconstsegment:=datasegment
  1189. else
  1190. curconstsegment:=consts;
  1191. l:=ttypedconstsym(sym).getsize;
  1192. { insert cut for smartlinking or alignment }
  1193. if (cs_create_smart in aktmoduleswitches) then
  1194. curconstSegment.concat(Tai_cut.Create);
  1195. curconstSegment.concat(Tai_align.create(const_align(l)));
  1196. {$ifdef GDB}
  1197. if cs_debuginfo in aktmoduleswitches then
  1198. ttypedconstsym(sym).concatstabto(curconstsegment);
  1199. {$endif GDB}
  1200. if (cs_create_smart in aktmoduleswitches) or
  1201. DLLSource then
  1202. begin
  1203. curconstSegment.concat(Tai_symbol.Createdataname_global(
  1204. ttypedconstsym(sym).mangledname,l));
  1205. end
  1206. else
  1207. begin
  1208. curconstSegment.concat(Tai_symbol.Createdataname(
  1209. ttypedconstsym(sym).mangledname,l));
  1210. end;
  1211. aktfilepos:=storefilepos;
  1212. end;
  1213. {****************************************************************************
  1214. TParaSymtable
  1215. ****************************************************************************}
  1216. constructor tparasymtable.create(level:byte);
  1217. begin
  1218. inherited create('');
  1219. symtabletype:=parasymtable;
  1220. symtablelevel:=level;
  1221. dataalignment:=aktalignment.paraalign;
  1222. address_fixup:=target_info.first_parm_offset;
  1223. end;
  1224. procedure tparasymtable.insert(sym:tsymentry);
  1225. var
  1226. hsym : tsym;
  1227. begin
  1228. { check for duplicate id in para symtable of methods }
  1229. if assigned(next) and
  1230. (next.symtabletype=objectsymtable) and
  1231. { funcretsym is allowed }
  1232. (not is_funcret_sym(sym)) then
  1233. begin
  1234. hsym:=search_class_member(tobjectdef(next.defowner),sym.name);
  1235. { private ids can be reused }
  1236. if assigned(hsym) and
  1237. tstoredsym(hsym).is_visible_for_object(tobjectdef(next.defowner)) then
  1238. begin
  1239. { delphi allows to reuse the names in a class, but not
  1240. in object (tp7 compatible) }
  1241. if not((m_delphi in aktmodeswitches) and
  1242. is_class_or_interface(tobjectdef(next.defowner))) then
  1243. begin
  1244. DuplicateSym(hsym);
  1245. exit;
  1246. end;
  1247. end;
  1248. end;
  1249. inherited insert(sym);
  1250. end;
  1251. procedure tparasymtable.insertvardata(sym : tsymentry);
  1252. var
  1253. l,varalign : longint;
  1254. begin
  1255. if sym.typ<>varsym then
  1256. internalerror(200208253);
  1257. { retrieve cdecl status }
  1258. if defowner.deftype<>procdef then
  1259. internalerror(200208256);
  1260. { here we need the size of a push instead of the
  1261. size of the data }
  1262. l:=paramanager.push_size(tvarsym(sym).varspez,tvarsym(sym).vartype.def,tprocdef(defowner).proccalloption);
  1263. varalign:=size_2_align(l);
  1264. tvarsym(sym).varstate:=vs_assigned;
  1265. { we need the new datasize already aligned so we can't
  1266. use the align_address here }
  1267. tvarsym(sym).address:=datasize;
  1268. varalign:=used_align(varalign,dataalignment,dataalignment);
  1269. datasize:=align(tvarsym(sym).address+l,varalign);
  1270. end;
  1271. {****************************************************************************
  1272. TAbstractUnitSymtable
  1273. ****************************************************************************}
  1274. constructor tabstractunitsymtable.create(const n : string);
  1275. begin
  1276. inherited create(n);
  1277. symsearch.usehash;
  1278. {$ifdef GDB}
  1279. { reset GDB things }
  1280. prev_dbx_counter := dbx_counter;
  1281. dbx_counter := nil;
  1282. is_stab_written:=false;
  1283. dbx_count := -1;
  1284. {$endif GDB}
  1285. end;
  1286. procedure tabstractunitsymtable.insertvardata(sym : tsymentry);
  1287. var
  1288. l,varalign : longint;
  1289. storefilepos : tfileposinfo;
  1290. begin
  1291. if sym.typ<>varsym then
  1292. internalerror(200208252);
  1293. storefilepos:=aktfilepos;
  1294. aktfilepos:=tsym(sym).fileinfo;
  1295. l:=tvarsym(sym).getvaluesize;
  1296. if (vo_is_thread_var in tvarsym(sym).varoptions) then
  1297. inc(l,pointer_size);
  1298. varalign:=var_align(l);
  1299. tvarsym(sym).address:=align(datasize,varalign);
  1300. { insert cut for smartlinking or alignment }
  1301. if (cs_create_smart in aktmoduleswitches) then
  1302. bssSegment.concat(Tai_cut.Create);
  1303. bssSegment.concat(Tai_align.create(varalign));
  1304. datasize:=tvarsym(sym).address+l;
  1305. {$ifdef GDB}
  1306. if cs_debuginfo in aktmoduleswitches then
  1307. tvarsym(sym).concatstabto(bsssegment);
  1308. {$endif GDB}
  1309. if (symtabletype=globalsymtable) or
  1310. (cs_create_smart in aktmoduleswitches) or
  1311. DLLSource or
  1312. (vo_is_exported in tvarsym(sym).varoptions) or
  1313. (vo_is_C_var in tvarsym(sym).varoptions) then
  1314. bssSegment.concat(Tai_datablock.Create_global(tvarsym(sym).mangledname,l))
  1315. else
  1316. bssSegment.concat(Tai_datablock.Create(tvarsym(sym).mangledname,l));
  1317. aktfilepos:=storefilepos;
  1318. end;
  1319. procedure tabstractunitsymtable.insertconstdata(sym : tsymentry);
  1320. var
  1321. storefilepos : tfileposinfo;
  1322. curconstsegment : taasmoutput;
  1323. l : longint;
  1324. begin
  1325. if sym.typ<>typedconstsym then
  1326. internalerror(200208254);
  1327. storefilepos:=aktfilepos;
  1328. aktfilepos:=tsym(sym).fileinfo;
  1329. if ttypedconstsym(sym).is_writable then
  1330. curconstsegment:=datasegment
  1331. else
  1332. curconstsegment:=consts;
  1333. l:=ttypedconstsym(sym).getsize;
  1334. { insert cut for smartlinking or alignment }
  1335. if (cs_create_smart in aktmoduleswitches) then
  1336. curconstSegment.concat(Tai_cut.Create);
  1337. curconstSegment.concat(Tai_align.create(const_align(l)));
  1338. {$ifdef GDB}
  1339. if cs_debuginfo in aktmoduleswitches then
  1340. ttypedconstsym(sym).concatstabto(curconstsegment);
  1341. {$endif GDB}
  1342. if (symtabletype=globalsymtable) or
  1343. (cs_create_smart in aktmoduleswitches) or
  1344. DLLSource then
  1345. begin
  1346. curconstSegment.concat(Tai_symbol.Createdataname_global(
  1347. ttypedconstsym(sym).mangledname,l));
  1348. end
  1349. else
  1350. begin
  1351. curconstSegment.concat(Tai_symbol.Createdataname(
  1352. ttypedconstsym(sym).mangledname,l));
  1353. end;
  1354. aktfilepos:=storefilepos;
  1355. end;
  1356. {$ifdef GDB}
  1357. procedure tabstractunitsymtable.concattypestabto(asmlist : taasmoutput);
  1358. var prev_dbx_count : plongint;
  1359. begin
  1360. if is_stab_written then
  1361. exit;
  1362. if not assigned(name) then
  1363. name := stringdup('Main_program');
  1364. if (symtabletype = globalsymtable) and
  1365. (current_module.globalsymtable<>self) then
  1366. begin
  1367. unitid:=current_module.unitcount;
  1368. inc(current_module.unitcount);
  1369. end;
  1370. asmList.concat(tai_comment.Create(strpnew('Begin unit '+name^+' has index '+tostr(unitid))));
  1371. if cs_gdb_dbx in aktglobalswitches then
  1372. begin
  1373. if dbx_count_ok then
  1374. begin
  1375. asmList.concat(tai_comment.Create(strpnew('"repeated" unit '+name^
  1376. +' has index '+tostr(unitid)+' dbx count = '+tostr(dbx_count))));
  1377. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1378. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count))));
  1379. exit;
  1380. end
  1381. else if (current_module.globalsymtable<>self) then
  1382. begin
  1383. prev_dbx_count := dbx_counter;
  1384. dbx_counter := nil;
  1385. do_count_dbx:=false;
  1386. if (symtabletype = globalsymtable) and (unitid<>0) then
  1387. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1388. dbx_counter := @dbx_count;
  1389. dbx_count:=0;
  1390. do_count_dbx:=assigned(dbx_counter);
  1391. end;
  1392. end;
  1393. foreach({$ifdef FPCPROCVAR}@{$endif}concattypestab,asmlist);
  1394. if cs_gdb_dbx in aktglobalswitches then
  1395. begin
  1396. if (current_module.globalsymtable<>self) then
  1397. begin
  1398. dbx_counter := prev_dbx_count;
  1399. do_count_dbx:=false;
  1400. asmList.concat(tai_comment.Create(strpnew('End unit '+name^
  1401. +' has index '+tostr(unitid))));
  1402. asmList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'
  1403. +tostr(N_EINCL)+',0,0,0')));
  1404. do_count_dbx:=assigned(dbx_counter);
  1405. dbx_count_ok := {true}false;
  1406. end;
  1407. end;
  1408. is_stab_written:=true;
  1409. end;
  1410. {$endif GDB}
  1411. {****************************************************************************
  1412. TStaticSymtable
  1413. ****************************************************************************}
  1414. constructor tstaticsymtable.create(const n : string);
  1415. begin
  1416. inherited create(n);
  1417. symtabletype:=staticsymtable;
  1418. symtablelevel:=main_program_level;
  1419. end;
  1420. procedure tstaticsymtable.ppuload(ppufile:tcompilerppufile);
  1421. begin
  1422. aktstaticsymtable:=self;
  1423. next:=symtablestack;
  1424. symtablestack:=self;
  1425. inherited ppuload(ppufile);
  1426. { now we can deref the syms and defs }
  1427. deref;
  1428. { restore symtablestack }
  1429. symtablestack:=next;
  1430. end;
  1431. procedure tstaticsymtable.ppuwrite(ppufile:tcompilerppufile);
  1432. begin
  1433. aktstaticsymtable:=self;
  1434. inherited ppuwrite(ppufile);
  1435. end;
  1436. procedure tstaticsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1437. begin
  1438. aktstaticsymtable:=self;
  1439. inherited load_references(ppufile,locals);
  1440. end;
  1441. procedure tstaticsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1442. begin
  1443. aktstaticsymtable:=self;
  1444. inherited write_references(ppufile,locals);
  1445. end;
  1446. procedure tstaticsymtable.insert(sym:tsymentry);
  1447. var
  1448. hsym : tsym;
  1449. begin
  1450. { also check the global symtable }
  1451. if assigned(next) and
  1452. (next.unitid=0) then
  1453. begin
  1454. hsym:=tsym(next.search(sym.name));
  1455. if assigned(hsym) then
  1456. begin
  1457. { Delphi you can have a symbol with the same name as the
  1458. unit, the unit can then not be accessed anymore using
  1459. <unit>.<id>, so we can hide the symbol }
  1460. if (m_duplicate_names in aktmodeswitches) and
  1461. (hsym.typ=symconst.unitsym) then
  1462. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1463. else
  1464. begin
  1465. DuplicateSym(hsym);
  1466. exit;
  1467. end;
  1468. end;
  1469. end;
  1470. inherited insert(sym);
  1471. end;
  1472. procedure tstaticsymtable.insertvardata(sym : tsymentry);
  1473. begin
  1474. inherited insertvardata(sym);
  1475. { enable unitialized warning for local symbols }
  1476. if sym.typ=varsym then
  1477. tvarsym(sym).varstate:=vs_declared;
  1478. end;
  1479. {****************************************************************************
  1480. TGlobalSymtable
  1481. ****************************************************************************}
  1482. constructor tglobalsymtable.create(const n : string);
  1483. begin
  1484. inherited create(n);
  1485. symtabletype:=globalsymtable;
  1486. symtablelevel:=main_program_level;
  1487. unitid:=0;
  1488. unitsym:=nil;
  1489. {$ifdef GDB}
  1490. if cs_gdb_dbx in aktglobalswitches then
  1491. begin
  1492. dbx_count := 0;
  1493. unittypecount:=1;
  1494. pglobaltypecount := @unittypecount;
  1495. {unitid:=current_module.unitcount;}
  1496. debugList.concat(tai_comment.Create(strpnew('Global '+name^+' has index '+tostr(unitid))));
  1497. debugList.concat(Tai_stabs.Create(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0')));
  1498. {inc(current_module.unitcount);}
  1499. { we can't use dbx_vcount, because we don't know
  1500. if the object file will be loaded before or afeter PM }
  1501. dbx_count_ok:=false;
  1502. dbx_counter:=@dbx_count;
  1503. do_count_dbx:=true;
  1504. end;
  1505. {$endif GDB}
  1506. end;
  1507. destructor tglobalsymtable.destroy;
  1508. var
  1509. pus : tunitsym;
  1510. begin
  1511. pus:=unitsym;
  1512. while assigned(pus) do
  1513. begin
  1514. unitsym:=pus.prevsym;
  1515. pus.prevsym:=nil;
  1516. pus.unitsymtable:=nil;
  1517. pus:=unitsym;
  1518. end;
  1519. inherited destroy;
  1520. end;
  1521. procedure tglobalsymtable.ppuload(ppufile:tcompilerppufile);
  1522. {$ifdef GDB}
  1523. var
  1524. b : byte;
  1525. {$endif GDB}
  1526. begin
  1527. {$ifdef GDB}
  1528. if cs_gdb_dbx in aktglobalswitches then
  1529. begin
  1530. UnitTypeCount:=1;
  1531. PglobalTypeCount:=@UnitTypeCount;
  1532. end;
  1533. {$endif GDB}
  1534. aktglobalsymtable:=self;
  1535. next:=symtablestack;
  1536. symtablestack:=self;
  1537. inherited ppuload(ppufile);
  1538. { now we can deref the syms and defs }
  1539. deref;
  1540. { restore symtablestack }
  1541. symtablestack:=next;
  1542. { read dbx count }
  1543. {$ifdef GDB}
  1544. if (current_module.flags and uf_has_dbx)<>0 then
  1545. begin
  1546. b:=ppufile.readentry;
  1547. if b<>ibdbxcount then
  1548. Message(unit_f_ppu_dbx_count_problem)
  1549. else
  1550. dbx_count:=ppufile.getlongint;
  1551. {$IfDef EXTDEBUG}
  1552. writeln('Read dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1553. {$ENDIF EXTDEBUG}
  1554. { we can't use dbx_vcount, because we don't know
  1555. if the object file will be loaded before or afeter PM }
  1556. dbx_count_ok := {true}false;
  1557. end
  1558. else
  1559. begin
  1560. dbx_count:=-1;
  1561. dbx_count_ok:=false;
  1562. end;
  1563. {$endif GDB}
  1564. end;
  1565. procedure tglobalsymtable.ppuwrite(ppufile:tcompilerppufile);
  1566. begin
  1567. aktglobalsymtable:=self;
  1568. { write the symtable entries }
  1569. inherited ppuwrite(ppufile);
  1570. { write dbx count }
  1571. {$ifdef GDB}
  1572. if cs_gdb_dbx in aktglobalswitches then
  1573. begin
  1574. {$IfDef EXTDEBUG}
  1575. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1576. {$ENDIF EXTDEBUG}
  1577. ppufile.do_crc:=false;
  1578. ppufile.putlongint(dbx_count);
  1579. ppufile.writeentry(ibdbxcount);
  1580. ppufile.do_crc:=true;
  1581. end;
  1582. {$endif GDB}
  1583. end;
  1584. procedure tglobalsymtable.load_references(ppufile:tcompilerppufile;locals:boolean);
  1585. begin
  1586. aktglobalsymtable:=self;
  1587. inherited load_references(ppufile,locals);
  1588. end;
  1589. procedure tglobalsymtable.write_references(ppufile:tcompilerppufile;locals:boolean);
  1590. begin
  1591. aktglobalsymtable:=self;
  1592. inherited write_references(ppufile,locals);
  1593. end;
  1594. procedure tglobalsymtable.insert(sym:tsymentry);
  1595. var
  1596. hsym : tsym;
  1597. begin
  1598. { also check the global symtable }
  1599. if assigned(next) and
  1600. (next.unitid=0) then
  1601. begin
  1602. hsym:=tsym(next.search(sym.name));
  1603. if assigned(hsym) then
  1604. begin
  1605. { Delphi you can have a symbol with the same name as the
  1606. unit, the unit can then not be accessed anymore using
  1607. <unit>.<id>, so we can hide the symbol }
  1608. if (m_duplicate_names in aktmodeswitches) and
  1609. (hsym.typ=symconst.unitsym) then
  1610. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1611. else
  1612. begin
  1613. DuplicateSym(hsym);
  1614. exit;
  1615. end;
  1616. end;
  1617. end;
  1618. hsym:=tsym(search(sym.name));
  1619. if assigned(hsym) then
  1620. begin
  1621. { Delphi you can have a symbol with the same name as the
  1622. unit, the unit can then not be accessed anymore using
  1623. <unit>.<id>, so we can hide the symbol }
  1624. if (m_duplicate_names in aktmodeswitches) and
  1625. (hsym.typ=symconst.unitsym) then
  1626. hsym.owner.rename(hsym.name,'hidden'+hsym.name)
  1627. else
  1628. begin
  1629. DuplicateSym(hsym);
  1630. exit;
  1631. end;
  1632. end;
  1633. inherited insert(sym);
  1634. end;
  1635. procedure tglobalsymtable.insertvardata(sym : tsymentry);
  1636. begin
  1637. inherited insertvardata(sym);
  1638. { this symbol can't be loaded to a register }
  1639. if sym.typ=varsym then
  1640. begin
  1641. exclude(tvarsym(sym).varoptions,vo_regable);
  1642. exclude(tvarsym(sym).varoptions,vo_fpuregable);
  1643. end;
  1644. end;
  1645. {$ifdef GDB}
  1646. function tglobalsymtable.getnewtypecount : word;
  1647. begin
  1648. if not (cs_gdb_dbx in aktglobalswitches) then
  1649. getnewtypecount:=inherited getnewtypecount
  1650. else
  1651. begin
  1652. getnewtypecount:=unittypecount;
  1653. inc(unittypecount);
  1654. end;
  1655. end;
  1656. {$endif}
  1657. {****************************************************************************
  1658. TWITHSYMTABLE
  1659. ****************************************************************************}
  1660. constructor twithsymtable.create(aowner:tdef;asymsearch:TDictionary;refnode:pointer{tnode});
  1661. begin
  1662. inherited create('');
  1663. symtabletype:=withsymtable;
  1664. withrefnode:=refnode;
  1665. { we don't need the symsearch }
  1666. symsearch.free;
  1667. { set the defaults }
  1668. symsearch:=asymsearch;
  1669. defowner:=aowner;
  1670. end;
  1671. destructor twithsymtable.destroy;
  1672. begin
  1673. symsearch:=nil;
  1674. inherited destroy;
  1675. end;
  1676. procedure twithsymtable.clear;
  1677. begin
  1678. { remove no entry from a withsymtable as it is only a pointer to the
  1679. recorddef or objectdef symtable }
  1680. end;
  1681. {****************************************************************************
  1682. TSTT_ExceptionSymtable
  1683. ****************************************************************************}
  1684. constructor tstt_exceptsymtable.create;
  1685. begin
  1686. inherited create('');
  1687. symtabletype:=stt_exceptsymtable;
  1688. end;
  1689. {*****************************************************************************
  1690. Helper Routines
  1691. *****************************************************************************}
  1692. function findunitsymtable(st:tsymtable):tsymtable;
  1693. begin
  1694. findunitsymtable:=nil;
  1695. repeat
  1696. if not assigned(st) then
  1697. internalerror(5566561);
  1698. case st.symtabletype of
  1699. localsymtable,
  1700. parasymtable,
  1701. staticsymtable :
  1702. exit;
  1703. globalsymtable :
  1704. begin
  1705. findunitsymtable:=st;
  1706. exit;
  1707. end;
  1708. objectsymtable :
  1709. st:=st.defowner.owner;
  1710. recordsymtable :
  1711. begin
  1712. { don't continue when the current
  1713. symtable is used for variant records }
  1714. if trecorddef(st.defowner).isunion then
  1715. begin
  1716. findunitsymtable:=nil;
  1717. exit;
  1718. end
  1719. else
  1720. st:=st.defowner.owner;
  1721. end;
  1722. else
  1723. internalerror(5566562);
  1724. end;
  1725. until false;
  1726. end;
  1727. procedure duplicatesym(sym:tsym);
  1728. var
  1729. st : tsymtable;
  1730. begin
  1731. Message1(sym_e_duplicate_id,sym.realname);
  1732. st:=findunitsymtable(sym.owner);
  1733. with sym.fileinfo do
  1734. begin
  1735. if assigned(st) and (st.unitid<>0) then
  1736. Message2(sym_h_duplicate_id_where,'unit '+st.name^,tostr(line))
  1737. else
  1738. Message2(sym_h_duplicate_id_where,current_module.sourcefiles.get_file_name(fileindex),tostr(line));
  1739. end;
  1740. end;
  1741. {*****************************************************************************
  1742. Search
  1743. *****************************************************************************}
  1744. function searchsym(const s : stringid;var srsym:tsym;var srsymtable:tsymtable):boolean;
  1745. var
  1746. speedvalue : cardinal;
  1747. begin
  1748. speedvalue:=getspeedvalue(s);
  1749. srsymtable:=symtablestack;
  1750. while assigned(srsymtable) do
  1751. begin
  1752. srsym:=tsym(srsymtable.speedsearch(s,speedvalue));
  1753. if assigned(srsym) and
  1754. tstoredsym(srsym).is_visible_for_proc(current_procdef) then
  1755. begin
  1756. searchsym:=true;
  1757. exit;
  1758. end
  1759. else
  1760. srsymtable:=srsymtable.next;
  1761. end;
  1762. searchsym:=false;
  1763. end;
  1764. function searchsymonlyin(p : tsymtable;const s : stringid):tsym;
  1765. var
  1766. srsym : tsym;
  1767. begin
  1768. { the caller have to take care if srsym=nil }
  1769. if assigned(p) then
  1770. begin
  1771. srsym:=tsym(p.search(s));
  1772. if assigned(srsym) then
  1773. begin
  1774. searchsymonlyin:=srsym;
  1775. exit;
  1776. end;
  1777. { also check in the local symtbale if it exists }
  1778. if (p=tsymtable(current_module.globalsymtable)) then
  1779. begin
  1780. srsym:=tsym(current_module.localsymtable.search(s));
  1781. if assigned(srsym) then
  1782. begin
  1783. searchsymonlyin:=srsym;
  1784. exit;
  1785. end;
  1786. end
  1787. end;
  1788. searchsymonlyin:=nil;
  1789. end;
  1790. function searchsym_in_class(classh:tobjectdef;const s : stringid):tsym;
  1791. var
  1792. speedvalue : cardinal;
  1793. topclassh : tobjectdef;
  1794. sym : tsym;
  1795. begin
  1796. speedvalue:=getspeedvalue(s);
  1797. { when the class passed is defined in this unit we
  1798. need to use the scope of that class. This is a trick
  1799. that can be used to access protected members in other
  1800. units. At least kylix supports it this way (PFV) }
  1801. if assigned(classh) and
  1802. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1803. (classh.owner.unitid=0) then
  1804. topclassh:=classh
  1805. else
  1806. topclassh:=nil;
  1807. sym:=nil;
  1808. while assigned(classh) do
  1809. begin
  1810. sym:=tsym(classh.symtable.speedsearch(s,speedvalue));
  1811. if assigned(sym) then
  1812. begin
  1813. if assigned(topclassh) then
  1814. begin
  1815. if tstoredsym(sym).is_visible_for_object(topclassh) then
  1816. break;
  1817. end
  1818. else
  1819. begin
  1820. if tstoredsym(sym).is_visible_for_proc(current_procdef) then
  1821. break;
  1822. end;
  1823. end;
  1824. classh:=classh.childof;
  1825. end;
  1826. searchsym_in_class:=sym;
  1827. end;
  1828. function searchsym_in_class_by_msgint(classh:tobjectdef;i:longint):tsym;
  1829. var
  1830. topclassh : tobjectdef;
  1831. def : tdef;
  1832. sym : tsym;
  1833. begin
  1834. { when the class passed is defined in this unit we
  1835. need to use the scope of that class. This is a trick
  1836. that can be used to access protected members in other
  1837. units. At least kylix supports it this way (PFV) }
  1838. if assigned(classh) and
  1839. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1840. (classh.owner.unitid=0) then
  1841. topclassh:=classh
  1842. else
  1843. topclassh:=nil;
  1844. sym:=nil;
  1845. def:=nil;
  1846. while assigned(classh) do
  1847. begin
  1848. def:=tdef(classh.symtable.defindex.first);
  1849. while assigned(def) do
  1850. begin
  1851. if (def.deftype=procdef) and
  1852. (po_msgint in tprocdef(def).procoptions) and
  1853. (tprocdef(def).messageinf.i=i) then
  1854. begin
  1855. sym:=tprocdef(def).procsym;
  1856. if assigned(topclassh) then
  1857. begin
  1858. if tprocdef(def).is_visible_for_object(topclassh) then
  1859. break;
  1860. end
  1861. else
  1862. begin
  1863. if tprocdef(def).is_visible_for_proc(current_procdef) then
  1864. break;
  1865. end;
  1866. end;
  1867. def:=tdef(def.indexnext);
  1868. end;
  1869. if assigned(sym) then
  1870. break;
  1871. classh:=classh.childof;
  1872. end;
  1873. searchsym_in_class_by_msgint:=sym;
  1874. end;
  1875. function searchsym_in_class_by_msgstr(classh:tobjectdef;const s:string):tsym;
  1876. var
  1877. topclassh : tobjectdef;
  1878. def : tdef;
  1879. sym : tsym;
  1880. begin
  1881. { when the class passed is defined in this unit we
  1882. need to use the scope of that class. This is a trick
  1883. that can be used to access protected members in other
  1884. units. At least kylix supports it this way (PFV) }
  1885. if assigned(classh) and
  1886. (classh.owner.symtabletype in [globalsymtable,staticsymtable]) and
  1887. (classh.owner.unitid=0) then
  1888. topclassh:=classh
  1889. else
  1890. topclassh:=nil;
  1891. sym:=nil;
  1892. def:=nil;
  1893. while assigned(classh) do
  1894. begin
  1895. def:=tdef(classh.symtable.defindex.first);
  1896. while assigned(def) do
  1897. begin
  1898. if (def.deftype=procdef) and
  1899. (po_msgstr in tprocdef(def).procoptions) and
  1900. (tprocdef(def).messageinf.str=s) then
  1901. begin
  1902. sym:=tprocdef(def).procsym;
  1903. if assigned(topclassh) then
  1904. begin
  1905. if tprocdef(def).is_visible_for_object(topclassh) then
  1906. break;
  1907. end
  1908. else
  1909. begin
  1910. if tprocdef(def).is_visible_for_proc(current_procdef) then
  1911. break;
  1912. end;
  1913. end;
  1914. def:=tdef(def.indexnext);
  1915. end;
  1916. if assigned(sym) then
  1917. break;
  1918. classh:=classh.childof;
  1919. end;
  1920. searchsym_in_class_by_msgstr:=sym;
  1921. end;
  1922. function searchsystype(const s: stringid; var srsym: ttypesym): boolean;
  1923. var
  1924. symowner: tsymtable;
  1925. begin
  1926. if not(cs_compilesystem in aktmoduleswitches) then
  1927. srsym := ttypesym(searchsymonlyin(systemunit,s))
  1928. else
  1929. searchsym(s,tsym(srsym),symowner);
  1930. searchsystype :=
  1931. assigned(srsym) and
  1932. (srsym.typ = typesym);
  1933. end;
  1934. function searchsysvar(const s: stringid; var srsym: tvarsym; var symowner: tsymtable): boolean;
  1935. begin
  1936. if not(cs_compilesystem in aktmoduleswitches) then
  1937. begin
  1938. srsym := tvarsym(searchsymonlyin(systemunit,s));
  1939. symowner := systemunit;
  1940. end
  1941. else
  1942. searchsym(s,tsym(srsym),symowner);
  1943. searchsysvar :=
  1944. assigned(srsym) and
  1945. (srsym.typ = varsym);
  1946. end;
  1947. function search_class_member(pd : tobjectdef;const s : string):tsym;
  1948. { searches n in symtable of pd and all anchestors }
  1949. var
  1950. speedvalue : cardinal;
  1951. srsym : tsym;
  1952. begin
  1953. speedvalue:=getspeedvalue(s);
  1954. while assigned(pd) do
  1955. begin
  1956. srsym:=tsym(pd.symtable.speedsearch(s,speedvalue));
  1957. if assigned(srsym) then
  1958. begin
  1959. search_class_member:=srsym;
  1960. exit;
  1961. end;
  1962. pd:=pd.childof;
  1963. end;
  1964. search_class_member:=nil;
  1965. end;
  1966. {*****************************************************************************
  1967. Definition Helpers
  1968. *****************************************************************************}
  1969. procedure globaldef(const s : string;var t:ttype);
  1970. var st : string;
  1971. symt : tsymtable;
  1972. srsym : tsym;
  1973. srsymtable : tsymtable;
  1974. begin
  1975. srsym := nil;
  1976. if pos('.',s) > 0 then
  1977. begin
  1978. st := copy(s,1,pos('.',s)-1);
  1979. searchsym(st,srsym,srsymtable);
  1980. st := copy(s,pos('.',s)+1,255);
  1981. if assigned(srsym) then
  1982. begin
  1983. if srsym.typ = unitsym then
  1984. begin
  1985. symt := tunitsym(srsym).unitsymtable;
  1986. srsym := tsym(symt.search(st));
  1987. end else srsym := nil;
  1988. end;
  1989. end else st := s;
  1990. if srsym = nil then
  1991. searchsym(st,srsym,srsymtable);
  1992. if srsym = nil then
  1993. srsym:=searchsymonlyin(systemunit,st);
  1994. if (not assigned(srsym)) or
  1995. (srsym.typ<>typesym) then
  1996. begin
  1997. Message(type_e_type_id_expected);
  1998. t:=generrortype;
  1999. exit;
  2000. end;
  2001. t := ttypesym(srsym).restype;
  2002. end;
  2003. {****************************************************************************
  2004. Object Helpers
  2005. ****************************************************************************}
  2006. var
  2007. _defaultprop : tpropertysym;
  2008. procedure tstoredsymtable.testfordefaultproperty(p : TNamedIndexItem;arg:pointer);
  2009. begin
  2010. if (tsym(p).typ=propertysym) and
  2011. (ppo_defaultproperty in tpropertysym(p).propoptions) then
  2012. _defaultprop:=tpropertysym(p);
  2013. end;
  2014. function search_default_property(pd : tobjectdef) : tpropertysym;
  2015. { returns the default property of a class, searches also anchestors }
  2016. begin
  2017. _defaultprop:=nil;
  2018. while assigned(pd) do
  2019. begin
  2020. pd.symtable.foreach({$ifdef FPCPROCVAR}@{$endif}tstoredsymtable(pd.symtable).testfordefaultproperty,nil);
  2021. if assigned(_defaultprop) then
  2022. break;
  2023. pd:=pd.childof;
  2024. end;
  2025. search_default_property:=_defaultprop;
  2026. end;
  2027. {$ifdef UNITALIASES}
  2028. {****************************************************************************
  2029. TUNIT_ALIAS
  2030. ****************************************************************************}
  2031. constructor tunit_alias.create(const n:string);
  2032. var
  2033. i : longint;
  2034. begin
  2035. i:=pos('=',n);
  2036. if i=0 then
  2037. fail;
  2038. inherited createname(Copy(n,1,i-1));
  2039. newname:=stringdup(Copy(n,i+1,255));
  2040. end;
  2041. destructor tunit_alias.destroy;
  2042. begin
  2043. stringdispose(newname);
  2044. inherited destroy;
  2045. end;
  2046. procedure addunitalias(const n:string);
  2047. begin
  2048. unitaliases^.insert(tunit_alias,init(Upper(n))));
  2049. end;
  2050. function getunitalias(const n:string):string;
  2051. var
  2052. p : punit_alias;
  2053. begin
  2054. p:=punit_alias(unitaliases^.search(Upper(n)));
  2055. if assigned(p) then
  2056. getunitalias:=punit_alias(p).newname^
  2057. else
  2058. getunitalias:=n;
  2059. end;
  2060. {$endif UNITALIASES}
  2061. {****************************************************************************
  2062. Symtable Stack
  2063. ****************************************************************************}
  2064. procedure RestoreUnitSyms;
  2065. var
  2066. p : tsymtable;
  2067. begin
  2068. p:=symtablestack;
  2069. while assigned(p) do
  2070. begin
  2071. if (p.symtabletype=globalsymtable) and
  2072. assigned(tglobalsymtable(p).unitsym) and
  2073. ((tglobalsymtable(p).unitsym.owner=current_module.globalsymtable) or
  2074. (tglobalsymtable(p).unitsym.owner=current_module.localsymtable)) then
  2075. tglobalsymtable(p).unitsym.restoreunitsym;
  2076. p:=p.next;
  2077. end;
  2078. end;
  2079. {$ifdef DEBUG}
  2080. procedure test_symtablestack;
  2081. var
  2082. p : tsymtable;
  2083. i : longint;
  2084. begin
  2085. p:=symtablestack;
  2086. i:=0;
  2087. while assigned(p) do
  2088. begin
  2089. inc(i);
  2090. p:=p.next;
  2091. if i>500 then
  2092. Message(sym_f_internal_error_in_symtablestack);
  2093. end;
  2094. end;
  2095. procedure list_symtablestack;
  2096. var
  2097. p : tsymtable;
  2098. i : longint;
  2099. begin
  2100. p:=symtablestack;
  2101. i:=0;
  2102. while assigned(p) do
  2103. begin
  2104. inc(i);
  2105. writeln(i,' ',p.name^);
  2106. p:=p.next;
  2107. if i>500 then
  2108. Message(sym_f_internal_error_in_symtablestack);
  2109. end;
  2110. end;
  2111. {$endif DEBUG}
  2112. {****************************************************************************
  2113. Init/Done Symtable
  2114. ****************************************************************************}
  2115. procedure InitSymtable;
  2116. var
  2117. token : ttoken;
  2118. begin
  2119. { Reset symbolstack }
  2120. registerdef:=false;
  2121. symtablestack:=nil;
  2122. systemunit:=nil;
  2123. {$ifdef GDB}
  2124. firstglobaldef:=nil;
  2125. lastglobaldef:=nil;
  2126. globaltypecount:=1;
  2127. pglobaltypecount:=@globaltypecount;
  2128. {$endif GDB}
  2129. { defs for internal use }
  2130. voidprocdef:=tprocdef.create(unknown_level);
  2131. { create error syms and def }
  2132. generrorsym:=terrorsym.create;
  2133. generrortype.setdef(terrordef.create);
  2134. {$ifdef UNITALIASES}
  2135. { unit aliases }
  2136. unitaliases:=tdictionary.create;
  2137. {$endif}
  2138. for token:=first_overloaded to last_overloaded do
  2139. overloaded_operators[token]:=nil;
  2140. end;
  2141. procedure DoneSymtable;
  2142. begin
  2143. voidprocdef.free;
  2144. generrorsym.free;
  2145. generrortype.def.free;
  2146. {$ifdef UNITALIASES}
  2147. unitaliases.free;
  2148. {$endif}
  2149. end;
  2150. end.
  2151. {
  2152. $Log$
  2153. Revision 1.104 2003-06-07 20:26:32 peter
  2154. * re-resolving added instead of reloading from ppu
  2155. * tderef object added to store deref info for resolving
  2156. Revision 1.103 2003/05/25 11:34:17 peter
  2157. * methodpointer self pushing fixed
  2158. Revision 1.102 2003/05/23 14:27:35 peter
  2159. * remove some unit dependencies
  2160. * current_procinfo changes to store more info
  2161. Revision 1.101 2003/05/16 14:32:58 peter
  2162. * fix dup check for hiding the result varsym in localst, the result
  2163. sym was already in the localst when adding the locals
  2164. Revision 1.100 2003/05/15 18:58:53 peter
  2165. * removed selfpointer_offset, vmtpointer_offset
  2166. * tvarsym.adjusted_address
  2167. * address in localsymtable is now in the real direction
  2168. * removed some obsolete globals
  2169. Revision 1.99 2003/05/13 15:17:13 peter
  2170. * fix crash with hiding function result. The function result is now
  2171. inserted as last so the symbol that we are going to insert is the
  2172. result and needs to be renamed instead of the already existing
  2173. symbol
  2174. Revision 1.98 2003/05/11 14:45:12 peter
  2175. * tloadnode does not support objectsymtable,withsymtable anymore
  2176. * withnode cleanup
  2177. * direct with rewritten to use temprefnode
  2178. Revision 1.97 2003/04/27 11:21:34 peter
  2179. * aktprocdef renamed to current_procdef
  2180. * procinfo renamed to current_procinfo
  2181. * procinfo will now be stored in current_module so it can be
  2182. cleaned up properly
  2183. * gen_main_procsym changed to create_main_proc and release_main_proc
  2184. to also generate a tprocinfo structure
  2185. * fixed unit implicit initfinal
  2186. Revision 1.96 2003/04/27 07:29:51 peter
  2187. * current_procdef cleanup, current_procdef is now always nil when parsing
  2188. a new procdef declaration
  2189. * aktprocsym removed
  2190. * lexlevel removed, use symtable.symtablelevel instead
  2191. * implicit init/final code uses the normal genentry/genexit
  2192. * funcret state checking updated for new funcret handling
  2193. Revision 1.95 2003/04/26 00:33:07 peter
  2194. * vo_is_result flag added for the special RESULT symbol
  2195. Revision 1.94 2003/04/25 20:59:35 peter
  2196. * removed funcretn,funcretsym, function result is now in varsym
  2197. and aliases for result and function name are added using absolutesym
  2198. * vs_hidden parameter for funcret passed in parameter
  2199. * vs_hidden fixes
  2200. * writenode changed to printnode and released from extdebug
  2201. * -vp option added to generate a tree.log with the nodetree
  2202. * nicer printnode for statements, callnode
  2203. Revision 1.93 2003/04/16 07:53:11 jonas
  2204. * calculation of parameter and resultlocation offsets now depends on
  2205. tg.direction instead of if(n)def powerpc
  2206. Revision 1.92 2003/04/05 21:09:32 jonas
  2207. * several ppc/generic result offset related fixes. The "normal" result
  2208. offset seems now to be calculated correctly and a lot of duplicate
  2209. calculations have been removed. Nested functions accessing the parent's
  2210. function result don't work at all though :(
  2211. Revision 1.91 2003/03/17 18:56:49 peter
  2212. * ignore hints for default parameter values
  2213. Revision 1.90 2003/03/17 16:54:41 peter
  2214. * support DefaultHandler and anonymous inheritance fixed
  2215. for message methods
  2216. Revision 1.89 2002/12/29 14:57:50 peter
  2217. * unit loading changed to first register units and load them
  2218. afterwards. This is needed to support uses xxx in yyy correctly
  2219. * unit dependency check fixed
  2220. Revision 1.88 2002/12/27 18:07:45 peter
  2221. * fix crashes when searching symbols
  2222. Revision 1.87 2002/12/25 01:26:56 peter
  2223. * duplicate procsym-unitsym fix
  2224. Revision 1.86 2002/12/21 13:07:34 peter
  2225. * type redefine fix for tb0437
  2226. Revision 1.85 2002/12/07 14:27:10 carl
  2227. * 3% memory optimization
  2228. * changed some types
  2229. + added type checking with different size for call node and for
  2230. parameters
  2231. Revision 1.84 2002/12/06 17:51:11 peter
  2232. * merged cdecl and array fixes
  2233. Revision 1.83 2002/11/30 11:12:48 carl
  2234. + checking for symbols used with hint directives is done mostly in pexpr
  2235. only now
  2236. Revision 1.82 2002/11/29 22:31:20 carl
  2237. + unimplemented hint directive added
  2238. * hint directive parsing implemented
  2239. * warning on these directives
  2240. Revision 1.81 2002/11/27 20:04:09 peter
  2241. * tvarsym.get_push_size replaced by paramanager.push_size
  2242. Revision 1.80 2002/11/22 22:45:49 carl
  2243. + small optimization for speed
  2244. Revision 1.79 2002/11/19 16:26:33 pierre
  2245. * correct a stabs generation problem that lead to use errordef in stabs
  2246. Revision 1.78 2002/11/18 17:32:00 peter
  2247. * pass proccalloption to ret_in_xxx and push_xxx functions
  2248. Revision 1.77 2002/11/15 01:58:54 peter
  2249. * merged changes from 1.0.7 up to 04-11
  2250. - -V option for generating bug report tracing
  2251. - more tracing for option parsing
  2252. - errors for cdecl and high()
  2253. - win32 import stabs
  2254. - win32 records<=8 are returned in eax:edx (turned off by default)
  2255. - heaptrc update
  2256. - more info for temp management in .s file with EXTDEBUG
  2257. Revision 1.76 2002/11/09 15:29:28 carl
  2258. + bss / constant alignment fixes
  2259. * avoid incrementing address/datasize in local symtable for const's
  2260. Revision 1.75 2002/10/14 19:44:43 peter
  2261. * threadvars need 4 bytes extra for storing the threadvar index
  2262. Revision 1.74 2002/10/06 19:41:31 peter
  2263. * Add finalization of typed consts
  2264. * Finalization of globals in the main program
  2265. Revision 1.73 2002/10/05 12:43:29 carl
  2266. * fixes for Delphi 6 compilation
  2267. (warning : Some features do not work under Delphi)
  2268. Revision 1.72 2002/09/09 19:41:46 peter
  2269. * real fix internalerror for dup ids in union sym
  2270. Revision 1.71 2002/09/09 17:34:16 peter
  2271. * tdicationary.replace added to replace and item in a dictionary. This
  2272. is only allowed for the same name
  2273. * varsyms are inserted in symtable before the types are parsed. This
  2274. fixes the long standing "var longint : longint" bug
  2275. - consume_idlist and idstringlist removed. The loops are inserted
  2276. at the callers place and uses the symtable for duplicate id checking
  2277. Revision 1.70 2002/09/05 19:29:45 peter
  2278. * memdebug enhancements
  2279. Revision 1.69 2002/08/25 19:25:21 peter
  2280. * sym.insert_in_data removed
  2281. * symtable.insertvardata/insertconstdata added
  2282. * removed insert_in_data call from symtable.insert, it needs to be
  2283. called separatly. This allows to deref the address calculation
  2284. * procedures now calculate the parast addresses after the procedure
  2285. directives are parsed. This fixes the cdecl parast problem
  2286. * push_addr_param has an extra argument that specifies if cdecl is used
  2287. or not
  2288. Revision 1.68 2002/08/18 20:06:27 peter
  2289. * inlining is now also allowed in interface
  2290. * renamed write/load to ppuwrite/ppuload
  2291. * tnode storing in ppu
  2292. * nld,ncon,nbas are already updated for storing in ppu
  2293. Revision 1.67 2002/08/17 09:23:43 florian
  2294. * first part of procinfo rewrite
  2295. Revision 1.66 2002/08/11 13:24:15 peter
  2296. * saving of asmsymbols in ppu supported
  2297. * asmsymbollist global is removed and moved into a new class
  2298. tasmlibrarydata that will hold the info of a .a file which
  2299. corresponds with a single module. Added librarydata to tmodule
  2300. to keep the library info stored for the module. In the future the
  2301. objectfiles will also be stored to the tasmlibrarydata class
  2302. * all getlabel/newasmsymbol and friends are moved to the new class
  2303. Revision 1.65 2002/07/23 09:51:27 daniel
  2304. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2305. are worth comitting.
  2306. Revision 1.64 2002/07/16 15:34:21 florian
  2307. * exit is now a syssym instead of a keyword
  2308. Revision 1.63 2002/07/15 19:44:53 florian
  2309. * fixed crash with default parameters and stdcall calling convention
  2310. Revision 1.62 2002/07/01 18:46:28 peter
  2311. * internal linker
  2312. * reorganized aasm layer
  2313. Revision 1.61 2002/05/18 13:34:19 peter
  2314. * readded missing revisions
  2315. Revision 1.60 2002/05/16 19:46:45 carl
  2316. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2317. + try to fix temp allocation (still in ifdef)
  2318. + generic constructor calls
  2319. + start of tassembler / tmodulebase class cleanup
  2320. Revision 1.58 2002/05/12 16:53:15 peter
  2321. * moved entry and exitcode to ncgutil and cgobj
  2322. * foreach gets extra argument for passing local data to the
  2323. iterator function
  2324. * -CR checks also class typecasts at runtime by changing them
  2325. into as
  2326. * fixed compiler to cycle with the -CR option
  2327. * fixed stabs with elf writer, finally the global variables can
  2328. be watched
  2329. * removed a lot of routines from cga unit and replaced them by
  2330. calls to cgobj
  2331. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2332. u32bit then the other is typecasted also to u32bit without giving
  2333. a rangecheck warning/error.
  2334. * fixed pascal calling method with reversing also the high tree in
  2335. the parast, detected by tcalcst3 test
  2336. Revision 1.57 2002/04/04 19:06:05 peter
  2337. * removed unused units
  2338. * use tlocation.size in cg.a_*loc*() routines
  2339. Revision 1.56 2002/03/04 19:10:11 peter
  2340. * removed compiler warnings
  2341. Revision 1.55 2002/02/03 09:30:07 peter
  2342. * more fixes for protected handling
  2343. Revision 1.54 2002/01/29 21:30:25 peter
  2344. * allow also dup id in delphi mode in interfaces
  2345. Revision 1.53 2002/01/29 19:46:00 peter
  2346. * fixed recordsymtable.insert_in() for inserting variant record fields
  2347. to not used symtable.insert() because that also updates alignmentinfo
  2348. which was already set
  2349. Revision 1.52 2002/01/24 18:25:50 peter
  2350. * implicit result variable generation for assembler routines
  2351. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  2352. }