symtype.pas 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  3. This unit handles the symbol tables
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symtype;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,
  23. cclasses,
  24. { global }
  25. globtype,globals,constexp,
  26. { symtable }
  27. symconst,symbase,
  28. { aasm }
  29. aasmbase,ppu,cpuinfo
  30. ;
  31. type
  32. {************************************************
  33. Required Forwards
  34. ************************************************}
  35. tsym = class;
  36. Tcompilerppufile=class;
  37. {************************************************
  38. TDef
  39. ************************************************}
  40. tgeTSymtable = (gs_none,gs_record,gs_local,gs_para);
  41. tdef = class(TDefEntry)
  42. typesym : tsym; { which type the definition was generated this def }
  43. { maybe it's useful to merge the dwarf and stabs debugging info with some hacking }
  44. { dwarf debugging }
  45. dwarf_lab : tasmsymbol;
  46. dwarf_ref_lab : tasmsymbol;
  47. { stabs debugging }
  48. stab_number : word;
  49. dbg_state : tdefdbgstatus;
  50. defoptions : tdefoptions;
  51. defstates : tdefstates;
  52. constructor create(dt:tdeftyp);
  53. procedure buildderef;virtual;abstract;
  54. procedure buildderefimpl;virtual;abstract;
  55. procedure deref;virtual;abstract;
  56. procedure derefimpl;virtual;abstract;
  57. function typename:string;
  58. function fulltypename:string;
  59. function GetTypeName:string;virtual;
  60. function typesymbolprettyname:string;virtual;
  61. function mangledparaname:string;
  62. function getmangledparaname:TSymStr;virtual;
  63. function rtti_mangledname(rt:trttitype):string;virtual;abstract;
  64. function OwnerHierarchyName: string; virtual; abstract;
  65. function fullownerhierarchyname:string;virtual;abstract;
  66. function size:asizeint;virtual;abstract;
  67. function packedbitsize:asizeint;virtual;
  68. function alignment:shortint;virtual;abstract;
  69. { alignment when this type appears in a record/class/... }
  70. function structalignment:shortint;virtual;
  71. function getvardef:longint;virtual;abstract;
  72. function getparentdef:tdef;virtual;
  73. function geTSymtable(t:tgeTSymtable):TSymtable;virtual;
  74. function is_publishable:boolean;virtual;abstract;
  75. function needs_inittable:boolean;virtual;abstract;
  76. function needs_separate_initrtti:boolean;virtual;abstract;
  77. procedure ChangeOwner(st:TSymtable);
  78. procedure register_created_object_type;virtual;
  79. function get_top_level_symtable: tsymtable;
  80. end;
  81. {************************************************
  82. TSym
  83. ************************************************}
  84. { this object is the base for all symbol objects }
  85. { tsym }
  86. tsym = class(TSymEntry)
  87. protected
  88. public
  89. fileinfo : tfileposinfo;
  90. { size of fileinfo is 10 bytes, so if a >word aligned type would follow,
  91. two bytes of memory would be wasted, so we put two one byte fields over here }
  92. visibility : tvisibility;
  93. isdbgwritten : boolean;
  94. symoptions : tsymoptions;
  95. refs : longint;
  96. reflist : TLinkedList;
  97. { deprecated optionally can have a message }
  98. deprecatedmsg: pshortstring;
  99. constructor create(st:tsymtyp;const aname:string);
  100. destructor destroy;override;
  101. function mangledname:TSymStr; virtual;
  102. function prettyname:string; virtual;
  103. procedure buildderef;virtual;
  104. procedure deref;virtual;
  105. procedure ChangeOwner(st:TSymtable);
  106. procedure IncRefCount;
  107. procedure IncRefCountBy(AValue : longint);
  108. procedure MaybeCreateRefList;
  109. procedure AddRef;
  110. end;
  111. tsymarr = array[0..maxlongint div sizeof(pointer)-1] of tsym;
  112. psymarr = ^tsymarr;
  113. {************************************************
  114. TDeref
  115. ************************************************}
  116. tderef = object
  117. dataidx : longint;
  118. procedure reset;
  119. procedure build(s:TObject);
  120. function resolve:TObject;
  121. end;
  122. pderef = ^tderef;
  123. {************************************************
  124. tpropaccesslist
  125. ************************************************}
  126. ppropaccesslistitem = ^tpropaccesslistitem;
  127. tpropaccesslistitem = record
  128. sltype : tsltype;
  129. next : ppropaccesslistitem;
  130. case byte of
  131. 0 : (sym : tsym; symderef : tderef);
  132. 1 : (value : TConstExprInt; valuedef: tdef; valuedefderef:tderef);
  133. 2 : (def: tdef; defderef:tderef);
  134. end;
  135. tpropaccesslist = class
  136. procdef : tdef;
  137. procdefderef : tderef;
  138. firstsym,
  139. lastsym : ppropaccesslistitem;
  140. constructor create;
  141. destructor destroy;override;
  142. function empty:boolean;
  143. function getcopy: tpropaccesslist;
  144. procedure addsym(slt:tsltype;p:tsym);
  145. procedure addconst(slt:tsltype;v:TConstExprInt;d:tdef);
  146. procedure addtype(slt:tsltype;d:tdef);
  147. procedure addsymderef(slt:tsltype;d:tderef);
  148. procedure addconstderef(slt:tsltype;v:TConstExprInt;d:tderef);
  149. procedure addtypederef(slt:tsltype;d:tderef);
  150. procedure clear;
  151. procedure resolve;
  152. procedure buildderef;
  153. end;
  154. {************************************************
  155. Tcompilerppufile
  156. ************************************************}
  157. tcompilerppufile=class(tppufile)
  158. public
  159. procedure checkerror;
  160. procedure getguid(var g: tguid);
  161. function getexprint:Tconstexprint;
  162. function getptruint:TConstPtrUInt;
  163. procedure getposinfo(var p:tfileposinfo);
  164. procedure getderef(var d:tderef);
  165. function getpropaccesslist:tpropaccesslist;
  166. function getasmsymbol:tasmsymbol;
  167. procedure putguid(const g: tguid);
  168. procedure putexprint(const v:tconstexprint);
  169. procedure PutPtrUInt(v:TConstPtrUInt);
  170. procedure putposinfo(const p:tfileposinfo);
  171. procedure putderef(const d:tderef);
  172. procedure putpropaccesslist(p:tpropaccesslist);
  173. procedure putasmsymbol(s:tasmsymbol);
  174. end;
  175. {$ifdef MEMDEBUG}
  176. var
  177. memmanglednames,
  178. memprocpara,
  179. memprocparast,
  180. memproclocalst,
  181. memprocnodetree : tmemdebug;
  182. {$endif MEMDEBUG}
  183. function FindUnitSymtable(st:TSymtable):TSymtable;
  184. implementation
  185. uses
  186. crefs,
  187. verbose,
  188. fmodule
  189. ;
  190. {****************************************************************************
  191. Utils
  192. ****************************************************************************}
  193. function FindUnitSymtable(st:TSymtable):TSymtable;
  194. begin
  195. result:=nil;
  196. repeat
  197. if not assigned(st) then
  198. internalerror(200602034);
  199. case st.symtabletype of
  200. localmacrosymtable,
  201. exportedmacrosymtable,
  202. staticsymtable,
  203. globalsymtable :
  204. begin
  205. result:=st;
  206. exit;
  207. end;
  208. recordsymtable,
  209. enumsymtable,
  210. arraysymtable,
  211. localsymtable,
  212. parasymtable,
  213. ObjectSymtable :
  214. st:=st.defowner.owner;
  215. else
  216. internalerror(200602035);
  217. end;
  218. until false;
  219. end;
  220. {****************************************************************************
  221. Tdef
  222. ****************************************************************************}
  223. constructor tdef.create(dt:tdeftyp);
  224. begin
  225. inherited create;
  226. typ:=dt;
  227. owner := nil;
  228. typesym := nil;
  229. defoptions:=[];
  230. dbg_state:=dbg_state_unused;
  231. stab_number:=0;
  232. end;
  233. function tdef.typename:string;
  234. begin
  235. result:=OwnerHierarchyName;
  236. if assigned(typesym) and
  237. not(typ in [procvardef,procdef]) and
  238. (typesym.realname[1]<>'$') then
  239. result:=result+typesym.realname
  240. else
  241. result:=result+GetTypeName;
  242. end;
  243. function tdef.fulltypename:string;
  244. begin
  245. result:=fullownerhierarchyname;
  246. if assigned(typesym) and
  247. not(typ in [procvardef,procdef]) and
  248. (typesym.realname[1]<>'$') then
  249. result:=result+typesym.realname
  250. else
  251. result:=result+GetTypeName;
  252. end;
  253. function tdef.GetTypeName : string;
  254. begin
  255. GetTypeName:='<unknown type>' end;
  256. function tdef.typesymbolprettyname:string;
  257. begin
  258. result:=OwnerHierarchyName;
  259. if assigned(typesym) then
  260. result:=result+typesym.prettyname
  261. else
  262. result:=result+'<no type symbol>'
  263. end;
  264. function tdef.mangledparaname:string;
  265. begin
  266. result:=OwnerHierarchyName;
  267. if assigned(typesym) then
  268. mangledparaname:=result+typesym.name
  269. else
  270. mangledparaname:=result+getmangledparaname;
  271. end;
  272. function tdef.getmangledparaname:TSymStr;
  273. begin
  274. result:='<unknown type>';
  275. end;
  276. function tdef.getparentdef:tdef;
  277. begin
  278. result:=nil;
  279. end;
  280. function tdef.geTSymtable(t:tgeTSymtable):TSymtable;
  281. begin
  282. result:=nil;
  283. end;
  284. function tdef.packedbitsize:asizeint;
  285. begin
  286. result:=size * 8;
  287. end;
  288. function tdef.structalignment: shortint;
  289. begin
  290. result:=alignment;
  291. end;
  292. procedure tdef.ChangeOwner(st:TSymtable);
  293. begin
  294. // if assigned(Owner) then
  295. // Owner.DefList.List[i]:=nil;
  296. Owner:=st;
  297. Owner.DefList.Add(self);
  298. end;
  299. procedure tdef.register_created_object_type;
  300. begin
  301. end;
  302. function tdef.get_top_level_symtable: tsymtable;
  303. begin
  304. result:=owner;
  305. while assigned(result) and
  306. assigned(result.defowner) do
  307. result:=tdef(result.defowner).owner;
  308. end;
  309. {****************************************************************************
  310. TSYM (base for all symtypes)
  311. ****************************************************************************}
  312. constructor tsym.create(st:tsymtyp;const aname:string);
  313. begin
  314. inherited CreateNotOwned;
  315. realname:=aname;
  316. typ:=st;
  317. RefList:=nil;
  318. symoptions:=[];
  319. fileinfo:=current_tokenpos;
  320. isdbgwritten := false;
  321. visibility:=vis_public;
  322. deprecatedmsg:=nil;
  323. end;
  324. destructor Tsym.destroy;
  325. begin
  326. stringdispose(deprecatedmsg);
  327. if assigned(RefList) then
  328. RefList.Free;
  329. inherited Destroy;
  330. end;
  331. procedure Tsym.IncRefCount;
  332. begin
  333. inc(refs);
  334. if cs_browser in current_settings.moduleswitches then
  335. begin
  336. MaybeCreateRefList;
  337. AddRef;
  338. end;
  339. end;
  340. procedure Tsym.IncRefCountBy(AValue : longint);
  341. begin
  342. inc(refs,AValue);
  343. end;
  344. procedure Tsym.MaybeCreateRefList;
  345. begin
  346. if not assigned(reflist) then
  347. reflist:=TRefLinkedList.create;
  348. end;
  349. procedure Tsym.AddRef;
  350. var
  351. RefItem: TRefItem;
  352. begin
  353. RefItem:=TRefItem.Create(current_tokenpos);
  354. RefList.Concat(RefItem);
  355. end;
  356. procedure Tsym.buildderef;
  357. begin
  358. end;
  359. procedure Tsym.deref;
  360. begin
  361. end;
  362. function tsym.mangledname : TSymStr;
  363. begin
  364. internalerror(200204171);
  365. result:='';
  366. end;
  367. function tsym.prettyname : string;
  368. begin
  369. result:=realname;
  370. end;
  371. procedure tsym.ChangeOwner(st:TSymtable);
  372. begin
  373. Owner:=st;
  374. inherited ChangeOwner(Owner.SymList);
  375. end;
  376. {****************************************************************************
  377. tpropaccesslist
  378. ****************************************************************************}
  379. constructor tpropaccesslist.create;
  380. begin
  381. procdef:=nil; { needed for procedures }
  382. firstsym:=nil;
  383. lastsym:=nil;
  384. end;
  385. destructor tpropaccesslist.destroy;
  386. begin
  387. clear;
  388. end;
  389. function tpropaccesslist.empty:boolean;
  390. begin
  391. empty:=(firstsym=nil);
  392. end;
  393. function tpropaccesslist.getcopy: tpropaccesslist;
  394. var
  395. hp, dest : ppropaccesslistitem;
  396. begin
  397. result:=tpropaccesslist.create;
  398. result.procdef:=procdef;
  399. hp:=firstsym;
  400. while assigned(hp) do
  401. begin
  402. new(dest);
  403. dest^:=hp^;
  404. dest^.next:=nil;
  405. if not assigned(result.firstsym) then
  406. result.firstsym:=dest;
  407. if assigned(result.lastsym) then
  408. result.lastsym^.next:=dest;
  409. result.lastsym:=dest;
  410. hp:=hp^.next;
  411. end;
  412. end;
  413. procedure tpropaccesslist.clear;
  414. var
  415. hp : ppropaccesslistitem;
  416. begin
  417. while assigned(firstsym) do
  418. begin
  419. hp:=firstsym;
  420. firstsym:=firstsym^.next;
  421. dispose(hp);
  422. end;
  423. firstsym:=nil;
  424. lastsym:=nil;
  425. procdef:=nil;
  426. end;
  427. procedure tpropaccesslist.addsym(slt:tsltype;p:tsym);
  428. var
  429. hp : ppropaccesslistitem;
  430. begin
  431. new(hp);
  432. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  433. hp^.sltype:=slt;
  434. hp^.sym:=p;
  435. hp^.symderef.reset;
  436. if assigned(lastsym) then
  437. lastsym^.next:=hp
  438. else
  439. firstsym:=hp;
  440. lastsym:=hp;
  441. end;
  442. procedure tpropaccesslist.addconst(slt:tsltype;v:TConstExprInt;d:tdef);
  443. var
  444. hp : ppropaccesslistitem;
  445. begin
  446. new(hp);
  447. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  448. hp^.sltype:=slt;
  449. hp^.value:=v;
  450. hp^.valuedef:=d;
  451. hp^.valuedefderef.reset;
  452. if assigned(lastsym) then
  453. lastsym^.next:=hp
  454. else
  455. firstsym:=hp;
  456. lastsym:=hp;
  457. end;
  458. procedure tpropaccesslist.addtype(slt:tsltype;d:tdef);
  459. var
  460. hp : ppropaccesslistitem;
  461. begin
  462. new(hp);
  463. fillchar(hp^,sizeof(tpropaccesslistitem),0);
  464. hp^.sltype:=slt;
  465. hp^.def:=d;
  466. hp^.defderef.reset;
  467. if assigned(lastsym) then
  468. lastsym^.next:=hp
  469. else
  470. firstsym:=hp;
  471. lastsym:=hp;
  472. end;
  473. procedure tpropaccesslist.addsymderef(slt:tsltype;d:tderef);
  474. begin
  475. addsym(slt,nil);
  476. lastsym^.symderef:=d;
  477. end;
  478. procedure tpropaccesslist.addconstderef(slt:tsltype;v:TConstExprInt;d:tderef);
  479. begin
  480. addconst(slt,v,nil);
  481. lastsym^.valuedefderef:=d;
  482. end;
  483. procedure tpropaccesslist.addtypederef(slt:tsltype;d:tderef);
  484. begin
  485. addtype(slt,nil);
  486. lastsym^.defderef:=d;
  487. end;
  488. procedure tpropaccesslist.resolve;
  489. var
  490. hp : ppropaccesslistitem;
  491. begin
  492. procdef:=tdef(procdefderef.resolve);
  493. hp:=firstsym;
  494. while assigned(hp) do
  495. begin
  496. case hp^.sltype of
  497. sl_call,
  498. sl_load,
  499. sl_subscript :
  500. hp^.sym:=tsym(hp^.symderef.resolve);
  501. sl_absolutetype,
  502. sl_typeconv :
  503. hp^.def:=tdef(hp^.defderef.resolve);
  504. sl_vec:
  505. hp^.valuedef:=tdef(hp^.valuedefderef.resolve);
  506. else
  507. internalerror(200110205);
  508. end;
  509. hp:=hp^.next;
  510. end;
  511. end;
  512. procedure tpropaccesslist.buildderef;
  513. var
  514. hp : ppropaccesslistitem;
  515. begin
  516. procdefderef.build(procdef);
  517. hp:=firstsym;
  518. while assigned(hp) do
  519. begin
  520. case hp^.sltype of
  521. sl_call,
  522. sl_load,
  523. sl_subscript :
  524. hp^.symderef.build(hp^.sym);
  525. sl_absolutetype,
  526. sl_typeconv :
  527. hp^.defderef.build(hp^.def);
  528. sl_vec:
  529. hp^.valuedefderef.build(hp^.valuedef);
  530. else
  531. internalerror(200110205);
  532. end;
  533. hp:=hp^.next;
  534. end;
  535. end;
  536. {****************************************************************************
  537. Tderef
  538. ****************************************************************************}
  539. procedure tderef.reset;
  540. begin
  541. dataidx:=-1;
  542. end;
  543. procedure tderef.build(s:TObject);
  544. var
  545. len : byte;
  546. st : TSymtable;
  547. data : array[0..255] of byte;
  548. idx : word;
  549. begin
  550. { skip length byte }
  551. len:=1;
  552. if assigned(s) then
  553. begin
  554. { TODO: ugly hack}
  555. if s is tsym then
  556. st:=FindUnitSymtable(tsym(s).owner)
  557. else
  558. st:=FindUnitSymtable(tdef(s).owner);
  559. if not st.iscurrentunit then
  560. begin
  561. { register that the unit is needed for resolving }
  562. data[len]:=ord(deref_unit);
  563. idx:=current_module.derefidx_unit(st.moduleid);
  564. data[len+1]:=idx shr 8 and $ff;
  565. data[len+2]:=idx and $ff;
  566. inc(len,3);
  567. end;
  568. if s is tsym then
  569. begin
  570. data[len]:=ord(deref_symid);
  571. data[len+1]:=tsym(s).symid shr 24 and $ff;
  572. data[len+2]:=tsym(s).symid shr 16 and $ff;
  573. data[len+3]:=tsym(s).symid shr 8 and $ff;
  574. data[len+4]:=tsym(s).symid and $ff;
  575. inc(len,5);
  576. end
  577. else
  578. begin
  579. data[len]:=ord(deref_defid);
  580. data[len+1]:=tdef(s).defid shr 24 and $ff;
  581. data[len+2]:=tdef(s).defid shr 16 and $ff;
  582. data[len+3]:=tdef(s).defid shr 8 and $ff;
  583. data[len+4]:=tdef(s).defid and $ff;
  584. inc(len,5);
  585. end;
  586. end
  587. else
  588. begin
  589. { nil pointer }
  590. data[len]:=ord(deref_nil);
  591. inc(len);
  592. end;
  593. { store data length in first byte }
  594. data[0]:=len-1;
  595. { store index and write to derefdata }
  596. dataidx:=current_module.derefdata.size;
  597. current_module.derefdata.write(data,len);
  598. end;
  599. function tderef.resolve:TObject;
  600. var
  601. pm : tmodule;
  602. typ : tdereftype;
  603. idx : longint;
  604. i : aint;
  605. len : byte;
  606. data : array[0..255] of byte;
  607. begin
  608. result:=nil;
  609. { not initialized or error }
  610. if dataidx<0 then
  611. internalerror(200306067);
  612. { read data }
  613. current_module.derefdata.seek(dataidx);
  614. if current_module.derefdata.read(len,1)<>1 then
  615. internalerror(200310221);
  616. if len>0 then
  617. begin
  618. if current_module.derefdata.read(data,len)<>len then
  619. internalerror(200310222);
  620. end;
  621. { process data }
  622. pm:=current_module;
  623. i:=0;
  624. while (i<len) do
  625. begin
  626. typ:=tdereftype(data[i]);
  627. inc(i);
  628. case typ of
  629. deref_unit :
  630. begin
  631. idx:=(data[i] shl 8) or data[i+1];
  632. inc(i,2);
  633. pm:=current_module.resolve_unit(idx);
  634. end;
  635. deref_defid :
  636. begin
  637. idx:=longint((data[i] shl 24) or (data[i+1] shl 16) or (data[i+2] shl 8) or data[i+3]);
  638. inc(i,4);
  639. result:=tdef(pm.deflist[idx]);
  640. end;
  641. deref_symid :
  642. begin
  643. idx:=longint((data[i] shl 24) or (data[i+1] shl 16) or (data[i+2] shl 8) or data[i+3]);
  644. inc(i,4);
  645. result:=tsym(pm.symlist[idx]);
  646. end;
  647. deref_nil :
  648. begin
  649. result:=nil;
  650. { Only allowed when no other deref is available }
  651. if len<>1 then
  652. internalerror(200306232);
  653. end;
  654. else
  655. internalerror(200212277);
  656. end;
  657. end;
  658. end;
  659. {*****************************************************************************
  660. TCompilerPPUFile
  661. *****************************************************************************}
  662. procedure tcompilerppufile.checkerror;
  663. begin
  664. if error then
  665. Message(unit_f_ppu_read_error);
  666. end;
  667. procedure tcompilerppufile.getguid(var g: tguid);
  668. begin
  669. longint(g.d1):=getlongint;
  670. g.d2:=getword;
  671. g.d3:=getword;
  672. getdata(g.d4,sizeof(g.d4));
  673. end;
  674. function tcompilerppufile.getexprint:Tconstexprint;
  675. begin
  676. getexprint.overflow:=false;
  677. getexprint.signed:=boolean(getbyte);
  678. getexprint.svalue:=getint64;
  679. end;
  680. function tcompilerppufile.getPtrUInt:TConstPtrUInt;
  681. begin
  682. {$if sizeof(TConstPtrUInt)=8}
  683. result:=tconstptruint(getint64);
  684. {$else}
  685. result:=TConstPtrUInt(getlongint);
  686. {$endif}
  687. end;
  688. procedure tcompilerppufile.getposinfo(var p:tfileposinfo);
  689. var
  690. info : byte;
  691. begin
  692. {
  693. info byte layout in bits:
  694. 0-1 - amount of bytes for fileindex
  695. 2-3 - amount of bytes for line
  696. 4-5 - amount of bytes for column
  697. }
  698. info:=getbyte;
  699. case (info and $03) of
  700. 0 : p.fileindex:=getbyte;
  701. 1 : p.fileindex:=getword;
  702. 2 : p.fileindex:=(getbyte shl 16) or getword;
  703. 3 : p.fileindex:=getlongint;
  704. end;
  705. case ((info shr 2) and $03) of
  706. 0 : p.line:=getbyte;
  707. 1 : p.line:=getword;
  708. 2 : p.line:=(getbyte shl 16) or getword;
  709. 3 : p.line:=getlongint;
  710. end;
  711. case ((info shr 4) and $03) of
  712. 0 : p.column:=getbyte;
  713. 1 : p.column:=getword;
  714. 2 : p.column:=(getbyte shl 16) or getword;
  715. 3 : p.column:=getlongint;
  716. end;
  717. p.moduleindex:=current_module.unit_index;
  718. end;
  719. procedure tcompilerppufile.getderef(var d:tderef);
  720. begin
  721. d.dataidx:=getlongint;
  722. end;
  723. function tcompilerppufile.getpropaccesslist:tpropaccesslist;
  724. var
  725. hderef : tderef;
  726. slt : tsltype;
  727. idx : longint;
  728. p : tpropaccesslist;
  729. begin
  730. p:=tpropaccesslist.create;
  731. getderef(p.procdefderef);
  732. repeat
  733. slt:=tsltype(getbyte);
  734. case slt of
  735. sl_none :
  736. break;
  737. sl_call,
  738. sl_load,
  739. sl_subscript :
  740. begin
  741. getderef(hderef);
  742. p.addsymderef(slt,hderef);
  743. end;
  744. sl_absolutetype,
  745. sl_typeconv :
  746. begin
  747. getderef(hderef);
  748. p.addtypederef(slt,hderef);
  749. end;
  750. sl_vec :
  751. begin
  752. idx:=getlongint;
  753. getderef(hderef);
  754. p.addconstderef(slt,idx,hderef);
  755. end;
  756. else
  757. internalerror(200110204);
  758. end;
  759. until false;
  760. getpropaccesslist:=tpropaccesslist(p);
  761. end;
  762. function tcompilerppufile.getasmsymbol:tasmsymbol;
  763. begin
  764. getlongint;
  765. getasmsymbol:=nil;
  766. end;
  767. procedure tcompilerppufile.putposinfo(const p:tfileposinfo);
  768. var
  769. oldcrc : boolean;
  770. info : byte;
  771. begin
  772. { posinfo is not relevant for changes in PPU }
  773. oldcrc:=do_crc;
  774. do_crc:=false;
  775. {
  776. info byte layout in bits:
  777. 0-1 - amount of bytes for fileindex
  778. 2-3 - amount of bytes for line
  779. 4-5 - amount of bytes for column
  780. }
  781. info:=0;
  782. { calculate info byte }
  783. if (p.fileindex>$ff) then
  784. begin
  785. info:=info or $1;
  786. { uncomment this code if tfileposinfo.fileindex type was changed
  787. if (p.fileindex<=$ffff) then
  788. info:=info or $1
  789. else
  790. if (p.fileindex<=$ffffff) then
  791. info:=info or $2
  792. else
  793. info:=info or $3;
  794. }
  795. end;
  796. if (p.line>$ff) then
  797. begin
  798. if (p.line<=$ffff) then
  799. info:=info or $4
  800. else
  801. if (p.line<=$ffffff) then
  802. info:=info or $8
  803. else
  804. info:=info or $c;
  805. end;
  806. if (p.column>$ff) then
  807. begin
  808. info:=info or $10;
  809. { uncomment this code if tfileposinfo.column type was changed
  810. if (p.column<=$ffff) then
  811. info:=info or $10
  812. else
  813. if (p.column<=$ffffff) then
  814. info:=info or $20
  815. else
  816. info:=info or $30;
  817. }
  818. end;
  819. { write data }
  820. putbyte(info);
  821. case (info and $03) of
  822. 0 : putbyte(p.fileindex);
  823. 1 : putword(p.fileindex);
  824. 2 : begin
  825. putbyte(p.fileindex shr 16);
  826. putword(p.fileindex and $ffff);
  827. end;
  828. 3 : putlongint(p.fileindex);
  829. end;
  830. case ((info shr 2) and $03) of
  831. 0 : putbyte(p.line);
  832. 1 : putword(p.line);
  833. 2 : begin
  834. putbyte(p.line shr 16);
  835. putword(p.line and $ffff);
  836. end;
  837. 3 : putlongint(p.line);
  838. end;
  839. case ((info shr 4) and $03) of
  840. 0 : putbyte(p.column);
  841. 1 : putword(p.column);
  842. 2 : begin
  843. putbyte(p.column shr 16);
  844. putword(p.column and $ffff);
  845. end;
  846. 3 : putlongint(p.column);
  847. end;
  848. do_crc:=oldcrc;
  849. end;
  850. procedure tcompilerppufile.putguid(const g: tguid);
  851. begin
  852. putlongint(longint(g.d1));
  853. putword(g.d2);
  854. putword(g.d3);
  855. putdata(g.d4,sizeof(g.d4));
  856. end;
  857. procedure Tcompilerppufile.putexprint(const v:Tconstexprint);
  858. begin
  859. if v.overflow then
  860. internalerror(200706102);
  861. putbyte(byte(v.signed));
  862. putint64(v.svalue);
  863. end;
  864. procedure tcompilerppufile.PutPtrUInt(v:TConstPtrUInt);
  865. begin
  866. {$if sizeof(TConstPtrUInt)=8}
  867. putint64(int64(v));
  868. {$else}
  869. putlongint(longint(v));
  870. {$endif}
  871. end;
  872. procedure tcompilerppufile.putderef(const d:tderef);
  873. var
  874. oldcrc : boolean;
  875. begin
  876. oldcrc:=do_crc;
  877. do_crc:=false;
  878. putlongint(d.dataidx);
  879. do_crc:=oldcrc;
  880. end;
  881. procedure tcompilerppufile.putpropaccesslist(p:tpropaccesslist);
  882. var
  883. hp : ppropaccesslistitem;
  884. begin
  885. putderef(p.procdefderef);
  886. hp:=p.firstsym;
  887. while assigned(hp) do
  888. begin
  889. putbyte(byte(hp^.sltype));
  890. case hp^.sltype of
  891. sl_call,
  892. sl_load,
  893. sl_subscript :
  894. putderef(hp^.symderef);
  895. sl_absolutetype,
  896. sl_typeconv :
  897. putderef(hp^.defderef);
  898. sl_vec :
  899. begin
  900. putlongint(int64(hp^.value));
  901. putderef(hp^.valuedefderef);
  902. end;
  903. else
  904. internalerror(200110205);
  905. end;
  906. hp:=hp^.next;
  907. end;
  908. putbyte(byte(sl_none));
  909. end;
  910. procedure tcompilerppufile.putasmsymbol(s:tasmsymbol);
  911. begin
  912. putlongint(0);
  913. end;
  914. {$ifdef MEMDEBUG}
  915. initialization
  916. memmanglednames:=TMemDebug.create('Manglednames');
  917. memmanglednames.stop;
  918. memprocpara:=TMemDebug.create('ProcPara');
  919. memprocpara.stop;
  920. memprocparast:=TMemDebug.create('ProcParaSt');
  921. memprocparast.stop;
  922. memproclocalst:=TMemDebug.create('ProcLocalSt');
  923. memproclocalst.stop;
  924. memprocnodetree:=TMemDebug.create('ProcNodeTree');
  925. memprocnodetree.stop;
  926. finalization
  927. memmanglednames.free;
  928. memprocpara.free;
  929. memprocparast.free;
  930. memproclocalst.free;
  931. memprocnodetree.free;
  932. {$endif MEMDEBUG}
  933. end.