symtable.pas 95 KB

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