symtable.pas 101 KB

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