symppu.pas 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. interface
  20. uses
  21. cobjects,
  22. globtype,
  23. symbase,
  24. ppu;
  25. var
  26. current_ppu : pppufile; { Current ppufile which is read }
  27. procedure writebyte(b:byte);
  28. procedure writeword(w:word);
  29. procedure writelong(l:longint);
  30. procedure writereal(d:bestreal);
  31. procedure writestring(const s:string);
  32. procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
  33. procedure writesmallset(var s);
  34. procedure writeguid(var g: tguid);
  35. procedure writeposinfo(const p:tfileposinfo);
  36. procedure writederef(p : psymtableentry);
  37. function readbyte:byte;
  38. function readword:word;
  39. function readlong:longint;
  40. function readreal : bestreal;
  41. function readstring : string;
  42. procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
  43. procedure readsmallset(var s);
  44. procedure readguid(var g: tguid);
  45. procedure readposinfo(var p:tfileposinfo);
  46. function readderef : psymtableentry;
  47. procedure closecurrentppu;
  48. implementation
  49. uses
  50. globals,
  51. symconst,
  52. verbose;
  53. {*****************************************************************************
  54. PPU Writing
  55. *****************************************************************************}
  56. procedure writebyte(b:byte);
  57. begin
  58. current_ppu^.putbyte(b);
  59. end;
  60. procedure writeword(w:word);
  61. begin
  62. current_ppu^.putword(w);
  63. end;
  64. procedure writelong(l:longint);
  65. begin
  66. current_ppu^.putlongint(l);
  67. end;
  68. procedure writereal(d:bestreal);
  69. begin
  70. current_ppu^.putreal(d);
  71. end;
  72. procedure writestring(const s:string);
  73. begin
  74. current_ppu^.putstring(s);
  75. end;
  76. procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
  77. begin
  78. current_ppu^.putdata(s,sizeof(tnormalset));
  79. end;
  80. procedure writesmallset(var s);
  81. begin
  82. current_ppu^.putdata(s,4);
  83. end;
  84. { posinfo is not relevant for changes in PPU }
  85. procedure writeposinfo(const p:tfileposinfo);
  86. var
  87. oldcrc : boolean;
  88. begin
  89. oldcrc:=current_ppu^.do_crc;
  90. current_ppu^.do_crc:=false;
  91. current_ppu^.putword(p.fileindex);
  92. current_ppu^.putlongint(p.line);
  93. current_ppu^.putword(p.column);
  94. current_ppu^.do_crc:=oldcrc;
  95. end;
  96. procedure writeguid(var g: tguid);
  97. begin
  98. current_ppu^.putdata(g,sizeof(g));
  99. end;
  100. procedure writederef(p : psymtableentry);
  101. begin
  102. if p=nil then
  103. current_ppu^.putbyte(ord(derefnil))
  104. else
  105. begin
  106. { Static symtable ? }
  107. if p^.owner^.symtabletype=staticsymtable then
  108. begin
  109. current_ppu^.putbyte(ord(derefaktstaticindex));
  110. current_ppu^.putword(p^.indexnr);
  111. end
  112. { Local record/object symtable ? }
  113. else if (p^.owner=aktrecordsymtable) then
  114. begin
  115. current_ppu^.putbyte(ord(derefaktrecordindex));
  116. current_ppu^.putword(p^.indexnr);
  117. end
  118. { Local local/para symtable ? }
  119. else if (p^.owner=aktlocalsymtable) then
  120. begin
  121. current_ppu^.putbyte(ord(derefaktlocal));
  122. current_ppu^.putword(p^.indexnr);
  123. end
  124. else
  125. begin
  126. current_ppu^.putbyte(ord(derefindex));
  127. current_ppu^.putword(p^.indexnr);
  128. { Current unit symtable ? }
  129. repeat
  130. if not assigned(p) then
  131. internalerror(556655);
  132. case p^.owner^.symtabletype of
  133. { when writing the pseudo PPU file
  134. to get CRC values the globalsymtable is not yet
  135. a unitsymtable PM }
  136. globalsymtable,
  137. unitsymtable :
  138. begin
  139. { check if the unit is available in the uses
  140. clause, else it's an error }
  141. if p^.owner^.unitid=$ffff then
  142. internalerror(55665566);
  143. current_ppu^.putbyte(ord(derefunit));
  144. current_ppu^.putword(p^.owner^.unitid);
  145. break;
  146. end;
  147. staticsymtable :
  148. begin
  149. current_ppu^.putbyte(ord(derefaktstaticindex));
  150. current_ppu^.putword(p^.indexnr);
  151. break;
  152. end;
  153. localsymtable :
  154. begin
  155. p:=p^.owner^.defowner;
  156. current_ppu^.putbyte(ord(dereflocal));
  157. current_ppu^.putword(p^.indexnr);
  158. end;
  159. parasymtable :
  160. begin
  161. p:=p^.owner^.defowner;
  162. current_ppu^.putbyte(ord(derefpara));
  163. current_ppu^.putword(p^.indexnr);
  164. end;
  165. objectsymtable,
  166. recordsymtable :
  167. begin
  168. p:=p^.owner^.defowner;
  169. current_ppu^.putbyte(ord(derefrecord));
  170. current_ppu^.putword(p^.indexnr);
  171. end;
  172. else
  173. internalerror(556656);
  174. end;
  175. until false;
  176. end;
  177. end;
  178. end;
  179. procedure closecurrentppu;
  180. begin
  181. {$ifdef Test_Double_checksum}
  182. if assigned(current_ppu^.crc_test) then
  183. dispose(current_ppu^.crc_test);
  184. if assigned(current_ppu^.crc_test2) then
  185. dispose(current_ppu^.crc_test2);
  186. {$endif Test_Double_checksum}
  187. { close }
  188. current_ppu^.close;
  189. dispose(current_ppu,done);
  190. current_ppu:=nil;
  191. end;
  192. {*****************************************************************************
  193. PPU Reading
  194. *****************************************************************************}
  195. function readbyte:byte;
  196. begin
  197. readbyte:=current_ppu^.getbyte;
  198. if current_ppu^.error then
  199. Message(unit_f_ppu_read_error);
  200. end;
  201. function readword:word;
  202. begin
  203. readword:=current_ppu^.getword;
  204. if current_ppu^.error then
  205. Message(unit_f_ppu_read_error);
  206. end;
  207. function readlong:longint;
  208. begin
  209. readlong:=current_ppu^.getlongint;
  210. if current_ppu^.error then
  211. Message(unit_f_ppu_read_error);
  212. end;
  213. function readreal : bestreal;
  214. begin
  215. readreal:=current_ppu^.getreal;
  216. if current_ppu^.error then
  217. Message(unit_f_ppu_read_error);
  218. end;
  219. function readstring : string;
  220. begin
  221. readstring:=current_ppu^.getstring;
  222. if current_ppu^.error then
  223. Message(unit_f_ppu_read_error);
  224. end;
  225. procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
  226. begin
  227. current_ppu^.getdata(s,sizeof(tnormalset));
  228. if current_ppu^.error then
  229. Message(unit_f_ppu_read_error);
  230. end;
  231. procedure readsmallset(var s);
  232. begin
  233. current_ppu^.getdata(s,4);
  234. if current_ppu^.error then
  235. Message(unit_f_ppu_read_error);
  236. end;
  237. procedure readguid(var g: tguid);
  238. begin
  239. current_ppu^.getdata(g,sizeof(g));
  240. if current_ppu^.error then
  241. Message(unit_f_ppu_read_error);
  242. end;
  243. procedure readposinfo(var p:tfileposinfo);
  244. begin
  245. p.fileindex:=current_ppu^.getword;
  246. p.line:=current_ppu^.getlongint;
  247. p.column:=current_ppu^.getword;
  248. end;
  249. function readderef : psymtableentry;
  250. var
  251. hp,p : pderef;
  252. b : tdereftype;
  253. begin
  254. p:=nil;
  255. repeat
  256. hp:=p;
  257. b:=tdereftype(current_ppu^.getbyte);
  258. case b of
  259. derefnil :
  260. break;
  261. derefunit,
  262. derefaktrecordindex,
  263. derefaktlocal,
  264. derefaktstaticindex :
  265. begin
  266. new(p,init(b,current_ppu^.getword));
  267. p^.next:=hp;
  268. break;
  269. end;
  270. derefindex,
  271. dereflocal,
  272. derefpara,
  273. derefrecord :
  274. begin
  275. new(p,init(b,current_ppu^.getword));
  276. p^.next:=hp;
  277. end;
  278. end;
  279. until false;
  280. readderef:=psymtableentry(p);
  281. end;
  282. end.
  283. {
  284. $Log$
  285. Revision 1.3 2000-11-29 00:30:41 florian
  286. * unused units removed from uses clause
  287. * some changes for widestrings
  288. Revision 1.2 2000/11/04 14:25:22 florian
  289. + merged Attila's changes for interfaces, not tested yet
  290. Revision 1.1 2000/10/31 22:02:52 peter
  291. * symtable splitted, no real code changes
  292. }