symtable.pas 103 KB

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