symtable.pas 121 KB

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