symppu.pas 9.6 KB

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