symsym.pas 73 KB

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