symsym.pas 78 KB

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