symtable.pas 99 KB

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