symtable.pas 95 KB

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