* fixed scannerfiles for macros

+ $I %<environment>%
This commit is contained in:
peter 1998-08-26 15:35:30 +00:00
parent 23225bea44
commit 547dca7111
4 changed files with 375 additions and 247 deletions

View File

@ -31,10 +31,10 @@ unit files;
const
{$ifdef FPC}
maxunits = 1024;
extbufsize = 65535;
InputFileBufSize=32*1024;
{$else}
maxunits = 128;
extbufsize=1024;
InputFileBufSize=1024;
{$endif}
type
@ -43,10 +43,17 @@ unit files;
path,name : pstring; { path and filename }
next : pinputfile; { next file for reading }
f : file; { current file handle }
is_macro,
endoffile, { still bytes left to read }
closed : boolean; { is the file closed }
inputbufsize : longint; { max size of the input buffer }
savebufstart, { save fields for scanner }
savebufsize,
savelastlinepos,
saveline_no : longint;
saveinputbuffer,
saveinputpointer : pchar;
@ -172,6 +179,17 @@ unit files;
name:=stringdup(n+e);
path:=stringdup(p);
next:=nil;
{ file info }
is_macro:=false;
endoffile:=false;
closed:=true;
inputbufsize:=InputFileBufSize;
saveinputbuffer:=nil;
saveinputpointer:=nil;
savebufstart:=0;
savebufsize:=0;
saveline_no:=0;
savelastlinepos:=0;
{ indexing refs }
ref_next:=nil;
ref_count:=0;
@ -647,7 +665,11 @@ unit files;
end.
{
$Log$
Revision 1.40 1998-08-26 10:08:48 peter
Revision 1.41 1998-08-26 15:35:30 peter
* fixed scannerfiles for macros
+ $I %<environment>%
Revision 1.40 1998/08/26 10:08:48 peter
* fixed problem with libprefix at the wrong place
* fixed lib generation with smartlinking and no -CS used

View File

@ -274,10 +274,10 @@ unit pmodules;
Message1(unit_f_cant_compile_unit,current_module^.modulename^)
else
begin
current_scanner^.close;
current_scanner^.tempclose;
compile(current_module^.mainsource^,compile_system);
if (not old_current_module^.compiled) then
current_scanner^.reopen;
current_scanner^.tempopen;
end;
end
else
@ -901,7 +901,11 @@ unit pmodules;
end.
{
$Log$
Revision 1.43 1998-08-26 10:08:47 peter
Revision 1.44 1998-08-26 15:35:33 peter
* fixed scannerfiles for macros
+ $I %<environment>%
Revision 1.43 1998/08/26 10:08:47 peter
* fixed problem with libprefix at the wrong place
* fixed lib generation with smartlinking and no -CS used

View File

@ -500,12 +500,47 @@ const
hs:=current_scanner^.readcomment;
while (hs<>'') and (hs[length(hs)]=' ') do
dec(byte(hs[0]));
if hs='' then
exit;
if (hs[1]='%') then
begin
{ save old }
path:=hs;
{ remove %'s }
Delete(hs,1,1);
if hs[length(hs)]='%' then
Delete(hs,length(hs),1);
{ first check for internal macros }
if hs='TIME' then
hs:=gettimestr
else
if hs='DATE' then
hs:=getdatestr
else
if hs='FPCVERSION' then
hs:=version_string
else
if hs='FPCTARGET' then
hs:=target_string
else
hs:=getenv(hs);
if hs='' then
Comment(V_Warning,'Include environment '+path+' not found in environment')
else
begin
{ make it a stringconst }
hs:=''''+hs+'''';
current_scanner^.insertmacro(@hs[1],length(hs));
end;
end
else
begin
hs:=FixFileName(hs);
fsplit(hs,path,name,ext);
{ first look in the path of _d then currentmodule }
path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found);
{ shutdown current file }
current_scanner^.close;
current_scanner^.tempclose;
{ load new file }
hp:=new(pinputfile,init(path+name+ext));
current_scanner^.addfile(hp);
@ -517,6 +552,7 @@ const
current_module^.sourcefiles.register_file(hp);
current_module^.current_index:=hp^.ref_index;
end;
end;
procedure dir_description(t:tdirectivetoken);
@ -732,7 +768,11 @@ const
{
$Log$
Revision 1.22 1998-08-19 14:57:50 peter
Revision 1.23 1998-08-26 15:35:34 peter
* fixed scannerfiles for macros
+ $I %<environment>%
Revision 1.22 1998/08/19 14:57:50 peter
* small fix for aktfilepos
Revision 1.20 1998/08/18 15:11:52 peter

View File

@ -33,11 +33,9 @@ unit scanner;
const
{$ifdef TP}
maxmacrolen=1024;
InputFileBufSize=1024;
linebufincrease=64;
{$else}
maxmacrolen=16*1024;
InputFileBufSize=32*1024;
linebufincrease=512;
{$endif}
@ -148,26 +146,18 @@ unit scanner;
tscannerfile = object
inputfile : pinputfile; { current inputfile list }
f : file; { current file handle }
filenotatend, { still bytes left to read }
closed : boolean; { is the file closed }
inputbufsize : longint; { max size of the input buffer }
{ these fields are called save* in inputfile, and are here
for speed reasons (PFV) }
bufstart,
bufsize,
line_no,
lastlinepos : longint;
inputbuffer,
inputpointer : pchar;
bufstart,
bufsize : longint;
line_no,
lasttokenpos,
lastlinepos : longint;
lasttokenpos : longint;
lasttoken : ttoken;
maxlinebuf : longint;
linebuf : plongint;
do_special, { 1=point after nr, 2=caret after id }
comment_level,
yylexcount : longint;
@ -179,7 +169,8 @@ unit scanner;
{ File buffer things }
function open:boolean;
procedure close;
function reopen:boolean;
procedure tempclose;
function tempopen:boolean;
procedure seekbuf(fpos:longint);
procedure readbuf;
procedure saveinputfile;
@ -188,6 +179,7 @@ unit scanner;
procedure addfile(hp:pinputfile);
procedure reload;
procedure setbuf(p:pchar;l:longint);
procedure insertmacro(p:pchar;len:longint);
{ Scanner things }
procedure gettokenpos;
procedure inc_comment_level;
@ -314,25 +306,14 @@ implementation
inputfile:=new(pinputfile,init(fn));
current_module^.sourcefiles.register_file(inputfile);
current_module^.current_index:=inputfile^.ref_index;
{ load inputfile values }
restoreinputfile;
{ reset scanner }
preprocstack:=nil;
comment_level:=0;
do_special:=0;
block_type:=bt_general;
{ reset buf }
closed:=true;
filenotatend:=true;
inputbufsize:=InputFileBufSize;
inputbuffer:=nil;
inputpointer:=nil;
bufstart:=0;
bufsize:=0;
{ line }
line_no:=0;
lastlinepos:=0;
lasttokenpos:=0;
linebuf:=nil;
maxlinebuf:=0;
{ load block }
if not open then
Message1(scan_f_cannot_open_input,fn);
@ -344,12 +325,14 @@ implementation
begin
checkpreprocstack;
{ close file }
if not closed then
if not inputfile^.closed then
close;
end;
procedure tscannerfile.seekbuf(fpos:longint);
begin
with inputfile^ do
begin
if closed then
exit;
@ -357,6 +340,7 @@ implementation
bufstart:=fpos;
bufsize:=0;
end;
end;
procedure tscannerfile.readbuf;
@ -365,6 +349,10 @@ implementation
w : word;
{$endif}
begin
with inputfile^ do
begin
if is_macro then
endoffile:=true;
if closed then
exit;
inc(bufstart,bufsize);
@ -375,13 +363,16 @@ implementation
blockread(f,inputbuffer^,inputbufsize-1,bufsize);
{$endif}
inputbuffer[bufsize]:=#0;
Filenotatend:=(bufsize=inputbufsize-1);
endoffile:=not(bufsize=inputbufsize-1);
end;
end;
function tscannerfile.open:boolean;
var
ofm : byte;
begin
with inputfile^ do
begin
open:=false;
if not closed then
@ -396,8 +387,8 @@ implementation
if ioresult<>0 then
exit;
{ file }
endoffile:=false;
closed:=false;
filenotatend:=true;
Getmem(inputbuffer,inputbufsize);
inputpointer:=inputbuffer;
bufstart:=0;
@ -408,13 +399,24 @@ implementation
lasttokenpos:=0;
open:=true;
end;
end;
procedure tscannerfile.close;
var
i : word;
begin
inc(bufstart,inputpointer-inputbuffer);
with inputfile^ do
begin
if is_macro then
begin
Freemem(inputbuffer,InputFileBufSize);
is_macro:=false;
inputbuffer:=nil;
inputpointer:=nil;
closed:=true;
exit;
end;
if not closed then
begin
{$I-}
@ -427,13 +429,45 @@ implementation
closed:=true;
end;
end;
end;
function tscannerfile.reopen:boolean;
procedure tscannerfile.tempclose;
var
i : word;
begin
with inputfile^ do
begin
inc(bufstart,inputpointer-inputbuffer);
if is_macro then
exit;
if not closed then
begin
{$I-}
system.close(f);
{$I+}
i:=ioresult;
Freemem(inputbuffer,InputFileBufSize);
inputbuffer:=nil;
inputpointer:=nil;
closed:=true;
end;
end;
end;
function tscannerfile.tempopen:boolean;
var
ofm : byte;
begin
reopen:=false;
with inputfile^ do
begin
tempopen:=false;
if is_macro then
begin
tempopen:=true;
exit;
end;
if not closed then
exit;
ofm:=filemode;
@ -453,7 +487,8 @@ implementation
seek(f,BufStart);
bufsize:=0;
readbuf;
reopen:=true;
tempopen:=true;
end;
end;
@ -461,12 +496,10 @@ implementation
begin
inputfile^.savebufstart:=bufstart;
inputfile^.savebufsize:=bufsize;
inputfile^.savelastlinepos:=lastlinepos;
inputfile^.saveline_no:=line_no;
inputfile^.saveinputbuffer:=inputbuffer;
inputfile^.saveinputpointer:=inputpointer;
inputfile^.linebuf:=linebuf;
inputfile^.maxlinebuf:=maxlinebuf;
inputfile^.savelastlinepos:=lastlinepos;
inputfile^.saveline_no:=line_no;
end;
@ -478,8 +511,6 @@ implementation
line_no:=inputfile^.saveline_no;
inputbuffer:=inputfile^.saveinputbuffer;
inputpointer:=inputfile^.saveinputpointer;
linebuf:=inputfile^.linebuf;
maxlinebuf:=inputfile^.maxlinebuf;
end;
@ -506,9 +537,8 @@ implementation
procedure tscannerfile.reload;
begin
{ safety check }
if closed then
exit;
with inputfile^ do
begin
repeat
{ still more to read?, then change the #0 to a space so its seen
as a seperator }
@ -519,7 +549,7 @@ implementation
exit;
end;
{ can we read more from this file ? }
if filenotatend then
if not endoffile then
begin
readbuf;
if line_no=0 then
@ -537,7 +567,7 @@ implementation
end;
{ load next file and reopen it }
nextfile;
reopen;
tempopen;
{ status }
Message1(scan_d_back_in,inputfile^.name^);
{ load some current_module fields }
@ -548,13 +578,53 @@ implementation
inc(longint(inputpointer));
until c<>#0; { if also end, then reload again }
end;
end;
procedure tscannerfile.setbuf(p:pchar;l:longint);
begin
inputbuffer:=p;
with inputfile^ do
begin
inputbufsize:=l;
inputbuffer:=p;
inputpointer:=p;
end;
end;
procedure tscannerfile.insertmacro(p:pchar;len:longint);
{ load the values of tokenpos and lasttokenpos }
var
macbuf : pchar;
hp : pinputfile;
begin
{ save old postion }
dec(longint(inputpointer));
current_scanner^.tempclose;
{ create macro 'file' }
hp:=new(pinputfile,init('Macro'));
addfile(hp);
getmem(macbuf,len+1);
setbuf(macbuf,len+1);
{ fill buffer }
with inputfile^ do
begin
move(p^,inputbuffer^,len);
inputbuffer[len]:=#0;
{ reset }
inputpointer:=inputbuffer;
bufstart:=0;
bufsize:=len;
line_no:=0;
lastlinepos:=0;
lasttokenpos:=0;
is_macro:=true;
endoffile:=true;
closed:=true;
{ load new c }
c:=inputpointer^;
inc(longint(inputpointer));
end;
end;
@ -602,8 +672,9 @@ implementation
{$endif SourceLine}
oldtokenpos,oldaktfilepos : tfileposinfo;
begin
if (byte(inputpointer^)=0) and
filenotatend then
with inputfile^ do
begin
if (byte(inputpointer^)=0) and not(endoffile) then
begin
cur:=c;
reload;
@ -647,6 +718,7 @@ implementation
aktfilepos:=oldaktfilepos;
tokenpos:=oldtokenpos;
end;
end;
procedure tscannerfile.checkpreprocstack;
@ -1004,8 +1076,6 @@ implementation
code : word;
l : longint;
mac : pmacrosym;
hp : pinputfile;
macbuf : pchar;
asciinr : string[3];
label
exit_label;
@ -1064,19 +1134,7 @@ implementation
mac:=pmacrosym(macros^.search(pattern));
if assigned(mac) and (assigned(mac^.buftext)) then
begin
{ don't forget the last char }
dec(longint(inputpointer));
hp:=new(pinputfile,init('Macro '+pattern));
addfile(hp);
getmem(macbuf,mac^.buflen+1);
setbuf(macbuf,mac^.buflen+1);
{ copy text }
move(mac^.buftext^,inputbuffer^,mac^.buflen);
{ put end sign }
inputbuffer[mac^.buflen+1]:=#0;
{ load c }
c:=inputbuffer^;
inputpointer:=inputbuffer+1;
insertmacro(mac^.buftext,mac^.buflen);
{ handle empty macros }
if c=#0 then
reload;
@ -1561,7 +1619,11 @@ exit_label:
end.
{
$Log$
Revision 1.44 1998-08-20 16:09:55 pierre
Revision 1.45 1998-08-26 15:35:35 peter
* fixed scannerfiles for macros
+ $I %<environment>%
Revision 1.44 1998/08/20 16:09:55 pierre
* tokenpos has to be restored also after
printstatus