symtable.pas 91 KB

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