symtable.pas 121 KB

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