symtable.pas 103 KB

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