symtable.pas 100 KB

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