symtable.pas 103 KB

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