symtable.pas 102 KB

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