symtable.pas 122 KB

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