symtable.pas 98 KB

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