symtable.pas 90 KB

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