symtable.pas 92 KB

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