symsym.pas 78 KB

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