symsym.pas 79 KB

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