symtable.pas 89 KB

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