symtable.pas 98 KB

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