symsym.pas 71 KB

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