symppu.pas 9.9 KB

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