symppu.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
  4. Implementation of the reading of PPU Files for 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 symppu;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. globtype,globals,
  23. symbase,symtype,
  24. ppu;
  25. type
  26. tcompilerppufile=class(tppufile)
  27. procedure checkerror;
  28. procedure getguid(var g: tguid);
  29. procedure getposinfo(var p:tfileposinfo);
  30. function getderef : tsymtableentry;
  31. function getsymlist:tsymlist;
  32. procedure gettype(var t:ttype);
  33. procedure putguid(const g: tguid);
  34. procedure putposinfo(const p:tfileposinfo);
  35. procedure putderef(p : tsymtableentry);
  36. procedure putsymlist(p:tsymlist);
  37. procedure puttype(const t:ttype);
  38. end;
  39. implementation
  40. uses
  41. symconst,
  42. verbose;
  43. {*****************************************************************************
  44. TCompilerPPUFile
  45. *****************************************************************************}
  46. procedure tcompilerppufile.checkerror;
  47. begin
  48. if error then
  49. Message(unit_f_ppu_read_error);
  50. end;
  51. procedure tcompilerppufile.getguid(var g: tguid);
  52. begin
  53. getdata(g,sizeof(g));
  54. end;
  55. procedure tcompilerppufile.getposinfo(var p:tfileposinfo);
  56. begin
  57. p.fileindex:=getword;
  58. p.line:=getlongint;
  59. p.column:=getword;
  60. end;
  61. function tcompilerppufile.getderef : tsymtableentry;
  62. var
  63. hp,p : tderef;
  64. b : tdereftype;
  65. begin
  66. p:=nil;
  67. repeat
  68. hp:=p;
  69. b:=tdereftype(getbyte);
  70. case b of
  71. derefnil :
  72. break;
  73. derefunit,
  74. derefaktrecordindex,
  75. derefaktlocal,
  76. derefaktstaticindex :
  77. begin
  78. p:=tderef.create(b,getword);
  79. p.next:=hp;
  80. break;
  81. end;
  82. derefindex,
  83. dereflocal,
  84. derefpara,
  85. derefrecord :
  86. begin
  87. p:=tderef.create(b,getword);
  88. p.next:=hp;
  89. end;
  90. end;
  91. until false;
  92. getderef:=tsymtableentry(p);
  93. end;
  94. function tcompilerppufile.getsymlist:tsymlist;
  95. var
  96. sym : tsym;
  97. p : tsymlist;
  98. begin
  99. p:=tsymlist.create;
  100. p.def:=tdef(getderef);
  101. repeat
  102. sym:=tsym(getderef);
  103. if sym=nil then
  104. break;
  105. p.addsym(sym);
  106. until false;
  107. getsymlist:=tsymlist(p);
  108. end;
  109. procedure tcompilerppufile.gettype(var t:ttype);
  110. begin
  111. t.def:=tdef(getderef);
  112. t.sym:=tsym(getderef);
  113. end;
  114. procedure tcompilerppufile.putposinfo(const p:tfileposinfo);
  115. var
  116. oldcrc : boolean;
  117. begin
  118. { posinfo is not relevant for changes in PPU }
  119. oldcrc:=do_crc;
  120. do_crc:=false;
  121. putword(p.fileindex);
  122. putlongint(p.line);
  123. putword(p.column);
  124. do_crc:=oldcrc;
  125. end;
  126. procedure tcompilerppufile.putguid(const g: tguid);
  127. begin
  128. putdata(g,sizeof(g));
  129. end;
  130. procedure tcompilerppufile.putderef(p : tsymtableentry);
  131. begin
  132. if p=nil then
  133. putbyte(ord(derefnil))
  134. else
  135. begin
  136. { Static symtable ? }
  137. if p.owner.symtabletype=staticsymtable then
  138. begin
  139. putbyte(ord(derefaktstaticindex));
  140. putword(p.indexnr);
  141. end
  142. { Local record/object symtable ? }
  143. else if (p.owner=aktrecordsymtable) then
  144. begin
  145. putbyte(ord(derefaktrecordindex));
  146. putword(p.indexnr);
  147. end
  148. { Local local/para symtable ? }
  149. else if (p.owner=aktlocalsymtable) then
  150. begin
  151. putbyte(ord(derefaktlocal));
  152. putword(p.indexnr);
  153. end
  154. else
  155. begin
  156. putbyte(ord(derefindex));
  157. putword(p.indexnr);
  158. { Current unit symtable ? }
  159. repeat
  160. if not assigned(p) then
  161. internalerror(556655);
  162. case p.owner.symtabletype of
  163. { when writing the pseudo PPU file
  164. to get CRC values the globalsymtable is not yet
  165. a unitsymtable PM }
  166. globalsymtable :
  167. begin
  168. { check if the unit is available in the uses
  169. clause, else it's an error }
  170. if p.owner.unitid=$ffff then
  171. internalerror(55665566);
  172. putbyte(ord(derefunit));
  173. putword(p.owner.unitid);
  174. break;
  175. end;
  176. staticsymtable :
  177. begin
  178. putbyte(ord(derefaktstaticindex));
  179. putword(p.indexnr);
  180. break;
  181. end;
  182. localsymtable :
  183. begin
  184. p:=p.owner.defowner;
  185. putbyte(ord(dereflocal));
  186. putword(p.indexnr);
  187. end;
  188. parasymtable :
  189. begin
  190. p:=p.owner.defowner;
  191. putbyte(ord(derefpara));
  192. putword(p.indexnr);
  193. end;
  194. objectsymtable,
  195. recordsymtable :
  196. begin
  197. p:=p.owner.defowner;
  198. putbyte(ord(derefrecord));
  199. putword(p.indexnr);
  200. end;
  201. else
  202. internalerror(556656);
  203. end;
  204. until false;
  205. end;
  206. end;
  207. end;
  208. procedure tcompilerppufile.putsymlist(p:tsymlist);
  209. var
  210. hp : psymlistitem;
  211. begin
  212. putderef(p.def);
  213. hp:=p.firstsym;
  214. while assigned(hp) do
  215. begin
  216. putderef(hp^.sym);
  217. hp:=hp^.next;
  218. end;
  219. putderef(nil);
  220. end;
  221. procedure tcompilerppufile.puttype(const t:ttype);
  222. begin
  223. { Don't write symbol references for the current unit
  224. and for the system unit }
  225. if assigned(t.sym) and
  226. (t.sym.owner.unitid<>0) and
  227. (t.sym.owner.unitid<>1) then
  228. begin
  229. putderef(nil);
  230. putderef(t.sym);
  231. end
  232. else
  233. begin
  234. putderef(t.def);
  235. putderef(nil);
  236. end;
  237. end;
  238. end.
  239. {
  240. $Log$
  241. Revision 1.6 2001-05-06 14:49:17 peter
  242. * ppu object to class rewrite
  243. * move ppu read and write stuff to fppu
  244. Revision 1.5 2001/04/13 01:22:16 peter
  245. * symtable change to classes
  246. * range check generation and errors fixed, make cycle DEBUG=1 works
  247. * memory leaks fixed
  248. Revision 1.4 2000/12/25 00:07:29 peter
  249. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  250. tlinkedlist objects)
  251. Revision 1.3 2000/11/29 00:30:41 florian
  252. * unused units removed from uses clause
  253. * some changes for widestrings
  254. Revision 1.2 2000/11/04 14:25:22 florian
  255. + merged Attila's changes for interfaces, not tested yet
  256. Revision 1.1 2000/10/31 22:02:52 peter
  257. * symtable splitted, no real code changes
  258. }