symsym.pas 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  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:boolean):Tprocdef;
  129. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  130. function search_procdef_by1paradef(firstpara:Tdef):Tprocdef;
  131. function search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
  132. matchtype:Tdefmatch):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. {$ifdef var_notification}
  165. notifications : Tlinkedlist;
  166. {$endif}
  167. constructor create(const n : string;const tt : ttype);
  168. constructor create_dll(const n : string;const tt : ttype);
  169. constructor create_C(const n,mangled : string;const tt : ttype);
  170. constructor ppuload(ppufile:tcompilerppufile);
  171. destructor destroy;override;
  172. procedure ppuwrite(ppufile:tcompilerppufile);override;
  173. procedure deref;override;
  174. procedure generate_mangledname;override;
  175. procedure set_mangledname(const s:string);
  176. function getsize : longint;
  177. function getvaluesize : longint;
  178. function getpushsize(is_cdecl:boolean): 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. tconstsym = class(tstoredsym)
  254. consttype : ttype;
  255. consttyp : tconsttyp;
  256. resstrindex, { needed for resource strings }
  257. valueord : tconstexprint; { used for ordinal values }
  258. valueordptr : TConstPtrUInt; { used for pointer values }
  259. valueptr : pointer; { used for string, set, real values }
  260. len : longint; { len is needed for string length }
  261. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint);
  262. constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  263. constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  264. constructor create_ptr(const n : string;t : tconsttyp;v : pointer);
  265. constructor create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  266. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  267. constructor ppuload(ppufile:tcompilerppufile);
  268. destructor destroy;override;
  269. function mangledname : string;
  270. procedure deref;override;
  271. procedure ppuwrite(ppufile:tcompilerppufile);override;
  272. {$ifdef GDB}
  273. function stabstring : pchar;override;
  274. procedure concatstabto(asmlist : taasmoutput);override;
  275. {$endif GDB}
  276. end;
  277. tenumsym = class(tstoredsym)
  278. value : longint;
  279. definition : tenumdef;
  280. nextenum : tenumsym;
  281. constructor create(const n : string;def : tenumdef;v : longint);
  282. constructor ppuload(ppufile:tcompilerppufile);
  283. procedure ppuwrite(ppufile:tcompilerppufile);override;
  284. procedure deref;override;
  285. procedure order;
  286. {$ifdef GDB}
  287. procedure concatstabto(asmlist : taasmoutput);override;
  288. {$endif GDB}
  289. end;
  290. tsyssym = class(tstoredsym)
  291. number : longint;
  292. constructor create(const n : string;l : longint);
  293. constructor ppuload(ppufile:tcompilerppufile);
  294. destructor destroy;override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. {$ifdef GDB}
  297. procedure concatstabto(asmlist : taasmoutput);override;
  298. {$endif GDB}
  299. end;
  300. { compiler generated symbol to point to rtti and init/finalize tables }
  301. trttisym = class(tstoredsym)
  302. lab : tasmsymbol;
  303. rttityp : trttitype;
  304. constructor create(const n:string;rt:trttitype);
  305. constructor ppuload(ppufile:tcompilerppufile);
  306. procedure ppuwrite(ppufile:tcompilerppufile);override;
  307. function mangledname:string;
  308. function get_label:tasmsymbol;
  309. end;
  310. { register variables }
  311. pregvarinfo = ^tregvarinfo;
  312. tregvarinfo = record
  313. regvars : array[1..maxvarregs] of tvarsym;
  314. regvars_para : array[1..maxvarregs] of boolean;
  315. regvars_refs : array[1..maxvarregs] of longint;
  316. fpuregvars : array[1..maxfpuvarregs] of tvarsym;
  317. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  318. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  319. end;
  320. var
  321. aktprocsym : tprocsym; { pointer to the symbol for the
  322. currently be parsed procedure }
  323. aktprocdef : tprocdef;
  324. aktcallprocdef : tabstractprocdef; { pointer to the definition of the
  325. currently called procedure,
  326. only set/unset in ncal }
  327. aktvarsym : tvarsym; { pointer to the symbol for the
  328. currently read var, only used
  329. for variable directives }
  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. globtype,verbose,
  346. { target }
  347. systems,
  348. { symtable }
  349. symtable,defbase,
  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:=-1; { 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(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 pd:Pprocdeflist;
  812. begin
  813. pd:=defs;
  814. while assigned(pd) do
  815. begin
  816. if Aprocsym.search_procdef_bypara(pd^.def.para,false)=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:boolean):Tprocdef;
  887. var pd:Pprocdeflist;
  888. begin
  889. search_procdef_bypara:=nil;
  890. pd:=defs;
  891. while assigned(pd) do
  892. begin
  893. if equal_paras(pd^.def.para,params,cp_value_equal_const) or
  894. (allowconvert and convertable_paras(pd^.def.para,params,
  895. cp_value_equal_const)) then
  896. begin
  897. search_procdef_bypara:=pd^.def;
  898. break;
  899. end;
  900. pd:=pd^.next;
  901. end;
  902. end;
  903. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  904. var pd:Pprocdeflist;
  905. begin
  906. {This function will return the pprocdef of pprocsym that
  907. is the best match for procvardef. When there are multiple
  908. matches it returns nil.}
  909. {Try to find an exact match first.}
  910. search_procdef_byprocvardef:=nil;
  911. pd:=defs;
  912. while assigned(pd) do
  913. begin
  914. if proc_to_procvar_equal(pd^.def,d,true) then
  915. begin
  916. { already found a match ? Then stop and return nil }
  917. if assigned(search_procdef_byprocvardef) then
  918. begin
  919. search_procdef_byprocvardef:=nil;
  920. break;
  921. end;
  922. search_procdef_byprocvardef:=pd^.def;
  923. end;
  924. pd:=pd^.next;
  925. end;
  926. {Try a convertable match, if no exact match was found.}
  927. if not assigned(search_procdef_byprocvardef) and not assigned(pd) then
  928. begin
  929. pd:=defs;
  930. while assigned(pd) do
  931. begin
  932. if proc_to_procvar_equal(pd^.def,d,false) then
  933. begin
  934. { already found a match ? Then stop and return nil }
  935. if assigned(search_procdef_byprocvardef) then
  936. begin
  937. search_procdef_byprocvardef:=nil;
  938. break;
  939. end;
  940. search_procdef_byprocvardef:=pd^.def;
  941. end;
  942. pd:=pd^.next;
  943. end;
  944. end;
  945. end;
  946. function Tprocsym.search_procdef_by1paradef(firstpara:Tdef):Tprocdef;
  947. var pd:Pprocdeflist;
  948. begin
  949. search_procdef_by1paradef:=nil;
  950. pd:=defs;
  951. while assigned(pd) do
  952. begin
  953. if is_equal(Tparaitem(pd^.def.para.first).paratype.def,firstpara) and
  954. (Tparaitem(pd^.def.para.first).next=nil) then
  955. begin
  956. search_procdef_by1paradef:=pd^.def;
  957. break;
  958. end;
  959. pd:=pd^.next;
  960. end;
  961. end;
  962. function Tprocsym.search_procdef_byretdef_by1paradef(retdef,firstpara:Tdef;
  963. matchtype:Tdefmatch):Tprocdef;
  964. var pd:Pprocdeflist;
  965. convtyp:Tconverttype;
  966. a,b:boolean;
  967. begin
  968. search_procdef_byretdef_by1paradef:=nil;
  969. pd:=defs;
  970. while assigned(pd) do
  971. begin
  972. a:=is_equal(retdef,pd^.def.rettype.def);
  973. {Alert alert alert alert alert alert alert!!!
  974. Make sure you never call isconvertable when a=false. You get
  975. endless recursion then. Originally a and b were placed in a
  976. single if statement. There was only one reason that it worked:
  977. short circuit boolean eval.}
  978. if a then
  979. case matchtype of
  980. dm_exact:
  981. b:=TParaItem(pd^.def.para.first).paratype.def=firstpara;
  982. dm_equal:
  983. b:=is_equal(Tparaitem(pd^.def.para.first).paratype.def,firstpara);
  984. dm_convertl1:
  985. b:=isconvertable(firstpara,Tparaitem(pd^.def.para.first).paratype.def,
  986. convtyp,ordconstn,false)=1;
  987. end;
  988. if a and b then
  989. begin
  990. search_procdef_byretdef_by1paradef:=pd^.def;
  991. break;
  992. end;
  993. pd:=pd^.next;
  994. end;
  995. end;
  996. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  997. var
  998. p : pprocdeflist;
  999. begin
  1000. inherited writesym(ppufile);
  1001. p:=defs;
  1002. while assigned(p) do
  1003. begin
  1004. { only write the proc definitions that belong
  1005. to this procsym }
  1006. if (p^.def.procsym=self) then
  1007. ppufile.putderef(p^.def);
  1008. p:=p^.next;
  1009. end;
  1010. ppufile.putderef(nil);
  1011. ppufile.writeentry(ibprocsym);
  1012. end;
  1013. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  1014. var
  1015. p : pprocdeflist;
  1016. begin
  1017. write_references:=false;
  1018. if not inherited write_references(ppufile,locals) then
  1019. exit;
  1020. write_references:=true;
  1021. p:=defs;
  1022. while assigned(p) do
  1023. begin
  1024. if (p^.def.procsym=self) then
  1025. p^.def.write_references(ppufile,locals);
  1026. p:=p^.next;
  1027. end;
  1028. end;
  1029. procedure tprocsym.unchain_overload;
  1030. var
  1031. p,hp,
  1032. first,
  1033. last : pprocdeflist;
  1034. begin
  1035. { remove all overloaded procdefs from the
  1036. procdeflist that are not in the current symtable }
  1037. first:=nil;
  1038. last:=nil;
  1039. p:=defs;
  1040. while assigned(p) do
  1041. begin
  1042. hp:=p^.next;
  1043. if (p^.def.procsym=self) then
  1044. begin
  1045. { keep in list }
  1046. if not assigned(first) then
  1047. begin
  1048. first:=p;
  1049. last:=p;
  1050. end
  1051. else
  1052. last^.next:=p;
  1053. last:=p;
  1054. p^.next:=nil;
  1055. end
  1056. else
  1057. begin
  1058. { remove }
  1059. dispose(p);
  1060. dec(procdef_count);
  1061. end;
  1062. p:=hp;
  1063. end;
  1064. defs:=first;
  1065. end;
  1066. {$ifdef GDB}
  1067. function tprocsym.stabstring : pchar;
  1068. begin
  1069. internalerror(200111171);
  1070. stabstring:=nil;
  1071. end;
  1072. procedure tprocsym.concatstabto(asmlist : taasmoutput);
  1073. begin
  1074. internalerror(200111172);
  1075. end;
  1076. {$endif GDB}
  1077. {****************************************************************************
  1078. TERRORSYM
  1079. ****************************************************************************}
  1080. constructor terrorsym.create;
  1081. begin
  1082. inherited create('');
  1083. typ:=errorsym;
  1084. end;
  1085. {****************************************************************************
  1086. TPROPERTYSYM
  1087. ****************************************************************************}
  1088. constructor tpropertysym.create(const n : string);
  1089. begin
  1090. inherited create(n);
  1091. typ:=propertysym;
  1092. propoptions:=[];
  1093. index:=0;
  1094. default:=0;
  1095. proptype.reset;
  1096. indextype.reset;
  1097. readaccess:=tsymlist.create;
  1098. writeaccess:=tsymlist.create;
  1099. storedaccess:=tsymlist.create;
  1100. end;
  1101. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1102. begin
  1103. inherited loadsym(ppufile);
  1104. typ:=propertysym;
  1105. ppufile.getsmallset(propoptions);
  1106. if (ppo_is_override in propoptions) then
  1107. begin
  1108. propoverriden:=tpropertysym(ppufile.getderef);
  1109. { we need to have these objects initialized }
  1110. readaccess:=tsymlist.create;
  1111. writeaccess:=tsymlist.create;
  1112. storedaccess:=tsymlist.create;
  1113. end
  1114. else
  1115. begin
  1116. ppufile.gettype(proptype);
  1117. index:=ppufile.getlongint;
  1118. default:=ppufile.getlongint;
  1119. ppufile.gettype(indextype);
  1120. readaccess:=ppufile.getsymlist;
  1121. writeaccess:=ppufile.getsymlist;
  1122. storedaccess:=ppufile.getsymlist;
  1123. end;
  1124. end;
  1125. destructor tpropertysym.destroy;
  1126. begin
  1127. readaccess.free;
  1128. writeaccess.free;
  1129. storedaccess.free;
  1130. inherited destroy;
  1131. end;
  1132. function tpropertysym.gettypedef:tdef;
  1133. begin
  1134. gettypedef:=proptype.def;
  1135. end;
  1136. procedure tpropertysym.deref;
  1137. begin
  1138. if (ppo_is_override in propoptions) then
  1139. begin
  1140. resolvesym(pointer(propoverriden));
  1141. dooverride(propoverriden);
  1142. end
  1143. else
  1144. begin
  1145. proptype.resolve;
  1146. indextype.resolve;
  1147. readaccess.resolve;
  1148. writeaccess.resolve;
  1149. storedaccess.resolve;
  1150. end;
  1151. end;
  1152. function tpropertysym.getsize : longint;
  1153. begin
  1154. getsize:=0;
  1155. end;
  1156. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1157. begin
  1158. inherited writesym(ppufile);
  1159. ppufile.putsmallset(propoptions);
  1160. if (ppo_is_override in propoptions) then
  1161. ppufile.putderef(propoverriden)
  1162. else
  1163. begin
  1164. ppufile.puttype(proptype);
  1165. ppufile.putlongint(index);
  1166. ppufile.putlongint(default);
  1167. ppufile.puttype(indextype);
  1168. ppufile.putsymlist(readaccess);
  1169. ppufile.putsymlist(writeaccess);
  1170. ppufile.putsymlist(storedaccess);
  1171. end;
  1172. ppufile.writeentry(ibpropertysym);
  1173. end;
  1174. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1175. begin
  1176. propoverriden:=overriden;
  1177. proptype:=overriden.proptype;
  1178. propoptions:=overriden.propoptions+[ppo_is_override];
  1179. index:=overriden.index;
  1180. default:=overriden.default;
  1181. indextype:=overriden.indextype;
  1182. readaccess.free;
  1183. readaccess:=overriden.readaccess.getcopy;
  1184. writeaccess.free;
  1185. writeaccess:=overriden.writeaccess.getcopy;
  1186. storedaccess.free;
  1187. storedaccess:=overriden.storedaccess.getcopy;
  1188. end;
  1189. {$ifdef GDB}
  1190. function tpropertysym.stabstring : pchar;
  1191. begin
  1192. { !!!! don't know how to handle }
  1193. stabstring:=strpnew('');
  1194. end;
  1195. procedure tpropertysym.concatstabto(asmlist : taasmoutput);
  1196. begin
  1197. { !!!! don't know how to handle }
  1198. end;
  1199. {$endif GDB}
  1200. {****************************************************************************
  1201. TFUNCRETSYM
  1202. ****************************************************************************}
  1203. constructor tfuncretsym.create(const n : string;const tt:ttype);
  1204. begin
  1205. inherited create(n);
  1206. typ:=funcretsym;
  1207. returntype:=tt;
  1208. funcretstate:=vs_declared;
  1209. { address valid for ret in param only }
  1210. { otherwise set by insert }
  1211. address:=procinfo.return_offset;
  1212. end;
  1213. constructor tfuncretsym.ppuload(ppufile:tcompilerppufile);
  1214. begin
  1215. inherited loadsym(ppufile);
  1216. ppufile.gettype(returntype);
  1217. address:=ppufile.getlongint;
  1218. typ:=funcretsym;
  1219. end;
  1220. destructor tfuncretsym.destroy;
  1221. begin
  1222. inherited destroy;
  1223. end;
  1224. procedure tfuncretsym.ppuwrite(ppufile:tcompilerppufile);
  1225. begin
  1226. inherited writesym(ppufile);
  1227. ppufile.puttype(returntype);
  1228. ppufile.putlongint(address);
  1229. ppufile.writeentry(ibfuncretsym);
  1230. funcretstate:=vs_used;
  1231. end;
  1232. procedure tfuncretsym.deref;
  1233. begin
  1234. returntype.resolve;
  1235. end;
  1236. {$ifdef GDB}
  1237. procedure tfuncretsym.concatstabto(asmlist : taasmoutput);
  1238. begin
  1239. { Nothing to do here, it is done in genexitcode }
  1240. end;
  1241. {$endif GDB}
  1242. {****************************************************************************
  1243. TABSOLUTESYM
  1244. ****************************************************************************}
  1245. constructor tabsolutesym.create(const n : string;const tt : ttype);
  1246. begin
  1247. inherited create(n,tt);
  1248. typ:=absolutesym;
  1249. end;
  1250. constructor tabsolutesym.ppuload(ppufile:tcompilerppufile);
  1251. begin
  1252. { Note: This needs to load everything of tvarsym.write }
  1253. inherited ppuload(ppufile);
  1254. { load absolute }
  1255. typ:=absolutesym;
  1256. ref:=nil;
  1257. address:=0;
  1258. asmname:=nil;
  1259. abstyp:=absolutetyp(ppufile.getbyte);
  1260. absseg:=false;
  1261. case abstyp of
  1262. tovar :
  1263. asmname:=stringdup(ppufile.getstring);
  1264. toasm :
  1265. asmname:=stringdup(ppufile.getstring);
  1266. toaddr :
  1267. begin
  1268. address:=ppufile.getlongint;
  1269. absseg:=boolean(ppufile.getbyte);
  1270. end;
  1271. end;
  1272. end;
  1273. procedure tabsolutesym.ppuwrite(ppufile:tcompilerppufile);
  1274. var
  1275. hvo : tvaroptions;
  1276. begin
  1277. { Note: This needs to write everything of tvarsym.write }
  1278. inherited writesym(ppufile);
  1279. ppufile.putbyte(byte(varspez));
  1280. ppufile.putlongint(address);
  1281. { write only definition or definitionsym }
  1282. ppufile.puttype(vartype);
  1283. hvo:=varoptions-[vo_regable];
  1284. ppufile.putsmallset(hvo);
  1285. ppufile.putbyte(byte(abstyp));
  1286. case abstyp of
  1287. tovar :
  1288. ppufile.putstring(ref.name);
  1289. toasm :
  1290. ppufile.putstring(asmname^);
  1291. toaddr :
  1292. begin
  1293. ppufile.putlongint(address);
  1294. ppufile.putbyte(byte(absseg));
  1295. end;
  1296. end;
  1297. ppufile.writeentry(ibabsolutesym);
  1298. end;
  1299. procedure tabsolutesym.deref;
  1300. var
  1301. srsym : tsym;
  1302. srsymtable : tsymtable;
  1303. begin
  1304. { inheritance of varsym.deref ! }
  1305. vartype.resolve;
  1306. { own absolute deref }
  1307. if (abstyp=tovar) and (asmname<>nil) then
  1308. begin
  1309. { search previous loaded symtables }
  1310. searchsym(asmname^,srsym,srsymtable);
  1311. if not assigned(srsym) then
  1312. srsym:=searchsymonlyin(owner,asmname^);
  1313. if not assigned(srsym) then
  1314. srsym:=generrorsym;
  1315. ref:=tstoredsym(srsym);
  1316. stringdispose(asmname);
  1317. end;
  1318. end;
  1319. function tabsolutesym.mangledname : string;
  1320. begin
  1321. case abstyp of
  1322. tovar :
  1323. begin
  1324. case ref.typ of
  1325. varsym :
  1326. mangledname:=tvarsym(ref).mangledname;
  1327. else
  1328. internalerror(200111011);
  1329. end;
  1330. end;
  1331. toasm :
  1332. mangledname:=asmname^;
  1333. toaddr :
  1334. mangledname:='$'+tostr(address);
  1335. else
  1336. internalerror(10002);
  1337. end;
  1338. end;
  1339. {$ifdef GDB}
  1340. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1341. begin
  1342. { I don't know how to handle this !! }
  1343. end;
  1344. {$endif GDB}
  1345. {****************************************************************************
  1346. TVARSYM
  1347. ****************************************************************************}
  1348. constructor tvarsym.create(const n : string;const tt : ttype);
  1349. begin
  1350. inherited create(n);
  1351. typ:=varsym;
  1352. vartype:=tt;
  1353. _mangledname:=nil;
  1354. varspez:=vs_value;
  1355. address:=0;
  1356. localvarsym:=nil;
  1357. refs:=0;
  1358. varstate:=vs_used;
  1359. varoptions:=[];
  1360. { can we load the value into a register ? }
  1361. if tstoreddef(tt.def).is_intregable then
  1362. include(varoptions,vo_regable)
  1363. else
  1364. exclude(varoptions,vo_regable);
  1365. if tstoreddef(tt.def).is_fpuregable then
  1366. include(varoptions,vo_fpuregable)
  1367. else
  1368. exclude(varoptions,vo_fpuregable);
  1369. reg:=R_NO;
  1370. end;
  1371. constructor tvarsym.create_dll(const n : string;const tt : ttype);
  1372. begin
  1373. tvarsym(self).create(n,tt);
  1374. include(varoptions,vo_is_dll_var);
  1375. end;
  1376. constructor tvarsym.create_C(const n,mangled : string;const tt : ttype);
  1377. begin
  1378. tvarsym(self).create(n,tt);
  1379. include(varoptions,vo_is_C_var);
  1380. stringdispose(_mangledname);
  1381. _mangledname:=stringdup(mangled);
  1382. end;
  1383. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1384. begin
  1385. inherited loadsym(ppufile);
  1386. typ:=varsym;
  1387. reg:=R_NO;
  1388. refs := 0;
  1389. varstate:=vs_used;
  1390. varspez:=tvarspez(ppufile.getbyte);
  1391. address:=ppufile.getlongint;
  1392. localvarsym:=nil;
  1393. ppufile.gettype(vartype);
  1394. ppufile.getsmallset(varoptions);
  1395. if (vo_is_C_var in varoptions) then
  1396. _mangledname:=stringdup(ppufile.getstring);
  1397. end;
  1398. destructor tvarsym.destroy;
  1399. begin
  1400. {$ifdef var_notification}
  1401. if assigned(notifications) then
  1402. notifications.destroy;
  1403. {$endif}
  1404. inherited destroy;
  1405. end;
  1406. procedure tvarsym.deref;
  1407. begin
  1408. vartype.resolve;
  1409. end;
  1410. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1411. var
  1412. hvo : tvaroptions;
  1413. begin
  1414. inherited writesym(ppufile);
  1415. ppufile.putbyte(byte(varspez));
  1416. ppufile.putlongint(address);
  1417. ppufile.puttype(vartype);
  1418. { symbols which are load are never candidates for a register,
  1419. turn off the regable }
  1420. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1421. ppufile.putsmallset(hvo);
  1422. if (vo_is_C_var in varoptions) then
  1423. ppufile.putstring(mangledname);
  1424. ppufile.writeentry(ibvarsym);
  1425. end;
  1426. procedure tvarsym.generate_mangledname;
  1427. begin
  1428. _mangledname:=stringdup(mangledname_prefix('U',owner)+name);
  1429. end;
  1430. procedure tvarsym.set_mangledname(const s:string);
  1431. begin
  1432. stringdispose(_mangledname);
  1433. _mangledname:=stringdup(s);
  1434. end;
  1435. function tvarsym.getsize : longint;
  1436. begin
  1437. if assigned(vartype.def) then
  1438. getsize:=vartype.def.size
  1439. else
  1440. getsize:=0;
  1441. end;
  1442. function tvarsym.getvaluesize : longint;
  1443. begin
  1444. if assigned(vartype.def) and
  1445. (varspez=vs_value) and
  1446. ((vartype.def.deftype<>arraydef) or
  1447. tarraydef(vartype.def).isDynamicArray or
  1448. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1449. getvaluesize:=vartype.def.size
  1450. else
  1451. getvaluesize:=0;
  1452. end;
  1453. function tvarsym.getpushsize(is_cdecl:boolean) : longint;
  1454. begin
  1455. getpushsize:=-1;
  1456. if assigned(vartype.def) then
  1457. begin
  1458. case varspez of
  1459. vs_out,
  1460. vs_var :
  1461. getpushsize:=pointer_size;
  1462. vs_value,
  1463. vs_const :
  1464. begin
  1465. if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1466. getpushsize:=pointer_size
  1467. else
  1468. getpushsize:=vartype.def.size;
  1469. end;
  1470. end;
  1471. end;
  1472. end;
  1473. {$ifdef var_notification}
  1474. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1475. Tnotification_callback):cardinal;
  1476. var n:Tnotification;
  1477. begin
  1478. if not assigned(notifications) then
  1479. notifications:=Tlinkedlist.create;
  1480. n:=Tnotification.create(flags,callback);
  1481. register_notification:=n.id;
  1482. notifications.concat(n);
  1483. end;
  1484. {$endif}
  1485. {$ifdef GDB}
  1486. function tvarsym.stabstring : pchar;
  1487. var
  1488. st : string;
  1489. is_cdecl : boolean;
  1490. begin
  1491. st:=tstoreddef(vartype.def).numberstring;
  1492. if (owner.symtabletype = objectsymtable) and
  1493. (sp_static in symoptions) then
  1494. begin
  1495. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1496. stabstring := strpnew('"'+upper(owner.name^)+'__'+name+':'+st+
  1497. '",'+
  1498. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1499. end
  1500. else if (owner.symtabletype = globalsymtable) then
  1501. begin
  1502. { Here we used S instead of
  1503. because with G GDB doesn't look at the address field
  1504. but searches the same name or with a leading underscore
  1505. but these names don't exist in pascal !}
  1506. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1507. stabstring := strpnew('"'+name+':'+st+'",'+
  1508. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1509. end
  1510. else if owner.symtabletype = staticsymtable then
  1511. begin
  1512. stabstring := strpnew('"'+name+':S'+st+'",'+
  1513. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1514. end
  1515. else if (owner.symtabletype in [parasymtable,inlineparasymtable]) then
  1516. begin
  1517. is_cdecl:=(tprocdef(owner.defowner).proccalloption in [pocall_cdecl,pocall_cppdecl]);
  1518. case varspez of
  1519. vs_out,
  1520. vs_var : st := 'v'+st;
  1521. vs_value,
  1522. vs_const : if paramanager.push_addr_param(vartype.def,is_cdecl) then
  1523. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1524. else
  1525. st := 'p'+st;
  1526. end;
  1527. stabstring := strpnew('"'+name+':'+st+'",'+
  1528. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1529. tostr(address+owner.address_fixup));
  1530. {offset to ebp => will not work if the framepointer is esp
  1531. so some optimizing will make things harder to debug }
  1532. end
  1533. else if (owner.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1534. if reg<>R_NO then
  1535. begin
  1536. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1537. { this is the register order for GDB}
  1538. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1539. tostr(N_RSYM)+',0,'+
  1540. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1541. end
  1542. else
  1543. { I don't know if this will work (PM) }
  1544. if (vo_is_C_var in varoptions) then
  1545. stabstring := strpnew('"'+name+':S'+st+'",'+
  1546. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1547. else
  1548. stabstring := strpnew('"'+name+':'+st+'",'+
  1549. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner.address_fixup))
  1550. else
  1551. stabstring := inherited stabstring;
  1552. end;
  1553. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1554. var stab_str : pchar;
  1555. begin
  1556. inherited concatstabto(asmlist);
  1557. if (owner.symtabletype=parasymtable) and
  1558. (reg<>R_NO) then
  1559. begin
  1560. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1561. { this is the register order for GDB}
  1562. stab_str:=strpnew('"'+name+':r'
  1563. +tstoreddef(vartype.def).numberstring+'",'+
  1564. tostr(N_RSYM)+',0,'+
  1565. tostr(fileinfo.line)+','+tostr(stab_regindex[reg]));
  1566. asmList.concat(Tai_stabs.Create(stab_str));
  1567. end;
  1568. end;
  1569. {$endif GDB}
  1570. {****************************************************************************
  1571. TTYPEDCONSTSYM
  1572. *****************************************************************************}
  1573. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1574. begin
  1575. inherited create(n);
  1576. typ:=typedconstsym;
  1577. typedconsttype.setdef(p);
  1578. is_writable:=writable;
  1579. end;
  1580. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1581. begin
  1582. inherited create(n);
  1583. typ:=typedconstsym;
  1584. typedconsttype:=tt;
  1585. is_writable:=writable;
  1586. end;
  1587. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1588. begin
  1589. inherited loadsym(ppufile);
  1590. typ:=typedconstsym;
  1591. ppufile.gettype(typedconsttype);
  1592. is_writable:=boolean(ppufile.getbyte);
  1593. end;
  1594. destructor ttypedconstsym.destroy;
  1595. begin
  1596. inherited destroy;
  1597. end;
  1598. procedure ttypedconstsym.generate_mangledname;
  1599. begin
  1600. _mangledname:=stringdup(mangledname_prefix('TC',owner)+name);
  1601. end;
  1602. function ttypedconstsym.getsize : longint;
  1603. begin
  1604. if assigned(typedconsttype.def) then
  1605. getsize:=typedconsttype.def.size
  1606. else
  1607. getsize:=0;
  1608. end;
  1609. procedure ttypedconstsym.deref;
  1610. begin
  1611. typedconsttype.resolve;
  1612. end;
  1613. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1614. begin
  1615. inherited writesym(ppufile);
  1616. ppufile.puttype(typedconsttype);
  1617. ppufile.putbyte(byte(is_writable));
  1618. ppufile.writeentry(ibtypedconstsym);
  1619. end;
  1620. {$ifdef GDB}
  1621. function ttypedconstsym.stabstring : pchar;
  1622. var
  1623. st : char;
  1624. begin
  1625. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1626. st := 'G'
  1627. else
  1628. st := 'S';
  1629. stabstring := strpnew('"'+name+':'+st+
  1630. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1631. tostr(fileinfo.line)+','+mangledname);
  1632. end;
  1633. {$endif GDB}
  1634. {****************************************************************************
  1635. TCONSTSYM
  1636. ****************************************************************************}
  1637. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1638. begin
  1639. inherited create(n);
  1640. typ:=constsym;
  1641. consttyp:=t;
  1642. valueord:=v;
  1643. valueordptr:=0;
  1644. valueptr:=nil;
  1645. ResStrIndex:=0;
  1646. consttype.reset;
  1647. len:=0;
  1648. end;
  1649. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1650. begin
  1651. inherited create(n);
  1652. typ:=constsym;
  1653. consttyp:=t;
  1654. valueord:=v;
  1655. valueordptr:=0;
  1656. valueptr:=nil;
  1657. ResStrIndex:=0;
  1658. consttype:=tt;
  1659. len:=0;
  1660. end;
  1661. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1662. begin
  1663. inherited create(n);
  1664. typ:=constsym;
  1665. consttyp:=t;
  1666. valueord:=0;
  1667. valueordptr:=v;
  1668. valueptr:=nil;
  1669. ResStrIndex:=0;
  1670. consttype:=tt;
  1671. len:=0;
  1672. end;
  1673. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1674. begin
  1675. inherited create(n);
  1676. typ:=constsym;
  1677. consttyp:=t;
  1678. valueord:=0;
  1679. valueordptr:=0;
  1680. valueptr:=v;
  1681. ResStrIndex:=0;
  1682. consttype.reset;
  1683. len:=0;
  1684. end;
  1685. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1686. begin
  1687. inherited create(n);
  1688. typ:=constsym;
  1689. consttyp:=t;
  1690. valueord:=0;
  1691. valueordptr:=0;
  1692. valueptr:=v;
  1693. ResStrIndex:=0;
  1694. consttype:=tt;
  1695. len:=0;
  1696. end;
  1697. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1698. begin
  1699. inherited create(n);
  1700. typ:=constsym;
  1701. consttyp:=t;
  1702. valueord:=0;
  1703. valueordptr:=0;
  1704. valueptr:=str;
  1705. consttype.reset;
  1706. len:=l;
  1707. if t=constresourcestring then
  1708. ResStrIndex:=ResourceStrings.Register(name,pchar(valueptr),len);
  1709. end;
  1710. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1711. var
  1712. pd : pbestreal;
  1713. ps : pnormalset;
  1714. pc : pchar;
  1715. begin
  1716. inherited loadsym(ppufile);
  1717. typ:=constsym;
  1718. consttype.reset;
  1719. consttyp:=tconsttyp(ppufile.getbyte);
  1720. valueord:=0;
  1721. valueordptr:=0;
  1722. valueptr:=nil;
  1723. case consttyp of
  1724. constint:
  1725. valueord:=ppufile.getexprint;
  1726. constwchar,
  1727. constbool,
  1728. constchar :
  1729. valueord:=ppufile.getlongint;
  1730. constord :
  1731. begin
  1732. ppufile.gettype(consttype);
  1733. valueord:=ppufile.getexprint;
  1734. end;
  1735. constpointer :
  1736. begin
  1737. ppufile.gettype(consttype);
  1738. valueordptr:=ppufile.getptruint;
  1739. end;
  1740. conststring,
  1741. constresourcestring :
  1742. begin
  1743. len:=ppufile.getlongint;
  1744. getmem(pc,len+1);
  1745. ppufile.getdata(pc^,len);
  1746. if consttyp=constresourcestring then
  1747. ResStrIndex:=ppufile.getlongint;
  1748. valueptr:=pc;
  1749. end;
  1750. constreal :
  1751. begin
  1752. new(pd);
  1753. pd^:=ppufile.getreal;
  1754. valueptr:=pd;
  1755. end;
  1756. constset :
  1757. begin
  1758. ppufile.gettype(consttype);
  1759. new(ps);
  1760. ppufile.getnormalset(ps^);
  1761. valueptr:=ps;
  1762. end;
  1763. constnil : ;
  1764. else
  1765. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1766. end;
  1767. end;
  1768. destructor tconstsym.destroy;
  1769. begin
  1770. case consttyp of
  1771. conststring,
  1772. constresourcestring :
  1773. freemem(pchar(valueptr),len+1);
  1774. constreal :
  1775. dispose(pbestreal(valueptr));
  1776. constset :
  1777. dispose(pnormalset(valueptr));
  1778. end;
  1779. inherited destroy;
  1780. end;
  1781. function tconstsym.mangledname : string;
  1782. begin
  1783. mangledname:=name;
  1784. end;
  1785. procedure tconstsym.deref;
  1786. begin
  1787. if consttyp in [constord,constpointer,constset] then
  1788. consttype.resolve;
  1789. end;
  1790. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1791. begin
  1792. inherited writesym(ppufile);
  1793. ppufile.putbyte(byte(consttyp));
  1794. case consttyp of
  1795. constnil : ;
  1796. constint:
  1797. ppufile.putexprint(valueord);
  1798. constbool,
  1799. constchar :
  1800. ppufile.putlongint(valueord);
  1801. constord :
  1802. begin
  1803. ppufile.puttype(consttype);
  1804. ppufile.putexprint(valueord);
  1805. end;
  1806. constpointer :
  1807. begin
  1808. ppufile.puttype(consttype);
  1809. ppufile.putptruint(valueordptr);
  1810. end;
  1811. conststring,
  1812. constresourcestring :
  1813. begin
  1814. ppufile.putlongint(len);
  1815. ppufile.putdata(pchar(valueptr)^,len);
  1816. if consttyp=constresourcestring then
  1817. ppufile.putlongint(ResStrIndex);
  1818. end;
  1819. constreal :
  1820. ppufile.putreal(pbestreal(valueptr)^);
  1821. constset :
  1822. begin
  1823. ppufile.puttype(consttype);
  1824. ppufile.putnormalset(valueptr^);
  1825. end;
  1826. else
  1827. internalerror(13);
  1828. end;
  1829. ppufile.writeentry(ibconstsym);
  1830. end;
  1831. {$ifdef GDB}
  1832. function tconstsym.stabstring : pchar;
  1833. var st : string;
  1834. begin
  1835. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1836. case consttyp of
  1837. conststring : begin
  1838. st := 's'''+strpas(pchar(valueptr))+'''';
  1839. end;
  1840. constbool,
  1841. constint,
  1842. constord,
  1843. constchar : st := 'i'+int64tostr(valueord);
  1844. constpointer :
  1845. st := 'i'+int64tostr(valueordptr);
  1846. constreal : begin
  1847. system.str(pbestreal(valueptr)^,st);
  1848. st := 'r'+st;
  1849. end;
  1850. { if we don't know just put zero !! }
  1851. else st:='i0';
  1852. {***SETCONST}
  1853. {constset:;} {*** I don't know what to do with a set.}
  1854. { sets are not recognized by GDB}
  1855. {***}
  1856. end;
  1857. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1858. tostr(fileinfo.line)+',0');
  1859. end;
  1860. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  1861. begin
  1862. if consttyp <> conststring then
  1863. inherited concatstabto(asmlist);
  1864. end;
  1865. {$endif GDB}
  1866. {****************************************************************************
  1867. TENUMSYM
  1868. ****************************************************************************}
  1869. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1870. begin
  1871. inherited create(n);
  1872. typ:=enumsym;
  1873. definition:=def;
  1874. value:=v;
  1875. { check for jumps }
  1876. if v>def.max+1 then
  1877. def.has_jumps:=true;
  1878. { update low and high }
  1879. if def.min>v then
  1880. def.setmin(v);
  1881. if def.max<v then
  1882. def.setmax(v);
  1883. order;
  1884. end;
  1885. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  1886. begin
  1887. inherited loadsym(ppufile);
  1888. typ:=enumsym;
  1889. definition:=tenumdef(ppufile.getderef);
  1890. value:=ppufile.getlongint;
  1891. nextenum := Nil;
  1892. end;
  1893. procedure tenumsym.deref;
  1894. begin
  1895. resolvedef(pointer(definition));
  1896. order;
  1897. end;
  1898. procedure tenumsym.order;
  1899. var
  1900. sym : tenumsym;
  1901. begin
  1902. sym := tenumsym(definition.firstenum);
  1903. if sym = nil then
  1904. begin
  1905. definition.firstenum := self;
  1906. nextenum := nil;
  1907. exit;
  1908. end;
  1909. { reorder the symbols in increasing value }
  1910. if value < sym.value then
  1911. begin
  1912. nextenum := sym;
  1913. definition.firstenum := self;
  1914. end
  1915. else
  1916. begin
  1917. while (sym.value <= value) and assigned(sym.nextenum) do
  1918. sym := sym.nextenum;
  1919. nextenum := sym.nextenum;
  1920. sym.nextenum := self;
  1921. end;
  1922. end;
  1923. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  1924. begin
  1925. inherited writesym(ppufile);
  1926. ppufile.putderef(definition);
  1927. ppufile.putlongint(value);
  1928. ppufile.writeentry(ibenumsym);
  1929. end;
  1930. {$ifdef GDB}
  1931. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  1932. begin
  1933. {enum elements have no stab !}
  1934. end;
  1935. {$EndIf GDB}
  1936. {****************************************************************************
  1937. TTYPESYM
  1938. ****************************************************************************}
  1939. constructor ttypesym.create(const n : string;const tt : ttype);
  1940. begin
  1941. inherited create(n);
  1942. typ:=typesym;
  1943. restype:=tt;
  1944. {$ifdef GDB}
  1945. isusedinstab := false;
  1946. {$endif GDB}
  1947. { register the typesym for the definition }
  1948. if assigned(restype.def) and
  1949. (restype.def.deftype<>errordef) and
  1950. not(assigned(restype.def.typesym)) then
  1951. restype.def.typesym:=self;
  1952. end;
  1953. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  1954. begin
  1955. inherited loadsym(ppufile);
  1956. typ:=typesym;
  1957. {$ifdef GDB}
  1958. isusedinstab := false;
  1959. {$endif GDB}
  1960. ppufile.gettype(restype);
  1961. end;
  1962. function ttypesym.gettypedef:tdef;
  1963. begin
  1964. gettypedef:=restype.def;
  1965. end;
  1966. procedure ttypesym.deref;
  1967. begin
  1968. restype.resolve;
  1969. end;
  1970. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  1971. begin
  1972. inherited writesym(ppufile);
  1973. ppufile.puttype(restype);
  1974. ppufile.writeentry(ibtypesym);
  1975. end;
  1976. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1977. begin
  1978. inherited load_references(ppufile,locals);
  1979. if (restype.def.deftype=recorddef) then
  1980. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1981. if (restype.def.deftype=objectdef) then
  1982. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1983. end;
  1984. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1985. begin
  1986. if not inherited write_references(ppufile,locals) then
  1987. begin
  1988. { write address of this symbol if record or object
  1989. even if no real refs are there
  1990. because we need it for the symtable }
  1991. if (restype.def.deftype in [recorddef,objectdef]) then
  1992. begin
  1993. ppufile.putderef(self);
  1994. ppufile.writeentry(ibsymref);
  1995. end;
  1996. end;
  1997. write_references:=true;
  1998. if (restype.def.deftype=recorddef) then
  1999. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2000. if (restype.def.deftype=objectdef) then
  2001. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2002. end;
  2003. {$ifdef GDB}
  2004. function ttypesym.stabstring : pchar;
  2005. var
  2006. stabchar : string[2];
  2007. short : string;
  2008. begin
  2009. if restype.def.deftype in tagtypes then
  2010. stabchar := 'Tt'
  2011. else
  2012. stabchar := 't';
  2013. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  2014. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  2015. stabstring := strpnew(short);
  2016. end;
  2017. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  2018. begin
  2019. {not stabs for forward defs }
  2020. if assigned(restype.def) then
  2021. if (restype.def.typesym = self) then
  2022. tstoreddef(restype.def).concatstabto(asmlist)
  2023. else
  2024. inherited concatstabto(asmlist);
  2025. end;
  2026. {$endif GDB}
  2027. {****************************************************************************
  2028. TSYSSYM
  2029. ****************************************************************************}
  2030. constructor tsyssym.create(const n : string;l : longint);
  2031. begin
  2032. inherited create(n);
  2033. typ:=syssym;
  2034. number:=l;
  2035. end;
  2036. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2037. begin
  2038. inherited loadsym(ppufile);
  2039. typ:=syssym;
  2040. number:=ppufile.getlongint;
  2041. end;
  2042. destructor tsyssym.destroy;
  2043. begin
  2044. inherited destroy;
  2045. end;
  2046. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2047. begin
  2048. inherited writesym(ppufile);
  2049. ppufile.putlongint(number);
  2050. ppufile.writeentry(ibsyssym);
  2051. end;
  2052. {$ifdef GDB}
  2053. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  2054. begin
  2055. end;
  2056. {$endif GDB}
  2057. {****************************************************************************
  2058. TRTTISYM
  2059. ****************************************************************************}
  2060. constructor trttisym.create(const n:string;rt:trttitype);
  2061. const
  2062. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2063. begin
  2064. inherited create(prefix[rt]+n);
  2065. typ:=rttisym;
  2066. lab:=nil;
  2067. rttityp:=rt;
  2068. end;
  2069. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2070. begin
  2071. inherited loadsym(ppufile);
  2072. typ:=rttisym;
  2073. lab:=nil;
  2074. rttityp:=trttitype(ppufile.getbyte);
  2075. end;
  2076. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2077. begin
  2078. inherited writesym(ppufile);
  2079. ppufile.putbyte(byte(rttityp));
  2080. ppufile.writeentry(ibrttisym);
  2081. end;
  2082. function trttisym.mangledname : string;
  2083. const
  2084. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2085. var
  2086. s : string;
  2087. p : tsymtable;
  2088. begin
  2089. s:='';
  2090. p:=owner;
  2091. while assigned(p) and (p.symtabletype=localsymtable) do
  2092. begin
  2093. s:=s+'_'+p.defowner.name;
  2094. p:=p.defowner.owner;
  2095. end;
  2096. if not(p.symtabletype in [globalsymtable,staticsymtable]) then
  2097. internalerror(200108265);
  2098. mangledname:=prefix[rttityp]+p.name^+s+'$_'+Copy(name,5,255);
  2099. end;
  2100. function trttisym.get_label:tasmsymbol;
  2101. begin
  2102. { the label is always a global label }
  2103. if not assigned(lab) then
  2104. lab:=objectlibrary.newasmsymboltype(mangledname,AB_GLOBAL,AT_DATA);
  2105. get_label:=lab;
  2106. end;
  2107. { persistent rtti generation }
  2108. procedure generate_rtti(p:tsym);
  2109. var
  2110. rsym : trttisym;
  2111. def : tstoreddef;
  2112. begin
  2113. { rtti can only be generated for classes that are always typesyms }
  2114. if not(p.typ=typesym) then
  2115. internalerror(200108261);
  2116. def:=tstoreddef(ttypesym(p).restype.def);
  2117. { only create rtti once for each definition }
  2118. if not(df_has_rttitable in def.defoptions) then
  2119. begin
  2120. { definition should be in the same symtable as the symbol }
  2121. if p.owner<>def.owner then
  2122. internalerror(200108262);
  2123. { create rttisym }
  2124. rsym:=trttisym.create(p.name,fullrtti);
  2125. p.owner.insert(rsym);
  2126. { register rttisym in definition }
  2127. include(def.defoptions,df_has_rttitable);
  2128. def.rttitablesym:=rsym;
  2129. { write rtti data }
  2130. def.write_child_rtti_data(fullrtti);
  2131. if (cs_create_smart in aktmoduleswitches) then
  2132. rttiList.concat(Tai_cut.Create);
  2133. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2134. def.write_rtti_data(fullrtti);
  2135. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2136. end;
  2137. end;
  2138. { persistent init table generation }
  2139. procedure generate_inittable(p:tsym);
  2140. var
  2141. rsym : trttisym;
  2142. def : tstoreddef;
  2143. begin
  2144. { anonymous types are also allowed for records that can be varsym }
  2145. case p.typ of
  2146. typesym :
  2147. def:=tstoreddef(ttypesym(p).restype.def);
  2148. varsym :
  2149. def:=tstoreddef(tvarsym(p).vartype.def);
  2150. else
  2151. internalerror(200108263);
  2152. end;
  2153. { only create inittable once for each definition }
  2154. if not(df_has_inittable in def.defoptions) then
  2155. begin
  2156. { definition should be in the same symtable as the symbol }
  2157. if p.owner<>def.owner then
  2158. internalerror(200108264);
  2159. { create rttisym }
  2160. rsym:=trttisym.create(p.name,initrtti);
  2161. p.owner.insert(rsym);
  2162. { register rttisym in definition }
  2163. include(def.defoptions,df_has_inittable);
  2164. def.inittablesym:=rsym;
  2165. { write inittable data }
  2166. def.write_child_rtti_data(initrtti);
  2167. if (cs_create_smart in aktmoduleswitches) then
  2168. rttiList.concat(Tai_cut.Create);
  2169. rttiList.concat(Tai_symbol.Create(rsym.get_label,0));
  2170. def.write_rtti_data(initrtti);
  2171. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2172. end;
  2173. end;
  2174. end.
  2175. {
  2176. $Log$
  2177. Revision 1.62 2002-09-07 15:25:10 peter
  2178. * old logs removed and tabs fixed
  2179. Revision 1.61 2002/09/05 19:29:45 peter
  2180. * memdebug enhancements
  2181. Revision 1.60 2002/09/05 14:51:42 peter
  2182. * internalerror instead of crash in getprocdef
  2183. Revision 1.59 2002/09/03 16:26:27 daniel
  2184. * Make Tprocdef.defs protected
  2185. Revision 1.58 2002/09/01 08:01:16 daniel
  2186. * Removed sets from Tcallnode.det_resulttype
  2187. + Added read/write notifications of variables. These will be usefull
  2188. for providing information for several optimizations. For example
  2189. the value of the loop variable of a for loop does matter is the
  2190. variable is read after the for loop, but if it's no longer used
  2191. or written, it doesn't matter and this can be used to optimize
  2192. the loop code generation.
  2193. Revision 1.57 2002/08/25 19:25:21 peter
  2194. * sym.insert_in_data removed
  2195. * symtable.insertvardata/insertconstdata added
  2196. * removed insert_in_data call from symtable.insert, it needs to be
  2197. called separatly. This allows to deref the address calculation
  2198. * procedures now calculate the parast addresses after the procedure
  2199. directives are parsed. This fixes the cdecl parast problem
  2200. * push_addr_param has an extra argument that specifies if cdecl is used
  2201. or not
  2202. Revision 1.56 2002/08/25 09:06:21 peter
  2203. * fixed loop in concat_procdefs
  2204. Revision 1.55 2002/08/20 16:54:40 peter
  2205. * write address of varsym always
  2206. Revision 1.54 2002/08/20 10:31:26 daniel
  2207. * Tcallnode.det_resulttype rewritten
  2208. Revision 1.53 2002/08/18 20:06:27 peter
  2209. * inlining is now also allowed in interface
  2210. * renamed write/load to ppuwrite/ppuload
  2211. * tnode storing in ppu
  2212. * nld,ncon,nbas are already updated for storing in ppu
  2213. Revision 1.52 2002/08/17 09:23:42 florian
  2214. * first part of procinfo rewrite
  2215. Revision 1.51 2002/08/16 14:24:59 carl
  2216. * issameref() to test if two references are the same (then emit no opcodes)
  2217. + ret_in_reg to replace ret_in_acc
  2218. (fix some register allocation bugs at the same time)
  2219. + save_std_register now has an extra parameter which is the
  2220. usedinproc registers
  2221. Revision 1.50 2002/08/13 21:40:57 florian
  2222. * more fixes for ppc calling conventions
  2223. Revision 1.49 2002/08/12 15:08:40 carl
  2224. + stab register indexes for powerpc (moved from gdb to cpubase)
  2225. + tprocessor enumeration moved to cpuinfo
  2226. + linker in target_info is now a class
  2227. * many many updates for m68k (will soon start to compile)
  2228. - removed some ifdef or correct them for correct cpu
  2229. Revision 1.48 2002/08/11 14:32:28 peter
  2230. * renamed current_library to objectlibrary
  2231. Revision 1.47 2002/08/11 13:24:14 peter
  2232. * saving of asmsymbols in ppu supported
  2233. * asmsymbollist global is removed and moved into a new class
  2234. tasmlibrarydata that will hold the info of a .a file which
  2235. corresponds with a single module. Added librarydata to tmodule
  2236. to keep the library info stored for the module. In the future the
  2237. objectfiles will also be stored to the tasmlibrarydata class
  2238. * all getlabel/newasmsymbol and friends are moved to the new class
  2239. Revision 1.46 2002/07/23 10:13:23 daniel
  2240. * Added important comment
  2241. Revision 1.45 2002/07/23 09:51:26 daniel
  2242. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2243. are worth comitting.
  2244. Revision 1.44 2002/07/20 17:45:29 daniel
  2245. * Register variables are now possible for global variables too. This is
  2246. important for small programs without procedures.
  2247. Revision 1.43 2002/07/20 11:57:58 florian
  2248. * types.pas renamed to defbase.pas because D6 contains a types
  2249. unit so this would conflicts if D6 programms are compiled
  2250. + Willamette/SSE2 instructions to assembler added
  2251. Revision 1.42 2002/07/11 14:41:31 florian
  2252. * start of the new generic parameter handling
  2253. }