symsym.pas 81 KB

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