symppu.pas 9.8 KB

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