123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- {
- $Id$
- Copyright (c) 1998-2000 by Florian Klaempfl, Pierre Muller
- Implementation of the reading of PPU Files for the symtable
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- unit symppu;
- interface
- uses
- cobjects,
- globtype,globals,
- symbase,
- ppu;
- var
- current_ppu : pppufile; { Current ppufile which is read }
- procedure writebyte(b:byte);
- procedure writeword(w:word);
- procedure writelong(l:longint);
- procedure writereal(d:bestreal);
- procedure writestring(const s:string);
- procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
- procedure writesmallset(var s);
- procedure writeguid(var g: tguid);
- procedure writeposinfo(const p:tfileposinfo);
- procedure writederef(p : psymtableentry);
- function readbyte:byte;
- function readword:word;
- function readlong:longint;
- function readreal : bestreal;
- function readstring : string;
- procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
- procedure readsmallset(var s);
- procedure readguid(var g: tguid);
- procedure readposinfo(var p:tfileposinfo);
- function readderef : psymtableentry;
- procedure closecurrentppu;
- implementation
- uses
- symconst,
- verbose;
- {*****************************************************************************
- PPU Writing
- *****************************************************************************}
- procedure writebyte(b:byte);
- begin
- current_ppu^.putbyte(b);
- end;
- procedure writeword(w:word);
- begin
- current_ppu^.putword(w);
- end;
- procedure writelong(l:longint);
- begin
- current_ppu^.putlongint(l);
- end;
- procedure writereal(d:bestreal);
- begin
- current_ppu^.putreal(d);
- end;
- procedure writestring(const s:string);
- begin
- current_ppu^.putstring(s);
- end;
- procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
- begin
- current_ppu^.putdata(s,sizeof(tnormalset));
- end;
- procedure writesmallset(var s);
- begin
- current_ppu^.putdata(s,4);
- end;
- { posinfo is not relevant for changes in PPU }
- procedure writeposinfo(const p:tfileposinfo);
- var
- oldcrc : boolean;
- begin
- oldcrc:=current_ppu^.do_crc;
- current_ppu^.do_crc:=false;
- current_ppu^.putword(p.fileindex);
- current_ppu^.putlongint(p.line);
- current_ppu^.putword(p.column);
- current_ppu^.do_crc:=oldcrc;
- end;
- procedure writeguid(var g: tguid);
- begin
- current_ppu^.putdata(g,sizeof(g));
- end;
- procedure writederef(p : psymtableentry);
- begin
- if p=nil then
- current_ppu^.putbyte(ord(derefnil))
- else
- begin
- { Static symtable ? }
- if p^.owner^.symtabletype=staticsymtable then
- begin
- current_ppu^.putbyte(ord(derefaktstaticindex));
- current_ppu^.putword(p^.indexnr);
- end
- { Local record/object symtable ? }
- else if (p^.owner=aktrecordsymtable) then
- begin
- current_ppu^.putbyte(ord(derefaktrecordindex));
- current_ppu^.putword(p^.indexnr);
- end
- { Local local/para symtable ? }
- else if (p^.owner=aktlocalsymtable) then
- begin
- current_ppu^.putbyte(ord(derefaktlocal));
- current_ppu^.putword(p^.indexnr);
- end
- else
- begin
- current_ppu^.putbyte(ord(derefindex));
- current_ppu^.putword(p^.indexnr);
- { Current unit symtable ? }
- repeat
- if not assigned(p) then
- internalerror(556655);
- case p^.owner^.symtabletype of
- { when writing the pseudo PPU file
- to get CRC values the globalsymtable is not yet
- a unitsymtable PM }
- globalsymtable,
- unitsymtable :
- begin
- { check if the unit is available in the uses
- clause, else it's an error }
- if p^.owner^.unitid=$ffff then
- internalerror(55665566);
- current_ppu^.putbyte(ord(derefunit));
- current_ppu^.putword(p^.owner^.unitid);
- break;
- end;
- staticsymtable :
- begin
- current_ppu^.putbyte(ord(derefaktstaticindex));
- current_ppu^.putword(p^.indexnr);
- break;
- end;
- localsymtable :
- begin
- p:=p^.owner^.defowner;
- current_ppu^.putbyte(ord(dereflocal));
- current_ppu^.putword(p^.indexnr);
- end;
- parasymtable :
- begin
- p:=p^.owner^.defowner;
- current_ppu^.putbyte(ord(derefpara));
- current_ppu^.putword(p^.indexnr);
- end;
- objectsymtable,
- recordsymtable :
- begin
- p:=p^.owner^.defowner;
- current_ppu^.putbyte(ord(derefrecord));
- current_ppu^.putword(p^.indexnr);
- end;
- else
- internalerror(556656);
- end;
- until false;
- end;
- end;
- end;
- procedure closecurrentppu;
- begin
- {$ifdef Test_Double_checksum}
- if assigned(current_ppu^.crc_test) then
- dispose(current_ppu^.crc_test);
- if assigned(current_ppu^.crc_test2) then
- dispose(current_ppu^.crc_test2);
- {$endif Test_Double_checksum}
- { close }
- current_ppu^.close;
- dispose(current_ppu,done);
- current_ppu:=nil;
- end;
- {*****************************************************************************
- PPU Reading
- *****************************************************************************}
- function readbyte:byte;
- begin
- readbyte:=current_ppu^.getbyte;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readword:word;
- begin
- readword:=current_ppu^.getword;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readlong:longint;
- begin
- readlong:=current_ppu^.getlongint;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readreal : bestreal;
- begin
- readreal:=current_ppu^.getreal;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readstring : string;
- begin
- readstring:=current_ppu^.getstring;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
- begin
- current_ppu^.getdata(s,sizeof(tnormalset));
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readsmallset(var s);
- begin
- current_ppu^.getdata(s,4);
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readguid(var g: tguid);
- begin
- current_ppu^.getdata(g,sizeof(g));
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readposinfo(var p:tfileposinfo);
- begin
- p.fileindex:=current_ppu^.getword;
- p.line:=current_ppu^.getlongint;
- p.column:=current_ppu^.getword;
- end;
- function readderef : psymtableentry;
- var
- hp,p : pderef;
- b : tdereftype;
- begin
- p:=nil;
- repeat
- hp:=p;
- b:=tdereftype(current_ppu^.getbyte);
- case b of
- derefnil :
- break;
- derefunit,
- derefaktrecordindex,
- derefaktlocal,
- derefaktstaticindex :
- begin
- new(p,init(b,current_ppu^.getword));
- p^.next:=hp;
- break;
- end;
- derefindex,
- dereflocal,
- derefpara,
- derefrecord :
- begin
- new(p,init(b,current_ppu^.getword));
- p^.next:=hp;
- end;
- end;
- until false;
- readderef:=psymtableentry(p);
- end;
- end.
- {
- $Log$
- Revision 1.4 2000-12-25 00:07:29 peter
- + new tlinkedlist class (merge of old tstringqueue,tcontainer and
- tlinkedlist objects)
- Revision 1.3 2000/11/29 00:30:41 florian
- * unused units removed from uses clause
- * some changes for widestrings
- Revision 1.2 2000/11/04 14:25:22 florian
- + merged Attila's changes for interfaces, not tested yet
- Revision 1.1 2000/10/31 22:02:52 peter
- * symtable splitted, no real code changes
- }
|