symtable.pas 120 KB

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