symtable.pas 97 KB

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