symsym.pas 78 KB

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