symtable.pas 99 KB

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