symtype.pas 29 KB

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