symtable.pas 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 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. {$ifdef TP}
  19. {$N+,E+,F+}
  20. {$endif}
  21. unit symtable;
  22. interface
  23. uses
  24. {$ifdef TP}
  25. objects,
  26. {$endif}
  27. strings,cobjects,
  28. globtype,globals,tokens,systems,verbose,
  29. aasm
  30. {$ifdef i386}
  31. {$ifndef OLDASM}
  32. ,i386base
  33. {$else}
  34. ,i386
  35. {$endif}
  36. {$endif}
  37. {$ifdef m68k}
  38. ,m68k
  39. {$endif}
  40. {$ifdef alpha}
  41. ,alpha
  42. {$endif}
  43. {$ifdef GDB}
  44. ,gdb
  45. {$endif}
  46. ;
  47. {$ifdef OLDPPU}
  48. {define NOLOCALBROWSER if you have problems with -bl option }
  49. {$endif}
  50. {************************************************
  51. Some internal constants
  52. ************************************************}
  53. const
  54. hasharraysize = 256;
  55. {$ifndef OLDPPU}
  56. {$ifdef TP}
  57. indexgrowsize = 256;
  58. {$else}
  59. indexgrowsize = 1024;
  60. {$endif}
  61. {$else}
  62. defhasharraysize = 16000;
  63. {$endif}
  64. {************************************************
  65. Constants
  66. ************************************************}
  67. {$i symconst.inc}
  68. {************************************************
  69. Needed forward pointers
  70. ************************************************}
  71. type
  72. { needed for owner (table) of symbol }
  73. psymtable = ^tsymtable;
  74. punitsymtable = ^tunitsymtable;
  75. { needed for names by the definitions }
  76. ptypesym = ^ttypesym;
  77. penumsym = ^tenumsym;
  78. pref = ^tref;
  79. tref = object
  80. nextref : pref;
  81. posinfo : tfileposinfo;
  82. moduleindex : word;
  83. is_written : boolean;
  84. constructor init(ref:pref;pos:pfileposinfo);
  85. destructor done; virtual;
  86. end;
  87. {************************************************
  88. TDef
  89. ************************************************}
  90. {$i symdefh.inc}
  91. {************************************************
  92. TSym
  93. ************************************************}
  94. {$i symsymh.inc}
  95. {************************************************
  96. TSymtable
  97. ************************************************}
  98. tsymtabletype = (invalidsymtable,withsymtable,staticsymtable,
  99. globalsymtable,unitsymtable,
  100. objectsymtable,recordsymtable,
  101. macrosymtable,localsymtable,
  102. parasymtable,inlineparasymtable,
  103. inlinelocalsymtable,stt_exceptsymtable,
  104. { only used for PPU reading of static part
  105. of a unit }
  106. staticppusymtable);
  107. tcallback = procedure(p : psym);
  108. {$ifdef OLDPPU}
  109. tnamedindexcallback = procedure(p : psym);
  110. {$endif}
  111. tsearchhasharray = array[0..hasharraysize-1] of psym;
  112. psearchhasharray = ^tsearchhasharray;
  113. {$ifdef OLDPPU}
  114. tdefhasharray = array[0..defhasharraysize-1] of pdef;
  115. pdefhasharray = ^tdefhasharray;
  116. {$endif}
  117. tsymtable = object
  118. symtabletype : tsymtabletype;
  119. unitid : word; { each symtable gets a number }
  120. name : pstring;
  121. datasize : longint;
  122. {$ifndef OLDPPU}
  123. symindex,
  124. defindex : pindexarray;
  125. symsearch : pdictionary;
  126. {$else}
  127. searchroot : psym;
  128. searchhasharray : psearchhasharray;
  129. lastsym : psym;
  130. rootdef : pdef;
  131. defhasharraysize : longint;
  132. defhasharray : pdefhasharray;
  133. {$endif}
  134. next : psymtable;
  135. defowner : pdef; { for records and objects }
  136. { alignment used in this symtable }
  137. alignment : longint;
  138. { only used for parameter symtable to determine the offset relative }
  139. { to the frame pointer and for local inline }
  140. address_fixup : longint;
  141. { this saves all definition to allow a proper clean up }
  142. { separate lexlevel from symtable type }
  143. symtablelevel : byte;
  144. constructor init(t : tsymtabletype);
  145. destructor done;virtual;
  146. { access }
  147. {$ifdef OLDPPU}
  148. { indexes all defs from 0 to num and return num + 1 }
  149. function number_defs:longint;
  150. { indexes all symbols from 1 to num and return num }
  151. function number_symbols:longint;
  152. {$endif}
  153. function getdefnr(l : longint) : pdef;
  154. function getsymnr(l : longint) : psym;
  155. { load/write }
  156. constructor load;
  157. procedure write;
  158. constructor loadas(typ : tsymtabletype);
  159. procedure writeas;
  160. procedure loaddefs;
  161. procedure loadsyms;
  162. procedure writedefs;
  163. procedure writesyms;
  164. {$ifndef OLDPPU}
  165. procedure deref;
  166. {$endif}
  167. procedure clear;
  168. function rename(const olds,news : stringid):psym;
  169. procedure foreach(proc2call : tnamedindexcallback);
  170. function insert(sym : psym):psym;
  171. function search(const s : stringid) : psym;
  172. function speedsearch(const s : stringid;speedvalue : longint) : psym;
  173. procedure registerdef(p : pdef);
  174. procedure allsymbolsused;
  175. procedure allunitsused;
  176. procedure check_forwards;
  177. procedure checklabels;
  178. { change alignment for args only parasymtable }
  179. procedure set_alignment(_alignment : byte);
  180. { find arg having offset only parasymtable }
  181. function find_at_offset(l : longint) : pvarsym;
  182. {$ifdef CHAINPROCSYMS}
  183. procedure chainprocsyms;
  184. {$endif CHAINPROCSYMS}
  185. procedure load_browser;
  186. procedure write_browser;
  187. {$ifdef BrowserLog}
  188. procedure writebrowserlog;
  189. {$endif BrowserLog}
  190. {$ifdef GDB}
  191. procedure concatstabto(asmlist : paasmoutput);virtual;
  192. {$endif GDB}
  193. function getnewtypecount : word; virtual;
  194. end;
  195. tunitsymtable = object(tsymtable)
  196. unittypecount : word;
  197. unitsym : punitsym;
  198. {$ifdef GDB}
  199. dbx_count : longint;
  200. prev_dbx_counter : plongint;
  201. dbx_count_ok : boolean;
  202. is_stab_written : boolean;
  203. {$endif GDB}
  204. constructor init(t : tsymtabletype;const n : string);
  205. constructor loadasunit;
  206. procedure writeasunit;
  207. {$ifdef GDB}
  208. {$ifdef OLDPPU}
  209. procedure orderdefs;
  210. {$endif}
  211. procedure concattypestabto(asmlist : paasmoutput);
  212. {$endif GDB}
  213. procedure load_symtable_refs;
  214. function getnewtypecount : word; virtual;
  215. end;
  216. pwithsymtable = ^twithsymtable;
  217. twithsymtable = object(tsymtable)
  218. {$ifndef NODIRECTWITH}
  219. { used for withsymtable for allowing constructors }
  220. direct_with : boolean;
  221. { in fact it is a ptree }
  222. withnode : pointer;
  223. { ptree to load of direct with var }
  224. { already usable before firstwith
  225. needed for firstpass of function parameters PM }
  226. withrefnode : pointer;
  227. {$endif def NODIRECTWITH}
  228. constructor init;
  229. destructor done;virtual;
  230. end;
  231. {****************************************************************************
  232. Var / Consts
  233. ****************************************************************************}
  234. const
  235. systemunit : punitsymtable = nil; { pointer to the system unit }
  236. objpasunit : punitsymtable = nil; { pointer to the objpas unit }
  237. current_object_option : symprop = sp_public;
  238. var
  239. { for STAB debugging }
  240. globaltypecount : word;
  241. pglobaltypecount : pword;
  242. registerdef : boolean; { true, when defs should be registered }
  243. defaultsymtablestack, { symtablestack after default units
  244. have been loaded }
  245. symtablestack : psymtable; { linked list of symtables }
  246. srsym : psym; { result of the last search }
  247. srsymtable : psymtable;
  248. lastsrsym : psym; { last sym found in statement }
  249. lastsrsymtable : psymtable;
  250. lastsymknown : boolean;
  251. forwardsallowed : boolean; { true, wenn forward pointers can be
  252. inserted }
  253. constsymtable : psymtable; { symtable were the constants can be
  254. inserted }
  255. voidpointerdef : ppointerdef; { pointer for Void-Pointerdef }
  256. charpointerdef : ppointerdef; { pointer for Char-Pointerdef }
  257. voidfarpointerdef : ppointerdef;
  258. cformaldef : pformaldef; { unique formal definition }
  259. voiddef : porddef; { Pointer to Void (procedure) }
  260. cchardef : porddef; { Pointer to Char }
  261. booldef : porddef; { pointer to boolean type }
  262. u8bitdef : porddef; { Pointer to 8-Bit unsigned }
  263. u16bitdef : porddef; { Pointer to 16-Bit unsigned }
  264. u32bitdef : porddef; { Pointer to 32-Bit unsigned }
  265. s32bitdef : porddef; { Pointer to 32-Bit signed }
  266. cu64bitdef : porddef; { pointer to 64 bit unsigned def }
  267. cs64bitdef : porddef; { pointer to 64 bit signed def, }
  268. { calculated by the int unit on i386 }
  269. s32floatdef : pfloatdef; { pointer for realconstn }
  270. s64floatdef : pfloatdef; { pointer for realconstn }
  271. s80floatdef : pfloatdef; { pointer to type of temp. floats }
  272. s32fixeddef : pfloatdef; { pointer to type of temp. fixed }
  273. cshortstringdef : pstringdef; { pointer to type of short string const }
  274. clongstringdef : pstringdef; { pointer to type of long string const }
  275. cansistringdef : pstringdef; { pointer to type of ansi string const }
  276. cwidestringdef : pstringdef; { pointer to type of wide string const }
  277. openshortstringdef : pstringdef; { pointer to type of an open shortstring,
  278. needed for readln() }
  279. openchararraydef : parraydef; { pointer to type of an open array of char,
  280. needed for readln() }
  281. cfiledef : pfiledef; { get the same definition for all file }
  282. { uses for stabs }
  283. firstglobaldef, { linked list of all globals defs }
  284. lastglobaldef : pdef; { used to reset stabs/ranges }
  285. class_tobject : pobjectdef; { pointer to the anchestor of all }
  286. { clases }
  287. aktprocsym : pprocsym; { pointer to the symbol for the
  288. currently be parsed procedure }
  289. aktcallprocsym : pprocsym; { pointer to the symbol for the
  290. currently be called procedure,
  291. only set/unset in firstcall }
  292. aktvarsym : pvarsym; { pointer to the symbol for the
  293. currently read var, only used
  294. for variable directives }
  295. procprefix : string; { eindeutige Namen bei geschachtel- }
  296. { ten Unterprogrammen erzeugen }
  297. lexlevel : longint; { level of code }
  298. { 1 for main procedure }
  299. { 2 for normal function or proc }
  300. { higher for locals }
  301. const
  302. main_program_level = 1;
  303. unit_init_level = 1;
  304. normal_function_level = 2;
  305. in_loading : boolean = false;
  306. {$ifdef i386}
  307. bestrealdef : ^pfloatdef = @s80floatdef;
  308. {$endif}
  309. {$ifdef m68k}
  310. bestrealdef : ^pfloatdef = @s64floatdef;
  311. {$endif}
  312. var
  313. macros : psymtable; { pointer for die Symboltabelle mit }
  314. { Makros }
  315. read_member : boolean; { true, wenn Members aus einer PPU- }
  316. { Datei gelesen werden, d.h. ein }
  317. { varsym seine Adresse einlesen soll }
  318. generrorsym : psym; { Jokersymbol, wenn das richtige }
  319. { Symbol nicht gefunden wird }
  320. generrordef : pdef; { Jokersymbol for eine fehlerhafte }
  321. { Typdefinition }
  322. aktobjectdef : pobjectdef; { used for private functions check !! }
  323. const
  324. { last operator which can be overloaded }
  325. first_overloaded = PLUS;
  326. last_overloaded = ASSIGNMENT;
  327. var
  328. overloaded_operators : array[first_overloaded..last_overloaded] of pprocsym;
  329. { unequal is not equal}
  330. const
  331. overloaded_names : array [first_overloaded..last_overloaded] of string[16] =
  332. ('plus','minus','star','slash','equal',
  333. 'greater','lower','greater_or_equal',
  334. 'lower_or_equal','as','is','in','sym_diff',
  335. 'starstar','assign');
  336. {****************************************************************************
  337. Functions
  338. ****************************************************************************}
  339. {*** Misc ***}
  340. function globaldef(const s : string) : pdef;
  341. procedure duplicatesym(sym:psym);
  342. {*** Search ***}
  343. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  344. procedure getsym(const s : stringid;notfounderror : boolean);
  345. procedure getsymonlyin(p : psymtable;const s : stringid);
  346. {*** Forwards ***}
  347. procedure save_forward(ppd : ppointerdef;typesym : ptypesym);
  348. procedure resolve_forwards;
  349. {*** PPU Write/Loading ***}
  350. procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
  351. procedure closecurrentppu;
  352. procedure numberunits;
  353. procedure load_interface;
  354. {*** GDB ***}
  355. {$ifdef GDB}
  356. function typeglobalnumber(const s : string) : string;
  357. {$endif}
  358. {*** Definition ***}
  359. procedure reset_global_defs;
  360. {*** Object Helpers ***}
  361. function search_class_member(pd : pobjectdef;const n : string) : psym;
  362. function search_default_property(pd : pobjectdef) : ppropertysym;
  363. {*** Macro ***}
  364. procedure def_macro(const s : string);
  365. procedure set_macro(const s : string;value : string);
  366. {*** symtable stack ***}
  367. procedure dellexlevel;
  368. {$ifdef DEBUG}
  369. procedure test_symtablestack;
  370. procedure list_symtablestack;
  371. {$endif DEBUG}
  372. {*** dispose of a pdefcoll (args of a function) ***}
  373. procedure disposepdefcoll(var para1 : pdefcoll);
  374. {*** Init / Done ***}
  375. procedure InitSymtable;
  376. procedure DoneSymtable;
  377. implementation
  378. uses
  379. version,
  380. types,ppu,
  381. gendef,files
  382. ,tree
  383. {$ifdef newcg}
  384. ,cgbase
  385. {$else}
  386. ,hcodegen
  387. {$endif}
  388. {$ifdef BrowserLog}
  389. ,browlog
  390. {$endif BrowserLog}
  391. ;
  392. var
  393. aktrecordsymtable : psymtable; { current record read from ppu symtable }
  394. aktstaticsymtable : psymtable; { current static for local ppu symtable }
  395. {$ifdef GDB}
  396. asmoutput : paasmoutput;
  397. {$endif GDB}
  398. {$ifdef TP}
  399. {$ifndef dpmi}
  400. symbolstream : temsstream; { stream which is used to store some info }
  401. {$else}
  402. symbolstream : tmemorystream;
  403. {$endif}
  404. {$endif}
  405. {to dispose the global symtable of a unit }
  406. const
  407. dispose_global : boolean = false;
  408. memsizeinc = 2048; { for long stabstrings }
  409. tagtypes : Set of tdeftype =
  410. [recorddef,enumdef,
  411. {$IfNDef GDBKnowsStrings}
  412. stringdef,
  413. {$EndIf not GDBKnowsStrings}
  414. {$IfNDef GDBKnowsFiles}
  415. filedef,
  416. {$EndIf not GDBKnowsFiles}
  417. objectdef];
  418. {*****************************************************************************
  419. Helper Routines
  420. *****************************************************************************}
  421. function demangledparas(s : string) : string;
  422. var
  423. r : string;
  424. l : longint;
  425. begin
  426. demangledparas:='';
  427. r:=',';
  428. { delete leading $$'s }
  429. l:=pos('$$',s);
  430. while l<>0 do
  431. begin
  432. delete(s,1,l+1);
  433. l:=pos('$$',s);
  434. end;
  435. l:=pos('$',s);
  436. if l=0 then
  437. exit;
  438. delete(s,1,l);
  439. l:=pos('$',s);
  440. if l=0 then
  441. l:=length(s)+1;
  442. while s<>'' do
  443. begin
  444. r:=r+copy(s,1,l-1)+',';
  445. delete(s,1,l);
  446. end;
  447. delete(r,1,1);
  448. delete(r,length(r),1);
  449. demangledparas:=r;
  450. end;
  451. procedure numberunits;
  452. var
  453. counter : longint;
  454. hp : pused_unit;
  455. begin
  456. counter:=1;
  457. psymtable(current_module^.globalsymtable)^.unitid:=0;
  458. hp:=pused_unit(current_module^.used_units.first);
  459. while assigned(hp) do
  460. begin
  461. psymtable(hp^.u^.globalsymtable)^.unitid:=counter;
  462. inc(counter);
  463. hp:=pused_unit(hp^.next);
  464. end;
  465. end;
  466. procedure setstring(var p : pchar;const s : string);
  467. begin
  468. {$ifdef TP}
  469. if use_big then
  470. begin
  471. p:=pchar(symbolstream.getsize);
  472. symbolstream.seek(longint(p));
  473. symbolstream.writestr(@s);
  474. end
  475. else
  476. {$endif TP}
  477. p:=strpnew(s);
  478. end;
  479. procedure duplicatesym(sym:psym);
  480. begin
  481. Message1(sym_e_duplicate_id,sym^.name);
  482. with sym^.fileinfo do
  483. Message2(sym_h_duplicate_id_where,current_module^.sourcefiles^.get_file_name(fileindex),tostr(line));
  484. end;
  485. {****************************************************************************
  486. TRef
  487. ****************************************************************************}
  488. constructor tref.init(ref :pref;pos : pfileposinfo);
  489. begin
  490. nextref:=nil;
  491. if pos<>nil then
  492. posinfo:=pos^;
  493. if assigned(current_module) then
  494. moduleindex:=current_module^.unit_index;
  495. if assigned(ref) then
  496. ref^.nextref:=@self;
  497. is_written:=false;
  498. end;
  499. destructor tref.done;
  500. var
  501. inputfile : pinputfile;
  502. begin
  503. inputfile:=get_source_file(moduleindex,posinfo.fileindex);
  504. if inputfile<>nil then
  505. dec(inputfile^.ref_count);
  506. if assigned(nextref) then
  507. dispose(nextref,done);
  508. nextref:=nil;
  509. end;
  510. {*****************************************************************************
  511. PPU Reading Writing
  512. *****************************************************************************}
  513. {$I symppu.inc}
  514. {*****************************************************************************
  515. Definition Helpers
  516. *****************************************************************************}
  517. function globaldef(const s : string) : pdef;
  518. var st : string;
  519. symt : psymtable;
  520. begin
  521. srsym := nil;
  522. if pos('.',s) > 0 then
  523. begin
  524. st := copy(s,1,pos('.',s)-1);
  525. getsym(st,false);
  526. st := copy(s,pos('.',s)+1,255);
  527. if assigned(srsym) then
  528. begin
  529. if srsym^.typ = unitsym then
  530. begin
  531. symt := punitsym(srsym)^.unitsymtable;
  532. srsym := symt^.search(st);
  533. end else srsym := nil;
  534. end;
  535. end else st := s;
  536. if srsym = nil then getsym(st,false);
  537. if srsym = nil then
  538. getsymonlyin(systemunit,st);
  539. if srsym^.typ<>typesym then
  540. begin
  541. Message(type_e_type_id_expected);
  542. exit;
  543. end;
  544. globaldef := ptypesym(srsym)^.definition;
  545. end;
  546. {*****************************************************************************
  547. Symbol / Definition Resolving
  548. *****************************************************************************}
  549. const localsymtablestack : psymtable = nil;
  550. function find_local_symtable(index : word) : psymtable;
  551. var
  552. p : psymtable;
  553. begin
  554. p:=localsymtablestack;
  555. while assigned(p) do
  556. begin
  557. if p^.unitid=index then break
  558. else
  559. p:=p^.next;
  560. end;
  561. if (p=nil) then
  562. comment(v_fatal,'Error in local browser');
  563. find_local_symtable:=p;
  564. end;
  565. procedure resolvesym(var d : psym);
  566. begin
  567. if longint(d)=-1 then
  568. d:=nil
  569. else
  570. begin
  571. if (longint(d) and $ffff)=$ffff then
  572. d:=aktrecordsymtable^.getsymnr(longint(d) shr 16)
  573. else
  574. if (longint(d) and $ffff)=$fffe then
  575. d:=aktstaticsymtable^.getsymnr(longint(d) shr 16)
  576. else if (longint(d) and $ffff)>$8000 then
  577. d:=find_local_symtable(longint(d) and $ffff)^.getsymnr(longint(d) shr 16)
  578. else
  579. {$ifdef NEWMAP}
  580. d:=psymtable(current_module^.map^[longint(d) and $ffff]^.globalsymtable)^.getsymnr(longint(d) shr 16);
  581. {$else NEWMAP}
  582. d:=psymtable(current_module^.map^[longint(d) and $ffff])^.getsymnr(longint(d) shr 16);
  583. {$endif NEWMAP}
  584. end;
  585. end;
  586. procedure resolvedef(var d : pdef);
  587. begin
  588. if longint(d)=-1 then
  589. d:=nil
  590. else
  591. begin
  592. if (longint(d) and $ffff)=$ffff then
  593. d:=aktrecordsymtable^.getdefnr(longint(d) shr 16)
  594. else
  595. if (longint(d) and $ffff)=$fffe then
  596. d:=aktstaticsymtable^.getdefnr(longint(d) shr 16)
  597. else if (longint(d) and $ffff)>$8000 then
  598. d:=find_local_symtable(longint(d) and $ffff)^.getdefnr(longint(d) shr 16)
  599. else
  600. {$ifdef NEWMAP}
  601. d:=psymtable(current_module^.map^[longint(d) and $ffff]^.globalsymtable)^.getdefnr(longint(d) shr 16);
  602. {$else NEWMAP}
  603. d:=psymtable(current_module^.map^[longint(d) and $ffff])^.getdefnr(longint(d) shr 16);
  604. {$endif NEWMAP}
  605. end;
  606. end;
  607. {*****************************************************************************
  608. Symbol Call Back Functions
  609. *****************************************************************************}
  610. {$ifdef OLDPPU}
  611. procedure writesym(p : psym);
  612. begin
  613. p^.write;
  614. end;
  615. {$endif}
  616. procedure derefsym(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  617. begin
  618. psym(p)^.deref;
  619. end;
  620. procedure derefsymsdelayed(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  621. begin
  622. if psym(p)^.typ in [absolutesym,propertysym] then
  623. psym(p)^.deref;
  624. end;
  625. procedure check_procsym_forward(sym : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  626. begin
  627. if psym(sym)^.typ=procsym then
  628. pprocsym(sym)^.check_forward
  629. { check also object method table }
  630. { we needn't to test the def list }
  631. { because each object has to have a type sym }
  632. else
  633. if (psym(sym)^.typ=typesym) and
  634. assigned(ptypesym(sym)^.definition) and
  635. (ptypesym(sym)^.definition^.deftype=objectdef) then
  636. pobjectdef(ptypesym(sym)^.definition)^.check_forwards;
  637. end;
  638. procedure labeldefined(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  639. begin
  640. if (psym(p)^.typ=labelsym) and
  641. not(plabelsym(p)^.defined) then
  642. Message1(sym_w_label_not_defined,p^.name);
  643. end;
  644. procedure unitsymbolused(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  645. begin
  646. if (psym(p)^.typ=unitsym) and
  647. (punitsym(p)^.refs=0) then
  648. comment(V_info,'Unit '+p^.name+' is not used');
  649. end;
  650. procedure varsymbolused(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  651. begin
  652. if (psym(p)^.typ=varsym) and
  653. ((psym(p)^.owner^.symtabletype in [parasymtable,localsymtable,staticsymtable])) then
  654. { unused symbol should be reported only if no }
  655. { error is reported }
  656. { if the symbol is in a register it is used }
  657. { also don't count the value parameters which have local copies }
  658. { also don't claim for high param of open parameters (PM) }
  659. if (pvarsym(p)^.refs=0) and
  660. (Errorcount=0) and
  661. (copy(p^.name,1,3)<>'val') and
  662. (copy(p^.name,1,4)<>'high') then
  663. begin
  664. if (psym(p)^.owner^.symtabletype=parasymtable) or pvarsym(p)^.islocalcopy then
  665. MessagePos1(psym(p)^.fileinfo,sym_h_para_identifier_not_used,p^.name)
  666. else
  667. MessagePos1(psym(p)^.fileinfo,sym_n_local_identifier_not_used,p^.name);
  668. end;
  669. end;
  670. {$ifdef GDB}
  671. procedure concatstab(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  672. begin
  673. if psym(p)^.typ <> procsym then
  674. psym(p)^.concatstabto(asmoutput);
  675. end;
  676. procedure concattypestab(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  677. begin
  678. if psym(p)^.typ = typesym then
  679. begin
  680. psym(p)^.isstabwritten:=false;
  681. psym(p)^.concatstabto(asmoutput);
  682. end;
  683. end;
  684. procedure forcestabto(asmlist : paasmoutput; pd : pdef);
  685. begin
  686. if not pd^.is_def_stab_written then
  687. begin
  688. if assigned(pd^.sym) then
  689. pd^.sym^.isusedinstab := true;
  690. pd^.concatstabto(asmlist);
  691. end;
  692. end;
  693. {$endif}
  694. {$ifdef CHAINPROCSYMS}
  695. procedure chainprocsym(p : psym);
  696. var
  697. storesymtablestack : psymtable;
  698. begin
  699. if p^.typ=procsym then
  700. begin
  701. storesymtablestack:=symtablestack;
  702. symtablestack:=p^.owner^.next;
  703. while assigned(symtablestack) do
  704. begin
  705. { search for same procsym in other units }
  706. getsym(p^.name,false);
  707. if assigned(srsym) and (srsym^.typ=procsym) then
  708. begin
  709. pprocsym(p)^.nextprocsym:=pprocsym(srsym);
  710. symtablestack:=storesymtablestack;
  711. exit;
  712. end
  713. else if srsym=nil then
  714. symtablestack:=nil
  715. else
  716. symtablestack:=srsymtable^.next;
  717. end;
  718. symtablestack:=storesymtablestack;
  719. end;
  720. end;
  721. {$endif}
  722. procedure write_refs(sym : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  723. begin
  724. psym(sym)^.write_references;
  725. end;
  726. {$ifdef BrowserLog}
  727. procedure add_to_browserlog(p : psym);
  728. begin
  729. p^.add_to_browserlog;
  730. end;
  731. {$endif UseBrowser}
  732. {****************************************************************************
  733. Forward Resolving
  734. ****************************************************************************}
  735. type
  736. presolvelist = ^tresolvelist;
  737. tresolvelist = record
  738. p : ppointerdef;
  739. typ : ptypesym;
  740. next : presolvelist;
  741. end;
  742. var
  743. sroot : presolvelist;
  744. procedure save_forward(ppd : ppointerdef;typesym : ptypesym);
  745. var
  746. p : presolvelist;
  747. begin
  748. new(p);
  749. p^.next:=sroot;
  750. p^.p:=ppd;
  751. ppd^.defsym := typesym;
  752. p^.typ:=typesym;
  753. sroot:=p;
  754. end;
  755. procedure resolve_forwards;
  756. var
  757. p : presolvelist;
  758. begin
  759. p:=sroot;
  760. while p<>nil do
  761. begin
  762. sroot:=sroot^.next;
  763. p^.p^.definition:=p^.typ^.definition;
  764. dispose(p);
  765. p:=sroot;
  766. end;
  767. end;
  768. {*****************************************************************************
  769. Search Symtables for Syms
  770. *****************************************************************************}
  771. procedure getsym(const s : stringid;notfounderror : boolean);
  772. var
  773. speedvalue : longint;
  774. begin
  775. speedvalue:=getspeedvalue(s);
  776. lastsrsym:=nil;
  777. srsymtable:=symtablestack;
  778. while assigned(srsymtable) do
  779. begin
  780. srsym:=srsymtable^.speedsearch(s,speedvalue);
  781. if assigned(srsym) then
  782. exit
  783. else
  784. srsymtable:=srsymtable^.next;
  785. end;
  786. if forwardsallowed then
  787. begin
  788. srsymtable:=symtablestack;
  789. while (srsymtable^.symtabletype in [objectsymtable,recordsymtable]) do
  790. srsymtable:=srsymtable^.next;
  791. srsym:=new(ptypesym,init(s,nil));
  792. srsym^.properties:=sp_forwarddef;
  793. srsymtable^.insert(srsym);
  794. end
  795. else if notfounderror then
  796. begin
  797. Message1(sym_e_id_not_found,s);
  798. srsym:=generrorsym;
  799. end
  800. else srsym:=nil;
  801. end;
  802. procedure getsymonlyin(p : psymtable;const s : stringid);
  803. begin
  804. { the caller have to take care if srsym=nil (FK) }
  805. srsym:=nil;
  806. if assigned(p) then
  807. begin
  808. srsymtable:=p;
  809. srsym:=srsymtable^.search(s);
  810. if assigned(srsym) then
  811. exit
  812. else
  813. begin
  814. if (punitsymtable(srsymtable)=punitsymtable(current_module^.globalsymtable)) then
  815. begin
  816. getsymonlyin(psymtable(current_module^.localsymtable),s);
  817. if assigned(srsym) then
  818. srsymtable:=psymtable(current_module^.localsymtable)
  819. else
  820. Message1(sym_e_id_not_found,s);
  821. end
  822. else
  823. Message1(sym_e_id_not_found,s);
  824. end;
  825. end;
  826. end;
  827. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  828. {Search for a symbol in a specified symbol table. Returns nil if
  829. the symtable is not found, and also if the symbol cannot be found
  830. in the desired symtable }
  831. var hsymtab:Psymtable;
  832. res:Psym;
  833. begin
  834. res:=nil;
  835. hsymtab:=symtablestack;
  836. while (hsymtab<>nil) and (hsymtab^.symtabletype<>symtabletype) do
  837. hsymtab:=hsymtab^.next;
  838. if hsymtab<>nil then
  839. {We found the desired symtable. Now check if the symbol we
  840. search for is defined in it }
  841. res:=hsymtab^.search(symbol);
  842. search_a_symtable:=res;
  843. end;
  844. {****************************************************************************
  845. TSYMTABLE
  846. ****************************************************************************}
  847. constructor tsymtable.init(t : tsymtabletype);
  848. begin
  849. symtabletype:=t;
  850. symtablelevel:=0;
  851. defowner:=nil;
  852. unitid:=0;
  853. next:=nil;
  854. name:=nil;
  855. address_fixup:=0;
  856. datasize:=0;
  857. {$ifndef OLDPPU}
  858. new(symindex,init(indexgrowsize));
  859. new(defindex,init(indexgrowsize));
  860. new(symsearch,init);
  861. symsearch^.noclear:=true;
  862. {$else}
  863. lastsym:=nil;
  864. rootdef:=nil;
  865. defhasharray:=nil;
  866. defhasharraysize:=0;
  867. searchroot:=nil;
  868. searchhasharray:=nil;
  869. {$endif}
  870. alignment:=def_alignment;
  871. end;
  872. destructor tsymtable.done;
  873. {$ifdef OLDPPU}
  874. var
  875. hp : pdef;
  876. {$ifdef GDB}
  877. last : pdef;
  878. {$endif GDB}
  879. {$endif}
  880. begin
  881. stringdispose(name);
  882. {$ifndef OLDPPU}
  883. dispose(symindex,done);
  884. dispose(defindex,done);
  885. { symsearch can already be disposed or set to nil for withsymtable }
  886. if assigned(symsearch) then
  887. begin
  888. dispose(symsearch,done);
  889. symsearch:=nil;
  890. end;
  891. {$else}
  892. if assigned(defhasharray) then
  893. begin
  894. freemem(defhasharray,sizeof(pdef)*defhasharraysize);
  895. defhasharray:=nil;
  896. end;
  897. { clear all entries, pprocsyms have still the definitions left }
  898. clear;
  899. {$ifdef GDB}
  900. last := Nil;
  901. {$endif GDB}
  902. hp:=rootdef;
  903. while assigned(hp) do
  904. begin
  905. {$ifdef GDB}
  906. if hp^.owner=@self then
  907. begin
  908. if assigned(last) then
  909. last^.next := hp^.next;
  910. {$endif GDB}
  911. rootdef:=hp^.next;
  912. dispose(hp,done);
  913. {$ifdef GDB}
  914. end
  915. else
  916. begin
  917. last := hp;
  918. rootdef:=hp^.next;
  919. end;
  920. {$endif GDB}
  921. hp:=rootdef;
  922. end;
  923. {$endif}
  924. end;
  925. constructor twithsymtable.init;
  926. begin
  927. inherited init(withsymtable);
  928. {$ifndef NODIRECTWITH}
  929. direct_with:=false;
  930. withnode:=nil;
  931. withrefnode:=nil;
  932. {$endif def NODIRECTWITH}
  933. end;
  934. destructor twithsymtable.done;
  935. begin
  936. {$ifndef OLDPPU}
  937. symsearch:=nil;
  938. {$endif}
  939. inherited done;
  940. end;
  941. {***********************************************
  942. Helpers
  943. ***********************************************}
  944. function tsymtable.getnewtypecount : word;
  945. begin
  946. getnewtypecount:=pglobaltypecount^;
  947. inc(pglobaltypecount^);
  948. end;
  949. procedure tsymtable.registerdef(p : pdef);
  950. begin
  951. {$ifndef OLDPPU}
  952. defindex^.insert(p);
  953. {$else}
  954. p^.next:=rootdef;
  955. rootdef:=p;
  956. {$endif}
  957. { set def owner and indexnb }
  958. p^.owner:=@self;
  959. end;
  960. {$ifndef OLDPPU}
  961. procedure tsymtable.foreach(proc2call : tnamedindexcallback);
  962. begin
  963. symindex^.foreach(proc2call);
  964. end;
  965. {$else}
  966. procedure tsymtable.foreach(proc2call : tnamedindexcallback);
  967. procedure a(p : psym);
  968. { must be preorder, because it's used by reading in }
  969. { a PPU file }
  970. { what does this mean ? I need to index
  971. so proc2call must be after left and before right !! PM }
  972. begin
  973. proc2call(p);
  974. if assigned(p^.left) then
  975. a(p^.left);
  976. if assigned(p^.right) then
  977. a(p^.right);
  978. end;
  979. var
  980. i : longint;
  981. begin
  982. if assigned(searchhasharray) then
  983. begin
  984. for i:=0 to hasharraysize-1 do
  985. if assigned(searchhasharray^[i]) then
  986. a(searchhasharray^[i]);
  987. end
  988. else
  989. if assigned(searchroot) then
  990. a(searchroot);
  991. end;
  992. {$endif}
  993. {$ifdef OLDPPU}
  994. function tsymtable.number_defs:longint;
  995. var
  996. pd : pdef;
  997. counter : longint;
  998. begin
  999. counter:=0;
  1000. pd:=rootdef;
  1001. while assigned(pd) do
  1002. begin
  1003. pd^.indexnb:=counter;
  1004. inc(counter);
  1005. pd:=pd^.next;
  1006. end;
  1007. number_defs:=counter;
  1008. end;
  1009. var symtable_index : longint;
  1010. procedure numbersym(p : psym);
  1011. begin
  1012. p^.indexnb:=symtable_index;
  1013. inc(symtable_index);
  1014. end;
  1015. function tsymtable.number_symbols:longint;
  1016. var old_nr : longint;
  1017. begin
  1018. old_nr:=symtable_index;
  1019. symtable_index:=1;
  1020. {$ifdef tp}
  1021. foreach(numbersym);
  1022. {$else}
  1023. foreach(@numbersym);
  1024. {$endif}
  1025. number_symbols:=symtable_index-1;
  1026. symtable_index:=old_nr;
  1027. end;
  1028. {$endif}
  1029. {***********************************************
  1030. LOAD / WRITE SYMTABLE FROM PPU
  1031. ***********************************************}
  1032. procedure tsymtable.loaddefs;
  1033. var
  1034. {$ifdef OLDPPU}
  1035. counter : longint;
  1036. last : pdef;
  1037. {$endif}
  1038. hp : pdef;
  1039. b : byte;
  1040. begin
  1041. { load start of definition section, which holds the amount of defs }
  1042. if current_ppu^.readentry<>ibstartdefs then
  1043. Message(unit_f_ppu_read_error);
  1044. {$ifdef OLDPPU}
  1045. if symtabletype=unitsymtable then
  1046. begin
  1047. defhasharraysize:=current_ppu^.getlongint;
  1048. getmem(defhasharray,sizeof(pdef)*defhasharraysize);
  1049. fillchar(defhasharray^,sizeof(pdef)*defhasharraysize,0);
  1050. end
  1051. else
  1052. {$endif}
  1053. current_ppu^.getlongint;
  1054. { read definitions }
  1055. {$ifdef OLDPPU}
  1056. counter:=0;
  1057. rootdef:=nil;
  1058. {$endif}
  1059. repeat
  1060. b:=current_ppu^.readentry;
  1061. case b of
  1062. ibpointerdef : hp:=new(ppointerdef,load);
  1063. ibarraydef : hp:=new(parraydef,load);
  1064. iborddef : hp:=new(porddef,load);
  1065. ibfloatdef : hp:=new(pfloatdef,load);
  1066. ibprocdef : hp:=new(pprocdef,load);
  1067. ibshortstringdef : hp:=new(pstringdef,shortload);
  1068. iblongstringdef : hp:=new(pstringdef,longload);
  1069. ibansistringdef : hp:=new(pstringdef,ansiload);
  1070. ibwidestringdef : hp:=new(pstringdef,wideload);
  1071. ibrecorddef : hp:=new(precdef,load);
  1072. ibobjectdef : hp:=new(pobjectdef,load);
  1073. ibenumdef : hp:=new(penumdef,load);
  1074. ibsetdef : hp:=new(psetdef,load);
  1075. ibprocvardef : hp:=new(pprocvardef,load);
  1076. ibfiledef : hp:=new(pfiledef,load);
  1077. ibclassrefdef : hp:=new(pclassrefdef,load);
  1078. ibformaldef : hp:=new(pformaldef,load);
  1079. ibenddefs : break;
  1080. ibend : Message(unit_f_ppu_read_error);
  1081. else
  1082. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1083. end;
  1084. {$ifndef OLDPPU}
  1085. hp^.owner:=@self;
  1086. defindex^.insert(hp);
  1087. {$else}
  1088. { each def gets a number }
  1089. hp^.indexnb:=counter;
  1090. if counter=0 then
  1091. begin
  1092. rootdef:=hp;
  1093. last:=hp;
  1094. end
  1095. else
  1096. begin
  1097. last^.next:=hp;
  1098. last:=hp;
  1099. end;
  1100. if assigned(defhasharray) then
  1101. begin
  1102. if counter<defhasharraysize then
  1103. defhasharray^[counter]:=hp
  1104. else
  1105. internalerror(10997);
  1106. end;
  1107. inc(counter);
  1108. {$endif}
  1109. until false;
  1110. {$ifdef OLDPPU}
  1111. number_defs;
  1112. {$endif}
  1113. end;
  1114. procedure tsymtable.loadsyms;
  1115. var
  1116. b : byte;
  1117. sym : psym;
  1118. begin
  1119. { load start of definition section, which holds the amount of defs }
  1120. if current_ppu^.readentry<>ibstartsyms then
  1121. Message(unit_f_ppu_read_error);
  1122. { skip amount of symbols, not used currently }
  1123. current_ppu^.getlongint;
  1124. { load datasize of this symboltable }
  1125. datasize:=current_ppu^.getlongint;
  1126. { now read the symbols }
  1127. repeat
  1128. b:=current_ppu^.readentry;
  1129. case b of
  1130. ibtypesym : sym:=new(ptypesym,load);
  1131. ibprocsym : sym:=new(pprocsym,load);
  1132. ibconstsym : sym:=new(pconstsym,load);
  1133. ibvarsym : sym:=new(pvarsym,load);
  1134. ibfuncretsym : sym:=new(pfuncretsym,load);
  1135. ibabsolutesym : sym:=new(pabsolutesym,load);
  1136. ibenumsym : sym:=new(penumsym,load);
  1137. ibtypedconstsym : sym:=new(ptypedconstsym,load);
  1138. ibpropertysym : sym:=new(ppropertysym,load);
  1139. ibunitsym : sym:=new(punitsym,load);
  1140. iblabelsym : sym:=new(plabelsym,load);
  1141. {$ifndef OLDPPU}
  1142. ibsyssym : sym:=new(psyssym,load);
  1143. {$endif}
  1144. ibendsyms : break;
  1145. ibend : Message(unit_f_ppu_read_error);
  1146. else
  1147. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1148. end;
  1149. {$ifndef OLDPPU}
  1150. sym^.owner:=@self;
  1151. symindex^.insert(sym);
  1152. symsearch^.insert(sym);
  1153. {$else}
  1154. if not (symtabletype in [recordsymtable,objectsymtable]) then
  1155. begin
  1156. { don't deref absolute symbols there, because it's possible }
  1157. { that the var sym which the absolute sym refers, isn't }
  1158. { loaded }
  1159. { but syms must be derefered to determine the definition }
  1160. { because must know the varsym size when inserting the symbol }
  1161. if not(b in [ibabsolutesym,ibpropertysym]) then
  1162. sym^.deref;
  1163. end;
  1164. insert(sym);
  1165. {$endif}
  1166. until false;
  1167. {$ifdef OLDPPU}
  1168. { symbol numbering for references }
  1169. number_symbols;
  1170. if not (symtabletype in [recordsymtable,objectsymtable]) then
  1171. begin
  1172. {$ifdef tp}
  1173. foreach(derefsymsdelayed);
  1174. {$else}
  1175. foreach(@derefsymsdelayed);
  1176. {$endif}
  1177. end;
  1178. {$endif}
  1179. end;
  1180. procedure tsymtable.writedefs;
  1181. var
  1182. pd : pdef;
  1183. begin
  1184. { each definition get a number, write then the amount of defs to the
  1185. ibstartdef entry }
  1186. {$ifndef OLDPPU}
  1187. current_ppu^.putlongint(defindex^.count);
  1188. {$else}
  1189. current_ppu^.putlongint(number_defs);
  1190. {$endif}
  1191. current_ppu^.writeentry(ibstartdefs);
  1192. { now write the definition }
  1193. {$ifndef OLDPPU}
  1194. pd:=pdef(defindex^.first);
  1195. {$else}
  1196. pd:=rootdef;
  1197. {$endif}
  1198. while assigned(pd) do
  1199. begin
  1200. pd^.write;
  1201. pd:=pdef(pd^.next);
  1202. end;
  1203. { write end of definitions }
  1204. current_ppu^.writeentry(ibenddefs);
  1205. end;
  1206. procedure tsymtable.writesyms;
  1207. {$ifndef OLDPPU}
  1208. var
  1209. pd : psym;
  1210. {$endif}
  1211. begin
  1212. { each definition get a number, write then the amount of syms and the
  1213. datasize to the ibsymdef entry }
  1214. {$ifndef OLDPPU}
  1215. current_ppu^.putlongint(symindex^.count);
  1216. {$else}
  1217. current_ppu^.putlongint(number_symbols);
  1218. {$endif}
  1219. current_ppu^.putlongint(datasize);
  1220. current_ppu^.writeentry(ibstartsyms);
  1221. { foreach is used to write all symbols }
  1222. {$ifndef OLDPPU}
  1223. pd:=psym(symindex^.first);
  1224. while assigned(pd) do
  1225. begin
  1226. pd^.write;
  1227. pd:=psym(pd^.next);
  1228. end;
  1229. {$else}
  1230. {$ifdef tp}
  1231. foreach(writesym);
  1232. {$else}
  1233. foreach(@writesym);
  1234. {$endif}
  1235. {$endif}
  1236. { end of symbols }
  1237. current_ppu^.writeentry(ibendsyms);
  1238. end;
  1239. {$ifndef OLDPPU}
  1240. procedure tsymtable.deref;
  1241. var
  1242. hp : pdef;
  1243. hs : psym;
  1244. begin
  1245. hp:=pdef(defindex^.first);
  1246. while assigned(hp) do
  1247. begin
  1248. hp^.deref;
  1249. hp^.symderef;
  1250. hp:=pdef(hp^.next);
  1251. end;
  1252. hs:=psym(symindex^.first);
  1253. while assigned(hs) do
  1254. begin
  1255. hs^.deref;
  1256. hs:=psym(hs^.next);
  1257. end;
  1258. end;
  1259. {$endif}
  1260. constructor tsymtable.load;
  1261. var
  1262. {$ifdef OLDPPU}
  1263. hp : pdef;
  1264. {$endif}
  1265. st_loading : boolean;
  1266. begin
  1267. st_loading:=in_loading;
  1268. in_loading:=true;
  1269. {$ifndef NEWMAP}
  1270. current_module^.map^[0]:=@self;
  1271. {$else NEWMAP}
  1272. current_module^.globalsymtable:=@self;
  1273. {$endif NEWMAP}
  1274. symtabletype:=unitsymtable;
  1275. symtablelevel:=0;
  1276. { unused for units }
  1277. address_fixup:=0;
  1278. datasize:=0;
  1279. defowner:=nil;
  1280. name:=nil;
  1281. unitid:=0;
  1282. defowner:=nil;
  1283. {$ifndef OLDPPU}
  1284. new(symindex,init(indexgrowsize));
  1285. new(defindex,init(indexgrowsize));
  1286. new(symsearch,init);
  1287. symsearch^.usehash;
  1288. symsearch^.noclear:=true;
  1289. {$else}
  1290. lastsym:=nil;
  1291. next:=nil;
  1292. rootdef:=nil;
  1293. defhasharray:=nil;
  1294. defhasharraysize:=0;
  1295. { reset search arrays }
  1296. searchroot:=nil;
  1297. new(searchhasharray);
  1298. fillchar(searchhasharray^,sizeof(searchhasharray^),0);
  1299. {$endif}
  1300. alignment:=def_alignment;
  1301. { load definitions }
  1302. loaddefs;
  1303. {$ifdef OLDPPU}
  1304. { solve the references to other definitions for each definition }
  1305. hp:=rootdef;
  1306. while assigned(hp) do
  1307. begin
  1308. hp^.deref;
  1309. { insert also the owner }
  1310. hp^.owner:=@self;
  1311. hp:=pdef(hp^.next);
  1312. end;
  1313. {$endif}
  1314. { load symbols }
  1315. loadsyms;
  1316. {$ifndef OLDPPU}
  1317. if not(symtabletype in [objectsymtable,recordsymtable]) then
  1318. deref;
  1319. {$endif}
  1320. {$ifdef NEWMAP}
  1321. { necessary for dependencies }
  1322. current_module^.globalsymtable:=nil;
  1323. {$endif NEWMAP}
  1324. in_loading:=st_loading;
  1325. end;
  1326. procedure tsymtable.write;
  1327. begin
  1328. { write definitions }
  1329. writedefs;
  1330. { write symbols }
  1331. writesyms;
  1332. end;
  1333. constructor tsymtable.loadas(typ : tsymtabletype);
  1334. var
  1335. storesymtable : psymtable;
  1336. {$ifdef OLDPPU}
  1337. hp : pdef;
  1338. {$endif}
  1339. st_loading : boolean;
  1340. begin
  1341. st_loading:=in_loading;
  1342. in_loading:=true;
  1343. symtabletype:=typ;
  1344. {$ifndef OLDPPU}
  1345. new(symindex,init(indexgrowsize));
  1346. new(defindex,init(indexgrowsize));
  1347. new(symsearch,init);
  1348. symsearch^.noclear:=true;
  1349. {$else}
  1350. lastsym:=nil;
  1351. next:=nil;
  1352. rootdef:=nil;
  1353. defhasharray:=nil;
  1354. defhasharraysize:=0;
  1355. searchroot:=nil;
  1356. searchhasharray:=nil;
  1357. {$endif}
  1358. defowner:=nil;
  1359. storesymtable:=aktrecordsymtable;
  1360. if typ in [recordsymtable,objectsymtable,
  1361. parasymtable,localsymtable] then
  1362. aktrecordsymtable:=@self;
  1363. { used for local browser }
  1364. if typ=staticppusymtable then
  1365. begin
  1366. aktstaticsymtable:=@self;
  1367. {$ifndef OLDPPU}
  1368. symsearch^.usehash;
  1369. {$else}
  1370. new(searchhasharray);
  1371. fillchar(searchhasharray^,sizeof(searchhasharray^),0);
  1372. {$endif}
  1373. end;
  1374. name:=nil;
  1375. alignment:=def_alignment;
  1376. { isn't used there }
  1377. datasize:=0;
  1378. address_fixup:= 0;
  1379. { also unused }
  1380. unitid:=0;
  1381. { load definitions }
  1382. { we need the correct symtable for registering }
  1383. if not (typ in [recordsymtable,objectsymtable]) then
  1384. begin
  1385. next:=symtablestack;
  1386. symtablestack:=@self;
  1387. end;
  1388. loaddefs;
  1389. {$ifdef OLDPPU}
  1390. { solve the references of the symbols for each definition }
  1391. hp:=rootdef;
  1392. if not (typ in [recordsymtable,objectsymtable]) then
  1393. while assigned(hp) do
  1394. begin
  1395. hp^.deref;
  1396. { insert also the owner }
  1397. hp^.owner:=@self;
  1398. hp:=pdef(hp^.next);
  1399. end;
  1400. {$endif}
  1401. { load symbols }
  1402. loadsyms;
  1403. {$ifndef OLDPPU}
  1404. if not (typ in [recordsymtable,objectsymtable]) then
  1405. deref;
  1406. {$endif}
  1407. aktrecordsymtable:=storesymtable;
  1408. if not (typ in [recordsymtable,objectsymtable]) then
  1409. begin
  1410. symtablestack:=next;
  1411. end;
  1412. in_loading:=st_loading;
  1413. end;
  1414. procedure tsymtable.writeas;
  1415. var
  1416. oldtyp : byte;
  1417. storesymtable : psymtable;
  1418. begin
  1419. oldtyp:=current_ppu^.entrytyp;
  1420. storesymtable:=aktrecordsymtable;
  1421. if symtabletype in [recordsymtable,objectsymtable,
  1422. parasymtable,localsymtable] then
  1423. aktrecordsymtable:=@self;
  1424. if (symtabletype in [recordsymtable,objectsymtable]) then
  1425. current_ppu^.entrytyp:=subentryid;
  1426. { write definitions }
  1427. writedefs;
  1428. { write symbols }
  1429. writesyms;
  1430. current_ppu^.entrytyp:=oldtyp;
  1431. aktrecordsymtable:=storesymtable;
  1432. end;
  1433. {***********************************************
  1434. Get Symbol / Def by Number
  1435. ***********************************************}
  1436. {$ifndef OLDPPU}
  1437. function tsymtable.getsymnr(l : longint) : psym;
  1438. var
  1439. hp : psym;
  1440. begin
  1441. hp:=psym(symindex^.search(l));
  1442. if hp=nil then
  1443. internalerror(10999);
  1444. getsymnr:=hp;
  1445. end;
  1446. function tsymtable.getdefnr(l : longint) : pdef;
  1447. var
  1448. hp : pdef;
  1449. begin
  1450. hp:=pdef(defindex^.search(l));
  1451. if hp=nil then
  1452. internalerror(10998);
  1453. getdefnr:=hp;
  1454. end;
  1455. {$else}
  1456. function tsymtable.getsymnr(l : longint) : psym;
  1457. var
  1458. hp : psym;
  1459. i : longint;
  1460. begin
  1461. getsymnr:=nil;
  1462. if assigned(searchhasharray) then
  1463. begin
  1464. hp:=nil;
  1465. for i:=0 to hasharraysize-1 do
  1466. if assigned(searchhasharray^[i]) then
  1467. if (searchhasharray^[i]^.indexnb>l) then
  1468. break
  1469. else
  1470. hp:=searchhasharray^[i];
  1471. end
  1472. else
  1473. hp:=searchroot;
  1474. { hp has an index that is <= l }
  1475. { if hp's index = l we found }
  1476. { if hp^.right exists and is also <= l }
  1477. { the sym is in the right branch }
  1478. { else in the left }
  1479. while assigned(hp) do
  1480. begin
  1481. if hp^.indexnb=l then
  1482. begin
  1483. getsymnr:=hp;
  1484. exit;
  1485. end
  1486. else if assigned(hp^.right) and (hp^.right^.indexnb<=l) then
  1487. hp:=hp^.right
  1488. else
  1489. hp:=hp^.left;
  1490. end;
  1491. InternalError(10999);
  1492. end;
  1493. function tsymtable.getdefnr(l : longint) : pdef;
  1494. var
  1495. hp : pdef;
  1496. begin
  1497. if assigned(defhasharray) and
  1498. (l<defhasharraysize) and
  1499. assigned(defhasharray^[l]) and
  1500. (defhasharray^[l]^.indexnb=l) then
  1501. begin
  1502. getdefnr:=defhasharray^[l];
  1503. exit;
  1504. end;
  1505. hp:=rootdef;
  1506. while (assigned(hp)) and (hp^.indexnb<>l) do
  1507. hp:=hp^.next;
  1508. if assigned(defhasharray) and
  1509. (l<defhasharraysize) then
  1510. if not assigned(defhasharray^[l]) then
  1511. defhasharray^[l]:=hp
  1512. else
  1513. begin
  1514. {$ifdef debug}
  1515. if (l<defhasharraysize) and
  1516. (hp<>defhasharray^[l]) then
  1517. InternalError(10998);
  1518. {$endif debug}
  1519. end;
  1520. if assigned(hp) then
  1521. getdefnr:=hp
  1522. else
  1523. InternalError(10998);
  1524. end;
  1525. {$endif}
  1526. {***********************************************
  1527. Table Access
  1528. ***********************************************}
  1529. {$ifndef OLDPPU}
  1530. procedure tsymtable.clear;
  1531. begin
  1532. { remove no entry from a withsymtable as it is only a pointer to the
  1533. recorddef or objectdef symtable }
  1534. if symtabletype=withsymtable then
  1535. exit;
  1536. symindex^.clear;
  1537. defindex^.clear;
  1538. end;
  1539. function tsymtable.insert(sym:psym):psym;
  1540. var
  1541. hp : psymtable;
  1542. hsym : psym;
  1543. begin
  1544. { set owner and sym indexnb }
  1545. sym^.owner:=@self;
  1546. {$ifdef CHAINPROCSYMS}
  1547. { set the nextprocsym field }
  1548. if sym^.typ=procsym then
  1549. chainprocsym(sym);
  1550. {$endif CHAINPROCSYMS}
  1551. { writes the symbol in data segment if required }
  1552. { also sets the datasize of owner }
  1553. if not in_loading then
  1554. sym^.insert_in_data;
  1555. if (symtabletype in [staticsymtable,globalsymtable]) then
  1556. begin
  1557. hp:=symtablestack;
  1558. while assigned(hp) do
  1559. begin
  1560. if hp^.symtabletype in [staticsymtable,globalsymtable] then
  1561. begin
  1562. hsym:=hp^.search(sym^.name);
  1563. if (assigned(hsym)) and
  1564. (hsym^.properties and sp_forwarddef=0) then
  1565. DuplicateSym(hsym);
  1566. end;
  1567. hp:=hp^.next;
  1568. end;
  1569. end;
  1570. { check for duplicate id in local and parsymtable symtable }
  1571. if (symtabletype=localsymtable) then
  1572. { to be on the sure side: }
  1573. begin
  1574. if assigned(next) and
  1575. (next^.symtabletype=parasymtable) then
  1576. begin
  1577. hsym:=next^.search(sym^.name);
  1578. if assigned(hsym) then
  1579. DuplicateSym(hsym);
  1580. end
  1581. else if (current_module^.flags and uf_local_browser)=0 then
  1582. internalerror(43789);
  1583. end;
  1584. { check for duplicate id in local symtable of methods }
  1585. if (symtabletype=localsymtable) and
  1586. assigned(next) and
  1587. assigned(next^.next) and
  1588. { funcretsym is allowed !! }
  1589. (sym^.typ <> funcretsym) and
  1590. (next^.next^.symtabletype=objectsymtable) then
  1591. begin
  1592. hsym:=search_class_member(pobjectdef(next^.next^.defowner),sym^.name);
  1593. { but private ids can be reused }
  1594. if assigned(hsym) and
  1595. ((hsym^.properties<>sp_private) or
  1596. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1597. DuplicateSym(hsym);
  1598. end;
  1599. { check for duplicate field id in inherited classes }
  1600. if (sym^.typ=varsym) and
  1601. (symtabletype=objectsymtable) and
  1602. assigned(defowner) then
  1603. begin
  1604. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1605. { but private ids can be reused }
  1606. if assigned(hsym) and
  1607. ((hsym^.properties<>sp_private) or
  1608. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1609. DuplicateSym(hsym);
  1610. end;
  1611. if sym^.typ = typesym then
  1612. if assigned(ptypesym(sym)^.definition) then
  1613. begin
  1614. if not assigned(ptypesym(sym)^.definition^.owner) and
  1615. (ptypesym(sym)^.definition^.deftype<>errordef) then
  1616. registerdef(ptypesym(sym)^.definition);
  1617. {$ifdef GDB}
  1618. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist)
  1619. and (symtabletype in [globalsymtable,staticsymtable]) then
  1620. begin
  1621. ptypesym(sym)^.isusedinstab := true;
  1622. sym^.concatstabto(debuglist);
  1623. end;
  1624. {$endif GDB}
  1625. end;
  1626. { insert in index and search hash }
  1627. symindex^.insert(sym);
  1628. symsearch^.insert(sym);
  1629. insert:=sym;
  1630. end;
  1631. function tsymtable.search(const s : stringid) : psym;
  1632. begin
  1633. search:=psym(symsearch^.search(s));
  1634. end;
  1635. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1636. var
  1637. hp : psym;
  1638. begin
  1639. hp:=psym(symsearch^.speedsearch(s,speedvalue));
  1640. if assigned(hp) then
  1641. begin
  1642. { reject non static members in static procedures,
  1643. be carefull aktprocsym^.definition is not allways
  1644. loaded already (PFV) }
  1645. if (symtabletype=objectsymtable) and
  1646. ((hp^.properties and sp_static)=0) and
  1647. allow_only_static
  1648. {assigned(aktprocsym) and
  1649. assigned(aktprocsym^.definition) and
  1650. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1651. Message(sym_e_only_static_in_static);
  1652. if (symtabletype=unitsymtable) and
  1653. assigned(punitsymtable(@self)^.unitsym) then
  1654. inc(punitsymtable(@self)^.unitsym^.refs);
  1655. { unitsym are only loaded for browsing PM }
  1656. { this was buggy anyway because we could use }
  1657. { unitsyms from other units in _USES !! }
  1658. if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1659. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1660. hp:=nil;
  1661. if assigned(hp) and
  1662. (cs_browser in aktmoduleswitches) and make_ref then
  1663. begin
  1664. hp^.lastref:=new(pref,init(hp^.lastref,@tokenpos));
  1665. { for symbols that are in tables without
  1666. browser info or syssyms (PM) }
  1667. if hp^.refcount=0 then
  1668. hp^.defref:=hp^.lastref;
  1669. inc(hp^.refcount);
  1670. end;
  1671. end;
  1672. speedsearch:=hp;
  1673. end;
  1674. function tsymtable.rename(const olds,news : stringid):psym;
  1675. begin
  1676. rename:=psym(symsearch^.rename(olds,news));
  1677. end;
  1678. {$else}
  1679. procedure tsymtable.clear;
  1680. var
  1681. w : longint;
  1682. begin
  1683. { remove no entry from a withsymtable as it is only a pointer to the
  1684. recorddef or objectdef symtable }
  1685. if symtabletype=withsymtable then
  1686. exit;
  1687. { remove all entry from a symbol table }
  1688. if assigned(searchroot) then
  1689. begin
  1690. dispose(searchroot,done);
  1691. searchroot:=nil;
  1692. end;
  1693. if assigned(searchhasharray) then
  1694. begin
  1695. for w:=0 to hasharraysize-1 do
  1696. if assigned(searchhasharray^[w]) then
  1697. begin
  1698. dispose(searchhasharray^[w],done);
  1699. searchhasharray^[w]:=nil;
  1700. end;
  1701. dispose(searchhasharray);
  1702. searchhasharray:=nil;
  1703. end;
  1704. end;
  1705. function tsymtable.insert(sym:psym):psym;
  1706. var
  1707. ref : pref;
  1708. function _insert(var osym : psym):psym;
  1709. {To prevent TP from allocating temp space for temp strings, we allocate
  1710. some temp strings manually. We can use two temp strings, plus a third
  1711. one that TP adds, where TP alone needs five temp strings!. Storing
  1712. these on the heap saves even more, totally 1016 bytes per recursion!}
  1713. var
  1714. s1,s2:^string;
  1715. lasthfp,hfp : pforwardpointer;
  1716. begin
  1717. if osym=nil then
  1718. begin
  1719. osym:=sym;
  1720. _insert:=osym;
  1721. {$ifndef nonextfield}
  1722. if assigned(lastsym) then
  1723. lastsym^.nextsym:=sym;
  1724. lastsym:=sym;
  1725. {$endif}
  1726. end
  1727. { first check speedvalue, to allow a fast insert }
  1728. else
  1729. if osym^.speedvalue>sym^.speedvalue then
  1730. _insert:=_insert(psym(osym^.right))
  1731. else
  1732. if osym^.speedvalue<sym^.speedvalue then
  1733. _insert:=_insert(psym(osym^.left))
  1734. else
  1735. begin
  1736. new(s1);
  1737. new(s2);
  1738. s1^:=osym^.name;
  1739. s2^:=sym^.name;
  1740. if s1^>s2^ then
  1741. begin
  1742. dispose(s2);
  1743. dispose(s1);
  1744. _insert:=_insert(psym(osym^.right));
  1745. end
  1746. else
  1747. if s1^<s2^ then
  1748. begin
  1749. dispose(s2);
  1750. dispose(s1);
  1751. _insert:=_insert(psym(osym^.left));
  1752. end
  1753. else
  1754. begin
  1755. dispose(s2);
  1756. dispose(s1);
  1757. if (osym^.typ=typesym) and (osym^.properties=sp_forwarddef) then
  1758. begin
  1759. if (sym^.typ<>typesym) then
  1760. Message(sym_f_id_already_typed);
  1761. {
  1762. if (ptypesym(sym)^.definition^.deftype<>recorddef) and
  1763. (ptypesym(sym)^.definition^.deftype<>objectdef) then
  1764. Message(sym_f_type_must_be_rec_or_class);
  1765. }
  1766. ptypesym(osym)^.definition:=ptypesym(sym)^.definition;
  1767. osym^.properties:=sp_public;
  1768. { resolve the definition right now !! }
  1769. {forward types have two defref chained
  1770. the first corresponding to the location
  1771. of the
  1772. ptype = ^ttype;
  1773. and the second
  1774. to the line
  1775. ttype = record }
  1776. if cs_browser in aktmoduleswitches then
  1777. begin
  1778. new(ref,init(nil,@sym^.fileinfo));
  1779. ref^.nextref:=osym^.defref;
  1780. osym^.defref:=ref;
  1781. end;
  1782. { update all forwardpointers to this definition }
  1783. hfp:=ptypesym(osym)^.forwardpointer;
  1784. while assigned(hfp) do
  1785. begin
  1786. lasthfp:=hfp;
  1787. hfp^.def^.definition:=ptypesym(osym)^.definition;
  1788. hfp:=hfp^.next;
  1789. dispose(lasthfp);
  1790. end;
  1791. if ptypesym(osym)^.definition^.sym = ptypesym(sym) then
  1792. ptypesym(osym)^.definition^.sym := ptypesym(osym);
  1793. {$ifdef GDB}
  1794. ptypesym(osym)^.isusedinstab := true;
  1795. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) then
  1796. osym^.concatstabto(debuglist);
  1797. {$endif GDB}
  1798. { don't do a done on sym
  1799. because it also disposes left and right !!
  1800. sym is new so it has no left nor right }
  1801. dispose(sym,done);
  1802. _insert:=osym;
  1803. end
  1804. else
  1805. begin
  1806. DuplicateSym(sym);
  1807. _insert:=osym;
  1808. end;
  1809. end;
  1810. end;
  1811. end;
  1812. var
  1813. hp : psymtable;
  1814. hsym : psym;
  1815. begin
  1816. { set owner and sym indexnb }
  1817. sym^.owner:=@self;
  1818. {$ifdef CHAINPROCSYMS}
  1819. { set the nextprocsym field }
  1820. if sym^.typ=procsym then
  1821. chainprocsym(sym);
  1822. {$endif CHAINPROCSYMS}
  1823. { writes the symbol in data segment if required }
  1824. { also sets the datasize of owner }
  1825. if not in_loading then
  1826. sym^.insert_in_data;
  1827. if (symtabletype in [staticsymtable,globalsymtable]) then
  1828. begin
  1829. hp:=symtablestack;
  1830. while assigned(hp) do
  1831. begin
  1832. if hp^.symtabletype in [staticsymtable,globalsymtable] then
  1833. begin
  1834. hsym:=hp^.search(sym^.name);
  1835. if (assigned(hsym)) and
  1836. (hsym^.properties and sp_forwarddef=0) then
  1837. DuplicateSym(hsym);
  1838. end;
  1839. hp:=hp^.next;
  1840. end;
  1841. end;
  1842. { check for duplicate id in local and parsymtable symtable }
  1843. if (symtabletype=localsymtable) then
  1844. { to be on the sure side: }
  1845. begin
  1846. if assigned(next) and
  1847. (next^.symtabletype=parasymtable) then
  1848. begin
  1849. hsym:=next^.search(sym^.name);
  1850. if assigned(hsym) then
  1851. DuplicateSym(hsym);
  1852. end
  1853. else if (current_module^.flags and uf_local_browser)=0 then
  1854. internalerror(43789);
  1855. end;
  1856. { check for duplicate id in local symtable of methods }
  1857. if (symtabletype=localsymtable) and
  1858. assigned(next) and
  1859. assigned(next^.next) and
  1860. { funcretsym is allowed !! }
  1861. (sym^.typ <> funcretsym) and
  1862. (next^.next^.symtabletype=objectsymtable) then
  1863. begin
  1864. hsym:=search_class_member(pobjectdef(next^.next^.defowner),sym^.name);
  1865. { but private ids can be reused }
  1866. if assigned(hsym) and
  1867. ((hsym^.properties<>sp_private) or
  1868. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1869. DuplicateSym(hsym);
  1870. end;
  1871. { check for duplicate field id in inherited classes }
  1872. if (sym^.typ=varsym) and
  1873. (symtabletype=objectsymtable) and
  1874. assigned(defowner) then
  1875. begin
  1876. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1877. { but private ids can be reused }
  1878. if assigned(hsym) and
  1879. ((hsym^.properties<>sp_private) or
  1880. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1881. DuplicateSym(hsym);
  1882. end;
  1883. if sym^.typ = typesym then
  1884. if assigned(ptypesym(sym)^.definition) then
  1885. begin
  1886. if not assigned(ptypesym(sym)^.definition^.owner) then
  1887. registerdef(ptypesym(sym)^.definition);
  1888. {$ifdef GDB}
  1889. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist)
  1890. and (symtabletype in [globalsymtable,staticsymtable]) then
  1891. begin
  1892. ptypesym(sym)^.isusedinstab := true;
  1893. sym^.concatstabto(debuglist);
  1894. end;
  1895. {$endif GDB}
  1896. end;
  1897. sym^.speedvalue:=getspeedvalue(sym^.name);
  1898. if assigned(searchhasharray) then
  1899. insert:=_insert(searchhasharray^[sym^.speedvalue mod hasharraysize])
  1900. else
  1901. insert:=_insert(searchroot);
  1902. { store the sym also in the index, must be after the insert the table
  1903. because }
  1904. end;
  1905. function tsymtable.search(const s : stringid) : psym;
  1906. begin
  1907. search:=speedsearch(s,getspeedvalue(s));
  1908. end;
  1909. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1910. var
  1911. hp : psym;
  1912. begin
  1913. if assigned(searchhasharray) then
  1914. hp:=searchhasharray^[speedvalue mod hasharraysize]
  1915. else
  1916. hp:=searchroot;
  1917. while assigned(hp) do
  1918. begin
  1919. if speedvalue>hp^.speedvalue then
  1920. hp:=hp^.left
  1921. else
  1922. if speedvalue<hp^.speedvalue then
  1923. hp:=hp^.right
  1924. else
  1925. begin
  1926. if (hp^.name=s) then
  1927. begin
  1928. { reject non static members in static procedures,
  1929. be carefull aktprocsym^.definition is not allways
  1930. loaded already (PFV) }
  1931. if (symtabletype=objectsymtable) and
  1932. ((hp^.properties and sp_static)=0) and
  1933. allow_only_static
  1934. {assigned(aktprocsym) and
  1935. assigned(aktprocsym^.definition) and
  1936. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1937. Message(sym_e_only_static_in_static);
  1938. if (symtabletype=unitsymtable) and
  1939. assigned(punitsymtable(@self)^.unitsym) then
  1940. inc(punitsymtable(@self)^.unitsym^.refs);
  1941. { unitsym are only loaded for browsing PM }
  1942. { this was buggy anyway because we could use }
  1943. { unitsyms from other units in _USES !! }
  1944. if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1945. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1946. hp:=nil;
  1947. if assigned(hp) and
  1948. (cs_browser in aktmoduleswitches) and make_ref then
  1949. begin
  1950. hp^.lastref:=new(pref,init(hp^.lastref,@tokenpos));
  1951. { for symbols that are in tables without
  1952. browser info or syssyms (PM) }
  1953. if hp^.refcount=0 then
  1954. hp^.defref:=hp^.lastref;
  1955. inc(hp^.refcount);
  1956. end;
  1957. speedsearch:=hp;
  1958. exit;
  1959. end
  1960. else
  1961. if s>hp^.name then
  1962. hp:=hp^.left
  1963. else
  1964. hp:=hp^.right;
  1965. end;
  1966. end;
  1967. speedsearch:=nil;
  1968. end;
  1969. function tsymtable.rename(const olds,news : stringid):psym;
  1970. var
  1971. spdval : longint;
  1972. lasthp,
  1973. hp,hp2,hp3 : psym;
  1974. function _insert(var osym:psym):psym;
  1975. var
  1976. s1,s2:^string;
  1977. begin
  1978. if osym=nil then
  1979. begin
  1980. osym:=hp;
  1981. _insert:=osym;
  1982. end
  1983. { first check speedvalue, to allow a fast insert }
  1984. else
  1985. if osym^.speedvalue>hp^.speedvalue then
  1986. _insert:=_insert(osym^.right)
  1987. else
  1988. if osym^.speedvalue<hp^.speedvalue then
  1989. _insert:=_insert(osym^.left)
  1990. else
  1991. begin
  1992. new(s1);
  1993. new(s2);
  1994. s1^:=osym^._name^;
  1995. s2^:=hp^._name^;
  1996. if s1^>s2^ then
  1997. begin
  1998. dispose(s2);
  1999. dispose(s1);
  2000. _insert:=_insert(osym^.right);
  2001. end
  2002. else
  2003. if s1^<s2^ then
  2004. begin
  2005. dispose(s2);
  2006. dispose(s1);
  2007. _insert:=_insert(osym^.left);
  2008. end
  2009. else
  2010. begin
  2011. dispose(s2);
  2012. dispose(s1);
  2013. _insert:=osym;
  2014. end;
  2015. end;
  2016. end;
  2017. procedure inserttree(p:psym);
  2018. begin
  2019. if assigned(p) then
  2020. begin
  2021. inserttree(p^.left);
  2022. inserttree(p^.right);
  2023. _insert(p);
  2024. end;
  2025. end;
  2026. begin
  2027. spdval:=getspeedvalue(olds);
  2028. if assigned(searchhasharray) then
  2029. hp:=searchhasharray^[spdval mod hasharraysize]
  2030. else
  2031. hp:=searchroot;
  2032. lasthp:=nil;
  2033. while assigned(hp) do
  2034. begin
  2035. if spdval>hp^.speedvalue then
  2036. begin
  2037. lasthp:=hp;
  2038. hp:=hp^.left
  2039. end
  2040. else
  2041. if spdval<hp^.speedvalue then
  2042. begin
  2043. lasthp:=hp;
  2044. hp:=hp^.right
  2045. end
  2046. else
  2047. begin
  2048. if (hp^.name=olds) then
  2049. begin
  2050. { get in hp2 the replacer for the root or hasharr }
  2051. hp2:=hp^.left;
  2052. hp3:=hp^.right;
  2053. if not assigned(hp2) then
  2054. begin
  2055. hp2:=hp^.right;
  2056. hp3:=hp^.left;
  2057. end;
  2058. { remove entry from the tree }
  2059. if assigned(lasthp) then
  2060. begin
  2061. if lasthp^.left=hp then
  2062. lasthp^.left:=hp2
  2063. else
  2064. lasthp^.right:=hp2;
  2065. end
  2066. else
  2067. begin
  2068. if assigned(searchhasharray) then
  2069. searchhasharray^[spdval mod hasharraysize]:=hp2
  2070. else
  2071. searchroot:=hp2;
  2072. end;
  2073. { reinsert the hp3 }
  2074. inserttree(hp3);
  2075. { reinsert }
  2076. hp^.setname(news);
  2077. hp^.speedvalue:=getspeedvalue(news);
  2078. if assigned(searchhasharray) then
  2079. rename:=_insert(searchhasharray^[hp^.speedvalue mod hasharraysize])
  2080. else
  2081. rename:=_insert(searchroot);
  2082. exit;
  2083. end
  2084. else
  2085. if olds>hp^.name then
  2086. begin
  2087. lasthp:=hp;
  2088. hp:=hp^.left
  2089. end
  2090. else
  2091. begin
  2092. lasthp:=hp;
  2093. hp:=hp^.right;
  2094. end;
  2095. end;
  2096. end;
  2097. end;
  2098. {$endif}
  2099. {***********************************************
  2100. Browser
  2101. ***********************************************}
  2102. procedure tsymtable.load_browser;
  2103. var
  2104. b : byte;
  2105. sym : psym;
  2106. prdef : pdef;
  2107. oldrecsyms : psymtable;
  2108. begin
  2109. if symtabletype in [recordsymtable,objectsymtable,
  2110. parasymtable,localsymtable] then
  2111. begin
  2112. oldrecsyms:=aktrecordsymtable;
  2113. aktrecordsymtable:=@self;
  2114. end;
  2115. if symtabletype=staticppusymtable then
  2116. aktstaticsymtable:=@self;
  2117. b:=current_ppu^.readentry;
  2118. if b <> ibbeginsymtablebrowser then
  2119. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2120. repeat
  2121. b:=current_ppu^.readentry;
  2122. case b of
  2123. ibsymref : begin
  2124. sym:=readsymref;
  2125. resolvesym(sym);
  2126. if assigned(sym) then
  2127. sym^.load_references;
  2128. end;
  2129. ibdefref : begin
  2130. prdef:=readdefref;
  2131. resolvedef(prdef);
  2132. if assigned(prdef) then
  2133. begin
  2134. if prdef^.deftype<>procdef then
  2135. Message(unit_f_ppu_read_error);
  2136. pprocdef(prdef)^.load_references;
  2137. end;
  2138. end;
  2139. ibendsymtablebrowser : break;
  2140. else
  2141. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2142. end;
  2143. until false;
  2144. if symtabletype in [recordsymtable,objectsymtable,
  2145. parasymtable,localsymtable] then
  2146. aktrecordsymtable:=oldrecsyms;
  2147. end;
  2148. procedure tsymtable.write_browser;
  2149. var
  2150. oldrecsyms : psymtable;
  2151. begin
  2152. { symbol numbering for references
  2153. should have been done in write PM
  2154. number_symbols;
  2155. number_defs; }
  2156. if symtabletype in [recordsymtable,objectsymtable,
  2157. parasymtable,localsymtable] then
  2158. begin
  2159. oldrecsyms:=aktrecordsymtable;
  2160. aktrecordsymtable:=@self;
  2161. end;
  2162. current_ppu^.writeentry(ibbeginsymtablebrowser);
  2163. {$ifdef tp}
  2164. foreach(write_refs);
  2165. {$else}
  2166. foreach(@write_refs);
  2167. {$endif}
  2168. current_ppu^.writeentry(ibendsymtablebrowser);
  2169. if symtabletype in [recordsymtable,objectsymtable,
  2170. parasymtable,localsymtable] then
  2171. aktrecordsymtable:=oldrecsyms;
  2172. end;
  2173. {$ifdef BrowserLog}
  2174. procedure tsymtable.writebrowserlog;
  2175. begin
  2176. if cs_browser in aktmoduleswitches then
  2177. begin
  2178. if assigned(name) then
  2179. Browserlog.AddLog('---Symtable '+name^)
  2180. else
  2181. begin
  2182. if (symtabletype=recordsymtable) and
  2183. assigned(defowner^.sym) then
  2184. Browserlog.AddLog('---Symtable '+defowner^.sym^.name)
  2185. else
  2186. Browserlog.AddLog('---Symtable with no name');
  2187. end;
  2188. Browserlog.Ident;
  2189. {$ifdef tp}
  2190. foreach(add_to_browserlog);
  2191. {$else}
  2192. foreach(@add_to_browserlog);
  2193. {$endif}
  2194. browserlog.Unident;
  2195. end;
  2196. end;
  2197. {$endif BrowserLog}
  2198. {***********************************************
  2199. Process all entries
  2200. ***********************************************}
  2201. { checks, if all procsyms and methods are defined }
  2202. procedure tsymtable.check_forwards;
  2203. begin
  2204. {$ifdef tp}
  2205. foreach(check_procsym_forward);
  2206. {$else}
  2207. foreach(@check_procsym_forward);
  2208. {$endif}
  2209. end;
  2210. procedure tsymtable.checklabels;
  2211. begin
  2212. {$ifdef tp}
  2213. foreach(labeldefined);
  2214. {$else}
  2215. foreach(@labeldefined);
  2216. {$endif}
  2217. end;
  2218. procedure tsymtable.set_alignment(_alignment : byte);
  2219. var
  2220. sym : pvarsym;
  2221. l : longint;
  2222. begin
  2223. { this can not be done if there is an
  2224. hasharray ! }
  2225. alignment:=_alignment;
  2226. if (symtabletype<>parasymtable)
  2227. {$ifdef OLDPPU}
  2228. or assigned(searchhasharray)
  2229. {$endif}
  2230. then
  2231. internalerror(1111);
  2232. {$ifndef OLDPPU}
  2233. sym:=pvarsym(symindex^.first);
  2234. {$else}
  2235. sym:=pvarsym(searchroot);
  2236. {$endif}
  2237. datasize:=0;
  2238. { there can be only varsyms }
  2239. while assigned(sym) do
  2240. begin
  2241. l:=sym^.getpushsize;
  2242. sym^.address:=datasize;
  2243. datasize:=align(datasize+l,alignment);
  2244. {$ifndef OLDPPU}
  2245. sym:=pvarsym(sym^.next);
  2246. {$else}
  2247. sym:=pvarsym(sym^.nextsym);
  2248. {$endif}
  2249. end;
  2250. end;
  2251. function tsymtable.find_at_offset(l : longint) : pvarsym;
  2252. var
  2253. sym : pvarsym;
  2254. begin
  2255. find_at_offset:=nil;
  2256. { this can not be done if there is an
  2257. hasharray ! }
  2258. if (symtabletype<>parasymtable)
  2259. {$ifdef OLDPPU}
  2260. or assigned(searchhasharray)
  2261. {$endif}
  2262. then
  2263. internalerror(1111);
  2264. {$ifndef OLDPPU}
  2265. sym:=pvarsym(symindex^.first);
  2266. {$else}
  2267. sym:=pvarsym(searchroot);
  2268. {$endif}
  2269. while assigned(sym) do
  2270. begin
  2271. if sym^.address+address_fixup=l then
  2272. begin
  2273. find_at_offset:=sym;
  2274. exit;
  2275. end;
  2276. {$ifndef OLDPPU}
  2277. sym:=pvarsym(sym^.next);
  2278. {$else}
  2279. sym:=pvarsym(sym^.nextsym);
  2280. {$endif}
  2281. end;
  2282. end;
  2283. procedure tsymtable.allunitsused;
  2284. begin
  2285. {$ifdef tp}
  2286. foreach(unitsymbolused);
  2287. {$else}
  2288. foreach(@unitsymbolused);
  2289. {$endif}
  2290. end;
  2291. procedure tsymtable.allsymbolsused;
  2292. begin
  2293. {$ifdef tp}
  2294. foreach(varsymbolused);
  2295. {$else}
  2296. foreach(@varsymbolused);
  2297. {$endif}
  2298. end;
  2299. {$ifdef CHAINPROCSYMS}
  2300. procedure tsymtable.chainprocsyms;
  2301. begin
  2302. {$ifdef tp}
  2303. foreach(chainprocsym);
  2304. {$else}
  2305. foreach(@chainprocsym);
  2306. {$endif}
  2307. end;
  2308. {$endif CHAINPROCSYMS}
  2309. {$ifdef GDB}
  2310. procedure tsymtable.concatstabto(asmlist : paasmoutput);
  2311. begin
  2312. asmoutput:=asmlist;
  2313. {$ifdef tp}
  2314. foreach(concatstab);
  2315. {$else}
  2316. foreach(@concatstab);
  2317. {$endif}
  2318. end;
  2319. {$endif}
  2320. {****************************************************************************
  2321. TUNITSYMTABLE
  2322. ****************************************************************************}
  2323. constructor tunitsymtable.init(t : tsymtabletype; const n : string);
  2324. begin
  2325. inherited init(t);
  2326. name:=stringdup(upper(n));
  2327. unitid:=0;
  2328. unitsym:=nil;
  2329. {$ifndef OLDPPU}
  2330. symsearch^.usehash;
  2331. {$else}
  2332. { create a hasharray }
  2333. new(searchhasharray);
  2334. fillchar(searchhasharray^,sizeof(searchhasharray^),0);
  2335. {$endif}
  2336. { reset GDB things }
  2337. {$ifdef GDB}
  2338. if t = globalsymtable then
  2339. begin
  2340. prev_dbx_counter := dbx_counter;
  2341. dbx_counter := @dbx_count;
  2342. end;
  2343. is_stab_written:=false;
  2344. if cs_gdb_dbx in aktglobalswitches then
  2345. begin
  2346. dbx_count := 0;
  2347. if (symtabletype=globalsymtable) then
  2348. pglobaltypecount := @unittypecount;
  2349. debuglist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0'))));
  2350. unitid:=current_module^.unitcount;
  2351. inc(current_module^.unitcount);
  2352. debuglist^.concat(new(pai_asm_comment,init(strpnew('Global '+name^+' has index '+tostr(unitid)))));
  2353. end;
  2354. {$endif GDB}
  2355. end;
  2356. constructor tunitsymtable.loadasunit;
  2357. var
  2358. storeGlobalTypeCount : pword;
  2359. b : byte;
  2360. begin
  2361. unitsym:=nil;
  2362. unitid:=0;
  2363. if (current_module^.flags and uf_has_dbx)<>0 then
  2364. begin
  2365. storeGlobalTypeCount:=PGlobalTypeCount;
  2366. PglobalTypeCount:=@UnitTypeCount;
  2367. end;
  2368. { load symtables }
  2369. inherited load;
  2370. { set the name after because it is set to nil in tsymtable.load !! }
  2371. name:=stringdup(current_module^.modulename^);
  2372. { dbx count }
  2373. {$ifdef GDB}
  2374. if (current_module^.flags and uf_has_dbx)<>0 then
  2375. begin
  2376. b := current_ppu^.readentry;
  2377. if b <> ibdbxcount then
  2378. Message(unit_f_ppu_dbx_count_problem)
  2379. else
  2380. dbx_count := readlong;
  2381. dbx_count_ok := true;
  2382. PGlobalTypeCount:=storeGlobalTypeCount;
  2383. end
  2384. else
  2385. dbx_count := 0;
  2386. is_stab_written:=false;
  2387. {$endif GDB}
  2388. b:=current_ppu^.readentry;
  2389. if b<>ibendimplementation then
  2390. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2391. end;
  2392. procedure tunitsymtable.load_symtable_refs;
  2393. var
  2394. b : byte;
  2395. unitindex : word;
  2396. begin
  2397. {$ifdef OLDPPU}
  2398. number_defs;
  2399. number_symbols;
  2400. {$endif}
  2401. if ((current_module^.flags and uf_local_browser)<>0) then
  2402. begin
  2403. current_module^.localsymtable:=new(psymtable,loadas(staticppusymtable));
  2404. psymtable(current_module^.localsymtable)^.name:=
  2405. stringdup('implementation of '+psymtable(current_module^.globalsymtable)^.name^);
  2406. end;
  2407. { load browser }
  2408. if (current_module^.flags and uf_has_browser)<>0 then
  2409. begin
  2410. {if not (cs_browser in aktmoduleswitches) then
  2411. current_ppu^.skipuntilentry(ibendbrowser)
  2412. else }
  2413. begin
  2414. load_browser;
  2415. unitindex:=1;
  2416. while assigned(current_module^.map^[unitindex]) do
  2417. begin
  2418. {each unit wrote one browser entry }
  2419. load_browser;
  2420. inc(unitindex);
  2421. end;
  2422. b:=current_ppu^.readentry;
  2423. if b<>ibendbrowser then
  2424. Message1(unit_f_ppu_invalid_entry,tostr(b));
  2425. end;
  2426. end;
  2427. if ((current_module^.flags and uf_local_browser)<>0) then
  2428. psymtable(current_module^.localsymtable)^.load_browser;
  2429. end;
  2430. procedure tunitsymtable.writeasunit;
  2431. var
  2432. pu : pused_unit;
  2433. begin
  2434. { first the unitname }
  2435. current_ppu^.putstring(name^);
  2436. current_ppu^.writeentry(ibmodulename);
  2437. writesourcefiles;
  2438. writeusedunit;
  2439. { write the objectfiles and libraries that come for this unit,
  2440. preserve the containers becuase they are still needed to load
  2441. the link.res. All doesn't depend on the crc! It doesn't matter
  2442. if a unit is in a .o or .a file }
  2443. current_ppu^.do_crc:=false;
  2444. writecontainer(current_module^.linkunitfiles,iblinkunitfiles,true,true);
  2445. writecontainer(current_module^.linkofiles,iblinkofiles,true,false);
  2446. writecontainer(current_module^.linksharedlibs,iblinksharedlibs,true,true);
  2447. writecontainer(current_module^.linkstaticlibs,iblinkstaticlibs,true,true);
  2448. current_ppu^.do_crc:=true;
  2449. current_ppu^.writeentry(ibendinterface);
  2450. { write the symtable entries }
  2451. inherited write;
  2452. { write dbx count }
  2453. {$ifdef GDB}
  2454. if cs_gdb_dbx in aktglobalswitches then
  2455. begin
  2456. {$IfDef EXTDEBUG}
  2457. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  2458. {$ENDIF EXTDEBUG}
  2459. current_ppu^.putlongint(dbx_count);
  2460. current_ppu^.writeentry(ibdbxcount);
  2461. end;
  2462. {$endif GDB}
  2463. current_ppu^.writeentry(ibendimplementation);
  2464. { write static symtable
  2465. needed for local debugging of unit functions }
  2466. if (current_module^.flags and uf_local_browser)<>0 then
  2467. psymtable(current_module^.localsymtable)^.write;
  2468. { write all browser section }
  2469. if (current_module^.flags and uf_has_browser)<>0 then
  2470. begin
  2471. current_ppu^.do_crc:=false; { doesn't affect crc }
  2472. write_browser;
  2473. pu:=pused_unit(current_module^.used_units.first);
  2474. while assigned(pu) do
  2475. begin
  2476. psymtable(pu^.u^.globalsymtable)^.write_browser;
  2477. pu:=pused_unit(pu^.next);
  2478. end;
  2479. current_ppu^.writeentry(ibendbrowser);
  2480. current_ppu^.do_crc:=true;
  2481. end;
  2482. if (current_module^.flags and uf_local_browser)<>0 then
  2483. psymtable(current_module^.localsymtable)^.write_browser;
  2484. { the last entry ibend is written automaticly }
  2485. end;
  2486. function tunitsymtable.getnewtypecount : word;
  2487. begin
  2488. {$ifdef GDB}
  2489. if not (cs_gdb_dbx in aktglobalswitches) then
  2490. getnewtypecount:=tsymtable.getnewtypecount
  2491. else
  2492. {$endif GDB}
  2493. if symtabletype = staticsymtable then
  2494. getnewtypecount:=tsymtable.getnewtypecount
  2495. else
  2496. begin
  2497. getnewtypecount:=unittypecount;
  2498. inc(unittypecount);
  2499. end;
  2500. end;
  2501. {$ifdef GDB}
  2502. {$ifdef OLDPPU}
  2503. procedure tunitsymtable.orderdefs;
  2504. var
  2505. firstd, last, nonum, pd, cur, prev, lnext : pdef;
  2506. begin
  2507. pd:=rootdef;
  2508. firstd:=nil;
  2509. last:=nil;
  2510. nonum:=nil;
  2511. while assigned(pd) do
  2512. begin
  2513. lnext:=pd^.next;
  2514. if pd^.globalnb > 0 then
  2515. if firstd = nil then
  2516. begin
  2517. firstd:=pd;
  2518. last:=pd;
  2519. last^.next:=nil;
  2520. end
  2521. else
  2522. begin
  2523. cur:=firstd;
  2524. prev:=nil;
  2525. while assigned(cur) and
  2526. (prev <> last) and
  2527. (cur^.globalnb>0) and
  2528. (cur^.globalnb<pd^.globalnb) do
  2529. begin
  2530. prev:=cur;
  2531. cur:=cur^.next;
  2532. end;
  2533. if cur = firstd then
  2534. begin
  2535. pd^.next:=firstd;
  2536. firstd:=pd;
  2537. end
  2538. else
  2539. if prev = last then
  2540. begin
  2541. pd^.next:=nil;
  2542. last^.next:=pd;
  2543. last:=pd;
  2544. end
  2545. else
  2546. begin
  2547. pd^.next:=cur;
  2548. prev^.next:=pd;
  2549. end;
  2550. end
  2551. else { without number }
  2552. begin
  2553. pd^.next:=nonum;
  2554. nonum:=pd;
  2555. end;
  2556. pd:=lnext;
  2557. end;
  2558. if assigned(firstd) then
  2559. begin
  2560. rootdef:=firstd;
  2561. last^.next:=nonum;
  2562. end else
  2563. rootdef:=nonum;
  2564. end;
  2565. {$endif}
  2566. procedure tunitsymtable.concattypestabto(asmlist : paasmoutput);
  2567. var prev_dbx_count : plongint;
  2568. begin
  2569. if is_stab_written then exit;
  2570. if not assigned(name) then name := stringdup('Main_program');
  2571. if symtabletype = unitsymtable then
  2572. begin
  2573. unitid:=current_module^.unitcount;
  2574. inc(current_module^.unitcount);
  2575. end;
  2576. asmlist^.concat(new(pai_asm_comment,init(strpnew('Begin unit '+name^
  2577. +' has index '+tostr(unitid)))));
  2578. if cs_gdb_dbx in aktglobalswitches then
  2579. begin
  2580. if dbx_count_ok then
  2581. begin
  2582. asmlist^.insert(new(pai_asm_comment,init(strpnew('"repeated" unit '+name^
  2583. +' has index '+tostr(unitid)))));
  2584. do_count_dbx:=true;
  2585. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2586. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count)))));
  2587. exit;
  2588. end;
  2589. prev_dbx_count := dbx_counter;
  2590. dbx_counter := nil;
  2591. if symtabletype = unitsymtable then
  2592. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2593. +tostr(N_BINCL)+',0,0,0'))));
  2594. dbx_counter := @dbx_count;
  2595. end;
  2596. asmoutput:=asmlist;
  2597. {$ifdef tp}
  2598. foreach(concattypestab);
  2599. {$else}
  2600. foreach(@concattypestab);
  2601. {$endif}
  2602. if cs_gdb_dbx in aktglobalswitches then
  2603. begin
  2604. dbx_counter := prev_dbx_count;
  2605. do_count_dbx:=true;
  2606. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  2607. +tostr(N_EINCL)+',0,0,0'))));
  2608. dbx_count_ok := true;
  2609. end;
  2610. asmlist^.concat(new(pai_asm_comment,init(strpnew('End unit '+name^
  2611. +' has index '+tostr(unitid)))));
  2612. is_stab_written:=true;
  2613. end;
  2614. {$endif}
  2615. {****************************************************************************
  2616. Definitions
  2617. ****************************************************************************}
  2618. {$I symdef.inc}
  2619. {****************************************************************************
  2620. Symbols
  2621. ****************************************************************************}
  2622. {$I symsym.inc}
  2623. {****************************************************************************
  2624. GDB Helpers
  2625. ****************************************************************************}
  2626. {$ifdef GDB}
  2627. function typeglobalnumber(const s : string) : string;
  2628. var st : string;
  2629. symt : psymtable;
  2630. old_make_ref : boolean;
  2631. begin
  2632. old_make_ref:=make_ref;
  2633. make_ref:=false;
  2634. typeglobalnumber := '0';
  2635. srsym := nil;
  2636. if pos('.',s) > 0 then
  2637. begin
  2638. st := copy(s,1,pos('.',s)-1);
  2639. getsym(st,false);
  2640. st := copy(s,pos('.',s)+1,255);
  2641. if assigned(srsym) then
  2642. begin
  2643. if srsym^.typ = unitsym then
  2644. begin
  2645. symt := punitsym(srsym)^.unitsymtable;
  2646. srsym := symt^.search(st);
  2647. end else srsym := nil;
  2648. end;
  2649. end else st := s;
  2650. if srsym = nil then getsym(st,true);
  2651. if srsym^.typ<>typesym then
  2652. begin
  2653. Message(type_e_type_id_expected);
  2654. exit;
  2655. end;
  2656. typeglobalnumber := ptypesym(srsym)^.definition^.numberstring;
  2657. make_ref:=old_make_ref;
  2658. end;
  2659. {$endif GDB}
  2660. {****************************************************************************
  2661. Definition Helpers
  2662. ****************************************************************************}
  2663. procedure reset_global_defs;
  2664. var
  2665. def : pdef;
  2666. {$ifdef debug}
  2667. prevdef : pdef;
  2668. {$endif debug}
  2669. begin
  2670. {$ifdef debug}
  2671. prevdef:=nil;
  2672. {$endif debug}
  2673. {$ifdef GDB}
  2674. pglobaltypecount:=@globaltypecount;
  2675. {$endif GDB}
  2676. def:=firstglobaldef;
  2677. while assigned(def) do
  2678. begin
  2679. {$ifdef GDB}
  2680. if assigned(def^.sym) then
  2681. def^.sym^.isusedinstab:=false;
  2682. def^.is_def_stab_written:=false;
  2683. {$endif GDB}
  2684. {if not current_module^.in_implementation then}
  2685. begin
  2686. { reset rangenr's }
  2687. case def^.deftype of
  2688. orddef : porddef(def)^.rangenr:=0;
  2689. enumdef : penumdef(def)^.rangenr:=0;
  2690. arraydef : parraydef(def)^.rangenr:=0;
  2691. end;
  2692. if def^.deftype<>objectdef then
  2693. def^.has_rtti:=false;
  2694. def^.has_inittable:=false;
  2695. end;
  2696. {$ifdef debug}
  2697. prevdef:=def;
  2698. {$endif debug}
  2699. def:=def^.nextglobal;
  2700. end;
  2701. end;
  2702. {****************************************************************************
  2703. Object Helpers
  2704. ****************************************************************************}
  2705. function search_class_member(pd : pobjectdef;const n : string) : psym;
  2706. { searches n in symtable of pd and all anchestors }
  2707. var
  2708. sym : psym;
  2709. begin
  2710. sym:=nil;
  2711. while assigned(pd) do
  2712. begin
  2713. sym:=pd^.publicsyms^.search(n);
  2714. if assigned(sym) then
  2715. break;
  2716. pd:=pd^.childof;
  2717. end;
  2718. { this is needed for static methods in do_member_read pexpr unit PM
  2719. caused bug0214 }
  2720. if assigned(sym) then
  2721. begin
  2722. srsymtable:=pd^.publicsyms;
  2723. end;
  2724. search_class_member:=sym;
  2725. end;
  2726. var
  2727. _defaultprop : ppropertysym;
  2728. procedure testfordefaultproperty(p : {$ifndef OLDPPU}pnamedindexobject{$else}psym{$endif});
  2729. begin
  2730. if (psym(p)^.typ=propertysym) and ((ppropertysym(p)^.options and ppo_defaultproperty)<>0) then
  2731. _defaultprop:=ppropertysym(p);
  2732. end;
  2733. function search_default_property(pd : pobjectdef) : ppropertysym;
  2734. { returns the default property of a class, searches also anchestors }
  2735. begin
  2736. _defaultprop:=nil;
  2737. while assigned(pd) do
  2738. begin
  2739. {$ifdef tp}
  2740. pd^.publicsyms^.foreach(testfordefaultproperty);
  2741. {$else}
  2742. pd^.publicsyms^.foreach(@testfordefaultproperty);
  2743. {$endif}
  2744. if assigned(_defaultprop) then
  2745. break;
  2746. pd:=pd^.childof;
  2747. end;
  2748. search_default_property:=_defaultprop;
  2749. end;
  2750. {****************************************************************************
  2751. Macro's
  2752. ****************************************************************************}
  2753. procedure def_macro(const s : string);
  2754. var
  2755. mac : pmacrosym;
  2756. begin
  2757. mac:=pmacrosym(macros^.search(s));
  2758. if mac=nil then
  2759. begin
  2760. mac:=new(pmacrosym,init(s));
  2761. Message1(parser_m_macro_defined,mac^.name);
  2762. macros^.insert(mac);
  2763. end;
  2764. mac^.defined:=true;
  2765. end;
  2766. procedure set_macro(const s : string;value : string);
  2767. var
  2768. mac : pmacrosym;
  2769. begin
  2770. mac:=pmacrosym(macros^.search(s));
  2771. if mac=nil then
  2772. begin
  2773. mac:=new(pmacrosym,init(s));
  2774. macros^.insert(mac);
  2775. end
  2776. else
  2777. begin
  2778. if assigned(mac^.buftext) then
  2779. freemem(mac^.buftext,mac^.buflen);
  2780. end;
  2781. Message2(parser_m_macro_set_to,mac^.name,value);
  2782. mac^.buflen:=length(value);
  2783. getmem(mac^.buftext,mac^.buflen);
  2784. move(value[1],mac^.buftext^,mac^.buflen);
  2785. mac^.defined:=true;
  2786. end;
  2787. {****************************************************************************
  2788. Symtable Stack
  2789. ****************************************************************************}
  2790. procedure dellexlevel;
  2791. var
  2792. p : psymtable;
  2793. begin
  2794. p:=symtablestack;
  2795. symtablestack:=p^.next;
  2796. { symbol tables of unit interfaces are never disposed }
  2797. { this is handle by the unit unitm }
  2798. if not(p^.symtabletype in [unitsymtable,globalsymtable,stt_exceptsymtable]) or dispose_global then
  2799. dispose(p,done);
  2800. end;
  2801. {$ifdef DEBUG}
  2802. procedure test_symtablestack;
  2803. var
  2804. p : psymtable;
  2805. i : longint;
  2806. begin
  2807. p:=symtablestack;
  2808. i:=0;
  2809. while assigned(p) do
  2810. begin
  2811. inc(i);
  2812. p:=p^.next;
  2813. if i>500 then
  2814. Message(sym_f_internal_error_in_symtablestack);
  2815. end;
  2816. end;
  2817. procedure list_symtablestack;
  2818. var
  2819. p : psymtable;
  2820. i : longint;
  2821. begin
  2822. p:=symtablestack;
  2823. i:=0;
  2824. while assigned(p) do
  2825. begin
  2826. inc(i);
  2827. writeln(i,' ',p^.name^);
  2828. p:=p^.next;
  2829. if i>500 then
  2830. Message(sym_f_internal_error_in_symtablestack);
  2831. end;
  2832. end;
  2833. {$endif DEBUG}
  2834. {****************************************************************************
  2835. Init/Done Symtable
  2836. ****************************************************************************}
  2837. {$ifdef tp}
  2838. procedure do_streamerror;
  2839. begin
  2840. if symbolstream.status=-2 then
  2841. WriteLn('Error: Not enough EMS memory')
  2842. else
  2843. WriteLn('Error: EMS Error ',symbolstream.status);
  2844. halt(1);
  2845. end;
  2846. {$endif TP}
  2847. procedure InitSymtable;
  2848. begin
  2849. {$ifdef TP}
  2850. { Allocate stream }
  2851. if use_big then
  2852. begin
  2853. streamerror:=@do_streamerror;
  2854. { symbolstream.init('TMPFILE',stcreate,16000); }
  2855. {$ifndef dpmi}
  2856. symbolstream.init(10000,4000000); {using ems streams}
  2857. {$else}
  2858. symbolstream.init(1000000,16000); {using memory streams}
  2859. {$endif}
  2860. if symbolstream.errorinfo=stiniterror then
  2861. do_streamerror;
  2862. { write something, because pos 0 means nil pointer }
  2863. symbolstream.writestr(@inputfile);
  2864. end;
  2865. {$endif tp}
  2866. { Reset symbolstack }
  2867. registerdef:=false;
  2868. read_member:=false;
  2869. symtablestack:=nil;
  2870. systemunit:=nil;
  2871. objpasunit:=nil;
  2872. sroot:=nil;
  2873. {$ifdef GDB}
  2874. firstglobaldef:=nil;
  2875. lastglobaldef:=nil;
  2876. {$endif GDB}
  2877. globaltypecount:=1;
  2878. pglobaltypecount:=@globaltypecount;
  2879. { create error syms and def }
  2880. generrorsym:=new(perrorsym,init);
  2881. generrordef:=new(perrordef,init);
  2882. end;
  2883. procedure DoneSymtable;
  2884. begin
  2885. dispose(generrorsym,done);
  2886. dispose(generrordef,done);
  2887. { unload all symtables
  2888. done with loaded_units
  2889. dispose_global:=true;
  2890. while assigned(symtablestack) do
  2891. dellexlevel; }
  2892. {$ifdef TP}
  2893. { close the stream }
  2894. if use_big then
  2895. symbolstream.done;
  2896. {$endif}
  2897. end;
  2898. end.
  2899. {
  2900. $Log$
  2901. Revision 1.10 1999-05-09 12:46:26 peter
  2902. + hint where a duplicate sym is already defined
  2903. Revision 1.9 1999/05/08 19:52:40 peter
  2904. + MessagePos() which is enhanced Message() function but also gets the
  2905. position info
  2906. * Removed comp warnings
  2907. Revision 1.8 1999/05/06 21:38:38 peter
  2908. * don't register errordef
  2909. Revision 1.7 1999/05/06 09:05:31 peter
  2910. * generic write_float and str_float
  2911. * fixed constant float conversions
  2912. Revision 1.6 1999/05/05 09:19:16 florian
  2913. * more fixes to get it with delphi running
  2914. Revision 1.5 1999/05/01 13:24:43 peter
  2915. * merged nasm compiler
  2916. * old asm moved to oldasm/
  2917. Revision 1.4 1999/04/29 17:25:37 peter
  2918. * small fix for deref
  2919. Revision 1.3 1999/04/26 18:30:03 peter
  2920. * farpointerdef moved into pointerdef.is_far
  2921. Revision 1.151 1999/04/26 13:31:54 peter
  2922. * release storenumber,double_checksum
  2923. Revision 1.150 1999/04/25 17:36:13 peter
  2924. * typo fix for storenumber
  2925. Revision 1.149 1999/04/21 22:05:28 pierre
  2926. + tsymtable.find_at_offset function
  2927. used by ra386att to give arg name from ebp offset with -vz option
  2928. Revision 1.148 1999/04/21 16:31:44 pierre
  2929. ra386att.pas : commit problem !
  2930. Revision 1.147 1999/04/21 09:43:57 peter
  2931. * storenumber works
  2932. * fixed some typos in double_checksum
  2933. + incompatible types type1 and type2 message (with storenumber)
  2934. Revision 1.146 1999/04/19 09:33:14 pierre
  2935. + added tsymtable.set_alignment(longint) function
  2936. to change the offsets of all function args
  2937. if declared as cdecl or stdcall
  2938. (this must be done after because the cdecl is parsed after
  2939. insertion of the function parameterss into parast symboltable)
  2940. Revision 1.145 1999/04/17 13:16:24 peter
  2941. * fixes for storenumber
  2942. Revision 1.144 1999/04/15 10:01:45 peter
  2943. * small update for storenumber
  2944. Revision 1.143 1999/04/14 09:15:04 peter
  2945. * first things to store the symbol/def number in the ppu
  2946. Revision 1.142 1999/04/08 14:54:10 pierre
  2947. * suppression of val para unused warnings
  2948. Revision 1.141 1999/04/07 15:31:09 pierre
  2949. * all formaldefs are now a sinlge definition
  2950. cformaldef (this was necessary for double_checksum)
  2951. + small part of double_checksum code
  2952. Revision 1.140 1999/03/31 13:55:24 peter
  2953. * assembler inlining working for ag386bin
  2954. Revision 1.139 1999/03/24 23:17:30 peter
  2955. * fixed bugs 212,222,225,227,229,231,233
  2956. Revision 1.138 1999/03/21 22:49:11 florian
  2957. * private ids of objects can be reused in child classes
  2958. if they are in another unit
  2959. Revision 1.137 1999/03/17 22:23:20 florian
  2960. * a FPC compiled compiler checks now also in debug mode in assigned
  2961. if a pointer points to the heap
  2962. * when a symtable is loaded, there is no need to check for duplicate
  2963. symbols. This leads to crashes because defowner isn't assigned
  2964. in this case
  2965. Revision 1.136 1999/03/01 13:45:07 pierre
  2966. + added staticppusymtable symtable type for local browsing
  2967. Revision 1.135 1999/02/23 18:29:28 pierre
  2968. * win32 compilation error fix
  2969. + some work for local browser (not cl=omplete yet)
  2970. Revision 1.134 1999/02/22 15:09:42 florian
  2971. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2972. Revision 1.133 1999/02/22 13:07:12 pierre
  2973. + -b and -bl options work !
  2974. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2975. is not enabled when quitting global section
  2976. * local vars and procedures are not yet stored into PPU
  2977. Revision 1.132 1999/02/22 02:15:40 peter
  2978. * updates for ag386bin
  2979. Revision 1.131 1999/02/16 00:44:34 peter
  2980. * tp7 fix, assigned() can only be used on vars, not on functions
  2981. Revision 1.130 1999/02/15 13:13:16 pierre
  2982. * fix for bug0216
  2983. Revision 1.129 1999/02/11 09:46:29 pierre
  2984. * fix for normal method calls inside static methods :
  2985. WARNING there were both parser and codegen errors !!
  2986. added static_call boolean to calln tree
  2987. Revision 1.128 1999/02/09 23:03:05 florian
  2988. * check for duplicate field names in inherited classes/objects
  2989. * bug with self from the mailing list solved (the problem
  2990. was that classes were sometimes pushed wrong)
  2991. Revision 1.127 1999/02/08 11:29:06 pierre
  2992. * fix for bug0214
  2993. several problems where combined
  2994. search_class_member did not set srsymtable
  2995. => in do_member_read the call node got a wrong symtable
  2996. in cg386cal the vmt was pushed twice without chacking if it exists
  2997. now %esi is set to zero and pushed if not vmt
  2998. (not very efficient but should work !)
  2999. Revision 1.126 1999/02/05 08:54:31 pierre
  3000. + linkofiles splitted inot linkofiles and linkunitfiles
  3001. because linkofiles must be stored with directory
  3002. to enabled linking of different objects with same name
  3003. in a different directory
  3004. Revision 1.125 1999/02/03 09:44:33 pierre
  3005. * symbol nubering begins with 1 in number_symbols
  3006. * program tmodule has globalsymtable for its staticsymtable
  3007. (to get it displayed in IDE globals list)
  3008. + list of symbol (browcol) greatly improved for IDE
  3009. Revision 1.124 1999/01/27 12:58:33 pierre
  3010. * unused var warning suppressed for high of open arrays
  3011. Revision 1.123 1999/01/21 16:41:03 pierre
  3012. * fix for constructor inside with statements
  3013. Revision 1.122 1999/01/20 10:16:44 peter
  3014. * don't update crc when writing objs,libs and sources
  3015. Revision 1.121 1999/01/14 21:50:00 peter
  3016. * fixed forwardpointer problem with multiple forwards for the same
  3017. typesym. It now uses a linkedlist instead of a single pointer
  3018. Revision 1.120 1999/01/13 14:29:22 daniel
  3019. * nonextfield repaired
  3020. Revision 1.119 1999/01/12 14:25:38 peter
  3021. + BrowserLog for browser.log generation
  3022. + BrowserCol for browser info in TCollections
  3023. * released all other UseBrowser
  3024. Revision 1.118 1999/01/05 08:20:10 florian
  3025. * mainly problem with invalid case ranges fixed (reported by Jonas)
  3026. Revision 1.117 1998/12/30 22:15:57 peter
  3027. + farpointer type
  3028. * absolutesym now also stores if its far
  3029. Revision 1.116 1998/12/30 13:41:16 peter
  3030. * released valuepara
  3031. Revision 1.115 1998/12/11 00:03:48 peter
  3032. + globtype,tokens,version unit splitted from globals
  3033. Revision 1.114 1998/12/10 09:47:29 florian
  3034. + basic operations with int64/qord (compiler with -dint64)
  3035. + rtti of enumerations extended: names are now written
  3036. Revision 1.113 1998/12/08 10:18:17 peter
  3037. + -gh for heaptrc unit
  3038. Revision 1.112 1998/12/04 10:18:10 florian
  3039. * some stuff for procedures of object added
  3040. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  3041. Revision 1.111 1998/11/30 16:34:46 pierre
  3042. * corrected problems with rangecheck
  3043. + added needed code for no rangecheck in CRC32 functions in ppu unit
  3044. * enumdef lso need its rangenr reset to zero
  3045. when calling reset_global_defs
  3046. Revision 1.110 1998/11/28 16:20:58 peter
  3047. + support for dll variables
  3048. Revision 1.109 1998/11/27 14:50:49 peter
  3049. + open strings, $P switch support
  3050. Revision 1.108 1998/11/24 23:00:32 peter
  3051. * small crash prevention
  3052. Revision 1.107 1998/11/20 15:36:01 florian
  3053. * problems with rtti fixed, hope it works
  3054. Revision 1.106 1998/11/18 15:44:20 peter
  3055. * VALUEPARA for tp7 compatible value parameters
  3056. Revision 1.105 1998/11/17 10:39:18 peter
  3057. * has_rtti,has_inittable reset
  3058. Revision 1.104 1998/11/16 10:13:52 peter
  3059. * label defines are checked at the end of the proc
  3060. Revision 1.103 1998/11/13 15:40:32 pierre
  3061. + added -Se in Makefile cvstest target
  3062. + lexlevel cleanup
  3063. normal_function_level main_program_level and unit_init_level defined
  3064. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  3065. (test added in code !)
  3066. * -Un option was wrong
  3067. * _FAIL and _SELF only keyword inside
  3068. constructors and methods respectively
  3069. Revision 1.102 1998/11/12 16:43:34 florian
  3070. * functions with ansi strings as result didn't work, solved
  3071. Revision 1.101 1998/11/12 12:55:18 pierre
  3072. * fix for bug0176 and bug0177
  3073. Revision 1.100 1998/11/10 10:09:15 peter
  3074. * va_list -> array of const
  3075. Revision 1.99 1998/11/09 11:44:38 peter
  3076. + va_list for printf support
  3077. Revision 1.98 1998/11/05 23:33:35 peter
  3078. * symtable.done sets vars to nil
  3079. Revision 1.97 1998/11/05 12:03:00 peter
  3080. * released useansistring
  3081. * removed -Sv, its now available in fpc modes
  3082. Revision 1.96 1998/10/28 18:26:19 pierre
  3083. * removed some erros after other errors (introduced by useexcept)
  3084. * stabs works again correctly (for how long !)
  3085. Revision 1.95 1998/10/21 08:40:01 florian
  3086. + ansistring operator +
  3087. + $h and string[n] for n>255 added
  3088. * small problem with TP fixed
  3089. Revision 1.94 1998/10/20 08:07:03 pierre
  3090. * several memory corruptions due to double freemem solved
  3091. => never use p^.loc.location:=p^.left^.loc.location;
  3092. + finally I added now by default
  3093. that ra386dir translates global and unit symbols
  3094. + added a first field in tsymtable and
  3095. a nextsym field in tsym
  3096. (this allows to obtain ordered type info for
  3097. records and objects in gdb !)
  3098. Revision 1.93 1998/10/19 08:55:08 pierre
  3099. * wrong stabs info corrected once again !!
  3100. + variable vmt offset with vmt field only if required
  3101. implemented now !!!
  3102. Revision 1.92 1998/10/16 13:12:56 pierre
  3103. * added vmt_offsets in destructors code also !!!
  3104. * vmt_offset code for m68k
  3105. Revision 1.91 1998/10/16 08:48:38 peter
  3106. * fixed some misplaced $endif GDB
  3107. Revision 1.90 1998/10/15 15:13:32 pierre
  3108. + added oo_hasconstructor and oo_hasdestructor
  3109. for objects options
  3110. Revision 1.89 1998/10/14 13:38:25 peter
  3111. * fixed path with staticlib/objects in ppufiles
  3112. Revision 1.88 1998/10/09 16:36:07 pierre
  3113. * some memory leaks specific to usebrowser define fixed
  3114. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  3115. Revision 1.87 1998/10/09 11:47:57 pierre
  3116. * still more memory leaks fixes !!
  3117. Revision 1.86 1998/10/08 17:17:35 pierre
  3118. * current_module old scanner tagged as invalid if unit is recompiled
  3119. + added ppheap for better info on tracegetmem of heaptrc
  3120. (adds line column and file index)
  3121. * several memory leaks removed ith help of heaptrc !!
  3122. Revision 1.85 1998/10/08 13:48:51 peter
  3123. * fixed memory leaks for do nothing source
  3124. * fixed unit interdependency
  3125. Revision 1.84 1998/10/06 17:16:58 pierre
  3126. * some memory leaks fixed (thanks to Peter for heaptrc !)
  3127. Revision 1.83 1998/09/26 17:45:45 peter
  3128. + idtoken and only one token table
  3129. Revision 1.82 1998/09/25 09:52:57 peter
  3130. + store also datasize and # of symbols in ppu
  3131. * # of defs is now also stored in structs
  3132. Revision 1.81 1998/09/24 23:49:21 peter
  3133. + aktmodeswitches
  3134. Revision 1.80 1998/09/23 12:20:51 pierre
  3135. * main program tmodule had no symtable (crashed browser)
  3136. * unit symbols problem fixed !!
  3137. Revision 1.79 1998/09/23 12:03:57 peter
  3138. * overloading fix for array of const
  3139. Revision 1.78 1998/09/22 17:13:54 pierre
  3140. + browsing updated and developed
  3141. records and objects fields are also stored
  3142. Revision 1.77 1998/09/22 15:37:24 peter
  3143. + array of const start
  3144. Revision 1.76 1998/09/21 10:00:08 peter
  3145. * store number of defs in ppu file
  3146. Revision 1.75 1998/09/21 08:58:31 peter
  3147. + speedsearch, which also needs speedvalue as parameter
  3148. Revision 1.74 1998/09/21 08:45:25 pierre
  3149. + added vmt_offset in tobjectdef.write for fututre use
  3150. (first steps to have objects without vmt if no virtual !!)
  3151. + added fpu_used field for tabstractprocdef :
  3152. sets this level to 2 if the functions return with value in FPU
  3153. (is then set to correct value at parsing of implementation)
  3154. THIS MIGHT refuse some code with FPU expression too complex
  3155. that were accepted before and even in some cases
  3156. that don't overflow in fact
  3157. ( like if f : float; is a forward that finally in implementation
  3158. only uses one fpu register !!)
  3159. Nevertheless I think that it will improve security on
  3160. FPU operations !!
  3161. * most other changes only for UseBrowser code
  3162. (added symtable references for record and objects)
  3163. local switch for refs to args and local of each function
  3164. (static symtable still missing)
  3165. UseBrowser still not stable and probably broken by
  3166. the definition hash array !!
  3167. Revision 1.73 1998/09/20 09:38:47 florian
  3168. * hasharray for defs fixed
  3169. * ansistring code generation corrected (init/final, assignement)
  3170. Revision 1.72 1998/09/19 22:56:18 florian
  3171. + hash table for getdefnr added
  3172. Revision 1.71 1998/09/18 08:01:40 pierre
  3173. + improvement on the usebrowser part
  3174. (does not work correctly for now)
  3175. Revision 1.70 1998/09/09 11:50:57 pierre
  3176. * forward def are not put in record or objects
  3177. + added check for forwards also in record and objects
  3178. * dummy parasymtable for unit initialization removed from
  3179. symtable stack
  3180. Revision 1.69 1998/09/07 23:10:25 florian
  3181. * a lot of stuff fixed regarding rtti and publishing of properties,
  3182. basics should now work
  3183. Revision 1.68 1998/09/07 19:33:26 florian
  3184. + some stuff for property rtti added:
  3185. - NameIndex of the TPropInfo record is now written correctly
  3186. - the DEFAULT/NODEFAULT keyword is supported now
  3187. - the default value and the storedsym/def are now written to
  3188. the PPU fiel
  3189. Revision 1.67 1998/09/07 18:46:14 peter
  3190. * update smartlinking, uses getdatalabel
  3191. * renamed ptree.value vars to value_str,value_real,value_set
  3192. Revision 1.66 1998/09/07 17:37:05 florian
  3193. * first fixes for published properties
  3194. Revision 1.65 1998/09/06 22:42:03 florian
  3195. + rtti genreation for properties added
  3196. Revision 1.64 1998/09/05 22:11:04 florian
  3197. + switch -vb
  3198. * while/repeat loops accept now also word/longbool conditions
  3199. * makebooltojump did an invalid ungetregister32, fixed
  3200. Revision 1.63 1998/09/04 17:34:23 pierre
  3201. * bug with datalabel corrected
  3202. + assembler errors better commented
  3203. * one nested record crash removed
  3204. Revision 1.62 1998/09/04 08:42:10 peter
  3205. * updated some error messages
  3206. Revision 1.61 1998/09/03 16:03:21 florian
  3207. + rtti generation
  3208. * init table generation changed
  3209. Revision 1.60 1998/09/01 17:39:52 peter
  3210. + internal constant functions
  3211. Revision 1.59 1998/09/01 12:53:27 peter
  3212. + aktpackenum
  3213. Revision 1.58 1998/09/01 07:54:26 pierre
  3214. * UseBrowser a little updated (might still be buggy !!)
  3215. * bug in psub.pas in function specifier removed
  3216. * stdcall allowed in interface and in implementation
  3217. (FPC will not yet complain if it is missing in either part
  3218. because stdcall is only a dummy !!)
  3219. Revision 1.57 1998/08/31 12:26:33 peter
  3220. * m68k and palmos updates from surebugfixes
  3221. Revision 1.56 1998/08/21 14:08:55 pierre
  3222. + TEST_FUNCRET now default (old code removed)
  3223. works also for m68k (at least compiles)
  3224. Revision 1.55 1998/08/21 08:43:32 pierre
  3225. * pocdecl and poclearstack are now different
  3226. external must but written as last specification
  3227. Revision 1.54 1998/08/20 09:26:48 pierre
  3228. + funcret setting in underproc testing
  3229. compile with _dTEST_FUNCRET
  3230. Revision 1.53 1998/08/19 18:04:56 peter
  3231. * fixed current_module^.in_implementation flag
  3232. Revision 1.51 1998/08/18 14:17:12 pierre
  3233. * bug about assigning the return value of a function to
  3234. a procvar fixed : warning
  3235. assigning a proc to a procvar need @ in FPC mode !!
  3236. * missing file/line info restored
  3237. Revision 1.50 1998/08/17 10:10:13 peter
  3238. - removed OLDPPU
  3239. Revision 1.49 1998/08/12 19:39:31 peter
  3240. * fixed some crashes
  3241. Revision 1.48 1998/08/10 14:50:32 peter
  3242. + localswitches, moduleswitches, globalswitches splitting
  3243. Revision 1.47 1998/08/10 10:00:19 peter
  3244. * Moved symbolstream to symtable.pas
  3245. Revision 1.46 1998/08/08 10:19:19 florian
  3246. * small fixes to write the extended type correct
  3247. Revision 1.45 1998/08/02 16:42:00 florian
  3248. * on o : tobject do should also work now, the exceptsymtable shouldn't be
  3249. disposed by dellexlevel
  3250. Revision 1.44 1998/07/30 11:18:21 florian
  3251. + first implementation of try ... except on .. do end;
  3252. * limitiation of 65535 bytes parameters for cdecl removed
  3253. Revision 1.43 1998/07/28 21:52:56 florian
  3254. + implementation of raise and try..finally
  3255. + some misc. exception stuff
  3256. Revision 1.42 1998/07/20 10:23:03 florian
  3257. * better ansi string assignement
  3258. Revision 1.41 1998/07/18 22:54:31 florian
  3259. * some ansi/wide/longstring support fixed:
  3260. o parameter passing
  3261. o returning as result from functions
  3262. Revision 1.40 1998/07/14 14:47:09 peter
  3263. * released NEWINPUT
  3264. Revision 1.39 1998/07/10 00:00:06 peter
  3265. * fixed ttypesym bug finally
  3266. * fileinfo in the symtable and better using for unused vars
  3267. Revision 1.38 1998/07/07 11:20:17 peter
  3268. + NEWINPUT for a better inputfile and scanner object
  3269. Revision 1.37 1998/06/24 14:48:42 peter
  3270. * ifdef newppu -> ifndef oldppu
  3271. Revision 1.36 1998/06/17 14:10:19 peter
  3272. * small os2 fixes
  3273. * fixed interdependent units with newppu (remake3 under linux works now)
  3274. Revision 1.35 1998/06/16 08:56:35 peter
  3275. + targetcpu
  3276. * cleaner pmodules for newppu
  3277. Revision 1.34 1998/06/15 15:38:12 pierre
  3278. * small bug in systems.pas corrected
  3279. + operators in different units better hanlded
  3280. Revision 1.33 1998/06/15 14:10:53 daniel
  3281. * File was ruined, fixed.
  3282. Revision 1.31 1998/06/13 00:10:20 peter
  3283. * working browser and newppu
  3284. * some small fixes against crashes which occured in bp7 (but not in
  3285. fpc?!)
  3286. Revision 1.30 1998/06/09 16:01:53 pierre
  3287. + added procedure directive parsing for procvars
  3288. (accepted are popstack cdecl and pascal)
  3289. + added C vars with the following syntax
  3290. var C calias 'true_c_name';(can be followed by external)
  3291. reason is that you must add the Cprefix
  3292. which is target dependent
  3293. Revision 1.29 1998/06/07 15:30:26 florian
  3294. + first working rtti
  3295. + data init/final. for local variables
  3296. Revision 1.28 1998/06/06 09:27:39 peter
  3297. * new depend file generated
  3298. Revision 1.27 1998/06/05 14:37:38 pierre
  3299. * fixes for inline for operators
  3300. * inline procedure more correctly restricted
  3301. Revision 1.26 1998/06/04 23:52:03 peter
  3302. * m68k compiles
  3303. + .def file creation moved to gendef.pas so it could also be used
  3304. for win32
  3305. Revision 1.25 1998/06/04 09:55:48 pierre
  3306. * demangled name of procsym reworked to become independant of the
  3307. mangling scheme
  3308. Revision 1.24 1998/06/03 22:49:04 peter
  3309. + wordbool,longbool
  3310. * rename bis,von -> high,low
  3311. * moved some systemunit loading/creating to psystem.pas
  3312. Revision 1.23 1998/05/28 14:40:30 peter
  3313. * fixes for newppu, remake3 works now with it
  3314. Revision 1.22 1998/05/27 19:45:09 peter
  3315. * symtable.pas splitted into includefiles
  3316. * symtable adapted for $ifndef OLDPPU
  3317. Revision 1.21 1998/05/23 01:21:31 peter
  3318. + aktasmmode, aktoptprocessor, aktoutputformat
  3319. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  3320. + $LIBNAME to set the library name where the unit will be put in
  3321. * splitted cgi386 a bit (codeseg to large for bp7)
  3322. * nasm, tasm works again. nasm moved to ag386nsm.pas
  3323. Revision 1.20 1998/05/21 19:33:37 peter
  3324. + better procedure directive handling and only one table
  3325. Revision 1.19 1998/05/20 09:42:37 pierre
  3326. + UseTokenInfo now default
  3327. * unit in interface uses and implementation uses gives error now
  3328. * only one error for unknown symbol (uses lastsymknown boolean)
  3329. the problem came from the label code !
  3330. + first inlined procedures and function work
  3331. (warning there might be allowed cases were the result is still wrong !!)
  3332. * UseBrower updated gives a global list of all position of all used symbols
  3333. with switch -gb
  3334. Revision 1.18 1998/05/11 13:07:57 peter
  3335. + $ifndef OLDPPU for the new ppuformat
  3336. + $define GDB not longer required
  3337. * removed all warnings and stripped some log comments
  3338. * no findfirst/findnext anymore to remove smartlink *.o files
  3339. Revision 1.17 1998/05/06 08:38:48 pierre
  3340. * better position info with UseTokenInfo
  3341. UseTokenInfo greatly simplified
  3342. + added check for changed tree after first time firstpass
  3343. (if we could remove all the cases were it happen
  3344. we could skip all firstpass if firstpasscount > 1)
  3345. Only with ExtDebug
  3346. Revision 1.16 1998/05/05 15:24:20 michael
  3347. * Fix to save units with classes.
  3348. Revision 1.15 1998/05/04 17:54:29 peter
  3349. + smartlinking works (only case jumptable left todo)
  3350. * redesign of systems.pas to support assemblers and linkers
  3351. + Unitname is now also in the PPU-file, increased version to 14
  3352. Revision 1.14 1998/05/01 16:38:46 florian
  3353. * handling of private and protected fixed
  3354. + change_keywords_to_tp implemented to remove
  3355. keywords which aren't supported by tp
  3356. * break and continue are now symbols of the system unit
  3357. + widestring, longstring and ansistring type released
  3358. Revision 1.13 1998/05/01 09:01:25 florian
  3359. + correct semantics of private and protected
  3360. * small fix in variable scope:
  3361. a id can be used in a parameter list of a method, even it is used in
  3362. an anchestor class as field id
  3363. Revision 1.12 1998/05/01 07:43:57 florian
  3364. + basics for rtti implemented
  3365. + switch $m (generate rtti for published sections)
  3366. Revision 1.11 1998/04/30 15:59:42 pierre
  3367. * GDB works again better :
  3368. correct type info in one pass
  3369. + UseTokenInfo for better source position
  3370. * fixed one remaining bug in scanner for line counts
  3371. * several little fixes
  3372. Revision 1.10 1998/04/29 10:34:05 pierre
  3373. + added some code for ansistring (not complete nor working yet)
  3374. * corrected operator overloading
  3375. * corrected nasm output
  3376. + started inline procedures
  3377. + added starstarn : use ** for exponentiation (^ gave problems)
  3378. + started UseTokenInfo cond to get accurate positions
  3379. Revision 1.9 1998/04/27 23:10:29 peter
  3380. + new scanner
  3381. * $makelib -> if smartlink
  3382. * small filename fixes pmodule.setfilename
  3383. * moved import from files.pas -> import.pas
  3384. Revision 1.8 1998/04/21 10:16:48 peter
  3385. * patches from strasbourg
  3386. * objects is not used anymore in the fpc compiled version
  3387. Revision 1.7 1998/04/13 22:20:36 florian
  3388. + stricter checking for duplicate id, solves also bug0097
  3389. Revision 1.6 1998/04/13 17:20:43 florian
  3390. * tdef.done much faster implemented
  3391. Revision 1.5 1998/04/10 21:36:56 florian
  3392. + some stuff to support method pointers (procedure of object) added
  3393. (declaration, parameter handling)
  3394. Revision 1.4 1998/04/08 16:58:08 pierre
  3395. * several bugfixes
  3396. ADD ADC and AND are also sign extended
  3397. nasm output OK (program still crashes at end
  3398. and creates wrong assembler files !!)
  3399. procsym types sym in tdef removed !!
  3400. Revision 1.3 1998/04/07 13:19:52 pierre
  3401. * bugfixes for reset_gdb_info
  3402. in MEM parsing for go32v2
  3403. better external symbol creation
  3404. support for rhgdb.exe (lowercase file names)
  3405. Revision 1.2 1998/04/06 13:09:04 daniel
  3406. * Emergency solution for bug in reset_gdb_info.
  3407. }