symtable.pas 90 KB

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