symtable.pas 120 KB

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