symtable.pas 89 KB

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