symtable.pas 88 KB

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