symtable.pas 97 KB

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