symppu.pas 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. slt : tsltype;
  98. idx : longint;
  99. p : tsymlist;
  100. begin
  101. p:=tsymlist.create;
  102. p.def:=tdef(getderef);
  103. repeat
  104. slt:=tsltype(getbyte);
  105. case slt of
  106. sl_none :
  107. break;
  108. sl_call,
  109. sl_load,
  110. sl_subscript :
  111. begin
  112. sym:=tsym(getderef);
  113. p.addsym(slt,sym);
  114. end;
  115. sl_vec :
  116. begin
  117. idx:=getlongint;
  118. p.addconst(slt,idx);
  119. end;
  120. else
  121. internalerror(200110204);
  122. end;
  123. until false;
  124. getsymlist:=tsymlist(p);
  125. end;
  126. procedure tcompilerppufile.gettype(var t:ttype);
  127. begin
  128. t.def:=tdef(getderef);
  129. t.sym:=tsym(getderef);
  130. end;
  131. procedure tcompilerppufile.putposinfo(const p:tfileposinfo);
  132. var
  133. oldcrc : boolean;
  134. begin
  135. { posinfo is not relevant for changes in PPU }
  136. oldcrc:=do_crc;
  137. do_crc:=false;
  138. putword(p.fileindex);
  139. putlongint(p.line);
  140. putword(p.column);
  141. do_crc:=oldcrc;
  142. end;
  143. procedure tcompilerppufile.putguid(const g: tguid);
  144. begin
  145. putdata(g,sizeof(g));
  146. end;
  147. procedure tcompilerppufile.putderef(p : tsymtableentry);
  148. begin
  149. if p=nil then
  150. putbyte(ord(derefnil))
  151. else
  152. begin
  153. { Static symtable ? }
  154. if p.owner.symtabletype=staticsymtable then
  155. begin
  156. putbyte(ord(derefaktstaticindex));
  157. putword(p.indexnr);
  158. end
  159. { Local record/object symtable ? }
  160. else if (p.owner=aktrecordsymtable) then
  161. begin
  162. putbyte(ord(derefaktrecordindex));
  163. putword(p.indexnr);
  164. end
  165. { Local local/para symtable ? }
  166. else if (p.owner=aktlocalsymtable) then
  167. begin
  168. putbyte(ord(derefaktlocal));
  169. putword(p.indexnr);
  170. end
  171. else
  172. begin
  173. putbyte(ord(derefindex));
  174. putword(p.indexnr);
  175. { Current unit symtable ? }
  176. repeat
  177. if not assigned(p) then
  178. internalerror(556655);
  179. case p.owner.symtabletype of
  180. { when writing the pseudo PPU file
  181. to get CRC values the globalsymtable is not yet
  182. a unitsymtable PM }
  183. globalsymtable :
  184. begin
  185. { check if the unit is available in the uses
  186. clause, else it's an error }
  187. if p.owner.unitid=$ffff then
  188. internalerror(55665566);
  189. putbyte(ord(derefunit));
  190. putword(p.owner.unitid);
  191. break;
  192. end;
  193. staticsymtable :
  194. begin
  195. putbyte(ord(derefaktstaticindex));
  196. putword(p.indexnr);
  197. break;
  198. end;
  199. localsymtable :
  200. begin
  201. p:=p.owner.defowner;
  202. putbyte(ord(dereflocal));
  203. putword(p.indexnr);
  204. end;
  205. parasymtable :
  206. begin
  207. p:=p.owner.defowner;
  208. putbyte(ord(derefpara));
  209. putword(p.indexnr);
  210. end;
  211. objectsymtable,
  212. recordsymtable :
  213. begin
  214. p:=p.owner.defowner;
  215. putbyte(ord(derefrecord));
  216. putword(p.indexnr);
  217. end;
  218. else
  219. internalerror(556656);
  220. end;
  221. until false;
  222. end;
  223. end;
  224. end;
  225. procedure tcompilerppufile.putsymlist(p:tsymlist);
  226. var
  227. hp : psymlistitem;
  228. begin
  229. putderef(p.def);
  230. hp:=p.firstsym;
  231. while assigned(hp) do
  232. begin
  233. putbyte(byte(hp^.sltype));
  234. case hp^.sltype of
  235. sl_call,
  236. sl_load,
  237. sl_subscript :
  238. putderef(hp^.sym);
  239. sl_vec :
  240. putlongint(hp^.value);
  241. else
  242. internalerror(200110205);
  243. end;
  244. hp:=hp^.next;
  245. end;
  246. putbyte(byte(sl_none));
  247. end;
  248. procedure tcompilerppufile.puttype(const t:ttype);
  249. begin
  250. { Don't write symbol references for the current unit
  251. and for the system unit }
  252. if assigned(t.sym) and
  253. (t.sym.owner.unitid<>0) and
  254. (t.sym.owner.unitid<>1) then
  255. begin
  256. putderef(nil);
  257. putderef(t.sym);
  258. end
  259. else
  260. begin
  261. putderef(t.def);
  262. putderef(nil);
  263. end;
  264. end;
  265. end.
  266. {
  267. $Log$
  268. Revision 1.7 2001-10-21 12:33:07 peter
  269. * array access for properties added
  270. Revision 1.6 2001/05/06 14:49:17 peter
  271. * ppu object to class rewrite
  272. * move ppu read and write stuff to fppu
  273. Revision 1.5 2001/04/13 01:22:16 peter
  274. * symtable change to classes
  275. * range check generation and errors fixed, make cycle DEBUG=1 works
  276. * memory leaks fixed
  277. Revision 1.4 2000/12/25 00:07:29 peter
  278. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  279. tlinkedlist objects)
  280. Revision 1.3 2000/11/29 00:30:41 florian
  281. * unused units removed from uses clause
  282. * some changes for widestrings
  283. Revision 1.2 2000/11/04 14:25:22 florian
  284. + merged Attila's changes for interfaces, not tested yet
  285. Revision 1.1 2000/10/31 22:02:52 peter
  286. * symtable splitted, no real code changes
  287. }