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