symsym.pas 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Implementation for the symbols types of the symtable
  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. unit symsym;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,
  24. { target }
  25. cpuinfo,globtype,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,
  28. { ppu }
  29. ppu,symppu,
  30. {$ifdef var_notification}
  31. cclasses,symnot,
  32. {$endif}
  33. { aasm }
  34. aasmbase,aasmtai,cpubase,
  35. globals
  36. ;
  37. type
  38. {************************************************
  39. TSym
  40. ************************************************}
  41. { this object is the base for all symbol objects }
  42. tstoredsym = class(tsym)
  43. protected
  44. _mangledname : pstring;
  45. public
  46. {$ifdef GDB}
  47. isstabwritten : boolean;
  48. {$endif GDB}
  49. refs : longint;
  50. lastref,
  51. defref,
  52. lastwritten : tref;
  53. refcount : longint;
  54. constructor create(const n : string);
  55. constructor loadsym(ppufile:tcompilerppufile);
  56. destructor destroy;override;
  57. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  58. procedure writesym(ppufile:tcompilerppufile);
  59. procedure deref;override;
  60. {$ifdef GDB}
  61. function stabstring : pchar;virtual;
  62. procedure concatstabto(asmlist : taasmoutput);virtual;
  63. {$endif GDB}
  64. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  65. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;virtual;
  66. function is_visible_for_proc(currprocdef:tprocdef):boolean;
  67. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  68. function mangledname : string;
  69. procedure generate_mangledname;virtual;abstract;
  70. end;
  71. tlabelsym = class(tstoredsym)
  72. lab : tasmlabel;
  73. used,
  74. defined : boolean;
  75. code : pointer; { should be tnode }
  76. constructor create(const n : string; l : tasmlabel);
  77. destructor destroy;override;
  78. constructor ppuload(ppufile:tcompilerppufile);
  79. procedure generate_mangledname;override;
  80. procedure ppuwrite(ppufile:tcompilerppufile);override;
  81. end;
  82. tunitsym = class(tstoredsym)
  83. unitsymtable : tsymtable;
  84. prevsym : tunitsym;
  85. constructor create(const n : string;ref : tsymtable);
  86. constructor ppuload(ppufile:tcompilerppufile);
  87. destructor destroy;override;
  88. procedure ppuwrite(ppufile:tcompilerppufile);override;
  89. procedure restoreunitsym;
  90. {$ifdef GDB}
  91. procedure concatstabto(asmlist : taasmoutput);override;
  92. {$endif GDB}
  93. end;
  94. terrorsym = class(tstoredsym)
  95. constructor create;
  96. end;
  97. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  98. tprocsym = class(tstoredsym)
  99. protected
  100. defs : pprocdeflist; { linked list of overloaded procdefs }
  101. function getprocdef(nr:cardinal):Tprocdef;
  102. public
  103. procdef_count : byte;
  104. is_global : boolean;
  105. overloadchecked : boolean;
  106. overloadcount : word; { amount of overloaded functions in this module }
  107. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  108. constructor create(const n : string);
  109. constructor ppuload(ppufile:tcompilerppufile);
  110. destructor destroy;override;
  111. { writes all declarations except the specified one }
  112. procedure write_parameter_lists(skipdef:tprocdef);
  113. { tests, if all procedures definitions are defined and not }
  114. { only forward }
  115. procedure check_forward;
  116. procedure unchain_overload;
  117. procedure ppuwrite(ppufile:tcompilerppufile);override;
  118. procedure deref;override;
  119. procedure addprocdef(p:tprocdef);
  120. procedure add_para_match_to(Aprocsym:Tprocsym);
  121. procedure concat_procdefs_to(s:Tprocsym);
  122. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  123. function first_procdef:Tprocdef;
  124. function last_procdef:Tprocdef;
  125. function search_procdef_nopara_boolret:Tprocdef;
  126. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  127. function search_procdef_bypara(params:Tparalinkedlist;
  128. allowconvert,
  129. allowdefault:boolean):Tprocdef;
  130. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  131. function search_procdef_by1paradef(firstpara:Tdef):Tprocdef;
  132. function search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  133. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  134. {$ifdef GDB}
  135. function stabstring : pchar;override;
  136. procedure concatstabto(asmlist : taasmoutput);override;
  137. {$endif GDB}
  138. end;
  139. ttypesym = class(tstoredsym)
  140. restype : ttype;
  141. {$ifdef GDB}
  142. isusedinstab : boolean;
  143. {$endif GDB}
  144. constructor create(const n : string;const tt : ttype);
  145. constructor ppuload(ppufile:tcompilerppufile);
  146. procedure ppuwrite(ppufile:tcompilerppufile);override;
  147. procedure deref;override;
  148. function gettypedef:tdef;override;
  149. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  150. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  151. {$ifdef GDB}
  152. function stabstring : pchar;override;
  153. procedure concatstabto(asmlist : taasmoutput);override;
  154. {$endif GDB}
  155. end;
  156. tvarsym = class(tstoredsym)
  157. address : longint;
  158. localvarsym : tvarsym;
  159. vartype : ttype;
  160. varoptions : tvaroptions;
  161. reg : tregister; { if reg<>R_NO, then the variable is an register variable }
  162. varspez : tvarspez; { sets the type of access }
  163. varstate : tvarstate;
  164. paraitem : tparaitem;
  165. {$ifdef var_notification}
  166. notifications : Tlinkedlist;
  167. {$endif}
  168. constructor create(const n : string;const tt : ttype);
  169. constructor create_dll(const n : string;const tt : ttype);
  170. constructor create_C(const n,mangled : string;const tt : ttype);
  171. constructor ppuload(ppufile:tcompilerppufile);
  172. destructor destroy;override;
  173. procedure ppuwrite(ppufile:tcompilerppufile);override;
  174. procedure deref;override;
  175. procedure generate_mangledname;override;
  176. procedure set_mangledname(const s:string);
  177. function getsize : longint;
  178. function getvaluesize : longint;
  179. {$ifdef var_notification}
  180. function register_notification(flags:Tnotification_flags;
  181. callback:Tnotification_callback):cardinal;
  182. {$endif}
  183. {$ifdef GDB}
  184. function stabstring : pchar;override;
  185. procedure concatstabto(asmlist : taasmoutput);override;
  186. {$endif GDB}
  187. end;
  188. tpropertysym = class(tstoredsym)
  189. propoptions : tpropertyoptions;
  190. propoverriden : tpropertysym;
  191. proptype,
  192. indextype : ttype;
  193. index,
  194. default : longint;
  195. readaccess,
  196. writeaccess,
  197. storedaccess : tsymlist;
  198. constructor create(const n : string);
  199. destructor destroy;override;
  200. constructor ppuload(ppufile:tcompilerppufile);
  201. function getsize : longint;
  202. procedure ppuwrite(ppufile:tcompilerppufile);override;
  203. function gettypedef:tdef;override;
  204. procedure deref;override;
  205. procedure dooverride(overriden:tpropertysym);
  206. {$ifdef GDB}
  207. function stabstring : pchar;override;
  208. procedure concatstabto(asmlist : taasmoutput);override;
  209. {$endif GDB}
  210. end;
  211. tfuncretsym = class(tstoredsym)
  212. returntype : ttype;
  213. address : longint;
  214. funcretstate : tvarstate;
  215. constructor create(const n : string;const tt : ttype);
  216. constructor ppuload(ppufile:tcompilerppufile);
  217. destructor destroy;override;
  218. procedure ppuwrite(ppufile:tcompilerppufile);override;
  219. procedure deref;override;
  220. {$ifdef GDB}
  221. procedure concatstabto(asmlist : taasmoutput);override;
  222. {$endif GDB}
  223. end;
  224. tabsolutesym = class(tvarsym)
  225. abstyp : absolutetyp;
  226. absseg : boolean;
  227. ref : tstoredsym;
  228. asmname : pstring;
  229. constructor create(const n : string;const tt : ttype);
  230. constructor ppuload(ppufile:tcompilerppufile);
  231. procedure deref;override;
  232. function mangledname : string;
  233. procedure ppuwrite(ppufile:tcompilerppufile);override;
  234. {$ifdef GDB}
  235. procedure concatstabto(asmlist : taasmoutput);override;
  236. {$endif GDB}
  237. end;
  238. ttypedconstsym = class(tstoredsym)
  239. typedconsttype : ttype;
  240. is_writable : boolean;
  241. constructor create(const n : string;p : tdef;writable : boolean);
  242. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  243. constructor ppuload(ppufile:tcompilerppufile);
  244. destructor destroy;override;
  245. procedure generate_mangledname;override;
  246. procedure ppuwrite(ppufile:tcompilerppufile);override;
  247. procedure deref;override;
  248. function getsize:longint;
  249. {$ifdef GDB}
  250. function stabstring : pchar;override;
  251. {$endif GDB}
  252. end;
  253. tconstvalue = record
  254. case integer of
  255. 0: (valueord : tconstexprint);
  256. 1: (valueordptr : tconstptruint);
  257. 2: (valueptr : pointer; len : longint);
  258. end;
  259. tconstsym = class(tstoredsym)
  260. consttype : ttype;
  261. consttyp : tconsttyp;
  262. value : tconstvalue;
  263. resstrindex : longint; { needed for resource strings }
  264. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint);
  265. constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  266. constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  267. constructor create_ptr(const n : string;t : tconsttyp;v : pointer);
  268. constructor create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  269. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  270. constructor ppuload(ppufile:tcompilerppufile);
  271. destructor destroy;override;
  272. function mangledname : string;
  273. procedure deref;override;
  274. procedure ppuwrite(ppufile:tcompilerppufile);override;
  275. {$ifdef GDB}
  276. function stabstring : pchar;override;
  277. procedure concatstabto(asmlist : taasmoutput);override;
  278. {$endif GDB}
  279. end;
  280. tenumsym = class(tstoredsym)
  281. value : longint;
  282. definition : tenumdef;
  283. nextenum : tenumsym;
  284. constructor create(const n : string;def : tenumdef;v : longint);
  285. constructor ppuload(ppufile:tcompilerppufile);
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure deref;override;
  288. procedure order;
  289. {$ifdef GDB}
  290. procedure concatstabto(asmlist : taasmoutput);override;
  291. {$endif GDB}
  292. end;
  293. tsyssym = class(tstoredsym)
  294. number : longint;
  295. constructor create(const n : string;l : longint);
  296. constructor ppuload(ppufile:tcompilerppufile);
  297. destructor destroy;override;
  298. procedure ppuwrite(ppufile:tcompilerppufile);override;
  299. {$ifdef GDB}
  300. procedure concatstabto(asmlist : taasmoutput);override;
  301. {$endif GDB}
  302. end;
  303. { compiler generated symbol to point to rtti and init/finalize tables }
  304. trttisym = class(tstoredsym)
  305. lab : tasmsymbol;
  306. rttityp : trttitype;
  307. constructor create(const n:string;rt:trttitype);
  308. constructor ppuload(ppufile:tcompilerppufile);
  309. procedure ppuwrite(ppufile:tcompilerppufile);override;
  310. function mangledname:string;
  311. function get_label:tasmsymbol;
  312. end;
  313. { register variables }
  314. pregvarinfo = ^tregvarinfo;
  315. tregvarinfo = record
  316. regvars : array[1..maxvarregs] of tvarsym;
  317. regvars_para : array[1..maxvarregs] of boolean;
  318. regvars_refs : array[1..maxvarregs] of longint;
  319. fpuregvars : array[1..maxfpuvarregs] of tvarsym;
  320. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  321. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  322. end;
  323. var
  324. aktprocsym : tprocsym; { pointer to the symbol for the
  325. currently be parsed procedure }
  326. aktprocdef : tprocdef;
  327. aktcallprocdef : tabstractprocdef; { pointer to the definition of the
  328. currently called procedure,
  329. only set/unset in ncal }
  330. generrorsym : tsym;
  331. otsym : tvarsym;
  332. const
  333. current_object_option : tsymoptions = [sp_public];
  334. { rtti and init/final }
  335. procedure generate_rtti(p:tsym);
  336. procedure generate_inittable(p:tsym);
  337. implementation
  338. uses
  339. {$ifdef Delphi}
  340. sysutils,
  341. {$else Delphi}
  342. strings,
  343. {$endif Delphi}
  344. { global }
  345. verbose,
  346. { target }
  347. systems,
  348. { symtable }
  349. symtable,defutil,defcmp,
  350. {$ifdef GDB}
  351. gdb,
  352. {$endif GDB}
  353. { tree }
  354. node,
  355. { aasm }
  356. aasmcpu,
  357. { module }
  358. fmodule,
  359. { codegen }
  360. paramgr,cgbase,cresstr
  361. ;
  362. {****************************************************************************
  363. Helpers
  364. ****************************************************************************}
  365. {****************************************************************************
  366. TSYM (base for all symtypes)
  367. ****************************************************************************}
  368. constructor tstoredsym.create(const n : string);
  369. begin
  370. inherited create(n);
  371. symoptions:=current_object_option;
  372. {$ifdef GDB}
  373. isstabwritten := false;
  374. {$endif GDB}
  375. fileinfo:=akttokenpos;
  376. defref:=nil;
  377. refs:=0;
  378. lastwritten:=nil;
  379. refcount:=0;
  380. if (cs_browser in aktmoduleswitches) and make_ref then
  381. begin
  382. defref:=tref.create(defref,@akttokenpos);
  383. inc(refcount);
  384. end;
  385. lastref:=defref;
  386. _mangledname:=nil;
  387. end;
  388. constructor tstoredsym.loadsym(ppufile:tcompilerppufile);
  389. var
  390. s : string;
  391. nr : word;
  392. begin
  393. nr:=ppufile.getword;
  394. s:=ppufile.getstring;
  395. inherited create(s);
  396. { force the correct indexnr. must be after create! }
  397. indexnr:=nr;
  398. ppufile.getsmallset(symoptions);
  399. ppufile.getposinfo(fileinfo);
  400. lastref:=nil;
  401. defref:=nil;
  402. refs:=0;
  403. lastwritten:=nil;
  404. refcount:=0;
  405. _mangledname:=nil;
  406. {$ifdef GDB}
  407. isstabwritten := false;
  408. {$endif GDB}
  409. end;
  410. procedure tstoredsym.deref;
  411. begin
  412. end;
  413. procedure tstoredsym.load_references(ppufile:tcompilerppufile;locals:boolean);
  414. var
  415. pos : tfileposinfo;
  416. move_last : boolean;
  417. begin
  418. move_last:=lastwritten=lastref;
  419. while (not ppufile.endofentry) do
  420. begin
  421. ppufile.getposinfo(pos);
  422. inc(refcount);
  423. lastref:=tref.create(lastref,@pos);
  424. lastref.is_written:=true;
  425. if refcount=1 then
  426. defref:=lastref;
  427. end;
  428. if move_last then
  429. lastwritten:=lastref;
  430. end;
  431. { big problem here :
  432. wrong refs were written because of
  433. interface parsing of other units PM
  434. moduleindex must be checked !! }
  435. function tstoredsym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  436. var
  437. ref : tref;
  438. symref_written,move_last : boolean;
  439. begin
  440. write_references:=false;
  441. if lastwritten=lastref then
  442. exit;
  443. { should we update lastref }
  444. move_last:=true;
  445. symref_written:=false;
  446. { write symbol refs }
  447. if assigned(lastwritten) then
  448. ref:=lastwritten
  449. else
  450. ref:=defref;
  451. while assigned(ref) do
  452. begin
  453. if ref.moduleindex=current_module.unit_index then
  454. begin
  455. { write address to this symbol }
  456. if not symref_written then
  457. begin
  458. ppufile.putderef(self);
  459. symref_written:=true;
  460. end;
  461. ppufile.putposinfo(ref.posinfo);
  462. ref.is_written:=true;
  463. if move_last then
  464. lastwritten:=ref;
  465. end
  466. else if not ref.is_written then
  467. move_last:=false
  468. else if move_last then
  469. lastwritten:=ref;
  470. ref:=ref.nextref;
  471. end;
  472. if symref_written then
  473. ppufile.writeentry(ibsymref);
  474. write_references:=symref_written;
  475. end;
  476. destructor tstoredsym.destroy;
  477. begin
  478. if assigned(_mangledname) then
  479. begin
  480. {$ifdef MEMDEBUG}
  481. memmanglednames.start;
  482. {$endif MEMDEBUG}
  483. stringdispose(_mangledname);
  484. {$ifdef MEMDEBUG}
  485. memmanglednames.stop;
  486. {$endif MEMDEBUG}
  487. end;
  488. if assigned(defref) then
  489. begin
  490. {$ifdef MEMDEBUG}
  491. membrowser.start;
  492. {$endif MEMDEBUG}
  493. defref.freechain;
  494. defref.free;
  495. {$ifdef MEMDEBUG}
  496. membrowser.stop;
  497. {$endif MEMDEBUG}
  498. end;
  499. inherited destroy;
  500. end;
  501. procedure tstoredsym.writesym(ppufile:tcompilerppufile);
  502. begin
  503. ppufile.putword(indexnr);
  504. ppufile.putstring(_realname^);
  505. ppufile.putsmallset(symoptions);
  506. ppufile.putposinfo(fileinfo);
  507. end;
  508. {$ifdef GDB}
  509. function tstoredsym.stabstring : pchar;
  510. begin
  511. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  512. tostr(fileinfo.line)+',0');
  513. end;
  514. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  515. var
  516. stab_str : pchar;
  517. begin
  518. if not isstabwritten then
  519. begin
  520. stab_str := stabstring;
  521. { count_dbx(stab_str); moved to GDB.PAS }
  522. asmList.concat(Tai_stabs.Create(stab_str));
  523. isstabwritten:=true;
  524. end;
  525. end;
  526. {$endif GDB}
  527. function tstoredsym.is_visible_for_proc(currprocdef:tprocdef):boolean;
  528. begin
  529. is_visible_for_proc:=false;
  530. { private symbols are allowed when we are in the same
  531. module as they are defined }
  532. if (sp_private in symoptions) and
  533. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  534. (owner.defowner.owner.unitid<>0) then
  535. exit;
  536. { protected symbols are vissible in the module that defines them and
  537. also visible to related objects }
  538. if (sp_protected in symoptions) and
  539. (
  540. (
  541. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  542. (owner.defowner.owner.unitid<>0)
  543. ) and
  544. not(
  545. assigned(currprocdef) and
  546. assigned(currprocdef._class) and
  547. currprocdef._class.is_related(tobjectdef(owner.defowner))
  548. )
  549. ) then
  550. exit;
  551. is_visible_for_proc:=true;
  552. end;
  553. function tstoredsym.is_visible_for_object(currobjdef:tobjectdef):boolean;
  554. begin
  555. is_visible_for_object:=false;
  556. { private symbols are allowed when we are in the same
  557. module as they are defined }
  558. if (sp_private in symoptions) and
  559. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  560. (owner.defowner.owner.unitid<>0) then
  561. exit;
  562. { protected symbols are vissible in the module that defines them and
  563. also visible to related objects }
  564. if (sp_protected in symoptions) and
  565. (
  566. (
  567. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  568. (owner.defowner.owner.unitid<>0)
  569. ) and
  570. not(
  571. assigned(currobjdef) and
  572. currobjdef.is_related(tobjectdef(owner.defowner))
  573. )
  574. ) then
  575. exit;
  576. is_visible_for_object:=true;
  577. end;
  578. function tstoredsym.mangledname : string;
  579. begin
  580. if not assigned(_mangledname) then
  581. begin
  582. generate_mangledname;
  583. if not assigned(_mangledname) then
  584. internalerror(200204171);
  585. end;
  586. mangledname:=_mangledname^
  587. end;
  588. {****************************************************************************
  589. TLABELSYM
  590. ****************************************************************************}
  591. constructor tlabelsym.create(const n : string; l : tasmlabel);
  592. begin
  593. inherited create(n);
  594. typ:=labelsym;
  595. lab:=l;
  596. used:=false;
  597. defined:=false;
  598. code:=nil;
  599. end;
  600. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  601. begin
  602. inherited loadsym(ppufile);
  603. typ:=labelsym;
  604. { this is all dummy
  605. it is only used for local browsing }
  606. lab:=nil;
  607. code:=nil;
  608. used:=false;
  609. defined:=true;
  610. end;
  611. destructor tlabelsym.destroy;
  612. begin
  613. inherited destroy;
  614. end;
  615. procedure tlabelsym.generate_mangledname;
  616. begin
  617. _mangledname:=stringdup(lab.name);
  618. end;
  619. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  620. begin
  621. if owner.symtabletype=globalsymtable then
  622. Message(sym_e_ill_label_decl)
  623. else
  624. begin
  625. inherited writesym(ppufile);
  626. ppufile.writeentry(iblabelsym);
  627. end;
  628. end;
  629. {****************************************************************************
  630. TUNITSYM
  631. ****************************************************************************}
  632. constructor tunitsym.create(const n : string;ref : tsymtable);
  633. var
  634. old_make_ref : boolean;
  635. begin
  636. old_make_ref:=make_ref;
  637. make_ref:=false;
  638. inherited create(n);
  639. make_ref:=old_make_ref;
  640. typ:=unitsym;
  641. unitsymtable:=ref;
  642. if assigned(ref) and
  643. (ref.symtabletype=globalsymtable) then
  644. begin
  645. prevsym:=tglobalsymtable(ref).unitsym;
  646. tglobalsymtable(ref).unitsym:=self;
  647. end;
  648. end;
  649. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  650. begin
  651. inherited loadsym(ppufile);
  652. typ:=unitsym;
  653. unitsymtable:=nil;
  654. prevsym:=nil;
  655. refs:=0;
  656. end;
  657. { we need to remove it from the prevsym chain ! }
  658. procedure tunitsym.restoreunitsym;
  659. var pus,ppus : tunitsym;
  660. begin
  661. if assigned(unitsymtable) and
  662. (unitsymtable.symtabletype=globalsymtable) then
  663. begin
  664. ppus:=nil;
  665. pus:=tglobalsymtable(unitsymtable).unitsym;
  666. if pus=self then
  667. tglobalsymtable(unitsymtable).unitsym:=prevsym
  668. else while assigned(pus) do
  669. begin
  670. if pus=self then
  671. begin
  672. ppus.prevsym:=prevsym;
  673. break;
  674. end
  675. else
  676. begin
  677. ppus:=pus;
  678. pus:=ppus.prevsym;
  679. end;
  680. end;
  681. end;
  682. unitsymtable:=nil;
  683. prevsym:=nil;
  684. end;
  685. destructor tunitsym.destroy;
  686. begin
  687. restoreunitsym;
  688. inherited destroy;
  689. end;
  690. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  691. begin
  692. inherited writesym(ppufile);
  693. ppufile.writeentry(ibunitsym);
  694. end;
  695. {$ifdef GDB}
  696. procedure tunitsym.concatstabto(asmlist : taasmoutput);
  697. begin
  698. {Nothing to write to stabs !}
  699. end;
  700. {$endif GDB}
  701. {****************************************************************************
  702. TPROCSYM
  703. ****************************************************************************}
  704. constructor tprocsym.create(const n : string);
  705. begin
  706. inherited create(n);
  707. typ:=procsym;
  708. defs:=nil;
  709. owner:=nil;
  710. is_global:=false;
  711. overloadchecked:=false;
  712. overloadcount:=0;
  713. procdef_count:=0;
  714. end;
  715. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  716. var
  717. pd : tprocdef;
  718. begin
  719. inherited loadsym(ppufile);
  720. typ:=procsym;
  721. defs:=nil;
  722. procdef_count:=0;
  723. repeat
  724. pd:=tprocdef(ppufile.getderef);
  725. if pd=nil then
  726. break;
  727. addprocdef(pd);
  728. until false;
  729. is_global:=false;
  730. overloadchecked:=false;
  731. overloadcount:=$ffff; { invalid, not used anymore }
  732. end;
  733. destructor tprocsym.destroy;
  734. var
  735. hp,p : pprocdeflist;
  736. begin
  737. p:=defs;
  738. while assigned(p) do
  739. begin
  740. hp:=p^.next;
  741. dispose(p);
  742. p:=hp;
  743. end;
  744. inherited destroy;
  745. end;
  746. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  747. var
  748. p : pprocdeflist;
  749. begin
  750. p:=defs;
  751. while assigned(p) do
  752. begin
  753. if p^.def<>skipdef then
  754. MessagePos1(p^.def.fileinfo,sym_b_param_list,p^.def.fullprocname);
  755. p:=p^.next;
  756. end;
  757. end;
  758. procedure tprocsym.check_forward;
  759. var
  760. p : pprocdeflist;
  761. begin
  762. p:=defs;
  763. while assigned(p) do
  764. begin
  765. if (p^.def.procsym=self) and
  766. (p^.def.forwarddef) then
  767. begin
  768. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname);
  769. { Turn futher error messages off }
  770. p^.def.forwarddef:=false;
  771. end;
  772. p:=p^.next;
  773. end;
  774. end;
  775. procedure tprocsym.deref;
  776. var
  777. p : pprocdeflist;
  778. begin
  779. p:=defs;
  780. while assigned(p) do
  781. begin
  782. resolvedef(pointer(p^.def));
  783. p:=p^.next;
  784. end;
  785. end;
  786. procedure tprocsym.addprocdef(p:tprocdef);
  787. var
  788. pd : pprocdeflist;
  789. begin
  790. new(pd);
  791. pd^.def:=p;
  792. pd^.next:=defs;
  793. defs:=pd;
  794. inc(procdef_count);
  795. end;
  796. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  797. var
  798. i : cardinal;
  799. pd : Pprocdeflist;
  800. begin
  801. pd:=defs;
  802. for i:=2 to nr do
  803. begin
  804. if not assigned(pd) then
  805. internalerror(200209051);
  806. pd:=pd^.next;
  807. end;
  808. getprocdef:=pd^.def;
  809. end;
  810. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym);
  811. var
  812. pd:Pprocdeflist;
  813. begin
  814. pd:=defs;
  815. while assigned(pd) do
  816. begin
  817. if Aprocsym.search_procdef_bypara(pd^.def.para,false,true)=nil then
  818. Aprocsym.addprocdef(pd^.def);
  819. pd:=pd^.next;
  820. end;
  821. end;
  822. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  823. var pd:Pprocdeflist;
  824. begin
  825. pd:=defs;
  826. while assigned(pd) do
  827. begin
  828. s.addprocdef(pd^.def);
  829. pd:=pd^.next;
  830. end;
  831. end;
  832. function Tprocsym.first_procdef:Tprocdef;
  833. begin
  834. first_procdef:=defs^.def;
  835. end;
  836. function Tprocsym.last_procdef:Tprocdef;
  837. var pd:Pprocdeflist;
  838. begin
  839. pd:=defs;
  840. while assigned(pd) do
  841. begin
  842. last_procdef:=pd^.def;
  843. pd:=pd^.next;
  844. end;
  845. end;
  846. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  847. var p:Pprocdeflist;
  848. begin
  849. p:=defs;
  850. while assigned(p) do
  851. begin
  852. proc2call(p^.def,arg);
  853. p:=p^.next;
  854. end;
  855. end;
  856. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  857. var p:Pprocdeflist;
  858. begin
  859. search_procdef_nopara_boolret:=nil;
  860. p:=defs;
  861. while p<>nil do
  862. begin
  863. if p^.def.para.empty and is_boolean(p^.def.rettype.def) then
  864. begin
  865. search_procdef_nopara_boolret:=p^.def;
  866. break;
  867. end;
  868. p:=p^.next;
  869. end;
  870. end;
  871. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  872. var p:Pprocdeflist;
  873. begin
  874. search_procdef_bytype:=nil;
  875. p:=defs;
  876. while p<>nil do
  877. begin
  878. if p^.def.proctypeoption=pt then
  879. begin
  880. search_procdef_bytype:=p^.def;
  881. break;
  882. end;
  883. p:=p^.next;
  884. end;
  885. end;
  886. function Tprocsym.search_procdef_bypara(params:Tparalinkedlist;
  887. allowconvert,
  888. allowdefault:boolean):Tprocdef;
  889. var
  890. pd:Pprocdeflist;
  891. eq : tequaltype;
  892. begin
  893. search_procdef_bypara:=nil;
  894. pd:=defs;
  895. while assigned(pd) do
  896. begin
  897. eq:=compare_paras(pd^.def.para,params,cp_value_equal_const,allowdefault);
  898. if (eq>=te_equal) or
  899. (allowconvert and (eq>te_incompatible)) then
  900. begin
  901. search_procdef_bypara:=pd^.def;
  902. break;
  903. end;
  904. pd:=pd^.next;
  905. end;
  906. end;
  907. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  908. var
  909. pd : Pprocdeflist;
  910. eq,besteq : tequaltype;
  911. bestpd : tprocdef;
  912. begin
  913. { This function will return the pprocdef of pprocsym that
  914. is the best match for procvardef. When there are multiple
  915. matches it returns nil.}
  916. search_procdef_byprocvardef:=nil;
  917. bestpd:=nil;
  918. besteq:=te_incompatible;
  919. pd:=defs;
  920. while assigned(pd) do
  921. begin
  922. eq:=proc_to_procvar_equal(pd^.def,d);
  923. if eq>=te_equal then
  924. begin
  925. { multiple procvars with the same equal level }
  926. if assigned(bestpd) and
  927. (besteq=eq) then
  928. exit;
  929. if eq>besteq then
  930. begin
  931. besteq:=eq;
  932. bestpd:=pd^.def;
  933. end;
  934. end;
  935. pd:=pd^.next;
  936. end;
  937. search_procdef_byprocvardef:=bestpd;
  938. end;
  939. function Tprocsym.search_procdef_by1paradef(firstpara:Tdef):Tprocdef;
  940. var
  941. pd:Pprocdeflist;
  942. begin
  943. search_procdef_by1paradef:=nil;
  944. pd:=defs;
  945. while assigned(pd) do
  946. begin
  947. if equal_defs(Tparaitem(pd^.def.para.first).paratype.def,firstpara) and
  948. (Tparaitem(pd^.def.para.first).next=nil) then
  949. begin
  950. search_procdef_by1paradef:=pd^.def;
  951. break;
  952. end;
  953. pd:=pd^.next;
  954. end;
  955. end;
  956. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  957. var
  958. convtyp : tconverttype;
  959. pd : pprocdeflist;
  960. bestpd : tprocdef;
  961. eq,
  962. besteq : tequaltype;
  963. hpd : tprocdef;
  964. begin
  965. search_procdef_assignment_operator:=nil;
  966. bestpd:=nil;
  967. besteq:=te_incompatible;
  968. pd:=defs;
  969. while assigned(pd) do
  970. begin
  971. if equal_defs(todef,pd^.def.rettype.def) then
  972. begin
  973. eq:=compare_defs_ext(fromdef,Tparaitem(pd^.def.para.first).paratype.def,
  974. nothingn,false,false,convtyp,hpd);
  975. if eq=te_exact then
  976. begin
  977. search_procdef_assignment_operator:=pd^.def;
  978. exit;
  979. end;
  980. if eq>besteq then
  981. begin
  982. bestpd:=pd^.def;
  983. besteq:=eq;
  984. end;
  985. end;
  986. pd:=pd^.next;
  987. end;
  988. search_procdef_assignment_operator:=bestpd;
  989. end;
  990. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  991. var
  992. p : pprocdeflist;
  993. begin
  994. inherited writesym(ppufile);
  995. p:=defs;
  996. while assigned(p) do
  997. begin
  998. { only write the proc definitions that belong
  999. to this procsym }
  1000. if (p^.def.procsym=self) then
  1001. ppufile.putderef(p^.def);
  1002. p:=p^.next;
  1003. end;
  1004. ppufile.putderef(nil);
  1005. ppufile.writeentry(ibprocsym);
  1006. end;
  1007. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  1008. var
  1009. p : pprocdeflist;
  1010. begin
  1011. write_references:=false;
  1012. if not inherited write_references(ppufile,locals) then
  1013. exit;
  1014. write_references:=true;
  1015. p:=defs;
  1016. while assigned(p) do
  1017. begin
  1018. if (p^.def.procsym=self) then
  1019. p^.def.write_references(ppufile,locals);
  1020. p:=p^.next;
  1021. end;
  1022. end;
  1023. procedure tprocsym.unchain_overload;
  1024. var
  1025. p,hp,
  1026. first,
  1027. last : pprocdeflist;
  1028. begin
  1029. { remove all overloaded procdefs from the
  1030. procdeflist that are not in the current symtable }
  1031. first:=nil;
  1032. last:=nil;
  1033. p:=defs;
  1034. while assigned(p) do
  1035. begin
  1036. hp:=p^.next;
  1037. if (p^.def.procsym=self) then
  1038. begin
  1039. { keep in list }
  1040. if not assigned(first) then
  1041. begin
  1042. first:=p;
  1043. last:=p;
  1044. end
  1045. else
  1046. last^.next:=p;
  1047. last:=p;
  1048. p^.next:=nil;
  1049. end
  1050. else
  1051. begin
  1052. { remove }
  1053. dispose(p);
  1054. dec(procdef_count);
  1055. end;
  1056. p:=hp;
  1057. end;
  1058. defs:=first;
  1059. end;
  1060. {$ifdef GDB}
  1061. function tprocsym.stabstring : pchar;
  1062. begin
  1063. internalerror(200111171);
  1064. stabstring:=nil;
  1065. end;
  1066. procedure tprocsym.concatstabto(asmlist : taasmoutput);
  1067. begin
  1068. internalerror(200111172);
  1069. end;
  1070. {$endif GDB}
  1071. {****************************************************************************
  1072. TERRORSYM
  1073. ****************************************************************************}
  1074. constructor terrorsym.create;
  1075. begin
  1076. inherited create('');
  1077. typ:=errorsym;
  1078. end;
  1079. {****************************************************************************
  1080. TPROPERTYSYM
  1081. ****************************************************************************}
  1082. constructor tpropertysym.create(const n : string);
  1083. begin
  1084. inherited create(n);
  1085. typ:=propertysym;
  1086. propoptions:=[];
  1087. index:=0;
  1088. default:=0;
  1089. proptype.reset;
  1090. indextype.reset;
  1091. readaccess:=tsymlist.create;
  1092. writeaccess:=tsymlist.create;
  1093. storedaccess:=tsymlist.create;
  1094. end;
  1095. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1096. begin
  1097. inherited loadsym(ppufile);
  1098. typ:=propertysym;
  1099. ppufile.getsmallset(propoptions);
  1100. if (ppo_is_override in propoptions) then
  1101. begin
  1102. propoverriden:=tpropertysym(ppufile.getderef);
  1103. { we need to have these objects initialized }
  1104. readaccess:=tsymlist.create;
  1105. writeaccess:=tsymlist.create;
  1106. storedaccess:=tsymlist.create;
  1107. end
  1108. else
  1109. begin
  1110. ppufile.gettype(proptype);
  1111. index:=ppufile.getlongint;
  1112. default:=ppufile.getlongint;
  1113. ppufile.gettype(indextype);
  1114. readaccess:=ppufile.getsymlist;
  1115. writeaccess:=ppufile.getsymlist;
  1116. storedaccess:=ppufile.getsymlist;
  1117. end;
  1118. end;
  1119. destructor tpropertysym.destroy;
  1120. begin
  1121. readaccess.free;
  1122. writeaccess.free;
  1123. storedaccess.free;
  1124. inherited destroy;
  1125. end;
  1126. function tpropertysym.gettypedef:tdef;
  1127. begin
  1128. gettypedef:=proptype.def;
  1129. end;
  1130. procedure tpropertysym.deref;
  1131. begin
  1132. if (ppo_is_override in propoptions) then
  1133. begin
  1134. resolvesym(pointer(propoverriden));
  1135. dooverride(propoverriden);
  1136. end
  1137. else
  1138. begin
  1139. proptype.resolve;
  1140. indextype.resolve;
  1141. readaccess.resolve;
  1142. writeaccess.resolve;
  1143. storedaccess.resolve;
  1144. end;
  1145. end;
  1146. function tpropertysym.getsize : longint;
  1147. begin
  1148. getsize:=0;
  1149. end;
  1150. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1151. begin
  1152. inherited writesym(ppufile);
  1153. ppufile.putsmallset(propoptions);
  1154. if (ppo_is_override in propoptions) then
  1155. ppufile.putderef(propoverriden)
  1156. else
  1157. begin
  1158. ppufile.puttype(proptype);
  1159. ppufile.putlongint(index);
  1160. ppufile.putlongint(default);
  1161. ppufile.puttype(indextype);
  1162. ppufile.putsymlist(readaccess);
  1163. ppufile.putsymlist(writeaccess);
  1164. ppufile.putsymlist(storedaccess);
  1165. end;
  1166. ppufile.writeentry(ibpropertysym);
  1167. end;
  1168. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1169. begin
  1170. propoverriden:=overriden;
  1171. proptype:=overriden.proptype;
  1172. propoptions:=overriden.propoptions+[ppo_is_override];
  1173. index:=overriden.index;
  1174. default:=overriden.default;
  1175. indextype:=overriden.indextype;
  1176. readaccess.free;
  1177. readaccess:=overriden.readaccess.getcopy;
  1178. writeaccess.free;
  1179. writeaccess:=overriden.writeaccess.getcopy;
  1180. storedaccess.free;
  1181. storedaccess:=overriden.storedaccess.getcopy;
  1182. end;
  1183. {$ifdef GDB}
  1184. function tpropertysym.stabstring : pchar;
  1185. begin
  1186. { !!!! don't know how to handle }
  1187. stabstring:=strpnew('');
  1188. end;
  1189. procedure tpropertysym.concatstabto(asmlist : taasmoutput);
  1190. begin
  1191. { !!!! don't know how to handle }
  1192. end;
  1193. {$endif GDB}
  1194. {****************************************************************************
  1195. TFUNCRETSYM
  1196. ****************************************************************************}
  1197. constructor tfuncretsym.create(const n : string;const tt:ttype);
  1198. begin
  1199. inherited create(n);
  1200. typ:=funcretsym;
  1201. returntype:=tt;
  1202. funcretstate:=vs_declared;
  1203. { address valid for ret in param only }
  1204. { otherwise set by insert }
  1205. address:=procinfo.return_offset;
  1206. end;
  1207. constructor tfuncretsym.ppuload(ppufile:tcompilerppufile);
  1208. begin
  1209. inherited loadsym(ppufile);
  1210. ppufile.gettype(returntype);
  1211. address:=ppufile.getlongint;
  1212. typ:=funcretsym;
  1213. end;
  1214. destructor tfuncretsym.destroy;
  1215. begin
  1216. inherited destroy;
  1217. end;
  1218. procedure tfuncretsym.ppuwrite(ppufile:tcompilerppufile);
  1219. begin
  1220. inherited writesym(ppufile);
  1221. ppufile.puttype(returntype);
  1222. ppufile.putlongint(address);
  1223. ppufile.writeentry(ibfuncretsym);
  1224. funcretstate:=vs_used;
  1225. end;
  1226. procedure tfuncretsym.deref;
  1227. begin
  1228. returntype.resolve;
  1229. end;
  1230. {$ifdef GDB}
  1231. procedure tfuncretsym.concatstabto(asmlist : taasmoutput);
  1232. begin
  1233. { Nothing to do here, it is done in genexitcode }
  1234. end;
  1235. {$endif GDB}
  1236. {****************************************************************************
  1237. TABSOLUTESYM
  1238. ****************************************************************************}
  1239. constructor tabsolutesym.create(const n : string;const tt : ttype);
  1240. begin
  1241. inherited create(n,tt);
  1242. typ:=absolutesym;
  1243. end;
  1244. constructor tabsolutesym.ppuload(ppufile:tcompilerppufile);
  1245. begin
  1246. { Note: This needs to load everything of tvarsym.write }
  1247. inherited ppuload(ppufile);
  1248. { load absolute }
  1249. typ:=absolutesym;
  1250. ref:=nil;
  1251. address:=0;
  1252. asmname:=nil;
  1253. abstyp:=absolutetyp(ppufile.getbyte);
  1254. absseg:=false;
  1255. case abstyp of
  1256. tovar :
  1257. asmname:=stringdup(ppufile.getstring);
  1258. toasm :
  1259. asmname:=stringdup(ppufile.getstring);
  1260. toaddr :
  1261. begin
  1262. address:=ppufile.getlongint;
  1263. absseg:=boolean(ppufile.getbyte);
  1264. end;
  1265. end;
  1266. end;
  1267. procedure tabsolutesym.ppuwrite(ppufile:tcompilerppufile);
  1268. var
  1269. hvo : tvaroptions;
  1270. begin
  1271. { Note: This needs to write everything of tvarsym.write }
  1272. inherited writesym(ppufile);
  1273. ppufile.putbyte(byte(varspez));
  1274. ppufile.putlongint(address);
  1275. { write only definition or definitionsym }
  1276. ppufile.puttype(vartype);
  1277. hvo:=varoptions-[vo_regable];
  1278. ppufile.putsmallset(hvo);
  1279. ppufile.putbyte(byte(abstyp));
  1280. case abstyp of
  1281. tovar :
  1282. ppufile.putstring(ref.name);
  1283. toasm :
  1284. ppufile.putstring(asmname^);
  1285. toaddr :
  1286. begin
  1287. ppufile.putlongint(address);
  1288. ppufile.putbyte(byte(absseg));
  1289. end;
  1290. end;
  1291. ppufile.writeentry(ibabsolutesym);
  1292. end;
  1293. procedure tabsolutesym.deref;
  1294. var
  1295. srsym : tsym;
  1296. srsymtable : tsymtable;
  1297. begin
  1298. { inheritance of varsym.deref ! }
  1299. vartype.resolve;
  1300. { own absolute deref }
  1301. if (abstyp=tovar) and (asmname<>nil) then
  1302. begin
  1303. { search previous loaded symtables }
  1304. searchsym(asmname^,srsym,srsymtable);
  1305. if not assigned(srsym) then
  1306. srsym:=searchsymonlyin(owner,asmname^);
  1307. if not assigned(srsym) then
  1308. srsym:=generrorsym;
  1309. ref:=tstoredsym(srsym);
  1310. stringdispose(asmname);
  1311. end;
  1312. end;
  1313. function tabsolutesym.mangledname : string;
  1314. begin
  1315. case abstyp of
  1316. tovar :
  1317. begin
  1318. case ref.typ of
  1319. varsym :
  1320. mangledname:=tvarsym(ref).mangledname;
  1321. else
  1322. internalerror(200111011);
  1323. end;
  1324. end;
  1325. toasm :
  1326. mangledname:=asmname^;
  1327. toaddr :
  1328. mangledname:='$'+tostr(address);
  1329. else
  1330. internalerror(10002);
  1331. end;
  1332. end;
  1333. {$ifdef GDB}
  1334. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1335. begin
  1336. { I don't know how to handle this !! }
  1337. end;
  1338. {$endif GDB}
  1339. {****************************************************************************
  1340. TVARSYM
  1341. ****************************************************************************}
  1342. constructor tvarsym.create(const n : string;const tt : ttype);
  1343. begin
  1344. inherited create(n);
  1345. typ:=varsym;
  1346. vartype:=tt;
  1347. _mangledname:=nil;
  1348. varspez:=vs_value;
  1349. address:=0;
  1350. localvarsym:=nil;
  1351. refs:=0;
  1352. varstate:=vs_used;
  1353. varoptions:=[];
  1354. { can we load the value into a register ? }
  1355. if tstoreddef(tt.def).is_intregable then
  1356. include(varoptions,vo_regable)
  1357. else
  1358. exclude(varoptions,vo_regable);
  1359. if tstoreddef(tt.def).is_fpuregable then
  1360. include(varoptions,vo_fpuregable)
  1361. else
  1362. exclude(varoptions,vo_fpuregable);
  1363. reg:=R_NO;
  1364. end;
  1365. constructor tvarsym.create_dll(const n : string;const tt : ttype);
  1366. begin
  1367. tvarsym(self).create(n,tt);
  1368. include(varoptions,vo_is_dll_var);
  1369. end;
  1370. constructor tvarsym.create_C(const n,mangled : string;const tt : ttype);
  1371. begin
  1372. tvarsym(self).create(n,tt);
  1373. stringdispose(_mangledname);
  1374. _mangledname:=stringdup(mangled);
  1375. end;
  1376. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1377. begin
  1378. inherited loadsym(ppufile);
  1379. typ:=varsym;
  1380. reg:=R_NO;
  1381. refs := 0;
  1382. varstate:=vs_used;
  1383. varspez:=tvarspez(ppufile.getbyte);
  1384. address:=ppufile.getlongint;
  1385. localvarsym:=nil;
  1386. ppufile.gettype(vartype);
  1387. ppufile.getsmallset(varoptions);
  1388. if (vo_is_C_var in varoptions) then
  1389. _mangledname:=stringdup(ppufile.getstring);
  1390. end;
  1391. destructor tvarsym.destroy;
  1392. begin
  1393. {$ifdef var_notification}
  1394. if assigned(notifications) then
  1395. notifications.destroy;
  1396. {$endif}
  1397. inherited destroy;
  1398. end;
  1399. procedure tvarsym.deref;
  1400. begin
  1401. vartype.resolve;
  1402. end;
  1403. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1404. var
  1405. hvo : tvaroptions;
  1406. begin
  1407. inherited writesym(ppufile);
  1408. ppufile.putbyte(byte(varspez));
  1409. ppufile.putlongint(address);
  1410. ppufile.puttype(vartype);
  1411. { symbols which are load are never candidates for a register,
  1412. turn off the regable }
  1413. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1414. ppufile.putsmallset(hvo);
  1415. if (vo_is_C_var in varoptions) then
  1416. ppufile.putstring(mangledname);
  1417. ppufile.writeentry(ibvarsym);
  1418. end;
  1419. procedure tvarsym.generate_mangledname;
  1420. begin
  1421. _mangledname:=stringdup(mangledname_prefix('U',owner)+name);
  1422. end;
  1423. procedure tvarsym.set_mangledname(const s:string);
  1424. begin
  1425. stringdispose(_mangledname);
  1426. _mangledname:=stringdup(s);
  1427. end;
  1428. function tvarsym.getsize : longint;
  1429. begin
  1430. if assigned(vartype.def) then
  1431. getsize:=vartype.def.size
  1432. else
  1433. getsize:=0;
  1434. end;
  1435. function tvarsym.getvaluesize : longint;
  1436. begin
  1437. if assigned(vartype.def) and
  1438. (varspez=vs_value) and
  1439. ((vartype.def.deftype<>arraydef) or
  1440. tarraydef(vartype.def).isDynamicArray or
  1441. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1442. getvaluesize:=vartype.def.size
  1443. else
  1444. getvaluesize:=0;
  1445. end;
  1446. {$ifdef var_notification}
  1447. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1448. Tnotification_callback):cardinal;
  1449. var n:Tnotification;
  1450. begin
  1451. if not assigned(notifications) then
  1452. notifications:=Tlinkedlist.create;
  1453. n:=Tnotification.create(flags,callback);
  1454. register_notification:=n.id;
  1455. notifications.concat(n);
  1456. end;
  1457. {$endif}
  1458. {$ifdef GDB}
  1459. function tvarsym.stabstring : pchar;
  1460. var
  1461. st : string;
  1462. begin
  1463. st:=tstoreddef(vartype.def).numberstring;
  1464. if (owner.symtabletype = objectsymtable) and
  1465. (sp_static in symoptions) then
  1466. begin
  1467. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1468. stabstring := strpnew('"'+owner.name^+'__'+name+':'+st+
  1469. '",'+
  1470. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1471. end
  1472. else if (owner.symtabletype = globalsymtable) then
  1473. begin
  1474. { Here we used S instead of
  1475. because with G GDB doesn't look at the address field
  1476. but searches the same name or with a leading underscore
  1477. but these names don't exist in pascal !}
  1478. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1479. stabstring := strpnew('"'+name+':'+st+'",'+
  1480. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1481. end
  1482. else if owner.symtabletype = staticsymtable then
  1483. begin
  1484. stabstring := strpnew('"'+name+':S'+st+'",'+
  1485. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1486. end
  1487. else if (owner.symtabletype in [parasymtable,inlineparasymtable]) then
  1488. begin
  1489. case varspez of
  1490. vs_out,
  1491. vs_var : st := 'v'+st;
  1492. vs_value,
  1493. vs_const : if paramanager.push_addr_param(vartype.def,tprocdef(owner.defowner).proccalloption) then
  1494. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1495. else
  1496. st := 'p'+st;
  1497. end;
  1498. stabstring := strpnew('"'+name+':'+st+'",'+
  1499. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1500. tostr(address+owner.address_fixup));
  1501. {offset to ebp => will not work if the framepointer is esp
  1502. so some optimizing will make things harder to debug }
  1503. end
  1504. else if (owner.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1505. if reg<>R_NO then
  1506. begin
  1507. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1508. { this is the register order for GDB}
  1509. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1510. tostr(N_RSYM)+',0,'+
  1511. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1512. end
  1513. else
  1514. { I don't know if this will work (PM) }
  1515. if (vo_is_C_var in varoptions) then
  1516. stabstring := strpnew('"'+name+':S'+st+'",'+
  1517. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1518. else
  1519. stabstring := strpnew('"'+name+':'+st+'",'+
  1520. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner.address_fixup))
  1521. else
  1522. stabstring := inherited stabstring;
  1523. end;
  1524. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1525. var stab_str : pchar;
  1526. begin
  1527. inherited concatstabto(asmlist);
  1528. if (owner.symtabletype=parasymtable) and
  1529. (reg<>R_NO) then
  1530. begin
  1531. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1532. { this is the register order for GDB}
  1533. stab_str:=strpnew('"'+name+':r'
  1534. +tstoreddef(vartype.def).numberstring+'",'+
  1535. tostr(N_RSYM)+',0,'+
  1536. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1537. asmList.concat(Tai_stabs.Create(stab_str));
  1538. end;
  1539. end;
  1540. {$endif GDB}
  1541. {****************************************************************************
  1542. TTYPEDCONSTSYM
  1543. *****************************************************************************}
  1544. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1545. begin
  1546. inherited create(n);
  1547. typ:=typedconstsym;
  1548. typedconsttype.setdef(p);
  1549. is_writable:=writable;
  1550. end;
  1551. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1552. begin
  1553. inherited create(n);
  1554. typ:=typedconstsym;
  1555. typedconsttype:=tt;
  1556. is_writable:=writable;
  1557. end;
  1558. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1559. begin
  1560. inherited loadsym(ppufile);
  1561. typ:=typedconstsym;
  1562. ppufile.gettype(typedconsttype);
  1563. is_writable:=boolean(ppufile.getbyte);
  1564. end;
  1565. destructor ttypedconstsym.destroy;
  1566. begin
  1567. inherited destroy;
  1568. end;
  1569. procedure ttypedconstsym.generate_mangledname;
  1570. begin
  1571. _mangledname:=stringdup(mangledname_prefix('TC',owner)+name);
  1572. end;
  1573. function ttypedconstsym.getsize : longint;
  1574. begin
  1575. if assigned(typedconsttype.def) then
  1576. getsize:=typedconsttype.def.size
  1577. else
  1578. getsize:=0;
  1579. end;
  1580. procedure ttypedconstsym.deref;
  1581. begin
  1582. typedconsttype.resolve;
  1583. end;
  1584. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1585. begin
  1586. inherited writesym(ppufile);
  1587. ppufile.puttype(typedconsttype);
  1588. ppufile.putbyte(byte(is_writable));
  1589. ppufile.writeentry(ibtypedconstsym);
  1590. end;
  1591. {$ifdef GDB}
  1592. function ttypedconstsym.stabstring : pchar;
  1593. var
  1594. st : char;
  1595. begin
  1596. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1597. st := 'G'
  1598. else
  1599. st := 'S';
  1600. stabstring := strpnew('"'+name+':'+st+
  1601. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1602. tostr(fileinfo.line)+','+mangledname);
  1603. end;
  1604. {$endif GDB}
  1605. {****************************************************************************
  1606. TCONSTSYM
  1607. ****************************************************************************}
  1608. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1609. begin
  1610. inherited create(n);
  1611. fillchar(value, sizeof(value), #0);
  1612. typ:=constsym;
  1613. consttyp:=t;
  1614. value.valueord:=v;
  1615. ResStrIndex:=0;
  1616. consttype.reset;
  1617. end;
  1618. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1619. begin
  1620. inherited create(n);
  1621. fillchar(value, sizeof(value), #0);
  1622. typ:=constsym;
  1623. consttyp:=t;
  1624. value.valueord:=v;
  1625. ResStrIndex:=0;
  1626. consttype:=tt;
  1627. end;
  1628. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1629. begin
  1630. inherited create(n);
  1631. fillchar(value, sizeof(value), #0);
  1632. typ:=constsym;
  1633. consttyp:=t;
  1634. value.valueordptr:=v;
  1635. ResStrIndex:=0;
  1636. consttype:=tt;
  1637. end;
  1638. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1639. begin
  1640. inherited create(n);
  1641. fillchar(value, sizeof(value), #0);
  1642. typ:=constsym;
  1643. consttyp:=t;
  1644. value.valueptr:=v;
  1645. ResStrIndex:=0;
  1646. consttype.reset;
  1647. end;
  1648. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1649. begin
  1650. inherited create(n);
  1651. fillchar(value, sizeof(value), #0);
  1652. typ:=constsym;
  1653. consttyp:=t;
  1654. value.valueptr:=v;
  1655. ResStrIndex:=0;
  1656. consttype:=tt;
  1657. end;
  1658. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1659. begin
  1660. inherited create(n);
  1661. fillchar(value, sizeof(value), #0);
  1662. typ:=constsym;
  1663. consttyp:=t;
  1664. value.valueptr:=str;
  1665. consttype.reset;
  1666. value.len:=l;
  1667. if t=constresourcestring then
  1668. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1669. end;
  1670. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1671. var
  1672. pd : pbestreal;
  1673. ps : pnormalset;
  1674. pc : pchar;
  1675. begin
  1676. inherited loadsym(ppufile);
  1677. typ:=constsym;
  1678. consttype.reset;
  1679. consttyp:=tconsttyp(ppufile.getbyte);
  1680. fillchar(value, sizeof(value), #0);
  1681. case consttyp of
  1682. constint:
  1683. value.valueord:=ppufile.getexprint;
  1684. constwchar,
  1685. constbool,
  1686. constchar :
  1687. value.valueord:=ppufile.getlongint;
  1688. constord :
  1689. begin
  1690. ppufile.gettype(consttype);
  1691. value.valueord:=ppufile.getexprint;
  1692. end;
  1693. constpointer :
  1694. begin
  1695. ppufile.gettype(consttype);
  1696. value.valueordptr:=ppufile.getptruint;
  1697. end;
  1698. conststring,
  1699. constresourcestring :
  1700. begin
  1701. value.len:=ppufile.getlongint;
  1702. getmem(pc,value.len+1);
  1703. ppufile.getdata(pc^,value.len);
  1704. if consttyp=constresourcestring then
  1705. ResStrIndex:=ppufile.getlongint;
  1706. value.valueptr:=pc;
  1707. end;
  1708. constreal :
  1709. begin
  1710. new(pd);
  1711. pd^:=ppufile.getreal;
  1712. value.valueptr:=pd;
  1713. end;
  1714. constset :
  1715. begin
  1716. ppufile.gettype(consttype);
  1717. new(ps);
  1718. ppufile.getnormalset(ps^);
  1719. value.valueptr:=ps;
  1720. end;
  1721. constguid :
  1722. begin
  1723. new(pguid(value.valueptr));
  1724. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1725. end;
  1726. constnil : ;
  1727. else
  1728. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1729. end;
  1730. end;
  1731. destructor tconstsym.destroy;
  1732. begin
  1733. case consttyp of
  1734. conststring,
  1735. constresourcestring :
  1736. freemem(pchar(value.valueptr),value.len+1);
  1737. constreal :
  1738. dispose(pbestreal(value.valueptr));
  1739. constset :
  1740. dispose(pnormalset(value.valueptr));
  1741. constguid :
  1742. dispose(pguid(value.valueptr));
  1743. end;
  1744. inherited destroy;
  1745. end;
  1746. function tconstsym.mangledname : string;
  1747. begin
  1748. mangledname:=name;
  1749. end;
  1750. procedure tconstsym.deref;
  1751. begin
  1752. if consttyp in [constord,constpointer,constset] then
  1753. consttype.resolve;
  1754. end;
  1755. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1756. begin
  1757. inherited writesym(ppufile);
  1758. ppufile.putbyte(byte(consttyp));
  1759. case consttyp of
  1760. constnil : ;
  1761. constint:
  1762. ppufile.putexprint(value.valueord);
  1763. constbool,
  1764. constchar :
  1765. ppufile.putlongint(value.valueord);
  1766. constord :
  1767. begin
  1768. ppufile.puttype(consttype);
  1769. ppufile.putexprint(value.valueord);
  1770. end;
  1771. constpointer :
  1772. begin
  1773. ppufile.puttype(consttype);
  1774. ppufile.putptruint(value.valueordptr);
  1775. end;
  1776. conststring,
  1777. constresourcestring :
  1778. begin
  1779. ppufile.putlongint(value.len);
  1780. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1781. if consttyp=constresourcestring then
  1782. ppufile.putlongint(ResStrIndex);
  1783. end;
  1784. constreal :
  1785. ppufile.putreal(pbestreal(value.valueptr)^);
  1786. constset :
  1787. begin
  1788. ppufile.puttype(consttype);
  1789. ppufile.putnormalset(value.valueptr^);
  1790. end;
  1791. constguid :
  1792. ppufile.putdata(value.valueptr^,sizeof(tguid));
  1793. else
  1794. internalerror(13);
  1795. end;
  1796. ppufile.writeentry(ibconstsym);
  1797. end;
  1798. {$ifdef GDB}
  1799. function tconstsym.stabstring : pchar;
  1800. var st : string;
  1801. begin
  1802. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1803. case consttyp of
  1804. conststring : begin
  1805. st := 's'''+strpas(pchar(value.valueptr))+'''';
  1806. end;
  1807. constbool,
  1808. constint,
  1809. constord,
  1810. constchar : st := 'i'+int64tostr(value.valueord);
  1811. constpointer :
  1812. st := 'i'+int64tostr(value.valueordptr);
  1813. constreal : begin
  1814. system.str(pbestreal(value.valueptr)^,st);
  1815. st := 'r'+st;
  1816. end;
  1817. { if we don't know just put zero !! }
  1818. else st:='i0';
  1819. {***SETCONST}
  1820. {constset:;} {*** I don't know what to do with a set.}
  1821. { sets are not recognized by GDB}
  1822. {***}
  1823. end;
  1824. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1825. tostr(fileinfo.line)+',0');
  1826. end;
  1827. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  1828. begin
  1829. if consttyp <> conststring then
  1830. inherited concatstabto(asmlist);
  1831. end;
  1832. {$endif GDB}
  1833. {****************************************************************************
  1834. TENUMSYM
  1835. ****************************************************************************}
  1836. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1837. begin
  1838. inherited create(n);
  1839. typ:=enumsym;
  1840. definition:=def;
  1841. value:=v;
  1842. { check for jumps }
  1843. if v>def.max+1 then
  1844. def.has_jumps:=true;
  1845. { update low and high }
  1846. if def.min>v then
  1847. def.setmin(v);
  1848. if def.max<v then
  1849. def.setmax(v);
  1850. order;
  1851. end;
  1852. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1853. begin
  1854. inherited loadsym(ppufile);
  1855. typ:=enumsym;
  1856. definition:=tenumdef(ppufile.getderef);
  1857. value:=ppufile.getlongint;
  1858. nextenum := Nil;
  1859. end;
  1860. procedure tenumsym.deref;
  1861. begin
  1862. resolvedef(pointer(definition));
  1863. order;
  1864. end;
  1865. procedure tenumsym.order;
  1866. var
  1867. sym : tenumsym;
  1868. begin
  1869. sym := tenumsym(definition.firstenum);
  1870. if sym = nil then
  1871. begin
  1872. definition.firstenum := self;
  1873. nextenum := nil;
  1874. exit;
  1875. end;
  1876. { reorder the symbols in increasing value }
  1877. if value < sym.value then
  1878. begin
  1879. nextenum := sym;
  1880. definition.firstenum := self;
  1881. end
  1882. else
  1883. begin
  1884. while (sym.value <= value) and assigned(sym.nextenum) do
  1885. sym := sym.nextenum;
  1886. nextenum := sym.nextenum;
  1887. sym.nextenum := self;
  1888. end;
  1889. end;
  1890. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1891. begin
  1892. inherited writesym(ppufile);
  1893. ppufile.putderef(definition);
  1894. ppufile.putlongint(value);
  1895. ppufile.writeentry(ibenumsym);
  1896. end;
  1897. {$ifdef GDB}
  1898. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  1899. begin
  1900. {enum elements have no stab !}
  1901. end;
  1902. {$EndIf GDB}
  1903. {****************************************************************************
  1904. TTYPESYM
  1905. ****************************************************************************}
  1906. constructor ttypesym.create(const n : string;const tt : ttype);
  1907. begin
  1908. inherited create(n);
  1909. typ:=typesym;
  1910. restype:=tt;
  1911. {$ifdef GDB}
  1912. isusedinstab := false;
  1913. {$endif GDB}
  1914. { register the typesym for the definition }
  1915. if assigned(restype.def) and
  1916. (restype.def.deftype<>errordef) and
  1917. not(assigned(restype.def.typesym)) then
  1918. restype.def.typesym:=self;
  1919. end;
  1920. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1921. begin
  1922. inherited loadsym(ppufile);
  1923. typ:=typesym;
  1924. {$ifdef GDB}
  1925. isusedinstab := false;
  1926. {$endif GDB}
  1927. ppufile.gettype(restype);
  1928. end;
  1929. function ttypesym.gettypedef:tdef;
  1930. begin
  1931. gettypedef:=restype.def;
  1932. end;
  1933. procedure ttypesym.deref;
  1934. begin
  1935. restype.resolve;
  1936. end;
  1937. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1938. begin
  1939. inherited writesym(ppufile);
  1940. ppufile.puttype(restype);
  1941. ppufile.writeentry(ibtypesym);
  1942. end;
  1943. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1944. begin
  1945. inherited load_references(ppufile,locals);
  1946. if (restype.def.deftype=recorddef) then
  1947. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1948. if (restype.def.deftype=objectdef) then
  1949. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1950. end;
  1951. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1952. begin
  1953. if not inherited write_references(ppufile,locals) then
  1954. begin
  1955. { write address of this symbol if record or object
  1956. even if no real refs are there
  1957. because we need it for the symtable }
  1958. if (restype.def.deftype in [recorddef,objectdef]) then
  1959. begin
  1960. ppufile.putderef(self);
  1961. ppufile.writeentry(ibsymref);
  1962. end;
  1963. end;
  1964. write_references:=true;
  1965. if (restype.def.deftype=recorddef) then
  1966. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1967. if (restype.def.deftype=objectdef) then
  1968. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1969. end;
  1970. {$ifdef GDB}
  1971. function ttypesym.stabstring : pchar;
  1972. var
  1973. stabchar : string[2];
  1974. short : string;
  1975. begin
  1976. if restype.def.deftype in tagtypes then
  1977. stabchar := 'Tt'
  1978. else
  1979. stabchar := 't';
  1980. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  1981. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1982. stabstring := strpnew(short);
  1983. end;
  1984. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  1985. begin
  1986. {not stabs for forward defs }
  1987. if assigned(restype.def) then
  1988. if (restype.def.typesym = self) then
  1989. tstoreddef(restype.def).concatstabto(asmlist)
  1990. else
  1991. inherited concatstabto(asmlist);
  1992. end;
  1993. {$endif GDB}
  1994. {****************************************************************************
  1995. TSYSSYM
  1996. ****************************************************************************}
  1997. constructor tsyssym.create(const n : string;l : longint);
  1998. begin
  1999. inherited create(n);
  2000. typ:=syssym;
  2001. number:=l;
  2002. end;
  2003. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2004. begin
  2005. inherited loadsym(ppufile);
  2006. typ:=syssym;
  2007. number:=ppufile.getlongint;
  2008. end;
  2009. destructor tsyssym.destroy;
  2010. begin
  2011. inherited destroy;
  2012. end;
  2013. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2014. begin
  2015. inherited writesym(ppufile);
  2016. ppufile.putlongint(number);
  2017. ppufile.writeentry(ibsyssym);
  2018. end;
  2019. {$ifdef GDB}
  2020. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  2021. begin
  2022. end;
  2023. {$endif GDB}
  2024. {****************************************************************************
  2025. TRTTISYM
  2026. ****************************************************************************}
  2027. constructor trttisym.create(const n:string;rt:trttitype);
  2028. const
  2029. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2030. begin
  2031. inherited create(prefix[rt]+n);
  2032. typ:=rttisym;
  2033. lab:=nil;
  2034. rttityp:=rt;
  2035. end;
  2036. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2037. begin
  2038. inherited loadsym(ppufile);
  2039. typ:=rttisym;
  2040. lab:=nil;
  2041. rttityp:=trttitype(ppufile.getbyte);
  2042. end;
  2043. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2044. begin
  2045. inherited writesym(ppufile);
  2046. ppufile.putbyte(byte(rttityp));
  2047. ppufile.writeentry(ibrttisym);
  2048. end;
  2049. function trttisym.mangledname : string;
  2050. const
  2051. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2052. var
  2053. s : string;
  2054. p : tsymtable;
  2055. begin
  2056. s:='';
  2057. p:=owner;
  2058. while assigned(p) and (p.symtabletype=localsymtable) do
  2059. begin
  2060. s:=s+'_'+p.defowner.name;
  2061. p:=p.defowner.owner;
  2062. end;
  2063. if not(p.symtabletype in [globalsymtable,staticsymtable]) then
  2064. internalerror(200108265);
  2065. mangledname:=prefix[rttityp]+p.name^+s+'$_'+Copy(name,5,255);
  2066. end;
  2067. function trttisym.get_label:tasmsymbol;
  2068. begin
  2069. { the label is always a global label }
  2070. if not assigned(lab) then
  2071. lab:=objectlibrary.newasmsymboltype(mangledname,AB_GLOBAL,AT_DATA);
  2072. get_label:=lab;
  2073. end;
  2074. { persistent rtti generation }
  2075. procedure generate_rtti(p:tsym);
  2076. var
  2077. rsym : trttisym;
  2078. def : tstoreddef;
  2079. begin
  2080. { rtti can only be generated for classes that are always typesyms }
  2081. if not(p.typ=typesym) then
  2082. internalerror(200108261);
  2083. def:=tstoreddef(ttypesym(p).restype.def);
  2084. { only create rtti once for each definition }
  2085. if not(df_has_rttitable in def.defoptions) then
  2086. begin
  2087. { definition should be in the same symtable as the symbol }
  2088. if p.owner<>def.owner then
  2089. internalerror(200108262);
  2090. { create rttisym }
  2091. rsym:=trttisym.create(p.name,fullrtti);
  2092. p.owner.insert(rsym);
  2093. { register rttisym in definition }
  2094. include(def.defoptions,df_has_rttitable);
  2095. def.rttitablesym:=rsym;
  2096. { write rtti data }
  2097. def.write_child_rtti_data(fullrtti);
  2098. if (cs_create_smart in aktmoduleswitches) then
  2099. rttiList.concat(Tai_cut.Create);
  2100. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2101. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2102. def.write_rtti_data(fullrtti);
  2103. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2104. end;
  2105. end;
  2106. { persistent init table generation }
  2107. procedure generate_inittable(p:tsym);
  2108. var
  2109. rsym : trttisym;
  2110. def : tstoreddef;
  2111. begin
  2112. { anonymous types are also allowed for records that can be varsym }
  2113. case p.typ of
  2114. typesym :
  2115. def:=tstoreddef(ttypesym(p).restype.def);
  2116. varsym :
  2117. def:=tstoreddef(tvarsym(p).vartype.def);
  2118. else
  2119. internalerror(200108263);
  2120. end;
  2121. { only create inittable once for each definition }
  2122. if not(df_has_inittable in def.defoptions) then
  2123. begin
  2124. { definition should be in the same symtable as the symbol }
  2125. if p.owner<>def.owner then
  2126. internalerror(200108264);
  2127. { create rttisym }
  2128. rsym:=trttisym.create(p.name,initrtti);
  2129. p.owner.insert(rsym);
  2130. { register rttisym in definition }
  2131. include(def.defoptions,df_has_inittable);
  2132. def.inittablesym:=rsym;
  2133. { write inittable data }
  2134. def.write_child_rtti_data(initrtti);
  2135. if (cs_create_smart in aktmoduleswitches) then
  2136. rttiList.concat(Tai_cut.Create);
  2137. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2138. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2139. def.write_rtti_data(initrtti);
  2140. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2141. end;
  2142. end;
  2143. end.
  2144. {
  2145. $Log$
  2146. Revision 1.79 2002-11-27 20:04:10 peter
  2147. * tvarsym.get_push_size replaced by paramanager.push_size
  2148. Revision 1.78 2002/11/27 02:34:20 peter
  2149. * only find real equal procvars
  2150. Revision 1.77 2002/11/25 18:43:34 carl
  2151. - removed the invalid if <> checking (Delphi is strange on this)
  2152. + implemented abstract warning on instance creation of class with
  2153. abstract methods.
  2154. * some error message cleanups
  2155. Revision 1.76 2002/11/25 17:43:26 peter
  2156. * splitted defbase in defutil,symutil,defcmp
  2157. * merged isconvertable and is_equal into compare_defs(_ext)
  2158. * made operator search faster by walking the list only once
  2159. Revision 1.75 2002/11/23 22:50:09 carl
  2160. * some small speed optimizations
  2161. + added several new warnings/hints
  2162. Revision 1.74 2002/11/22 22:48:11 carl
  2163. * memory optimization with tconstsym (1.5%)
  2164. Revision 1.73 2002/11/18 17:31:59 peter
  2165. * pass proccalloption to ret_in_xxx and push_xxx functions
  2166. Revision 1.72 2002/11/17 16:31:57 carl
  2167. * memory optimization (3-4%) : cleanup of tai fields,
  2168. cleanup of tdef and tsym fields.
  2169. * make it work for m68k
  2170. Revision 1.71 2002/11/09 15:30:07 carl
  2171. + align RTTI tables
  2172. Revision 1.70 2002/10/13 21:33:37 peter
  2173. * give correct fileposition for undefined forward procs
  2174. Revision 1.69 2002/10/05 12:43:29 carl
  2175. * fixes for Delphi 6 compilation
  2176. (warning : Some features do not work under Delphi)
  2177. Revision 1.68 2002/10/05 00:52:20 peter
  2178. * split boolean check in two lines for easier debugging
  2179. Revision 1.67 2002/09/26 12:04:53 florian
  2180. + constsym with type=constguid can be written to ppu now,
  2181. fixes web bug 1820
  2182. Revision 1.66 2002/09/16 14:11:13 peter
  2183. * add argument to equal_paras() to support default values or not
  2184. Revision 1.65 2002/09/09 17:34:16 peter
  2185. * tdicationary.replace added to replace and item in a dictionary. This
  2186. is only allowed for the same name
  2187. * varsyms are inserted in symtable before the types are parsed. This
  2188. fixes the long standing "var longint : longint" bug
  2189. - consume_idlist and idstringlist removed. The loops are inserted
  2190. at the callers place and uses the symtable for duplicate id checking
  2191. Revision 1.64 2002/09/08 11:10:17 carl
  2192. * bugfix 2109 (bad imho, but only way)
  2193. Revision 1.63 2002/09/07 18:17:41 florian
  2194. + tvarsym.paraitem added
  2195. Revision 1.62 2002/09/07 15:25:10 peter
  2196. * old logs removed and tabs fixed
  2197. Revision 1.61 2002/09/05 19:29:45 peter
  2198. * memdebug enhancements
  2199. Revision 1.60 2002/09/05 14:51:42 peter
  2200. * internalerror instead of crash in getprocdef
  2201. Revision 1.59 2002/09/03 16:26:27 daniel
  2202. * Make Tprocdef.defs protected
  2203. Revision 1.58 2002/09/01 08:01:16 daniel
  2204. * Removed sets from Tcallnode.det_resulttype
  2205. + Added read/write notifications of variables. These will be usefull
  2206. for providing information for several optimizations. For example
  2207. the value of the loop variable of a for loop does matter is the
  2208. variable is read after the for loop, but if it's no longer used
  2209. or written, it doesn't matter and this can be used to optimize
  2210. the loop code generation.
  2211. Revision 1.57 2002/08/25 19:25:21 peter
  2212. * sym.insert_in_data removed
  2213. * symtable.insertvardata/insertconstdata added
  2214. * removed insert_in_data call from symtable.insert, it needs to be
  2215. called separatly. This allows to deref the address calculation
  2216. * procedures now calculate the parast addresses after the procedure
  2217. directives are parsed. This fixes the cdecl parast problem
  2218. * push_addr_param has an extra argument that specifies if cdecl is used
  2219. or not
  2220. Revision 1.56 2002/08/25 09:06:21 peter
  2221. * fixed loop in concat_procdefs
  2222. Revision 1.55 2002/08/20 16:54:40 peter
  2223. * write address of varsym always
  2224. Revision 1.54 2002/08/20 10:31:26 daniel
  2225. * Tcallnode.det_resulttype rewritten
  2226. Revision 1.53 2002/08/18 20:06:27 peter
  2227. * inlining is now also allowed in interface
  2228. * renamed write/load to ppuwrite/ppuload
  2229. * tnode storing in ppu
  2230. * nld,ncon,nbas are already updated for storing in ppu
  2231. Revision 1.52 2002/08/17 09:23:42 florian
  2232. * first part of procinfo rewrite
  2233. Revision 1.51 2002/08/16 14:24:59 carl
  2234. * issameref() to test if two references are the same (then emit no opcodes)
  2235. + ret_in_reg to replace ret_in_acc
  2236. (fix some register allocation bugs at the same time)
  2237. + save_std_register now has an extra parameter which is the
  2238. usedinproc registers
  2239. Revision 1.50 2002/08/13 21:40:57 florian
  2240. * more fixes for ppc calling conventions
  2241. Revision 1.49 2002/08/12 15:08:40 carl
  2242. + stab register indexes for powerpc (moved from gdb to cpubase)
  2243. + tprocessor enumeration moved to cpuinfo
  2244. + linker in target_info is now a class
  2245. * many many updates for m68k (will soon start to compile)
  2246. - removed some ifdef or correct them for correct cpu
  2247. Revision 1.48 2002/08/11 14:32:28 peter
  2248. * renamed current_library to objectlibrary
  2249. Revision 1.47 2002/08/11 13:24:14 peter
  2250. * saving of asmsymbols in ppu supported
  2251. * asmsymbollist global is removed and moved into a new class
  2252. tasmlibrarydata that will hold the info of a .a file which
  2253. corresponds with a single module. Added librarydata to tmodule
  2254. to keep the library info stored for the module. In the future the
  2255. objectfiles will also be stored to the tasmlibrarydata class
  2256. * all getlabel/newasmsymbol and friends are moved to the new class
  2257. Revision 1.46 2002/07/23 10:13:23 daniel
  2258. * Added important comment
  2259. Revision 1.45 2002/07/23 09:51:26 daniel
  2260. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2261. are worth comitting.
  2262. Revision 1.44 2002/07/20 17:45:29 daniel
  2263. * Register variables are now possible for global variables too. This is
  2264. important for small programs without procedures.
  2265. Revision 1.43 2002/07/20 11:57:58 florian
  2266. * types.pas renamed to defbase.pas because D6 contains a types
  2267. unit so this would conflicts if D6 programms are compiled
  2268. + Willamette/SSE2 instructions to assembler added
  2269. Revision 1.42 2002/07/11 14:41:31 florian
  2270. * start of the new generic parameter handling
  2271. }