symsym.pas 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306
  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;locals:boolean);virtual;
  59. function write_references(ppufile:tcompilerppufile;locals:boolean):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;locals:boolean);override;
  106. function write_references(ppufile:tcompilerppufile;locals:boolean):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. procedure deref;override;
  121. function gettypedef:tdef;override;
  122. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  123. function write_references(ppufile:tcompilerppufile;locals:boolean):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. returntype : ttype;
  182. address : longint;
  183. funcretstate : tvarstate;
  184. constructor create(const n : string;const tt : ttype);
  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;locals:boolean);
  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;locals:boolean):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;locals:boolean);
  692. (*var
  693. prdef,prdef2 : tprocdef;
  694. b : byte; *)
  695. begin
  696. inherited load_references(ppufile,locals);
  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;locals:boolean) : boolean;
  715. var
  716. prdef : tprocdef;
  717. begin
  718. write_references:=false;
  719. if not inherited write_references(ppufile,locals) 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,locals);
  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;const tt:ttype);
  909. begin
  910. inherited create(n);
  911. typ:=funcretsym;
  912. returntype:=tt;
  913. funcretstate:=vs_declared;
  914. { address valid for ret in param only }
  915. { otherwise set by insert }
  916. address:=pprocinfo(procinfo)^.return_offset;
  917. end;
  918. constructor tfuncretsym.load(ppufile:tcompilerppufile);
  919. begin
  920. inherited loadsym(ppufile);
  921. ppufile.gettype(returntype);
  922. address:=ppufile.getlongint;
  923. typ:=funcretsym;
  924. end;
  925. destructor tfuncretsym.destroy;
  926. begin
  927. inherited destroy;
  928. end;
  929. procedure tfuncretsym.write(ppufile:tcompilerppufile);
  930. begin
  931. inherited writesym(ppufile);
  932. ppufile.puttype(returntype);
  933. ppufile.putlongint(address);
  934. ppufile.writeentry(ibfuncretsym);
  935. funcretstate:=vs_used;
  936. end;
  937. procedure tfuncretsym.deref;
  938. begin
  939. returntype.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. varalign,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(returntype.def) or
  959. (returntype.def.deftype=floatdef) then
  960. begin
  961. l:=returntype.def.size;
  962. varalign:=size_2_align(l);
  963. varalign:=used_align(varalign,aktalignment.localalignmin,owner.dataalignment);
  964. address:=align(owner.datasize+l,varalign);
  965. owner.datasize:=address;
  966. procinfo^.return_offset:=-address;
  967. end;
  968. end;
  969. end;
  970. {****************************************************************************
  971. TABSOLUTESYM
  972. ****************************************************************************}
  973. constructor tabsolutesym.create(const n : string;const tt : ttype);
  974. begin
  975. inherited create(n,tt);
  976. typ:=absolutesym;
  977. end;
  978. constructor tabsolutesym.load(ppufile:tcompilerppufile);
  979. begin
  980. { Note: This needs to load everything of tvarsym.write }
  981. inherited load(ppufile);
  982. { load absolute }
  983. typ:=absolutesym;
  984. ref:=nil;
  985. address:=0;
  986. asmname:=nil;
  987. abstyp:=absolutetyp(ppufile.getbyte);
  988. absseg:=false;
  989. case abstyp of
  990. tovar :
  991. asmname:=stringdup(ppufile.getstring);
  992. toasm :
  993. asmname:=stringdup(ppufile.getstring);
  994. toaddr :
  995. begin
  996. address:=ppufile.getlongint;
  997. absseg:=boolean(ppufile.getbyte);
  998. end;
  999. end;
  1000. end;
  1001. procedure tabsolutesym.write(ppufile:tcompilerppufile);
  1002. var
  1003. hvo : tvaroptions;
  1004. begin
  1005. { Note: This needs to write everything of tvarsym.write }
  1006. inherited writesym(ppufile);
  1007. ppufile.putbyte(byte(varspez));
  1008. if read_member then
  1009. ppufile.putlongint(address);
  1010. { write only definition or definitionsym }
  1011. ppufile.puttype(vartype);
  1012. hvo:=varoptions-[vo_regable];
  1013. ppufile.putsmallset(hvo);
  1014. ppufile.putbyte(byte(abstyp));
  1015. case abstyp of
  1016. tovar :
  1017. ppufile.putstring(ref.name);
  1018. toasm :
  1019. ppufile.putstring(asmname^);
  1020. toaddr :
  1021. begin
  1022. ppufile.putlongint(address);
  1023. ppufile.putbyte(byte(absseg));
  1024. end;
  1025. end;
  1026. ppufile.writeentry(ibabsolutesym);
  1027. end;
  1028. procedure tabsolutesym.deref;
  1029. var
  1030. srsym : tsym;
  1031. srsymtable : tsymtable;
  1032. begin
  1033. { inheritance of varsym.deref ! }
  1034. vartype.resolve;
  1035. { own absolute deref }
  1036. if (abstyp=tovar) and (asmname<>nil) then
  1037. begin
  1038. { search previous loaded symtables }
  1039. searchsym(asmname^,srsym,srsymtable);
  1040. if not assigned(srsym) then
  1041. srsym:=searchsymonlyin(owner,asmname^);
  1042. if not assigned(srsym) then
  1043. srsym:=generrorsym;
  1044. ref:=tstoredsym(srsym);
  1045. stringdispose(asmname);
  1046. end;
  1047. end;
  1048. function tabsolutesym.mangledname : string;
  1049. begin
  1050. case abstyp of
  1051. tovar :
  1052. mangledname:=ref.mangledname;
  1053. toasm :
  1054. mangledname:=asmname^;
  1055. toaddr :
  1056. mangledname:='$'+tostr(address);
  1057. else
  1058. internalerror(10002);
  1059. end;
  1060. end;
  1061. procedure tabsolutesym.insert_in_data;
  1062. begin
  1063. end;
  1064. {$ifdef GDB}
  1065. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1066. begin
  1067. { I don't know how to handle this !! }
  1068. end;
  1069. {$endif GDB}
  1070. {****************************************************************************
  1071. TVARSYM
  1072. ****************************************************************************}
  1073. constructor tvarsym.create(const n : string;const tt : ttype);
  1074. begin
  1075. inherited create(n);
  1076. typ:=varsym;
  1077. vartype:=tt;
  1078. _mangledname:=nil;
  1079. varspez:=vs_value;
  1080. address:=0;
  1081. localvarsym:=nil;
  1082. refs:=0;
  1083. varstate:=vs_used;
  1084. varoptions:=[];
  1085. { can we load the value into a register ? }
  1086. if tstoreddef(tt.def).is_intregable then
  1087. include(varoptions,vo_regable)
  1088. else
  1089. exclude(varoptions,vo_regable);
  1090. if tstoreddef(tt.def).is_fpuregable then
  1091. include(varoptions,vo_fpuregable)
  1092. else
  1093. exclude(varoptions,vo_fpuregable);
  1094. reg:=R_NO;
  1095. end;
  1096. constructor tvarsym.create_dll(const n : string;const tt : ttype);
  1097. begin
  1098. tvarsym(self).create(n,tt);
  1099. include(varoptions,vo_is_dll_var);
  1100. end;
  1101. constructor tvarsym.create_C(const n,mangled : string;const tt : ttype);
  1102. begin
  1103. tvarsym(self).create(n,tt);
  1104. include(varoptions,vo_is_C_var);
  1105. setmangledname(mangled);
  1106. end;
  1107. constructor tvarsym.load(ppufile:tcompilerppufile);
  1108. begin
  1109. inherited loadsym(ppufile);
  1110. typ:=varsym;
  1111. _mangledname:=nil;
  1112. reg:=R_NO;
  1113. refs := 0;
  1114. varstate:=vs_used;
  1115. varspez:=tvarspez(ppufile.getbyte);
  1116. if read_member then
  1117. address:=ppufile.getlongint
  1118. else
  1119. address:=0;
  1120. localvarsym:=nil;
  1121. ppufile.gettype(vartype);
  1122. ppufile.getsmallset(varoptions);
  1123. if (vo_is_C_var in varoptions) then
  1124. setmangledname(ppufile.getstring);
  1125. end;
  1126. destructor tvarsym.destroy;
  1127. begin
  1128. strdispose(_mangledname);
  1129. inherited destroy;
  1130. end;
  1131. procedure tvarsym.deref;
  1132. begin
  1133. vartype.resolve;
  1134. end;
  1135. procedure tvarsym.write(ppufile:tcompilerppufile);
  1136. var
  1137. hvo : tvaroptions;
  1138. begin
  1139. inherited writesym(ppufile);
  1140. ppufile.putbyte(byte(varspez));
  1141. if read_member then
  1142. ppufile.putlongint(address);
  1143. ppufile.puttype(vartype);
  1144. { symbols which are load are never candidates for a register,
  1145. turn off the regable }
  1146. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1147. ppufile.putsmallset(hvo);
  1148. if (vo_is_C_var in varoptions) then
  1149. ppufile.putstring(mangledname);
  1150. ppufile.writeentry(ibvarsym);
  1151. end;
  1152. procedure tvarsym.setmangledname(const s : string);
  1153. begin
  1154. _mangledname:=strpnew(s);
  1155. end;
  1156. function tvarsym.mangledname : string;
  1157. var
  1158. prefix : string;
  1159. begin
  1160. if assigned(_mangledname) then
  1161. begin
  1162. mangledname:=strpas(_mangledname);
  1163. exit;
  1164. end;
  1165. case owner.symtabletype of
  1166. staticsymtable :
  1167. if (cs_create_smart in aktmoduleswitches) then
  1168. prefix:='_'+upper(owner.name^)+'$$$_'
  1169. else
  1170. prefix:='_';
  1171. globalsymtable :
  1172. prefix:=
  1173. 'U_'+upper(owner.name^)+'_';
  1174. else
  1175. Message(sym_e_invalid_call_tvarsymmangledname);
  1176. end;
  1177. mangledname:=prefix+name;
  1178. end;
  1179. function tvarsym.getsize : longint;
  1180. begin
  1181. if assigned(vartype.def) then
  1182. getsize:=vartype.def.size
  1183. else
  1184. getsize:=0;
  1185. end;
  1186. function tvarsym.getvaluesize : longint;
  1187. begin
  1188. if assigned(vartype.def) and
  1189. (varspez=vs_value) and
  1190. ((vartype.def.deftype<>arraydef) or
  1191. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1192. getvaluesize:=vartype.def.size
  1193. else
  1194. getvaluesize:=0;
  1195. end;
  1196. function tvarsym.getpushsize : longint;
  1197. begin
  1198. if assigned(vartype.def) then
  1199. begin
  1200. case varspez of
  1201. vs_out,
  1202. vs_var :
  1203. getpushsize:=target_info.size_of_pointer;
  1204. vs_value,
  1205. vs_const :
  1206. begin
  1207. if push_addr_param(vartype.def) then
  1208. getpushsize:=target_info.size_of_pointer
  1209. else
  1210. getpushsize:=vartype.def.size;
  1211. end;
  1212. end;
  1213. end
  1214. else
  1215. getpushsize:=0;
  1216. end;
  1217. procedure tvarsym.insert_in_data;
  1218. var
  1219. varalign,
  1220. l,modulo : longint;
  1221. storefilepos : tfileposinfo;
  1222. begin
  1223. if (vo_is_external in varoptions) then
  1224. exit;
  1225. { handle static variables of objects especially }
  1226. if read_member and (owner.symtabletype=objectsymtable) and
  1227. (sp_static in symoptions) then
  1228. begin
  1229. { the data filed is generated in parser.pas
  1230. with a tobject_FIELDNAME variable }
  1231. { this symbol can't be loaded to a register }
  1232. exclude(varoptions,vo_regable);
  1233. exclude(varoptions,vo_fpuregable);
  1234. end
  1235. else
  1236. if not(read_member) then
  1237. begin
  1238. { made problems with parameters etc. ! (FK) }
  1239. { check for instance of an abstract object or class }
  1240. {
  1241. if (tvarsym(sym).definition.deftype=objectdef) and
  1242. ((tobjectdef(tvarsym(sym).definition).options and oo_is_abstract)<>0) then
  1243. Message(sym_e_no_instance_of_abstract_object);
  1244. }
  1245. storefilepos:=aktfilepos;
  1246. aktfilepos:=akttokenpos;
  1247. if (vo_is_thread_var in varoptions) then
  1248. l:=target_info.size_of_pointer
  1249. else
  1250. l:=getvaluesize;
  1251. case owner.symtabletype of
  1252. stt_exceptsymtable:
  1253. { can contain only one symbol, address calculated later }
  1254. ;
  1255. localsymtable :
  1256. begin
  1257. varstate:=vs_declared;
  1258. varalign:=size_2_align(l);
  1259. varalign:=used_align(varalign,aktalignment.localalignmin,aktalignment.localalignmax);
  1260. address:=align(owner.datasize+l,varalign);
  1261. owner.datasize:=address;
  1262. end;
  1263. staticsymtable :
  1264. begin
  1265. { enable unitialized warning for local symbols }
  1266. varstate:=vs_declared;
  1267. varalign:=size_2_align(l);
  1268. varalign:=used_align(varalign,aktalignment.varalignmin,aktalignment.varalignmax);
  1269. address:=align(owner.datasize,varalign);
  1270. { insert cut for smartlinking or alignment }
  1271. if (cs_create_smart in aktmoduleswitches) then
  1272. bssSegment.concat(Tai_cut.Create)
  1273. else if (address<>owner.datasize) then
  1274. bssSegment.concat(Tai_align.create(varalign));
  1275. owner.datasize:=address+l;
  1276. {$ifdef GDB}
  1277. if cs_debuginfo in aktmoduleswitches then
  1278. concatstabto(bsssegment);
  1279. {$endif GDB}
  1280. if (cs_create_smart in aktmoduleswitches) or
  1281. DLLSource or
  1282. (vo_is_exported in varoptions) or
  1283. (vo_is_C_var in varoptions) then
  1284. bssSegment.concat(Tai_datablock.Create_global(mangledname,l))
  1285. else
  1286. bssSegment.concat(Tai_datablock.Create(mangledname,l));
  1287. { this symbol can't be loaded to a register }
  1288. exclude(varoptions,vo_regable);
  1289. exclude(varoptions,vo_fpuregable);
  1290. end;
  1291. globalsymtable :
  1292. begin
  1293. varalign:=size_2_align(l);
  1294. varalign:=used_align(varalign,aktalignment.varalignmin,aktalignment.varalignmax);
  1295. address:=align(owner.datasize,varalign);
  1296. { insert cut for smartlinking or alignment }
  1297. if (cs_create_smart in aktmoduleswitches) then
  1298. bssSegment.concat(Tai_cut.Create)
  1299. else if (address<>owner.datasize) then
  1300. bssSegment.concat(Tai_align.create(varalign));
  1301. owner.datasize:=address+l;
  1302. {$ifdef GDB}
  1303. if cs_debuginfo in aktmoduleswitches then
  1304. concatstabto(bsssegment);
  1305. {$endif GDB}
  1306. bssSegment.concat(Tai_datablock.Create_global(mangledname,l));
  1307. { this symbol can't be loaded to a register }
  1308. exclude(varoptions,vo_regable);
  1309. exclude(varoptions,vo_fpuregable);
  1310. end;
  1311. recordsymtable,
  1312. objectsymtable :
  1313. begin
  1314. { this symbol can't be loaded to a register }
  1315. exclude(varoptions,vo_regable);
  1316. exclude(varoptions,vo_fpuregable);
  1317. { get the alignment size }
  1318. if (aktalignment.recordalignmax=-1) then
  1319. begin
  1320. varalign:=vartype.def.alignment;
  1321. if (varalign>4) and ((varalign mod 4)<>0) and
  1322. (vartype.def.deftype=arraydef) then
  1323. begin
  1324. Message1(sym_w_wrong_C_pack,vartype.def.typename);
  1325. end;
  1326. if varalign=0 then
  1327. varalign:=l;
  1328. if (owner.dataalignment<aktalignment.maxCrecordalign) then
  1329. begin
  1330. if (varalign>16) and (owner.dataalignment<32) then
  1331. owner.dataalignment:=32
  1332. else if (varalign>12) and (owner.dataalignment<16) then
  1333. owner.dataalignment:=16
  1334. { 12 is needed for long double }
  1335. else if (varalign>8) and (owner.dataalignment<12) then
  1336. owner.dataalignment:=12
  1337. else if (varalign>4) and (owner.dataalignment<8) then
  1338. owner.dataalignment:=8
  1339. else if (varalign>2) and (owner.dataalignment<4) then
  1340. owner.dataalignment:=4
  1341. else if (varalign>1) and (owner.dataalignment<2) then
  1342. owner.dataalignment:=2;
  1343. end;
  1344. owner.dataalignment:=max(owner.dataalignment,aktalignment.maxCrecordalign);
  1345. end
  1346. else
  1347. varalign:=vartype.def.alignment;
  1348. if varalign=0 then
  1349. varalign:=size_2_align(l);
  1350. varalign:=used_align(varalign,aktalignment.recordalignmin,owner.dataalignment);
  1351. address:=align(owner.datasize,varalign);
  1352. owner.datasize:=address+l;
  1353. end;
  1354. parasymtable :
  1355. begin
  1356. { here we need the size of a push instead of the
  1357. size of the data }
  1358. l:=getpushsize;
  1359. varalign:=size_2_align(l);
  1360. varstate:=vs_assigned;
  1361. { we need the new datasize already aligned so we can't
  1362. use the align_address here }
  1363. address:=owner.datasize;
  1364. varalign:=used_align(varalign,owner.dataalignment,owner.dataalignment);
  1365. owner.datasize:=align(address+l,varalign);
  1366. end
  1367. else
  1368. begin
  1369. modulo:=owner.datasize and 3;
  1370. if (l>=4) and (modulo<>0) then
  1371. inc(owner.datasize,4-modulo)
  1372. else
  1373. if (l>=2) and ((modulo and 1)<>0) then
  1374. inc(owner.datasize);
  1375. address:=owner.datasize;
  1376. inc(owner.datasize,l);
  1377. end;
  1378. end;
  1379. aktfilepos:=storefilepos;
  1380. end;
  1381. end;
  1382. {$ifdef GDB}
  1383. function tvarsym.stabstring : pchar;
  1384. var
  1385. st : string;
  1386. begin
  1387. st:=tstoreddef(vartype.def).numberstring;
  1388. if (owner.symtabletype = objectsymtable) and
  1389. (sp_static in symoptions) then
  1390. begin
  1391. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1392. stabstring := strpnew('"'+upper(owner.name^)+'__'+name+':'+st+
  1393. '",'+
  1394. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1395. end
  1396. else if (owner.symtabletype = globalsymtable) then
  1397. begin
  1398. { Here we used S instead of
  1399. because with G GDB doesn't look at the address field
  1400. but searches the same name or with a leading underscore
  1401. but these names don't exist in pascal !}
  1402. if (cs_gdb_gsym in aktglobalswitches) then st := 'G'+st else st := 'S'+st;
  1403. stabstring := strpnew('"'+name+':'+st+'",'+
  1404. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1405. end
  1406. else if owner.symtabletype = staticsymtable then
  1407. begin
  1408. stabstring := strpnew('"'+name+':S'+st+'",'+
  1409. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1410. end
  1411. else if (owner.symtabletype in [parasymtable,inlineparasymtable]) then
  1412. begin
  1413. case varspez of
  1414. vs_out,
  1415. vs_var : st := 'v'+st;
  1416. vs_value,
  1417. vs_const : if push_addr_param(vartype.def) then
  1418. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1419. else
  1420. st := 'p'+st;
  1421. end;
  1422. stabstring := strpnew('"'+name+':'+st+'",'+
  1423. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1424. tostr(address+owner.address_fixup));
  1425. {offset to ebp => will not work if the framepointer is esp
  1426. so some optimizing will make things harder to debug }
  1427. end
  1428. else if (owner.symtabletype in [localsymtable,inlinelocalsymtable]) then
  1429. {$ifdef i386}
  1430. if reg<>R_NO then
  1431. begin
  1432. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1433. { this is the register order for GDB}
  1434. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1435. tostr(N_RSYM)+',0,'+
  1436. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1437. end
  1438. else
  1439. {$endif i386}
  1440. { I don't know if this will work (PM) }
  1441. if (vo_is_C_var in varoptions) then
  1442. stabstring := strpnew('"'+name+':S'+st+'",'+
  1443. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname)
  1444. else
  1445. stabstring := strpnew('"'+name+':'+st+'",'+
  1446. tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',-'+tostr(address-owner.address_fixup))
  1447. else
  1448. stabstring := inherited stabstring;
  1449. end;
  1450. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1451. {$ifdef i386}
  1452. var stab_str : pchar;
  1453. {$endif i386}
  1454. begin
  1455. inherited concatstabto(asmlist);
  1456. {$ifdef i386}
  1457. if (owner.symtabletype=parasymtable) and
  1458. (reg<>R_NO) then
  1459. begin
  1460. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1461. { this is the register order for GDB}
  1462. stab_str:=strpnew('"'+name+':r'
  1463. +tstoreddef(vartype.def).numberstring+'",'+
  1464. tostr(N_RSYM)+',0,'+
  1465. tostr(fileinfo.line)+','+tostr(GDB_i386index[reg]));
  1466. asmList.concat(Tai_stabs.Create(stab_str));
  1467. end;
  1468. {$endif i386}
  1469. end;
  1470. {$endif GDB}
  1471. {****************************************************************************
  1472. TTYPEDCONSTSYM
  1473. *****************************************************************************}
  1474. constructor ttypedconstsym.create(const n : string;p : tdef;really_const : boolean);
  1475. begin
  1476. inherited create(n);
  1477. typ:=typedconstsym;
  1478. typedconsttype.setdef(p);
  1479. is_really_const:=really_const;
  1480. prefix:=stringdup(procprefix);
  1481. end;
  1482. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;really_const : boolean);
  1483. begin
  1484. ttypedconstsym(self).create(n,nil,really_const);
  1485. typedconsttype:=tt;
  1486. end;
  1487. constructor ttypedconstsym.load(ppufile:tcompilerppufile);
  1488. begin
  1489. inherited loadsym(ppufile);
  1490. typ:=typedconstsym;
  1491. ppufile.gettype(typedconsttype);
  1492. prefix:=stringdup(ppufile.getstring);
  1493. is_really_const:=boolean(ppufile.getbyte);
  1494. end;
  1495. destructor ttypedconstsym.destroy;
  1496. begin
  1497. stringdispose(prefix);
  1498. inherited destroy;
  1499. end;
  1500. function ttypedconstsym.mangledname : string;
  1501. begin
  1502. mangledname:='TC_'+prefix^+'_'+name;
  1503. end;
  1504. function ttypedconstsym.getsize : longint;
  1505. begin
  1506. if assigned(typedconsttype.def) then
  1507. getsize:=typedconsttype.def.size
  1508. else
  1509. getsize:=0;
  1510. end;
  1511. procedure ttypedconstsym.deref;
  1512. begin
  1513. typedconsttype.resolve;
  1514. end;
  1515. procedure ttypedconstsym.write(ppufile:tcompilerppufile);
  1516. begin
  1517. inherited writesym(ppufile);
  1518. ppufile.puttype(typedconsttype);
  1519. ppufile.putstring(prefix^);
  1520. ppufile.putbyte(byte(is_really_const));
  1521. ppufile.writeentry(ibtypedconstsym);
  1522. end;
  1523. procedure ttypedconstsym.insert_in_data;
  1524. var
  1525. curconstsegment : taasmoutput;
  1526. address,l,varalign : longint;
  1527. storefilepos : tfileposinfo;
  1528. begin
  1529. storefilepos:=aktfilepos;
  1530. aktfilepos:=akttokenpos;
  1531. if is_really_const then
  1532. curconstsegment:=consts
  1533. else
  1534. curconstsegment:=datasegment;
  1535. l:=getsize;
  1536. varalign:=size_2_align(l);
  1537. varalign:=used_align(varalign,aktalignment.constalignmin,aktalignment.constalignmax);
  1538. address:=align(owner.datasize,varalign);
  1539. { insert cut for smartlinking or alignment }
  1540. if (cs_create_smart in aktmoduleswitches) then
  1541. curconstSegment.concat(Tai_cut.Create)
  1542. else if (address<>owner.datasize) then
  1543. curconstSegment.concat(Tai_align.create(varalign));
  1544. owner.datasize:=address+l;
  1545. {$ifdef GDB}
  1546. if cs_debuginfo in aktmoduleswitches then
  1547. concatstabto(curconstsegment);
  1548. {$endif GDB}
  1549. if (owner.symtabletype=globalsymtable) then
  1550. begin
  1551. if (owner.unitid=0) then
  1552. curconstSegment.concat(Tai_symbol.Createdataname_global(mangledname,getsize));
  1553. end
  1554. else
  1555. begin
  1556. if (cs_create_smart in aktmoduleswitches) or
  1557. DLLSource then
  1558. curconstSegment.concat(Tai_symbol.Createdataname_global(mangledname,getsize))
  1559. else
  1560. curconstSegment.concat(Tai_symbol.Createdataname(mangledname,getsize));
  1561. end;
  1562. aktfilepos:=storefilepos;
  1563. end;
  1564. {$ifdef GDB}
  1565. function ttypedconstsym.stabstring : pchar;
  1566. var
  1567. st : char;
  1568. begin
  1569. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1570. st := 'G'
  1571. else
  1572. st := 'S';
  1573. stabstring := strpnew('"'+name+':'+st+
  1574. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1575. tostr(fileinfo.line)+','+mangledname);
  1576. end;
  1577. {$endif GDB}
  1578. {****************************************************************************
  1579. TCONSTSYM
  1580. ****************************************************************************}
  1581. constructor tconstsym.create(const n : string;t : tconsttyp;v : TConstExprInt);
  1582. begin
  1583. inherited create(n);
  1584. typ:=constsym;
  1585. consttyp:=t;
  1586. value:=v;
  1587. ResStrIndex:=0;
  1588. consttype.reset;
  1589. len:=0;
  1590. end;
  1591. constructor tconstsym.create_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1592. begin
  1593. inherited create(n);
  1594. typ:=constsym;
  1595. consttyp:=t;
  1596. value:=v;
  1597. ResStrIndex:=0;
  1598. consttype:=tt;
  1599. len:=0;
  1600. end;
  1601. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1602. begin
  1603. inherited create(n);
  1604. typ:=constsym;
  1605. consttyp:=t;
  1606. value:=longint(str);
  1607. consttype.reset;
  1608. len:=l;
  1609. if t=constresourcestring then
  1610. ResStrIndex:=ResourceStrings.Register(name,pchar(tpointerord(value)),len);
  1611. end;
  1612. constructor tconstsym.load(ppufile:tcompilerppufile);
  1613. var
  1614. pd : pbestreal;
  1615. ps : pnormalset;
  1616. pc : pchar;
  1617. l1,l2 : longint;
  1618. begin
  1619. inherited loadsym(ppufile);
  1620. typ:=constsym;
  1621. consttype.reset;
  1622. consttyp:=tconsttyp(ppufile.getbyte);
  1623. case consttyp of
  1624. constint:
  1625. if sizeof(tconstexprint)=8 then
  1626. begin
  1627. l1:=ppufile.getlongint;
  1628. l2:=ppufile.getlongint;
  1629. {$ifopt R+}
  1630. {$define Range_check_on}
  1631. {$endif opt R+}
  1632. {$R- needed here }
  1633. value:=qword(l1)+(int64(l2) shl 32);
  1634. {$ifdef Range_check_on}
  1635. {$R+}
  1636. {$undef Range_check_on}
  1637. {$endif Range_check_on}
  1638. end
  1639. else
  1640. value:=ppufile.getlongint;
  1641. constwchar,
  1642. constbool,
  1643. constchar :
  1644. value:=ppufile.getlongint;
  1645. constpointer,
  1646. constord :
  1647. begin
  1648. ppufile.gettype(consttype);
  1649. if sizeof(TConstExprInt)=8 then
  1650. begin
  1651. l1:=ppufile.getlongint;
  1652. l2:=ppufile.getlongint;
  1653. {$ifopt R+}
  1654. {$define Range_check_on}
  1655. {$endif opt R+}
  1656. {$R- needed here }
  1657. value:=qword(l1)+(int64(l2) shl 32);
  1658. {$ifdef Range_check_on}
  1659. {$R+}
  1660. {$undef Range_check_on}
  1661. {$endif Range_check_on}
  1662. end
  1663. else
  1664. value:=ppufile.getlongint;
  1665. end;
  1666. conststring,constresourcestring :
  1667. begin
  1668. len:=ppufile.getlongint;
  1669. getmem(pc,len+1);
  1670. ppufile.getdata(pc^,len);
  1671. if consttyp=constresourcestring then
  1672. ResStrIndex:=ppufile.getlongint;
  1673. value:=tpointerord(pc);
  1674. end;
  1675. constreal :
  1676. begin
  1677. new(pd);
  1678. pd^:=ppufile.getreal;
  1679. value:=tpointerord(pd);
  1680. end;
  1681. constset :
  1682. begin
  1683. ppufile.gettype(consttype);
  1684. new(ps);
  1685. ppufile.getnormalset(ps^);
  1686. value:=tpointerord(ps);
  1687. end;
  1688. constnil : ;
  1689. else
  1690. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1691. end;
  1692. end;
  1693. destructor tconstsym.destroy;
  1694. begin
  1695. case consttyp of
  1696. conststring,constresourcestring :
  1697. freemem(pchar(tpointerord(value)),len+1);
  1698. constreal :
  1699. dispose(pbestreal(tpointerord(value)));
  1700. constset :
  1701. dispose(pnormalset(tpointerord(value)));
  1702. end;
  1703. inherited destroy;
  1704. end;
  1705. function tconstsym.mangledname : string;
  1706. begin
  1707. mangledname:=name;
  1708. end;
  1709. procedure tconstsym.deref;
  1710. begin
  1711. if consttyp in [constord,constpointer,constset] then
  1712. consttype.resolve;
  1713. end;
  1714. procedure tconstsym.write(ppufile:tcompilerppufile);
  1715. begin
  1716. inherited writesym(ppufile);
  1717. ppufile.putbyte(byte(consttyp));
  1718. case consttyp of
  1719. constnil : ;
  1720. constint:
  1721. if sizeof(TConstExprInt)=8 then
  1722. begin
  1723. ppufile.putlongint(longint(lo(value)));
  1724. ppufile.putlongint(longint(hi(value)));
  1725. end
  1726. else
  1727. ppufile.putlongint(value);
  1728. constbool,
  1729. constchar :
  1730. ppufile.putlongint(value);
  1731. constpointer,
  1732. constord :
  1733. begin
  1734. ppufile.puttype(consttype);
  1735. if sizeof(TConstExprInt)=8 then
  1736. begin
  1737. ppufile.putlongint(longint(lo(value)));
  1738. ppufile.putlongint(longint(hi(value)));
  1739. end
  1740. else
  1741. ppufile.putlongint(value);
  1742. end;
  1743. conststring,constresourcestring :
  1744. begin
  1745. ppufile.putlongint(len);
  1746. ppufile.putdata(pchar(TPointerOrd(value))^,len);
  1747. if consttyp=constresourcestring then
  1748. ppufile.putlongint(ResStrIndex);
  1749. end;
  1750. constreal :
  1751. ppufile.putreal(pbestreal(TPointerOrd(value))^);
  1752. constset :
  1753. begin
  1754. ppufile.puttype(consttype);
  1755. ppufile.putnormalset(pointer(TPointerOrd(value))^);
  1756. end;
  1757. else
  1758. internalerror(13);
  1759. end;
  1760. ppufile.writeentry(ibconstsym);
  1761. end;
  1762. {$ifdef GDB}
  1763. function tconstsym.stabstring : pchar;
  1764. var st : string;
  1765. begin
  1766. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  1767. case consttyp of
  1768. conststring : begin
  1769. { I had to remove ibm2ascii !! }
  1770. st := pstring(TPointerOrd(value))^;
  1771. {st := ibm2ascii(pstring(value)^);}
  1772. st := 's'''+st+'''';
  1773. end;
  1774. constbool,
  1775. constint,
  1776. constpointer,
  1777. constord,
  1778. constchar : st := 'i'+int64tostr(value);
  1779. constreal : begin
  1780. system.str(pbestreal(TPointerOrd(value))^,st);
  1781. st := 'r'+st;
  1782. end;
  1783. { if we don't know just put zero !! }
  1784. else st:='i0';
  1785. {***SETCONST}
  1786. {constset:;} {*** I don't know what to do with a set.}
  1787. { sets are not recognized by GDB}
  1788. {***}
  1789. end;
  1790. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  1791. tostr(fileinfo.line)+',0');
  1792. end;
  1793. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  1794. begin
  1795. if consttyp <> conststring then
  1796. inherited concatstabto(asmlist);
  1797. end;
  1798. {$endif GDB}
  1799. {****************************************************************************
  1800. TENUMSYM
  1801. ****************************************************************************}
  1802. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  1803. begin
  1804. inherited create(n);
  1805. typ:=enumsym;
  1806. definition:=def;
  1807. value:=v;
  1808. if def.min>v then
  1809. def.setmin(v);
  1810. if def.max<v then
  1811. def.setmax(v);
  1812. order;
  1813. end;
  1814. constructor tenumsym.load(ppufile:tcompilerppufile);
  1815. begin
  1816. inherited loadsym(ppufile);
  1817. typ:=enumsym;
  1818. definition:=tenumdef(ppufile.getderef);
  1819. value:=ppufile.getlongint;
  1820. nextenum := Nil;
  1821. end;
  1822. procedure tenumsym.deref;
  1823. begin
  1824. resolvedef(tdef(definition));
  1825. order;
  1826. end;
  1827. procedure tenumsym.order;
  1828. var
  1829. sym : tenumsym;
  1830. begin
  1831. sym := tenumsym(definition.firstenum);
  1832. if sym = nil then
  1833. begin
  1834. definition.firstenum := self;
  1835. nextenum := nil;
  1836. exit;
  1837. end;
  1838. { reorder the symbols in increasing value }
  1839. if value < sym.value then
  1840. begin
  1841. nextenum := sym;
  1842. definition.firstenum := self;
  1843. end
  1844. else
  1845. begin
  1846. while (sym.value <= value) and assigned(sym.nextenum) do
  1847. sym := sym.nextenum;
  1848. nextenum := sym.nextenum;
  1849. sym.nextenum := self;
  1850. end;
  1851. end;
  1852. procedure tenumsym.write(ppufile:tcompilerppufile);
  1853. begin
  1854. inherited writesym(ppufile);
  1855. ppufile.putderef(definition);
  1856. ppufile.putlongint(value);
  1857. ppufile.writeentry(ibenumsym);
  1858. end;
  1859. {$ifdef GDB}
  1860. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  1861. begin
  1862. {enum elements have no stab !}
  1863. end;
  1864. {$EndIf GDB}
  1865. {****************************************************************************
  1866. TTYPESYM
  1867. ****************************************************************************}
  1868. constructor ttypesym.create(const n : string;const tt : ttype);
  1869. begin
  1870. inherited create(n);
  1871. typ:=typesym;
  1872. restype:=tt;
  1873. {$ifdef GDB}
  1874. isusedinstab := false;
  1875. {$endif GDB}
  1876. { register the typesym for the definition }
  1877. if assigned(restype.def) and
  1878. (restype.def.deftype<>errordef) and
  1879. not(assigned(restype.def.typesym)) then
  1880. restype.def.typesym:=self;
  1881. end;
  1882. constructor ttypesym.load(ppufile:tcompilerppufile);
  1883. begin
  1884. inherited loadsym(ppufile);
  1885. typ:=typesym;
  1886. {$ifdef GDB}
  1887. isusedinstab := false;
  1888. {$endif GDB}
  1889. ppufile.gettype(restype);
  1890. end;
  1891. function ttypesym.gettypedef:tdef;
  1892. begin
  1893. gettypedef:=restype.def;
  1894. end;
  1895. procedure ttypesym.deref;
  1896. begin
  1897. restype.resolve;
  1898. end;
  1899. procedure ttypesym.write(ppufile:tcompilerppufile);
  1900. begin
  1901. inherited writesym(ppufile);
  1902. ppufile.puttype(restype);
  1903. ppufile.writeentry(ibtypesym);
  1904. end;
  1905. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  1906. begin
  1907. inherited load_references(ppufile,locals);
  1908. if (restype.def.deftype=recorddef) then
  1909. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  1910. if (restype.def.deftype=objectdef) then
  1911. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  1912. end;
  1913. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  1914. begin
  1915. if not inherited write_references(ppufile,locals) then
  1916. begin
  1917. { write address of this symbol if record or object
  1918. even if no real refs are there
  1919. because we need it for the symtable }
  1920. if (restype.def.deftype in [recorddef,objectdef]) then
  1921. begin
  1922. ppufile.putderef(self);
  1923. ppufile.writeentry(ibsymref);
  1924. end;
  1925. end;
  1926. write_references:=true;
  1927. if (restype.def.deftype=recorddef) then
  1928. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  1929. if (restype.def.deftype=objectdef) then
  1930. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  1931. end;
  1932. {$ifdef GDB}
  1933. function ttypesym.stabstring : pchar;
  1934. var
  1935. stabchar : string[2];
  1936. short : string;
  1937. begin
  1938. if restype.def.deftype in tagtypes then
  1939. stabchar := 'Tt'
  1940. else
  1941. stabchar := 't';
  1942. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  1943. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  1944. stabstring := strpnew(short);
  1945. end;
  1946. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  1947. begin
  1948. {not stabs for forward defs }
  1949. if assigned(restype.def) then
  1950. if (restype.def.typesym = self) then
  1951. tstoreddef(restype.def).concatstabto(asmlist)
  1952. else
  1953. inherited concatstabto(asmlist);
  1954. end;
  1955. {$endif GDB}
  1956. {****************************************************************************
  1957. TSYSSYM
  1958. ****************************************************************************}
  1959. constructor tsyssym.create(const n : string;l : longint);
  1960. begin
  1961. inherited create(n);
  1962. typ:=syssym;
  1963. number:=l;
  1964. end;
  1965. constructor tsyssym.load(ppufile:tcompilerppufile);
  1966. begin
  1967. inherited loadsym(ppufile);
  1968. typ:=syssym;
  1969. number:=ppufile.getlongint;
  1970. end;
  1971. destructor tsyssym.destroy;
  1972. begin
  1973. inherited destroy;
  1974. end;
  1975. procedure tsyssym.write(ppufile:tcompilerppufile);
  1976. begin
  1977. inherited writesym(ppufile);
  1978. ppufile.putlongint(number);
  1979. ppufile.writeentry(ibsyssym);
  1980. end;
  1981. {$ifdef GDB}
  1982. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  1983. begin
  1984. end;
  1985. {$endif GDB}
  1986. end.
  1987. {
  1988. $Log$
  1989. Revision 1.18 2001-08-19 09:39:28 peter
  1990. * local browser support fixed
  1991. Revision 1.16 2001/08/12 20:00:26 peter
  1992. * don't write fpuregable for varoptions
  1993. Revision 1.15 2001/08/06 21:40:48 peter
  1994. * funcret moved from tprocinfo to tprocdef
  1995. Revision 1.14 2001/07/01 20:16:17 peter
  1996. * alignmentinfo record added
  1997. * -Oa argument supports more alignment settings that can be specified
  1998. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1999. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  2000. required alignment and the maximum usefull alignment. The final
  2001. alignment will be choosen per variable size dependent on these
  2002. settings
  2003. Revision 1.13 2001/05/08 21:06:32 florian
  2004. * some more support for widechars commited especially
  2005. regarding type casting and constants
  2006. Revision 1.12 2001/05/06 14:49:17 peter
  2007. * ppu object to class rewrite
  2008. * move ppu read and write stuff to fppu
  2009. Revision 1.11 2001/04/18 22:01:59 peter
  2010. * registration of targets and assemblers
  2011. Revision 1.10 2001/04/13 01:22:16 peter
  2012. * symtable change to classes
  2013. * range check generation and errors fixed, make cycle DEBUG=1 works
  2014. * memory leaks fixed
  2015. Revision 1.9 2001/04/02 21:20:35 peter
  2016. * resulttype rewrite
  2017. Revision 1.8 2001/03/11 22:58:51 peter
  2018. * getsym redesign, removed the globals srsym,srsymtable
  2019. Revision 1.7 2000/12/25 00:07:30 peter
  2020. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  2021. tlinkedlist objects)
  2022. Revision 1.6 2000/11/28 00:25:17 pierre
  2023. + use int64tostr function for integer consts
  2024. Revision 1.5 2000/11/13 14:44:35 jonas
  2025. * fixes so no more range errors with improved range checking code
  2026. Revision 1.4 2000/11/08 23:15:17 florian
  2027. * tprocdef.procsym must be set also when a tprocdef is loaded from a PPU
  2028. Revision 1.3 2000/11/06 23:13:53 peter
  2029. * uppercase manglednames
  2030. Revision 1.2 2000/11/01 23:04:38 peter
  2031. * tprocdef.fullprocname added for better casesensitve writing of
  2032. procedures
  2033. Revision 1.1 2000/10/31 22:02:52 peter
  2034. * symtable splitted, no real code changes
  2035. }