symtable.pas 120 KB

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