symtable.pas 89 KB

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