symtable.pas 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
  4. This unit handles the symbol tables
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {$ifdef TP}
  19. {$N+,E+,F+}
  20. {$endif}
  21. unit symtable;
  22. interface
  23. uses
  24. {$ifdef TP}
  25. {$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);
  808. begin
  809. psym(sym)^.write_references;
  810. end;
  811. {$ifdef BrowserLog}
  812. procedure add_to_browserlog(p : psym);
  813. begin
  814. p^.add_to_browserlog;
  815. end;
  816. {$endif UseBrowser}
  817. {****************************************************************************
  818. Forward Resolving
  819. ****************************************************************************}
  820. type
  821. presolvelist = ^tresolvelist;
  822. tresolvelist = record
  823. p : ppointerdef;
  824. typ : ptypesym;
  825. next : presolvelist;
  826. end;
  827. var
  828. sroot : presolvelist;
  829. procedure save_forward(ppd : ppointerdef;typesym : ptypesym);
  830. var
  831. p : presolvelist;
  832. begin
  833. new(p);
  834. p^.next:=sroot;
  835. p^.p:=ppd;
  836. ppd^.defsym := typesym;
  837. p^.typ:=typesym;
  838. sroot:=p;
  839. end;
  840. procedure resolve_forwards;
  841. var
  842. p : presolvelist;
  843. begin
  844. p:=sroot;
  845. while p<>nil do
  846. begin
  847. sroot:=sroot^.next;
  848. p^.p^.definition:=p^.typ^.definition;
  849. dispose(p);
  850. p:=sroot;
  851. end;
  852. end;
  853. {*****************************************************************************
  854. Search Symtables for Syms
  855. *****************************************************************************}
  856. procedure getsym(const s : stringid;notfounderror : boolean);
  857. var
  858. speedvalue : longint;
  859. begin
  860. speedvalue:=getspeedvalue(s);
  861. lastsrsym:=nil;
  862. srsymtable:=symtablestack;
  863. while assigned(srsymtable) do
  864. begin
  865. srsym:=srsymtable^.speedsearch(s,speedvalue);
  866. if assigned(srsym) then
  867. exit
  868. else
  869. srsymtable:=srsymtable^.next;
  870. end;
  871. if forwardsallowed then
  872. begin
  873. srsymtable:=symtablestack;
  874. while (srsymtable^.symtabletype in [objectsymtable,recordsymtable]) do
  875. srsymtable:=srsymtable^.next;
  876. srsym:=new(ptypesym,init(s,nil));
  877. srsym^.symoptions:=[sp_forwarddef];
  878. srsymtable^.insert(srsym);
  879. end
  880. else if notfounderror then
  881. begin
  882. Message1(sym_e_id_not_found,s);
  883. srsym:=generrorsym;
  884. end
  885. else srsym:=nil;
  886. end;
  887. procedure getsymonlyin(p : psymtable;const s : stringid);
  888. begin
  889. { the caller have to take care if srsym=nil (FK) }
  890. srsym:=nil;
  891. if assigned(p) then
  892. begin
  893. srsymtable:=p;
  894. srsym:=srsymtable^.search(s);
  895. if assigned(srsym) then
  896. exit
  897. else
  898. begin
  899. if (punitsymtable(srsymtable)=punitsymtable(current_module^.globalsymtable)) then
  900. begin
  901. getsymonlyin(psymtable(current_module^.localsymtable),s);
  902. if assigned(srsym) then
  903. srsymtable:=psymtable(current_module^.localsymtable)
  904. else
  905. Message1(sym_e_id_not_found,s);
  906. end
  907. else
  908. Message1(sym_e_id_not_found,s);
  909. end;
  910. end;
  911. end;
  912. function search_a_symtable(const symbol:string;symtabletype:tsymtabletype):Psym;
  913. {Search for a symbol in a specified symbol table. Returns nil if
  914. the symtable is not found, and also if the symbol cannot be found
  915. in the desired symtable }
  916. var hsymtab:Psymtable;
  917. res:Psym;
  918. begin
  919. res:=nil;
  920. hsymtab:=symtablestack;
  921. while (hsymtab<>nil) and (hsymtab^.symtabletype<>symtabletype) do
  922. hsymtab:=hsymtab^.next;
  923. if hsymtab<>nil then
  924. {We found the desired symtable. Now check if the symbol we
  925. search for is defined in it }
  926. res:=hsymtab^.search(symbol);
  927. search_a_symtable:=res;
  928. end;
  929. {****************************************************************************
  930. TSYMTABLE
  931. ****************************************************************************}
  932. constructor tsymtable.init(t : tsymtabletype);
  933. begin
  934. symtabletype:=t;
  935. symtablelevel:=0;
  936. defowner:=nil;
  937. unitid:=0;
  938. next:=nil;
  939. name:=nil;
  940. address_fixup:=0;
  941. datasize:=0;
  942. dataalignment:=1;
  943. new(symindex,init(indexgrowsize));
  944. new(defindex,init(indexgrowsize));
  945. if symtabletype<>withsymtable then
  946. begin
  947. new(symsearch,init);
  948. symsearch^.noclear:=true;
  949. end
  950. else
  951. symsearch:=nil;
  952. alignment:=def_alignment;
  953. end;
  954. destructor tsymtable.done;
  955. begin
  956. stringdispose(name);
  957. dispose(symindex,done);
  958. dispose(defindex,done);
  959. { symsearch can already be disposed or set to nil for withsymtable }
  960. if assigned(symsearch) then
  961. begin
  962. dispose(symsearch,done);
  963. symsearch:=nil;
  964. end;
  965. end;
  966. constructor twithsymtable.init;
  967. begin
  968. inherited init(withsymtable);
  969. direct_with:=false;
  970. withnode:=nil;
  971. withrefnode:=nil;
  972. end;
  973. destructor twithsymtable.done;
  974. begin
  975. symsearch:=nil;
  976. inherited done;
  977. end;
  978. {***********************************************
  979. Helpers
  980. ***********************************************}
  981. function tsymtable.getnewtypecount : word;
  982. begin
  983. getnewtypecount:=pglobaltypecount^;
  984. inc(pglobaltypecount^);
  985. end;
  986. procedure tsymtable.registerdef(p : pdef);
  987. begin
  988. defindex^.insert(p);
  989. { set def owner and indexnb }
  990. p^.owner:=@self;
  991. end;
  992. procedure tsymtable.foreach(proc2call : tnamedindexcallback);
  993. begin
  994. symindex^.foreach(proc2call);
  995. end;
  996. {***********************************************
  997. LOAD / WRITE SYMTABLE FROM PPU
  998. ***********************************************}
  999. procedure tsymtable.loaddefs;
  1000. var
  1001. hp : pdef;
  1002. b : byte;
  1003. begin
  1004. { load start of definition section, which holds the amount of defs }
  1005. if current_ppu^.readentry<>ibstartdefs then
  1006. Message(unit_f_ppu_read_error);
  1007. current_ppu^.getlongint;
  1008. { read definitions }
  1009. repeat
  1010. b:=current_ppu^.readentry;
  1011. case b of
  1012. ibpointerdef : hp:=new(ppointerdef,load);
  1013. ibarraydef : hp:=new(parraydef,load);
  1014. iborddef : hp:=new(porddef,load);
  1015. ibfloatdef : hp:=new(pfloatdef,load);
  1016. ibprocdef : hp:=new(pprocdef,load);
  1017. ibshortstringdef : hp:=new(pstringdef,shortload);
  1018. iblongstringdef : hp:=new(pstringdef,longload);
  1019. ibansistringdef : hp:=new(pstringdef,ansiload);
  1020. ibwidestringdef : hp:=new(pstringdef,wideload);
  1021. ibrecorddef : hp:=new(precorddef,load);
  1022. ibobjectdef : hp:=new(pobjectdef,load);
  1023. ibenumdef : hp:=new(penumdef,load);
  1024. ibsetdef : hp:=new(psetdef,load);
  1025. ibprocvardef : hp:=new(pprocvardef,load);
  1026. ibfiledef : hp:=new(pfiledef,load);
  1027. ibclassrefdef : hp:=new(pclassrefdef,load);
  1028. ibformaldef : hp:=new(pformaldef,load);
  1029. ibenddefs : break;
  1030. ibend : Message(unit_f_ppu_read_error);
  1031. else
  1032. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1033. end;
  1034. hp^.owner:=@self;
  1035. defindex^.insert(hp);
  1036. until false;
  1037. end;
  1038. procedure tsymtable.loadsyms;
  1039. var
  1040. b : byte;
  1041. sym : psym;
  1042. begin
  1043. { load start of definition section, which holds the amount of defs }
  1044. if current_ppu^.readentry<>ibstartsyms then
  1045. Message(unit_f_ppu_read_error);
  1046. { skip amount of symbols, not used currently }
  1047. current_ppu^.getlongint;
  1048. { load datasize,dataalignment of this symboltable }
  1049. datasize:=current_ppu^.getlongint;
  1050. dataalignment:=current_ppu^.getlongint;
  1051. { now read the symbols }
  1052. repeat
  1053. b:=current_ppu^.readentry;
  1054. case b of
  1055. ibtypesym : sym:=new(ptypesym,load);
  1056. ibprocsym : sym:=new(pprocsym,load);
  1057. ibconstsym : sym:=new(pconstsym,load);
  1058. ibvarsym : sym:=new(pvarsym,load);
  1059. ibfuncretsym : sym:=new(pfuncretsym,load);
  1060. ibabsolutesym : sym:=new(pabsolutesym,load);
  1061. ibenumsym : sym:=new(penumsym,load);
  1062. ibtypedconstsym : sym:=new(ptypedconstsym,load);
  1063. ibpropertysym : sym:=new(ppropertysym,load);
  1064. ibunitsym : sym:=new(punitsym,load);
  1065. iblabelsym : sym:=new(plabelsym,load);
  1066. ibsyssym : sym:=new(psyssym,load);
  1067. ibendsyms : break;
  1068. ibend : Message(unit_f_ppu_read_error);
  1069. else
  1070. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1071. end;
  1072. sym^.owner:=@self;
  1073. symindex^.insert(sym);
  1074. symsearch^.insert(sym);
  1075. until false;
  1076. end;
  1077. procedure tsymtable.writedefs;
  1078. var
  1079. pd : pdef;
  1080. begin
  1081. { each definition get a number, write then the amount of defs to the
  1082. ibstartdef entry }
  1083. current_ppu^.putlongint(defindex^.count);
  1084. current_ppu^.writeentry(ibstartdefs);
  1085. { now write the definition }
  1086. pd:=pdef(defindex^.first);
  1087. while assigned(pd) do
  1088. begin
  1089. pd^.write;
  1090. pd:=pdef(pd^.next);
  1091. end;
  1092. { write end of definitions }
  1093. current_ppu^.writeentry(ibenddefs);
  1094. end;
  1095. procedure tsymtable.writesyms;
  1096. var
  1097. pd : psym;
  1098. begin
  1099. { each definition get a number, write then the amount of syms and the
  1100. datasize to the ibsymdef entry }
  1101. current_ppu^.putlongint(symindex^.count);
  1102. current_ppu^.putlongint(datasize);
  1103. current_ppu^.putlongint(dataalignment);
  1104. current_ppu^.writeentry(ibstartsyms);
  1105. { foreach is used to write all symbols }
  1106. pd:=psym(symindex^.first);
  1107. while assigned(pd) do
  1108. begin
  1109. pd^.write;
  1110. pd:=psym(pd^.next);
  1111. end;
  1112. { end of symbols }
  1113. current_ppu^.writeentry(ibendsyms);
  1114. end;
  1115. procedure tsymtable.deref;
  1116. var
  1117. hp : pdef;
  1118. hs : psym;
  1119. begin
  1120. hp:=pdef(defindex^.first);
  1121. while assigned(hp) do
  1122. begin
  1123. hp^.deref;
  1124. hp^.symderef;
  1125. hp:=pdef(hp^.next);
  1126. end;
  1127. hs:=psym(symindex^.first);
  1128. while assigned(hs) do
  1129. begin
  1130. hs^.deref;
  1131. hs:=psym(hs^.next);
  1132. end;
  1133. end;
  1134. constructor tsymtable.load;
  1135. var
  1136. st_loading : boolean;
  1137. begin
  1138. st_loading:=in_loading;
  1139. in_loading:=true;
  1140. {$ifndef NEWMAP}
  1141. current_module^.map^[0]:=@self;
  1142. {$else NEWMAP}
  1143. current_module^.globalsymtable:=@self;
  1144. {$endif NEWMAP}
  1145. symtabletype:=unitsymtable;
  1146. symtablelevel:=0;
  1147. { unused for units }
  1148. address_fixup:=0;
  1149. datasize:=0;
  1150. defowner:=nil;
  1151. name:=nil;
  1152. unitid:=0;
  1153. defowner:=nil;
  1154. new(symindex,init(indexgrowsize));
  1155. new(defindex,init(indexgrowsize));
  1156. new(symsearch,init);
  1157. symsearch^.usehash;
  1158. symsearch^.noclear:=true;
  1159. alignment:=def_alignment;
  1160. { load definitions }
  1161. loaddefs;
  1162. { load symbols }
  1163. loadsyms;
  1164. { Now we can deref the symbols and definitions }
  1165. if not(symtabletype in [objectsymtable,recordsymtable]) then
  1166. deref;
  1167. {$ifdef NEWMAP}
  1168. { necessary for dependencies }
  1169. current_module^.globalsymtable:=nil;
  1170. {$endif NEWMAP}
  1171. in_loading:=st_loading;
  1172. end;
  1173. procedure tsymtable.write;
  1174. begin
  1175. { write definitions }
  1176. writedefs;
  1177. { write symbols }
  1178. writesyms;
  1179. end;
  1180. constructor tsymtable.loadas(typ : tsymtabletype);
  1181. var
  1182. storesymtable : psymtable;
  1183. st_loading : boolean;
  1184. begin
  1185. st_loading:=in_loading;
  1186. in_loading:=true;
  1187. symtabletype:=typ;
  1188. new(symindex,init(indexgrowsize));
  1189. new(defindex,init(indexgrowsize));
  1190. new(symsearch,init);
  1191. symsearch^.noclear:=true;
  1192. defowner:=nil;
  1193. storesymtable:=aktrecordsymtable;
  1194. if typ in [recordsymtable,objectsymtable,
  1195. parasymtable,localsymtable] then
  1196. aktrecordsymtable:=@self;
  1197. { used for local browser }
  1198. if typ=staticppusymtable then
  1199. begin
  1200. aktstaticsymtable:=@self;
  1201. symsearch^.usehash;
  1202. end;
  1203. name:=nil;
  1204. alignment:=def_alignment;
  1205. { isn't used there }
  1206. datasize:=0;
  1207. address_fixup:= 0;
  1208. { also unused }
  1209. unitid:=0;
  1210. { load definitions }
  1211. { we need the correct symtable for registering }
  1212. if not (typ in [recordsymtable,objectsymtable]) then
  1213. begin
  1214. next:=symtablestack;
  1215. symtablestack:=@self;
  1216. end;
  1217. { load definitions }
  1218. loaddefs;
  1219. { load symbols }
  1220. loadsyms;
  1221. { now we can deref the syms and defs }
  1222. if not (typ in [recordsymtable,objectsymtable]) then
  1223. deref;
  1224. aktrecordsymtable:=storesymtable;
  1225. if not (typ in [recordsymtable,objectsymtable]) then
  1226. begin
  1227. symtablestack:=next;
  1228. end;
  1229. in_loading:=st_loading;
  1230. end;
  1231. procedure tsymtable.writeas;
  1232. var
  1233. oldtyp : byte;
  1234. storesymtable : psymtable;
  1235. begin
  1236. oldtyp:=current_ppu^.entrytyp;
  1237. storesymtable:=aktrecordsymtable;
  1238. if symtabletype in [recordsymtable,objectsymtable,
  1239. parasymtable,localsymtable] then
  1240. aktrecordsymtable:=@self;
  1241. if (symtabletype in [recordsymtable,objectsymtable]) then
  1242. current_ppu^.entrytyp:=subentryid;
  1243. { write definitions }
  1244. writedefs;
  1245. { write symbols }
  1246. writesyms;
  1247. current_ppu^.entrytyp:=oldtyp;
  1248. aktrecordsymtable:=storesymtable;
  1249. end;
  1250. {***********************************************
  1251. Get Symbol / Def by Number
  1252. ***********************************************}
  1253. function tsymtable.getsymnr(l : longint) : psym;
  1254. var
  1255. hp : psym;
  1256. begin
  1257. hp:=psym(symindex^.search(l));
  1258. if hp=nil then
  1259. internalerror(10999);
  1260. getsymnr:=hp;
  1261. end;
  1262. function tsymtable.getdefnr(l : longint) : pdef;
  1263. var
  1264. hp : pdef;
  1265. begin
  1266. hp:=pdef(defindex^.search(l));
  1267. if hp=nil then
  1268. internalerror(10998);
  1269. getdefnr:=hp;
  1270. end;
  1271. {***********************************************
  1272. Table Access
  1273. ***********************************************}
  1274. procedure tsymtable.clear;
  1275. begin
  1276. { remove no entry from a withsymtable as it is only a pointer to the
  1277. recorddef or objectdef symtable }
  1278. if symtabletype=withsymtable then
  1279. exit;
  1280. symindex^.clear;
  1281. defindex^.clear;
  1282. end;
  1283. function tsymtable.insert(sym:psym):psym;
  1284. var
  1285. hp : psymtable;
  1286. hsym : psym;
  1287. begin
  1288. { set owner and sym indexnb }
  1289. sym^.owner:=@self;
  1290. {$ifdef CHAINPROCSYMS}
  1291. { set the nextprocsym field }
  1292. if sym^.typ=procsym then
  1293. chainprocsym(sym);
  1294. {$endif CHAINPROCSYMS}
  1295. { writes the symbol in data segment if required }
  1296. { also sets the datasize of owner }
  1297. if not in_loading then
  1298. sym^.insert_in_data;
  1299. if (symtabletype in [staticsymtable,globalsymtable]) then
  1300. begin
  1301. hp:=symtablestack;
  1302. while assigned(hp) do
  1303. begin
  1304. if hp^.symtabletype in [staticsymtable,globalsymtable] then
  1305. begin
  1306. hsym:=hp^.search(sym^.name);
  1307. if assigned(hsym) and
  1308. not(sp_forwarddef in hsym^.symoptions) then
  1309. DuplicateSym(hsym);
  1310. end;
  1311. hp:=hp^.next;
  1312. end;
  1313. end;
  1314. { check for duplicate id in local and parsymtable symtable }
  1315. if (symtabletype=localsymtable) then
  1316. { to be on the sure side: }
  1317. begin
  1318. if assigned(next) and
  1319. (next^.symtabletype=parasymtable) then
  1320. begin
  1321. hsym:=next^.search(sym^.name);
  1322. if assigned(hsym) then
  1323. DuplicateSym(hsym);
  1324. end
  1325. else if (current_module^.flags and uf_local_browser)=0 then
  1326. internalerror(43789);
  1327. end;
  1328. { check for duplicate id in local symtable of methods }
  1329. if (symtabletype=localsymtable) and
  1330. assigned(next) and
  1331. assigned(next^.next) and
  1332. { funcretsym is allowed !! }
  1333. (sym^.typ <> funcretsym) and
  1334. (next^.next^.symtabletype=objectsymtable) then
  1335. begin
  1336. hsym:=search_class_member(pobjectdef(next^.next^.defowner),sym^.name);
  1337. { but private ids can be reused }
  1338. if assigned(hsym) and
  1339. (not(sp_private in hsym^.symoptions) or
  1340. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1341. DuplicateSym(hsym);
  1342. end;
  1343. { check for duplicate id in para symtable of methods }
  1344. if (symtabletype=parasymtable) and
  1345. assigned(procinfo._class) and
  1346. { but not in nested procedures !}
  1347. (not(assigned(procinfo.parent^._class))) and
  1348. { funcretsym is allowed !! }
  1349. (sym^.typ <> funcretsym) then
  1350. begin
  1351. hsym:=search_class_member(procinfo._class,sym^.name);
  1352. { but private ids can be reused }
  1353. if assigned(hsym) and
  1354. (not(sp_private in hsym^.symoptions) or
  1355. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1356. DuplicateSym(hsym);
  1357. end;
  1358. { check for duplicate field id in inherited classes }
  1359. if (sym^.typ=varsym) and
  1360. (symtabletype=objectsymtable) and
  1361. assigned(defowner) then
  1362. begin
  1363. hsym:=search_class_member(pobjectdef(defowner),sym^.name);
  1364. { but private ids can be reused }
  1365. if assigned(hsym) and
  1366. (not(sp_private in hsym^.symoptions) or
  1367. (hsym^.owner^.defowner^.owner^.symtabletype<>unitsymtable)) then
  1368. DuplicateSym(hsym);
  1369. end;
  1370. { register definition of typesym }
  1371. if (sym^.typ = typesym) and
  1372. assigned(ptypesym(sym)^.definition) then
  1373. begin
  1374. if not(assigned(ptypesym(sym)^.definition^.owner)) and
  1375. (ptypesym(sym)^.definition^.deftype<>errordef) then
  1376. registerdef(ptypesym(sym)^.definition);
  1377. {$ifdef GDB}
  1378. if (cs_debuginfo in aktmoduleswitches) and assigned(debuglist) and
  1379. (symtabletype in [globalsymtable,staticsymtable]) then
  1380. begin
  1381. ptypesym(sym)^.isusedinstab := true;
  1382. sym^.concatstabto(debuglist);
  1383. end;
  1384. {$endif GDB}
  1385. end;
  1386. { insert in index and search hash }
  1387. symindex^.insert(sym);
  1388. symsearch^.insert(sym);
  1389. insert:=sym;
  1390. end;
  1391. function tsymtable.search(const s : stringid) : psym;
  1392. begin
  1393. {search:=psym(symsearch^.search(s));
  1394. this bypasses the ref generation (PM) }
  1395. search:=speedsearch(s,getspeedvalue(s));
  1396. end;
  1397. function tsymtable.speedsearch(const s : stringid;speedvalue : longint) : psym;
  1398. var
  1399. hp : psym;
  1400. begin
  1401. hp:=psym(symsearch^.speedsearch(s,speedvalue));
  1402. if assigned(hp) then
  1403. begin
  1404. { reject non static members in static procedures,
  1405. be carefull aktprocsym^.definition is not allways
  1406. loaded already (PFV) }
  1407. if (symtabletype=objectsymtable) and
  1408. not(sp_static in hp^.symoptions) and
  1409. allow_only_static
  1410. {assigned(aktprocsym) and
  1411. assigned(aktprocsym^.definition) and
  1412. ((aktprocsym^.definition^.options and postaticmethod)<>0)} then
  1413. Message(sym_e_only_static_in_static);
  1414. if (symtabletype=unitsymtable) and
  1415. assigned(punitsymtable(@self)^.unitsym) then
  1416. inc(punitsymtable(@self)^.unitsym^.refs);
  1417. { unitsym are only loaded for browsing PM }
  1418. { this was buggy anyway because we could use }
  1419. { unitsyms from other units in _USES !! }
  1420. if (symtabletype=unitsymtable) and (hp^.typ=unitsym) and
  1421. assigned(current_module) and (current_module^.globalsymtable<>@self) then
  1422. hp:=nil;
  1423. if assigned(hp) and
  1424. (cs_browser in aktmoduleswitches) and make_ref then
  1425. begin
  1426. hp^.lastref:=new(pref,init(hp^.lastref,@tokenpos));
  1427. { for symbols that are in tables without
  1428. browser info or syssyms (PM) }
  1429. if hp^.refcount=0 then
  1430. hp^.defref:=hp^.lastref;
  1431. inc(hp^.refcount);
  1432. end;
  1433. end;
  1434. speedsearch:=hp;
  1435. end;
  1436. function tsymtable.rename(const olds,news : stringid):psym;
  1437. begin
  1438. rename:=psym(symsearch^.rename(olds,news));
  1439. end;
  1440. {***********************************************
  1441. Browser
  1442. ***********************************************}
  1443. procedure tsymtable.load_browser;
  1444. var
  1445. b : byte;
  1446. sym : psym;
  1447. prdef : pdef;
  1448. oldrecsyms : psymtable;
  1449. begin
  1450. if symtabletype in [recordsymtable,objectsymtable,
  1451. parasymtable,localsymtable] then
  1452. begin
  1453. oldrecsyms:=aktrecordsymtable;
  1454. aktrecordsymtable:=@self;
  1455. end;
  1456. if symtabletype=staticppusymtable then
  1457. aktstaticsymtable:=@self;
  1458. b:=current_ppu^.readentry;
  1459. if b <> ibbeginsymtablebrowser then
  1460. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1461. repeat
  1462. b:=current_ppu^.readentry;
  1463. case b of
  1464. ibsymref : begin
  1465. sym:=readsymref;
  1466. resolvesym(sym);
  1467. if assigned(sym) then
  1468. sym^.load_references;
  1469. end;
  1470. ibdefref : begin
  1471. prdef:=readdefref;
  1472. resolvedef(prdef);
  1473. if assigned(prdef) then
  1474. begin
  1475. if prdef^.deftype<>procdef then
  1476. Message(unit_f_ppu_read_error);
  1477. pprocdef(prdef)^.load_references;
  1478. end;
  1479. end;
  1480. ibendsymtablebrowser : break;
  1481. else
  1482. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1483. end;
  1484. until false;
  1485. if symtabletype in [recordsymtable,objectsymtable,
  1486. parasymtable,localsymtable] then
  1487. aktrecordsymtable:=oldrecsyms;
  1488. end;
  1489. procedure tsymtable.write_browser;
  1490. var
  1491. oldrecsyms : psymtable;
  1492. begin
  1493. { symbol numbering for references
  1494. should have been done in write PM
  1495. number_symbols;
  1496. number_defs; }
  1497. if symtabletype in [recordsymtable,objectsymtable,
  1498. parasymtable,localsymtable] then
  1499. begin
  1500. oldrecsyms:=aktrecordsymtable;
  1501. aktrecordsymtable:=@self;
  1502. end;
  1503. current_ppu^.writeentry(ibbeginsymtablebrowser);
  1504. foreach({$ifndef TP}@{$endif}write_refs);
  1505. current_ppu^.writeentry(ibendsymtablebrowser);
  1506. if symtabletype in [recordsymtable,objectsymtable,
  1507. parasymtable,localsymtable] then
  1508. aktrecordsymtable:=oldrecsyms;
  1509. end;
  1510. {$ifdef BrowserLog}
  1511. procedure tsymtable.writebrowserlog;
  1512. begin
  1513. if cs_browser in aktmoduleswitches then
  1514. begin
  1515. if assigned(name) then
  1516. Browserlog.AddLog('---Symtable '+name^)
  1517. else
  1518. begin
  1519. if (symtabletype=recordsymtable) and
  1520. assigned(defowner^.sym) then
  1521. Browserlog.AddLog('---Symtable '+defowner^.sym^.name)
  1522. else
  1523. Browserlog.AddLog('---Symtable with no name');
  1524. end;
  1525. Browserlog.Ident;
  1526. foreach({$ifndef TP}@{$endif}add_to_browserlog);
  1527. browserlog.Unident;
  1528. end;
  1529. end;
  1530. {$endif BrowserLog}
  1531. {***********************************************
  1532. Process all entries
  1533. ***********************************************}
  1534. { checks, if all procsyms and methods are defined }
  1535. procedure tsymtable.check_forwards;
  1536. begin
  1537. foreach({$ifndef TP}@{$endif}check_procsym_forward);
  1538. end;
  1539. procedure tsymtable.checklabels;
  1540. begin
  1541. foreach({$ifndef TP}@{$endif}labeldefined);
  1542. end;
  1543. procedure tsymtable.set_alignment(_alignment : byte);
  1544. var
  1545. sym : pvarsym;
  1546. l : longint;
  1547. begin
  1548. { this can not be done if there is an
  1549. hasharray ! }
  1550. alignment:=_alignment;
  1551. if (symtabletype<>parasymtable) then
  1552. internalerror(1111);
  1553. sym:=pvarsym(symindex^.first);
  1554. datasize:=0;
  1555. { there can be only varsyms }
  1556. while assigned(sym) do
  1557. begin
  1558. l:=sym^.getpushsize;
  1559. sym^.address:=datasize;
  1560. datasize:=align(datasize+l,alignment);
  1561. sym:=pvarsym(sym^.next);
  1562. end;
  1563. end;
  1564. function tsymtable.find_at_offset(l : longint) : pvarsym;
  1565. var
  1566. sym : pvarsym;
  1567. begin
  1568. find_at_offset:=nil;
  1569. { this can not be done if there is an
  1570. hasharray ! }
  1571. if (symtabletype<>parasymtable) then
  1572. internalerror(1111);
  1573. sym:=pvarsym(symindex^.first);
  1574. while assigned(sym) do
  1575. begin
  1576. if sym^.address+address_fixup=l then
  1577. begin
  1578. find_at_offset:=sym;
  1579. exit;
  1580. end;
  1581. sym:=pvarsym(sym^.next);
  1582. end;
  1583. end;
  1584. procedure tsymtable.allunitsused;
  1585. begin
  1586. foreach({$ifndef TP}@{$endif}unitsymbolused);
  1587. end;
  1588. procedure tsymtable.allsymbolsused;
  1589. begin
  1590. foreach({$ifndef TP}@{$endif}varsymbolused);
  1591. end;
  1592. {$ifdef CHAINPROCSYMS}
  1593. procedure tsymtable.chainprocsyms;
  1594. begin
  1595. foreach({$ifndef TP}@{$endif}chainprocsym);
  1596. end;
  1597. {$endif CHAINPROCSYMS}
  1598. {$ifdef GDB}
  1599. procedure tsymtable.concatstabto(asmlist : paasmoutput);
  1600. begin
  1601. asmoutput:=asmlist;
  1602. foreach({$ifndef TP}@{$endif}concatstab);
  1603. end;
  1604. {$endif}
  1605. {****************************************************************************
  1606. TUNITSYMTABLE
  1607. ****************************************************************************}
  1608. constructor tunitsymtable.init(t : tsymtabletype; const n : string);
  1609. begin
  1610. inherited init(t);
  1611. name:=stringdup(upper(n));
  1612. unitid:=0;
  1613. unitsym:=nil;
  1614. symsearch^.usehash;
  1615. { reset GDB things }
  1616. {$ifdef GDB}
  1617. if t = globalsymtable then
  1618. begin
  1619. prev_dbx_counter := dbx_counter;
  1620. dbx_counter := @dbx_count;
  1621. end;
  1622. is_stab_written:=false;
  1623. if cs_gdb_dbx in aktglobalswitches then
  1624. begin
  1625. dbx_count := 0;
  1626. if (symtabletype=globalsymtable) then
  1627. pglobaltypecount := @unittypecount;
  1628. debuglist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'+tostr(N_BINCL)+',0,0,0'))));
  1629. unitid:=current_module^.unitcount;
  1630. inc(current_module^.unitcount);
  1631. debuglist^.concat(new(pai_asm_comment,init(strpnew('Global '+name^+' has index '+tostr(unitid)))));
  1632. end;
  1633. {$endif GDB}
  1634. end;
  1635. constructor tunitsymtable.loadasunit;
  1636. var
  1637. storeGlobalTypeCount : pword;
  1638. b : byte;
  1639. begin
  1640. unitsym:=nil;
  1641. unitid:=0;
  1642. if (current_module^.flags and uf_has_dbx)<>0 then
  1643. begin
  1644. storeGlobalTypeCount:=PGlobalTypeCount;
  1645. PglobalTypeCount:=@UnitTypeCount;
  1646. end;
  1647. { load symtables }
  1648. inherited load;
  1649. { set the name after because it is set to nil in tsymtable.load !! }
  1650. name:=stringdup(current_module^.modulename^);
  1651. { dbx count }
  1652. {$ifdef GDB}
  1653. if (current_module^.flags and uf_has_dbx)<>0 then
  1654. begin
  1655. b := current_ppu^.readentry;
  1656. if b <> ibdbxcount then
  1657. Message(unit_f_ppu_dbx_count_problem)
  1658. else
  1659. dbx_count := readlong;
  1660. dbx_count_ok := true;
  1661. PGlobalTypeCount:=storeGlobalTypeCount;
  1662. end
  1663. else
  1664. dbx_count := 0;
  1665. is_stab_written:=false;
  1666. {$endif GDB}
  1667. b:=current_ppu^.readentry;
  1668. if b<>ibendimplementation then
  1669. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1670. end;
  1671. destructor tunitsymtable.done;
  1672. var
  1673. pus : punitsym;
  1674. begin
  1675. pus:=unitsym;
  1676. while assigned(pus) do
  1677. begin
  1678. unitsym:=pus^.prevsym;
  1679. pus^.prevsym:=nil;
  1680. pus^.unitsymtable:=nil;
  1681. pus:=unitsym;
  1682. end;
  1683. inherited done;
  1684. end;
  1685. procedure tunitsymtable.load_symtable_refs;
  1686. var
  1687. b : byte;
  1688. unitindex : word;
  1689. begin
  1690. if ((current_module^.flags and uf_local_browser)<>0) then
  1691. begin
  1692. current_module^.localsymtable:=new(punitsymtable,loadas(staticppusymtable));
  1693. psymtable(current_module^.localsymtable)^.name:=
  1694. stringdup('implementation of '+psymtable(current_module^.globalsymtable)^.name^);
  1695. end;
  1696. { load browser }
  1697. if (current_module^.flags and uf_has_browser)<>0 then
  1698. begin
  1699. {if not (cs_browser in aktmoduleswitches) then
  1700. current_ppu^.skipuntilentry(ibendbrowser)
  1701. else }
  1702. begin
  1703. load_browser;
  1704. unitindex:=1;
  1705. while assigned(current_module^.map^[unitindex]) do
  1706. begin
  1707. {each unit wrote one browser entry }
  1708. load_browser;
  1709. inc(unitindex);
  1710. end;
  1711. b:=current_ppu^.readentry;
  1712. if b<>ibendbrowser then
  1713. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1714. end;
  1715. end;
  1716. if ((current_module^.flags and uf_local_browser)<>0) then
  1717. psymtable(current_module^.localsymtable)^.load_browser;
  1718. end;
  1719. procedure tunitsymtable.writeasunit;
  1720. var
  1721. pu : pused_unit;
  1722. begin
  1723. { first the unitname }
  1724. current_ppu^.putstring(name^);
  1725. current_ppu^.writeentry(ibmodulename);
  1726. writesourcefiles;
  1727. writeusedmacros;
  1728. writeusedunit;
  1729. { write the objectfiles and libraries that come for this unit,
  1730. preserve the containers becuase they are still needed to load
  1731. the link.res. All doesn't depend on the crc! It doesn't matter
  1732. if a unit is in a .o or .a file }
  1733. current_ppu^.do_crc:=false;
  1734. writelinkcontainer(current_module^.linkunitofiles,iblinkunitofiles,true);
  1735. writelinkcontainer(current_module^.linkunitstaticlibs,iblinkunitstaticlibs,true);
  1736. writelinkcontainer(current_module^.linkunitsharedlibs,iblinkunitsharedlibs,true);
  1737. writelinkcontainer(current_module^.linkotherofiles,iblinkotherofiles,false);
  1738. writelinkcontainer(current_module^.linkotherstaticlibs,iblinkotherstaticlibs,true);
  1739. writelinkcontainer(current_module^.linkothersharedlibs,iblinkothersharedlibs,true);
  1740. current_ppu^.do_crc:=true;
  1741. current_ppu^.writeentry(ibendinterface);
  1742. { write the symtable entries }
  1743. inherited write;
  1744. { write dbx count }
  1745. {$ifdef GDB}
  1746. if cs_gdb_dbx in aktglobalswitches then
  1747. begin
  1748. {$IfDef EXTDEBUG}
  1749. writeln('Writing dbx_count ',dbx_count,' in unit ',name^,'.ppu');
  1750. {$ENDIF EXTDEBUG}
  1751. current_ppu^.putlongint(dbx_count);
  1752. current_ppu^.writeentry(ibdbxcount);
  1753. end;
  1754. {$endif GDB}
  1755. current_ppu^.writeentry(ibendimplementation);
  1756. { all after doesn't affect crc }
  1757. current_ppu^.do_crc:=false;
  1758. { write static symtable
  1759. needed for local debugging of unit functions }
  1760. if ((current_module^.flags and uf_local_browser)<>0) and
  1761. assigned(current_module^.localsymtable) then
  1762. psymtable(current_module^.localsymtable)^.write;
  1763. { write all browser section }
  1764. if (current_module^.flags and uf_has_browser)<>0 then
  1765. begin
  1766. write_browser;
  1767. pu:=pused_unit(current_module^.used_units.first);
  1768. while assigned(pu) do
  1769. begin
  1770. psymtable(pu^.u^.globalsymtable)^.write_browser;
  1771. pu:=pused_unit(pu^.next);
  1772. end;
  1773. current_ppu^.writeentry(ibendbrowser);
  1774. end;
  1775. if ((current_module^.flags and uf_local_browser)<>0) and
  1776. assigned(current_module^.localsymtable) then
  1777. psymtable(current_module^.localsymtable)^.write_browser;
  1778. { the last entry ibend is written automaticly }
  1779. end;
  1780. function tunitsymtable.getnewtypecount : word;
  1781. begin
  1782. {$ifdef GDB}
  1783. if not (cs_gdb_dbx in aktglobalswitches) then
  1784. getnewtypecount:=tsymtable.getnewtypecount
  1785. else
  1786. {$endif GDB}
  1787. if symtabletype = staticsymtable then
  1788. getnewtypecount:=tsymtable.getnewtypecount
  1789. else
  1790. begin
  1791. getnewtypecount:=unittypecount;
  1792. inc(unittypecount);
  1793. end;
  1794. end;
  1795. {$ifdef GDB}
  1796. procedure tunitsymtable.concattypestabto(asmlist : paasmoutput);
  1797. var prev_dbx_count : plongint;
  1798. begin
  1799. if is_stab_written then exit;
  1800. if not assigned(name) then name := stringdup('Main_program');
  1801. if symtabletype = unitsymtable then
  1802. begin
  1803. unitid:=current_module^.unitcount;
  1804. inc(current_module^.unitcount);
  1805. end;
  1806. asmlist^.concat(new(pai_asm_comment,init(strpnew('Begin unit '+name^
  1807. +' has index '+tostr(unitid)))));
  1808. if cs_gdb_dbx in aktglobalswitches then
  1809. begin
  1810. if dbx_count_ok then
  1811. begin
  1812. asmlist^.insert(new(pai_asm_comment,init(strpnew('"repeated" unit '+name^
  1813. +' has index '+tostr(unitid)))));
  1814. do_count_dbx:=true;
  1815. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1816. +tostr(N_EXCL)+',0,0,'+tostr(dbx_count)))));
  1817. exit;
  1818. end;
  1819. prev_dbx_count := dbx_counter;
  1820. dbx_counter := nil;
  1821. if symtabletype = unitsymtable then
  1822. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1823. +tostr(N_BINCL)+',0,0,0'))));
  1824. dbx_counter := @dbx_count;
  1825. end;
  1826. asmoutput:=asmlist;
  1827. foreach({$ifndef TP}@{$endif}concattypestab);
  1828. if cs_gdb_dbx in aktglobalswitches then
  1829. begin
  1830. dbx_counter := prev_dbx_count;
  1831. do_count_dbx:=true;
  1832. asmlist^.concat(new(pai_stabs,init(strpnew('"'+name^+'",'
  1833. +tostr(N_EINCL)+',0,0,0'))));
  1834. dbx_count_ok := true;
  1835. end;
  1836. asmlist^.concat(new(pai_asm_comment,init(strpnew('End unit '+name^
  1837. +' has index '+tostr(unitid)))));
  1838. is_stab_written:=true;
  1839. end;
  1840. {$endif}
  1841. {****************************************************************************
  1842. Definitions
  1843. ****************************************************************************}
  1844. {$I symdef.inc}
  1845. {****************************************************************************
  1846. Symbols
  1847. ****************************************************************************}
  1848. {$I symsym.inc}
  1849. {****************************************************************************
  1850. GDB Helpers
  1851. ****************************************************************************}
  1852. {$ifdef GDB}
  1853. function typeglobalnumber(const s : string) : string;
  1854. var st : string;
  1855. symt : psymtable;
  1856. old_make_ref : boolean;
  1857. begin
  1858. old_make_ref:=make_ref;
  1859. make_ref:=false;
  1860. typeglobalnumber := '0';
  1861. srsym := nil;
  1862. if pos('.',s) > 0 then
  1863. begin
  1864. st := copy(s,1,pos('.',s)-1);
  1865. getsym(st,false);
  1866. st := copy(s,pos('.',s)+1,255);
  1867. if assigned(srsym) then
  1868. begin
  1869. if srsym^.typ = unitsym then
  1870. begin
  1871. symt := punitsym(srsym)^.unitsymtable;
  1872. srsym := symt^.search(st);
  1873. end else srsym := nil;
  1874. end;
  1875. end else st := s;
  1876. if srsym = nil then getsym(st,true);
  1877. if srsym^.typ<>typesym then
  1878. begin
  1879. Message(type_e_type_id_expected);
  1880. exit;
  1881. end;
  1882. typeglobalnumber := ptypesym(srsym)^.definition^.numberstring;
  1883. make_ref:=old_make_ref;
  1884. end;
  1885. {$endif GDB}
  1886. {****************************************************************************
  1887. Definition Helpers
  1888. ****************************************************************************}
  1889. procedure reset_global_defs;
  1890. var
  1891. def : pdef;
  1892. {$ifdef debug}
  1893. prevdef : pdef;
  1894. {$endif debug}
  1895. begin
  1896. {$ifdef debug}
  1897. prevdef:=nil;
  1898. {$endif debug}
  1899. {$ifdef GDB}
  1900. pglobaltypecount:=@globaltypecount;
  1901. {$endif GDB}
  1902. def:=firstglobaldef;
  1903. while assigned(def) do
  1904. begin
  1905. {$ifdef GDB}
  1906. if assigned(def^.sym) then
  1907. def^.sym^.isusedinstab:=false;
  1908. def^.is_def_stab_written:=false;
  1909. {$endif GDB}
  1910. {if not current_module^.in_implementation then}
  1911. begin
  1912. { reset rangenr's }
  1913. case def^.deftype of
  1914. orddef : porddef(def)^.rangenr:=0;
  1915. enumdef : penumdef(def)^.rangenr:=0;
  1916. arraydef : parraydef(def)^.rangenr:=0;
  1917. end;
  1918. if def^.deftype<>objectdef then
  1919. def^.has_rtti:=false;
  1920. def^.has_inittable:=false;
  1921. end;
  1922. {$ifdef debug}
  1923. prevdef:=def;
  1924. {$endif debug}
  1925. def:=def^.nextglobal;
  1926. end;
  1927. end;
  1928. {****************************************************************************
  1929. Object Helpers
  1930. ****************************************************************************}
  1931. function search_class_member(pd : pobjectdef;const n : string) : psym;
  1932. { searches n in symtable of pd and all anchestors }
  1933. var
  1934. sym : psym;
  1935. begin
  1936. sym:=nil;
  1937. while assigned(pd) do
  1938. begin
  1939. sym:=pd^.symtable^.search(n);
  1940. if assigned(sym) then
  1941. break;
  1942. pd:=pd^.childof;
  1943. end;
  1944. { this is needed for static methods in do_member_read pexpr unit PM
  1945. caused bug0214 }
  1946. if assigned(sym) then
  1947. begin
  1948. srsymtable:=pd^.symtable;
  1949. end;
  1950. search_class_member:=sym;
  1951. end;
  1952. var
  1953. _defaultprop : ppropertysym;
  1954. procedure testfordefaultproperty(p : pnamedindexobject);
  1955. begin
  1956. if (psym(p)^.typ=propertysym) and
  1957. (ppo_defaultproperty in ppropertysym(p)^.propoptions) then
  1958. _defaultprop:=ppropertysym(p);
  1959. end;
  1960. function search_default_property(pd : pobjectdef) : ppropertysym;
  1961. { returns the default property of a class, searches also anchestors }
  1962. begin
  1963. _defaultprop:=nil;
  1964. while assigned(pd) do
  1965. begin
  1966. pd^.symtable^.foreach({$ifndef TP}@{$endif}testfordefaultproperty);
  1967. if assigned(_defaultprop) then
  1968. break;
  1969. pd:=pd^.childof;
  1970. end;
  1971. search_default_property:=_defaultprop;
  1972. end;
  1973. {****************************************************************************
  1974. Macro's
  1975. ****************************************************************************}
  1976. procedure def_macro(const s : string);
  1977. var
  1978. mac : pmacrosym;
  1979. begin
  1980. mac:=pmacrosym(macros^.search(s));
  1981. if mac=nil then
  1982. begin
  1983. mac:=new(pmacrosym,init(s));
  1984. Message1(parser_m_macro_defined,mac^.name);
  1985. macros^.insert(mac);
  1986. end;
  1987. mac^.defined:=true;
  1988. mac^.defined_at_startup:=true;
  1989. end;
  1990. procedure set_macro(const s : string;value : string);
  1991. var
  1992. mac : pmacrosym;
  1993. begin
  1994. mac:=pmacrosym(macros^.search(s));
  1995. if mac=nil then
  1996. begin
  1997. mac:=new(pmacrosym,init(s));
  1998. macros^.insert(mac);
  1999. end
  2000. else
  2001. begin
  2002. if assigned(mac^.buftext) then
  2003. freemem(mac^.buftext,mac^.buflen);
  2004. end;
  2005. Message2(parser_m_macro_set_to,mac^.name,value);
  2006. mac^.buflen:=length(value);
  2007. getmem(mac^.buftext,mac^.buflen);
  2008. move(value[1],mac^.buftext^,mac^.buflen);
  2009. mac^.defined:=true;
  2010. mac^.defined_at_startup:=true;
  2011. end;
  2012. {****************************************************************************
  2013. Symtable Stack
  2014. ****************************************************************************}
  2015. procedure dellexlevel;
  2016. var
  2017. p : psymtable;
  2018. begin
  2019. p:=symtablestack;
  2020. symtablestack:=p^.next;
  2021. { symbol tables of unit interfaces are never disposed }
  2022. { this is handle by the unit unitm }
  2023. if not(p^.symtabletype in [unitsymtable,globalsymtable,stt_exceptsymtable]) or dispose_global then
  2024. dispose(p,done);
  2025. end;
  2026. {$ifdef DEBUG}
  2027. procedure test_symtablestack;
  2028. var
  2029. p : psymtable;
  2030. i : longint;
  2031. begin
  2032. p:=symtablestack;
  2033. i:=0;
  2034. while assigned(p) do
  2035. begin
  2036. inc(i);
  2037. p:=p^.next;
  2038. if i>500 then
  2039. Message(sym_f_internal_error_in_symtablestack);
  2040. end;
  2041. end;
  2042. procedure list_symtablestack;
  2043. var
  2044. p : psymtable;
  2045. i : longint;
  2046. begin
  2047. p:=symtablestack;
  2048. i:=0;
  2049. while assigned(p) do
  2050. begin
  2051. inc(i);
  2052. writeln(i,' ',p^.name^);
  2053. p:=p^.next;
  2054. if i>500 then
  2055. Message(sym_f_internal_error_in_symtablestack);
  2056. end;
  2057. end;
  2058. {$endif DEBUG}
  2059. {****************************************************************************
  2060. Init/Done Symtable
  2061. ****************************************************************************}
  2062. {$ifndef Delphi}
  2063. {$ifdef tp}
  2064. procedure do_streamerror;
  2065. begin
  2066. if symbolstream.status=-2 then
  2067. WriteLn('Error: Not enough EMS memory')
  2068. else
  2069. WriteLn('Error: EMS Error ',symbolstream.status);
  2070. halt(1);
  2071. end;
  2072. {$endif TP}
  2073. {$endif Delphi}
  2074. procedure InitSymtable;
  2075. begin
  2076. {$ifndef Delphi}
  2077. {$ifdef TP}
  2078. { Allocate stream }
  2079. if use_big then
  2080. begin
  2081. streamerror:=@do_streamerror;
  2082. { symbolstream.init('TMPFILE',stcreate,16000); }
  2083. {$ifndef dpmi}
  2084. symbolstream.init(10000,4000000); {using ems streams}
  2085. {$else}
  2086. symbolstream.init(1000000,16000); {using memory streams}
  2087. {$endif}
  2088. if symbolstream.errorinfo=stiniterror then
  2089. do_streamerror;
  2090. { write something, because pos 0 means nil pointer }
  2091. symbolstream.writestr(@inputfile);
  2092. end;
  2093. {$endif tp}
  2094. {$endif Delphi}
  2095. { Reset symbolstack }
  2096. registerdef:=false;
  2097. read_member:=false;
  2098. symtablestack:=nil;
  2099. systemunit:=nil;
  2100. objpasunit:=nil;
  2101. sroot:=nil;
  2102. {$ifdef GDB}
  2103. firstglobaldef:=nil;
  2104. lastglobaldef:=nil;
  2105. {$endif GDB}
  2106. globaltypecount:=1;
  2107. pglobaltypecount:=@globaltypecount;
  2108. { create error syms and def }
  2109. generrorsym:=new(perrorsym,init);
  2110. generrordef:=new(perrordef,init);
  2111. end;
  2112. procedure DoneSymtable;
  2113. begin
  2114. dispose(generrorsym,done);
  2115. dispose(generrordef,done);
  2116. { unload all symtables
  2117. done with loaded_units
  2118. dispose_global:=true;
  2119. while assigned(symtablestack) do
  2120. dellexlevel; }
  2121. {$ifndef Delphi}
  2122. {$ifdef TP}
  2123. { close the stream }
  2124. if use_big then
  2125. symbolstream.done;
  2126. {$endif}
  2127. {$endif Delphi}
  2128. end;
  2129. end.
  2130. {
  2131. $Log$
  2132. Revision 1.47 1999-09-12 08:48:09 florian
  2133. * bugs 593 and 607 fixed
  2134. * some other potential bugs with array constructors fixed
  2135. * for classes compiled in $M+ and it's childs, the default access method
  2136. is now published
  2137. * fixed copyright message (it is now 1993-99)
  2138. Revision 1.46 1999/09/10 18:48:10 florian
  2139. * some bug fixes (e.g. must_be_valid and procinfo.funcret_is_valid)
  2140. * most things for stored properties fixed
  2141. Revision 1.45 1999/09/08 08:05:44 peter
  2142. * fixed bug 248
  2143. Revision 1.44 1999/08/31 15:46:21 pierre
  2144. * do_crc must be false for all browser stuff
  2145. + tmacrosym defined_at_startup set in def_macro and set_macro
  2146. Revision 1.43 1999/08/27 10:39:24 pierre
  2147. * uf_local_browser made problem when computing interface CRC
  2148. Revision 1.42 1999/08/13 21:33:13 peter
  2149. * support for array constructors extended and more error checking
  2150. Revision 1.41 1999/08/13 14:24:22 pierre
  2151. + stabs for classes and classref working,
  2152. a class still needs an ^ to get that content of it,
  2153. but the class fields inside a class don't result into an
  2154. infinite loop anymore!
  2155. Revision 1.40 1999/08/10 16:25:42 pierre
  2156. * unitid changed to word
  2157. Revision 1.39 1999/08/10 12:33:36 pierre
  2158. * pprocsym defined earlier for use in tprocdef
  2159. Revision 1.38 1999/08/05 16:53:18 peter
  2160. * V_Fatal=1, all other V_ are also increased
  2161. * Check for local procedure when assigning procvar
  2162. * fixed comment parsing because directives
  2163. * oldtp mode directives better supported
  2164. * added some messages to errore.msg
  2165. Revision 1.37 1999/08/04 13:03:09 jonas
  2166. * all tokens now start with an underscore
  2167. * PowerPC compiles!!
  2168. Revision 1.36 1999/08/04 00:23:31 florian
  2169. * renamed i386asm and i386base to cpuasm and cpubase
  2170. Revision 1.35 1999/08/03 22:03:22 peter
  2171. * moved bitmask constants to sets
  2172. * some other type/const renamings
  2173. Revision 1.34 1999/08/03 17:51:45 florian
  2174. * reduced memory usage by factor 2-3 (it
  2175. improved also the speed) by reducing the
  2176. growsize of the symbol tables
  2177. Revision 1.33 1999/08/03 00:03:24 florian
  2178. * added bestrealdef for alpha and powerpc
  2179. Revision 1.32 1999/08/01 23:09:27 michael
  2180. * procbase -> cpubase
  2181. Revision 1.31 1999/08/01 23:04:50 michael
  2182. + Changes for Alpha
  2183. Revision 1.30 1999/07/24 00:13:26 peter
  2184. * also number units for program
  2185. Revision 1.29 1999/07/23 16:05:33 peter
  2186. * alignment is now saved in the symtable
  2187. * C alignment added for records
  2188. * PPU version increased to solve .12 <-> .13 probs
  2189. Revision 1.28 1999/07/23 12:02:20 peter
  2190. * fixed crash in previous commit
  2191. Revision 1.27 1999/07/23 11:37:50 peter
  2192. * error for illegal type reference, instead of 10998
  2193. Revision 1.26 1999/07/22 09:37:58 florian
  2194. + resourcestring implemented
  2195. + start of longstring support
  2196. Revision 1.25 1999/07/18 14:47:34 florian
  2197. * bug 487 fixed, (inc(<property>) isn't allowed)
  2198. * more fixes to compile with Delphi
  2199. Revision 1.24 1999/07/03 00:30:01 peter
  2200. * new link writing to the ppu, one .ppu is needed for all link types,
  2201. static (.o) is now always created also when smartlinking is used
  2202. Revision 1.23 1999/06/28 17:02:44 pierre
  2203. merged from v0-99-12 branch
  2204. Revision 1.21.2.2 1999/06/28 16:59:55 pierre
  2205. * fix to get method reference info
  2206. Revision 1.21.2.1 1999/06/22 16:26:46 pierre
  2207. * local browser stuff corrected
  2208. Revision 1.21 1999/06/08 22:23:50 pierre
  2209. * staticppusymtable was loaded a tsymtable instead of tunitsymtable
  2210. Revision 1.20 1999/06/02 22:44:23 pierre
  2211. * previous wrong log corrected
  2212. Revision 1.19 1999/06/02 22:25:53 pierre
  2213. * changed $ifdef FPC @ into $ifndef TP
  2214. Revision 1.18 1999/06/01 14:45:58 peter
  2215. * @procvar is now always needed for FPC
  2216. Revision 1.17 1999/05/27 19:45:08 peter
  2217. * removed oldasm
  2218. * plabel -> pasmlabel
  2219. * -a switches to source writing automaticly
  2220. * assembler readers OOPed
  2221. * asmsymbol automaticly external
  2222. * jumptables and other label fixes for asm readers
  2223. Revision 1.16 1999/05/23 18:42:16 florian
  2224. * better error recovering in typed constants
  2225. * some problems with arrays of const fixed, some problems
  2226. due my previous
  2227. - the location type of array constructor is now LOC_MEM
  2228. - the pushing of high fixed
  2229. - parameter copying fixed
  2230. - zero temp. allocation removed
  2231. * small problem in the assembler writers fixed:
  2232. ref to nil wasn't written correctly
  2233. Revision 1.15 1999/05/17 23:51:41 peter
  2234. * with temp vars now use a reference with a persistant temp instead
  2235. of setting datasize
  2236. Revision 1.14 1999/05/14 17:52:29 peter
  2237. * new deref code
  2238. Revision 1.13 1999/05/13 21:59:48 peter
  2239. * removed oldppu code
  2240. * warning if objpas is loaded from uses
  2241. * first things for new deref writing
  2242. Revision 1.12 1999/05/10 22:34:59 pierre
  2243. * one more unitsym problem fix
  2244. Revision 1.11 1999/05/10 15:02:51 pierre
  2245. unitsym finally problem fixed
  2246. Revision 1.10 1999/05/09 12:46:26 peter
  2247. + hint where a duplicate sym is already defined
  2248. Revision 1.9 1999/05/08 19:52:40 peter
  2249. + MessagePos() which is enhanced Message() function but also gets the
  2250. position info
  2251. * Removed comp warnings
  2252. Revision 1.8 1999/05/06 21:38:38 peter
  2253. * don't register errordef
  2254. Revision 1.7 1999/05/06 09:05:31 peter
  2255. * generic write_float and str_float
  2256. * fixed constant float conversions
  2257. Revision 1.6 1999/05/05 09:19:16 florian
  2258. * more fixes to get it with delphi running
  2259. Revision 1.5 1999/05/01 13:24:43 peter
  2260. * merged nasm compiler
  2261. * old asm moved to oldasm/
  2262. Revision 1.4 1999/04/29 17:25:37 peter
  2263. * small fix for deref
  2264. Revision 1.3 1999/04/26 18:30:03 peter
  2265. * farpointerdef moved into pointerdef.is_far
  2266. Revision 1.151 1999/04/26 13:31:54 peter
  2267. * release storenumber,double_checksum
  2268. Revision 1.150 1999/04/25 17:36:13 peter
  2269. * typo fix for storenumber
  2270. Revision 1.149 1999/04/21 22:05:28 pierre
  2271. + tsymtable.find_at_offset function
  2272. used by ra386att to give arg name from ebp offset with -vz option
  2273. Revision 1.148 1999/04/21 16:31:44 pierre
  2274. ra386att.pas : commit problem !
  2275. Revision 1.147 1999/04/21 09:43:57 peter
  2276. * storenumber works
  2277. * fixed some typos in double_checksum
  2278. + incompatible types type1 and type2 message (with storenumber)
  2279. Revision 1.146 1999/04/19 09:33:14 pierre
  2280. + added tsymtable.set_alignment(longint) function
  2281. to change the offsets of all function args
  2282. if declared as cdecl or stdcall
  2283. (this must be done after because the cdecl is parsed after
  2284. insertion of the function parameterss into parast symboltable)
  2285. Revision 1.145 1999/04/17 13:16:24 peter
  2286. * fixes for storenumber
  2287. Revision 1.144 1999/04/15 10:01:45 peter
  2288. * small update for storenumber
  2289. Revision 1.143 1999/04/14 09:15:04 peter
  2290. * first things to store the symbol/def number in the ppu
  2291. Revision 1.142 1999/04/08 14:54:10 pierre
  2292. * suppression of val para unused warnings
  2293. Revision 1.141 1999/04/07 15:31:09 pierre
  2294. * all formaldefs are now a sinlge definition
  2295. cformaldef (this was necessary for double_checksum)
  2296. + small part of double_checksum code
  2297. Revision 1.140 1999/03/31 13:55:24 peter
  2298. * assembler inlining working for ag386bin
  2299. Revision 1.139 1999/03/24 23:17:30 peter
  2300. * fixed bugs 212,222,225,227,229,231,233
  2301. Revision 1.138 1999/03/21 22:49:11 florian
  2302. * private ids of objects can be reused in child classes
  2303. if they are in another unit
  2304. Revision 1.137 1999/03/17 22:23:20 florian
  2305. * a FPC compiled compiler checks now also in debug mode in assigned
  2306. if a pointer points to the heap
  2307. * when a symtable is loaded, there is no need to check for duplicate
  2308. symbols. This leads to crashes because defowner isn't assigned
  2309. in this case
  2310. Revision 1.136 1999/03/01 13:45:07 pierre
  2311. + added staticppusymtable symtable type for local browsing
  2312. Revision 1.135 1999/02/23 18:29:28 pierre
  2313. * win32 compilation error fix
  2314. + some work for local browser (not cl=omplete yet)
  2315. Revision 1.134 1999/02/22 15:09:42 florian
  2316. * behaviaor of PROTECTED and PRIVATE fixed, works now like TP/Delphi
  2317. Revision 1.133 1999/02/22 13:07:12 pierre
  2318. + -b and -bl options work !
  2319. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2320. is not enabled when quitting global section
  2321. * local vars and procedures are not yet stored into PPU
  2322. Revision 1.132 1999/02/22 02:15:40 peter
  2323. * updates for ag386bin
  2324. Revision 1.131 1999/02/16 00:44:34 peter
  2325. * tp7 fix, assigned() can only be used on vars, not on functions
  2326. Revision 1.130 1999/02/15 13:13:16 pierre
  2327. * fix for bug0216
  2328. Revision 1.129 1999/02/11 09:46:29 pierre
  2329. * fix for normal method calls inside static methods :
  2330. WARNING there were both parser and codegen errors !!
  2331. added static_call boolean to calln tree
  2332. Revision 1.128 1999/02/09 23:03:05 florian
  2333. * check for duplicate field names in inherited classes/objects
  2334. * bug with self from the mailing list solved (the problem
  2335. was that classes were sometimes pushed wrong)
  2336. Revision 1.127 1999/02/08 11:29:06 pierre
  2337. * fix for bug0214
  2338. several problems where combined
  2339. search_class_member did not set srsymtable
  2340. => in do_member_read the call node got a wrong symtable
  2341. in cg386cal the vmt was pushed twice without chacking if it exists
  2342. now %esi is set to zero and pushed if not vmt
  2343. (not very efficient but should work !)
  2344. Revision 1.126 1999/02/05 08:54:31 pierre
  2345. + linkofiles splitted inot linkofiles and linkunitfiles
  2346. because linkofiles must be stored with directory
  2347. to enabled linking of different objects with same name
  2348. in a different directory
  2349. Revision 1.125 1999/02/03 09:44:33 pierre
  2350. * symbol nubering begins with 1 in number_symbols
  2351. * program tmodule has globalsymtable for its staticsymtable
  2352. (to get it displayed in IDE globals list)
  2353. + list of symbol (browcol) greatly improved for IDE
  2354. Revision 1.124 1999/01/27 12:58:33 pierre
  2355. * unused var warning suppressed for high of open arrays
  2356. Revision 1.123 1999/01/21 16:41:03 pierre
  2357. * fix for constructor inside with statements
  2358. Revision 1.122 1999/01/20 10:16:44 peter
  2359. * don't update crc when writing objs,libs and sources
  2360. Revision 1.121 1999/01/14 21:50:00 peter
  2361. * fixed forwardpointer problem with multiple forwards for the same
  2362. typesym. It now uses a linkedlist instead of a single pointer
  2363. Revision 1.120 1999/01/13 14:29:22 daniel
  2364. * nonextfield repaired
  2365. Revision 1.119 1999/01/12 14:25:38 peter
  2366. + BrowserLog for browser.log generation
  2367. + BrowserCol for browser info in TCollections
  2368. * released all other UseBrowser
  2369. Revision 1.118 1999/01/05 08:20:10 florian
  2370. * mainly problem with invalid case ranges fixed (reported by Jonas)
  2371. Revision 1.117 1998/12/30 22:15:57 peter
  2372. + farpointer type
  2373. * absolutesym now also stores if its far
  2374. Revision 1.116 1998/12/30 13:41:16 peter
  2375. * released valuepara
  2376. Revision 1.115 1998/12/11 00:03:48 peter
  2377. + globtype,tokens,version unit splitted from globals
  2378. Revision 1.114 1998/12/10 09:47:29 florian
  2379. + basic operations with int64/qord (compiler with -dint64)
  2380. + rtti of enumerations extended: names are now written
  2381. Revision 1.113 1998/12/08 10:18:17 peter
  2382. + -gh for heaptrc unit
  2383. Revision 1.112 1998/12/04 10:18:10 florian
  2384. * some stuff for procedures of object added
  2385. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  2386. Revision 1.111 1998/11/30 16:34:46 pierre
  2387. * corrected problems with rangecheck
  2388. + added needed code for no rangecheck in CRC32 functions in ppu unit
  2389. * enumdef lso need its rangenr reset to zero
  2390. when calling reset_global_defs
  2391. Revision 1.110 1998/11/28 16:20:58 peter
  2392. + support for dll variables
  2393. Revision 1.109 1998/11/27 14:50:49 peter
  2394. + open strings, $P switch support
  2395. Revision 1.108 1998/11/24 23:00:32 peter
  2396. * small crash prevention
  2397. Revision 1.107 1998/11/20 15:36:01 florian
  2398. * problems with rtti fixed, hope it works
  2399. Revision 1.106 1998/11/18 15:44:20 peter
  2400. * VALUEPARA for tp7 compatible value parameters
  2401. Revision 1.105 1998/11/17 10:39:18 peter
  2402. * has_rtti,has_inittable reset
  2403. Revision 1.104 1998/11/16 10:13:52 peter
  2404. * label defines are checked at the end of the proc
  2405. Revision 1.103 1998/11/13 15:40:32 pierre
  2406. + added -Se in Makefile cvstest target
  2407. + lexlevel cleanup
  2408. normal_function_level main_program_level and unit_init_level defined
  2409. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2410. (test added in code !)
  2411. * -Un option was wrong
  2412. * _FAIL and _SELF only keyword inside
  2413. constructors and methods respectively
  2414. Revision 1.102 1998/11/12 16:43:34 florian
  2415. * functions with ansi strings as result didn't work, solved
  2416. Revision 1.101 1998/11/12 12:55:18 pierre
  2417. * fix for bug0176 and bug0177
  2418. Revision 1.100 1998/11/10 10:09:15 peter
  2419. * va_list -> array of const
  2420. Revision 1.99 1998/11/09 11:44:38 peter
  2421. + va_list for printf support
  2422. Revision 1.98 1998/11/05 23:33:35 peter
  2423. * symtable.done sets vars to nil
  2424. Revision 1.97 1998/11/05 12:03:00 peter
  2425. * released useansistring
  2426. * removed -Sv, its now available in fpc modes
  2427. Revision 1.96 1998/10/28 18:26:19 pierre
  2428. * removed some erros after other errors (introduced by useexcept)
  2429. * stabs works again correctly (for how long !)
  2430. Revision 1.95 1998/10/21 08:40:01 florian
  2431. + ansistring operator +
  2432. + $h and string[n] for n>255 added
  2433. * small problem with TP fixed
  2434. Revision 1.94 1998/10/20 08:07:03 pierre
  2435. * several memory corruptions due to double freemem solved
  2436. => never use p^.loc.location:=p^.left^.loc.location;
  2437. + finally I added now by default
  2438. that ra386dir translates global and unit symbols
  2439. + added a first field in tsymtable and
  2440. a nextsym field in tsym
  2441. (this allows to obtain ordered type info for
  2442. records and objects in gdb !)
  2443. Revision 1.93 1998/10/19 08:55:08 pierre
  2444. * wrong stabs info corrected once again !!
  2445. + variable vmt offset with vmt field only if required
  2446. implemented now !!!
  2447. Revision 1.92 1998/10/16 13:12:56 pierre
  2448. * added vmt_offsets in destructors code also !!!
  2449. * vmt_offset code for m68k
  2450. Revision 1.91 1998/10/16 08:48:38 peter
  2451. * fixed some misplaced $endif GDB
  2452. Revision 1.90 1998/10/15 15:13:32 pierre
  2453. + added oo_hasconstructor and oo_hasdestructor
  2454. for objects options
  2455. Revision 1.89 1998/10/14 13:38:25 peter
  2456. * fixed path with staticlib/objects in ppufiles
  2457. Revision 1.88 1998/10/09 16:36:07 pierre
  2458. * some memory leaks specific to usebrowser define fixed
  2459. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  2460. Revision 1.87 1998/10/09 11:47:57 pierre
  2461. * still more memory leaks fixes !!
  2462. Revision 1.86 1998/10/08 17:17:35 pierre
  2463. * current_module old scanner tagged as invalid if unit is recompiled
  2464. + added ppheap for better info on tracegetmem of heaptrc
  2465. (adds line column and file index)
  2466. * several memory leaks removed ith help of heaptrc !!
  2467. Revision 1.85 1998/10/08 13:48:51 peter
  2468. * fixed memory leaks for do nothing source
  2469. * fixed unit interdependency
  2470. Revision 1.84 1998/10/06 17:16:58 pierre
  2471. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2472. Revision 1.83 1998/09/26 17:45:45 peter
  2473. + idtoken and only one token table
  2474. Revision 1.82 1998/09/25 09:52:57 peter
  2475. + store also datasize and # of symbols in ppu
  2476. * # of defs is now also stored in structs
  2477. Revision 1.81 1998/09/24 23:49:21 peter
  2478. + aktmodeswitches
  2479. Revision 1.80 1998/09/23 12:20:51 pierre
  2480. * main program tmodule had no symtable (crashed browser)
  2481. * unit symbols problem fixed !!
  2482. Revision 1.79 1998/09/23 12:03:57 peter
  2483. * overloading fix for array of const
  2484. Revision 1.78 1998/09/22 17:13:54 pierre
  2485. + browsing updated and developed
  2486. records and objects fields are also stored
  2487. Revision 1.77 1998/09/22 15:37:24 peter
  2488. + array of const start
  2489. Revision 1.76 1998/09/21 10:00:08 peter
  2490. * store number of defs in ppu file
  2491. Revision 1.75 1998/09/21 08:58:31 peter
  2492. + speedsearch, which also needs speedvalue as parameter
  2493. Revision 1.74 1998/09/21 08:45:25 pierre
  2494. + added vmt_offset in tobjectdef.write for fututre use
  2495. (first steps to have objects without vmt if no virtual !!)
  2496. + added fpu_used field for tabstractprocdef :
  2497. sets this level to 2 if the functions return with value in FPU
  2498. (is then set to correct value at parsing of implementation)
  2499. THIS MIGHT refuse some code with FPU expression too complex
  2500. that were accepted before and even in some cases
  2501. that don't overflow in fact
  2502. ( like if f : float; is a forward that finally in implementation
  2503. only uses one fpu register !!)
  2504. Nevertheless I think that it will improve security on
  2505. FPU operations !!
  2506. * most other changes only for UseBrowser code
  2507. (added symtable references for record and objects)
  2508. local switch for refs to args and local of each function
  2509. (static symtable still missing)
  2510. UseBrowser still not stable and probably broken by
  2511. the definition hash array !!
  2512. Revision 1.73 1998/09/20 09:38:47 florian
  2513. * hasharray for defs fixed
  2514. * ansistring code generation corrected (init/final, assignement)
  2515. Revision 1.72 1998/09/19 22:56:18 florian
  2516. + hash table for getdefnr added
  2517. Revision 1.71 1998/09/18 08:01:40 pierre
  2518. + improvement on the usebrowser part
  2519. (does not work correctly for now)
  2520. Revision 1.70 1998/09/09 11:50:57 pierre
  2521. * forward def are not put in record or objects
  2522. + added check for forwards also in record and objects
  2523. * dummy parasymtable for unit initialization removed from
  2524. symtable stack
  2525. Revision 1.69 1998/09/07 23:10:25 florian
  2526. * a lot of stuff fixed regarding rtti and publishing of properties,
  2527. basics should now work
  2528. Revision 1.68 1998/09/07 19:33:26 florian
  2529. + some stuff for property rtti added:
  2530. - NameIndex of the TPropInfo record is now written correctly
  2531. - the DEFAULT/NODEFAULT keyword is supported now
  2532. - the default value and the storedsym/def are now written to
  2533. the PPU fiel
  2534. Revision 1.67 1998/09/07 18:46:14 peter
  2535. * update smartlinking, uses getdatalabel
  2536. * renamed ptree.value vars to value_str,value_real,value_set
  2537. Revision 1.66 1998/09/07 17:37:05 florian
  2538. * first fixes for published properties
  2539. Revision 1.65 1998/09/06 22:42:03 florian
  2540. + rtti genreation for properties added
  2541. Revision 1.64 1998/09/05 22:11:04 florian
  2542. + switch -vb
  2543. * while/repeat loops accept now also word/longbool conditions
  2544. * makebooltojump did an invalid ungetregister32, fixed
  2545. Revision 1.63 1998/09/04 17:34:23 pierre
  2546. * bug with datalabel corrected
  2547. + assembler errors better commented
  2548. * one nested record crash removed
  2549. Revision 1.62 1998/09/04 08:42:10 peter
  2550. * updated some error messages
  2551. Revision 1.61 1998/09/03 16:03:21 florian
  2552. + rtti generation
  2553. * init table generation changed
  2554. Revision 1.60 1998/09/01 17:39:52 peter
  2555. + internal constant functions
  2556. Revision 1.59 1998/09/01 12:53:27 peter
  2557. + aktpackenum
  2558. Revision 1.58 1998/09/01 07:54:26 pierre
  2559. * UseBrowser a little updated (might still be buggy !!)
  2560. * bug in psub.pas in function specifier removed
  2561. * stdcall allowed in interface and in implementation
  2562. (FPC will not yet complain if it is missing in either part
  2563. because stdcall is only a dummy !!)
  2564. Revision 1.57 1998/08/31 12:26:33 peter
  2565. * m68k and palmos updates from surebugfixes
  2566. Revision 1.56 1998/08/21 14:08:55 pierre
  2567. + TEST_FUNCRET now default (old code removed)
  2568. works also for m68k (at least compiles)
  2569. Revision 1.55 1998/08/21 08:43:32 pierre
  2570. * pocdecl and poclearstack are now different
  2571. external must but written as last specification
  2572. Revision 1.54 1998/08/20 09:26:48 pierre
  2573. + funcret setting in underproc testing
  2574. compile with _dTEST_FUNCRET
  2575. Revision 1.53 1998/08/19 18:04:56 peter
  2576. * fixed current_module^.in_implementation flag
  2577. Revision 1.51 1998/08/18 14:17:12 pierre
  2578. * bug about assigning the return value of a function to
  2579. a procvar fixed : warning
  2580. assigning a proc to a procvar need @ in FPC mode !!
  2581. * missing file/line info restored
  2582. Revision 1.50 1998/08/17 10:10:13 peter
  2583. - removed OLDPPU
  2584. Revision 1.49 1998/08/12 19:39:31 peter
  2585. * fixed some crashes
  2586. Revision 1.48 1998/08/10 14:50:32 peter
  2587. + localswitches, moduleswitches, globalswitches splitting
  2588. Revision 1.47 1998/08/10 10:00:19 peter
  2589. * Moved symbolstream to symtable.pas
  2590. Revision 1.46 1998/08/08 10:19:19 florian
  2591. * small fixes to write the extended type correct
  2592. Revision 1.45 1998/08/02 16:42:00 florian
  2593. * on o : tobject do should also work now, the exceptsymtable shouldn't be
  2594. disposed by dellexlevel
  2595. Revision 1.44 1998/07/30 11:18:21 florian
  2596. + first implementation of try ... except on .. do end;
  2597. * limitiation of 65535 bytes parameters for cdecl removed
  2598. Revision 1.43 1998/07/28 21:52:56 florian
  2599. + implementation of raise and try..finally
  2600. + some misc. exception stuff
  2601. Revision 1.42 1998/07/20 10:23:03 florian
  2602. * better ansi string assignement
  2603. Revision 1.41 1998/07/18 22:54:31 florian
  2604. * some ansi/wide/longstring support fixed:
  2605. o parameter passing
  2606. o returning as result from functions
  2607. Revision 1.40 1998/07/14 14:47:09 peter
  2608. * released NEWINPUT
  2609. Revision 1.39 1998/07/10 00:00:06 peter
  2610. * fixed ttypesym bug finally
  2611. * fileinfo in the symtable and better using for unused vars
  2612. Revision 1.38 1998/07/07 11:20:17 peter
  2613. + NEWINPUT for a better inputfile and scanner object
  2614. Revision 1.37 1998/06/24 14:48:42 peter
  2615. * ifdef newppu -> ifndef oldppu
  2616. Revision 1.36 1998/06/17 14:10:19 peter
  2617. * small os2 fixes
  2618. * fixed interdependent units with newppu (remake3 under linux works now)
  2619. Revision 1.35 1998/06/16 08:56:35 peter
  2620. + targetcpu
  2621. * cleaner pmodules for newppu
  2622. Revision 1.34 1998/06/15 15:38:12 pierre
  2623. * small bug in systems.pas corrected
  2624. + operators in different units better hanlded
  2625. Revision 1.33 1998/06/15 14:10:53 daniel
  2626. * File was ruined, fixed.
  2627. Revision 1.31 1998/06/13 00:10:20 peter
  2628. * working browser and newppu
  2629. * some small fixes against crashes which occured in bp7 (but not in
  2630. fpc?!)
  2631. Revision 1.30 1998/06/09 16:01:53 pierre
  2632. + added procedure directive parsing for procvars
  2633. (accepted are popstack cdecl and pascal)
  2634. + added C vars with the following syntax
  2635. var C calias 'true_c_name';(can be followed by external)
  2636. reason is that you must add the Cprefix
  2637. which is target dependent
  2638. Revision 1.29 1998/06/07 15:30:26 florian
  2639. + first working rtti
  2640. + data init/final. for local variables
  2641. Revision 1.28 1998/06/06 09:27:39 peter
  2642. * new depend file generated
  2643. Revision 1.27 1998/06/05 14:37:38 pierre
  2644. * fixes for inline for operators
  2645. * inline procedure more correctly restricted
  2646. Revision 1.26 1998/06/04 23:52:03 peter
  2647. * m68k compiles
  2648. + .def file creation moved to gendef.pas so it could also be used
  2649. for win32
  2650. Revision 1.25 1998/06/04 09:55:48 pierre
  2651. * demangled name of procsym reworked to become independant of the
  2652. mangling scheme
  2653. Revision 1.24 1998/06/03 22:49:04 peter
  2654. + wordbool,longbool
  2655. * rename bis,von -> high,low
  2656. * moved some systemunit loading/creating to psystem.pas
  2657. Revision 1.23 1998/05/28 14:40:30 peter
  2658. * fixes for newppu, remake3 works now with it
  2659. Revision 1.22 1998/05/27 19:45:09 peter
  2660. * symtable.pas splitted into includefiles
  2661. * symtable adapted for $ifndef OLDPPU
  2662. Revision 1.21 1998/05/23 01:21:31 peter
  2663. + aktasmmode, aktoptprocessor, aktoutputformat
  2664. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2665. + $LIBNAME to set the library name where the unit will be put in
  2666. * splitted cgi386 a bit (codeseg to large for bp7)
  2667. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2668. Revision 1.20 1998/05/21 19:33:37 peter
  2669. + better procedure directive handling and only one table
  2670. Revision 1.19 1998/05/20 09:42:37 pierre
  2671. + UseTokenInfo now default
  2672. * unit in interface uses and implementation uses gives error now
  2673. * only one error for unknown symbol (uses lastsymknown boolean)
  2674. the problem came from the label code !
  2675. + first inlined procedures and function work
  2676. (warning there might be allowed cases were the result is still wrong !!)
  2677. * UseBrower updated gives a global list of all position of all used symbols
  2678. with switch -gb
  2679. Revision 1.18 1998/05/11 13:07:57 peter
  2680. + $ifndef OLDPPU for the new ppuformat
  2681. + $define GDB not longer required
  2682. * removed all warnings and stripped some log comments
  2683. * no findfirst/findnext anymore to remove smartlink *.o files
  2684. Revision 1.17 1998/05/06 08:38:48 pierre
  2685. * better position info with UseTokenInfo
  2686. UseTokenInfo greatly simplified
  2687. + added check for changed tree after first time firstpass
  2688. (if we could remove all the cases were it happen
  2689. we could skip all firstpass if firstpasscount > 1)
  2690. Only with ExtDebug
  2691. Revision 1.16 1998/05/05 15:24:20 michael
  2692. * Fix to save units with classes.
  2693. Revision 1.15 1998/05/04 17:54:29 peter
  2694. + smartlinking works (only case jumptable left todo)
  2695. * redesign of systems.pas to support assemblers and linkers
  2696. + Unitname is now also in the PPU-file, increased version to 14
  2697. Revision 1.14 1998/05/01 16:38:46 florian
  2698. * handling of private and protected fixed
  2699. + change_keywords_to_tp implemented to remove
  2700. keywords which aren't supported by tp
  2701. * break and continue are now symbols of the system unit
  2702. + widestring, longstring and ansistring type released
  2703. Revision 1.13 1998/05/01 09:01:25 florian
  2704. + correct semantics of private and protected
  2705. * small fix in variable scope:
  2706. a id can be used in a parameter list of a method, even it is used in
  2707. an anchestor class as field id
  2708. Revision 1.12 1998/05/01 07:43:57 florian
  2709. + basics for rtti implemented
  2710. + switch $m (generate rtti for published sections)
  2711. Revision 1.11 1998/04/30 15:59:42 pierre
  2712. * GDB works again better :
  2713. correct type info in one pass
  2714. + UseTokenInfo for better source position
  2715. * fixed one remaining bug in scanner for line counts
  2716. * several little fixes
  2717. Revision 1.10 1998/04/29 10:34:05 pierre
  2718. + added some code for ansistring (not complete nor working yet)
  2719. * corrected operator overloading
  2720. * corrected nasm output
  2721. + started inline procedures
  2722. + added starstarn : use ** for exponentiation (^ gave problems)
  2723. + started UseTokenInfo cond to get accurate positions
  2724. Revision 1.9 1998/04/27 23:10:29 peter
  2725. + new scanner
  2726. * $makelib -> if smartlink
  2727. * small filename fixes pmodule.setfilename
  2728. * moved import from files.pas -> import.pas
  2729. Revision 1.8 1998/04/21 10:16:48 peter
  2730. * patches from strasbourg
  2731. * objects is not used anymore in the fpc compiled version
  2732. Revision 1.7 1998/04/13 22:20:36 florian
  2733. + stricter checking for duplicate id, solves also bug0097
  2734. Revision 1.6 1998/04/13 17:20:43 florian
  2735. * tdef.done much faster implemented
  2736. Revision 1.5 1998/04/10 21:36:56 florian
  2737. + some stuff to support method pointers (procedure of object) added
  2738. (declaration, parameter handling)
  2739. Revision 1.4 1998/04/08 16:58:08 pierre
  2740. * several bugfixes
  2741. ADD ADC and AND are also sign extended
  2742. nasm output OK (program still crashes at end
  2743. and creates wrong assembler files !!)
  2744. procsym types sym in tdef removed !!
  2745. Revision 1.3 1998/04/07 13:19:52 pierre
  2746. * bugfixes for reset_gdb_info
  2747. in MEM parsing for go32v2
  2748. better external symbol creation
  2749. support for rhgdb.exe (lowercase file names)
  2750. Revision 1.2 1998/04/06 13:09:04 daniel
  2751. * Emergency solution for bug in reset_gdb_info.
  2752. }