* 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 const
{$ifdef FPC} {$ifdef FPC}
maxunits = 1024; maxunits = 1024;
extbufsize = 65535; InputFileBufSize=32*1024;
{$else} {$else}
maxunits = 128; maxunits = 128;
extbufsize=1024; InputFileBufSize=1024;
{$endif} {$endif}
type type
@ -43,10 +43,17 @@ unit files;
path,name : pstring; { path and filename } path,name : pstring; { path and filename }
next : pinputfile; { next file for reading } 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 } savebufstart, { save fields for scanner }
savebufsize, savebufsize,
savelastlinepos, savelastlinepos,
saveline_no : longint; saveline_no : longint;
saveinputbuffer, saveinputbuffer,
saveinputpointer : pchar; saveinputpointer : pchar;
@ -172,6 +179,17 @@ unit files;
name:=stringdup(n+e); name:=stringdup(n+e);
path:=stringdup(p); path:=stringdup(p);
next:=nil; 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 } { indexing refs }
ref_next:=nil; ref_next:=nil;
ref_count:=0; ref_count:=0;
@ -647,7 +665,11 @@ unit files;
end. end.
{ {
$Log$ $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 problem with libprefix at the wrong place
* fixed lib generation with smartlinking and no -CS used * 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^) Message1(unit_f_cant_compile_unit,current_module^.modulename^)
else else
begin begin
current_scanner^.close; current_scanner^.tempclose;
compile(current_module^.mainsource^,compile_system); compile(current_module^.mainsource^,compile_system);
if (not old_current_module^.compiled) then if (not old_current_module^.compiled) then
current_scanner^.reopen; current_scanner^.tempopen;
end; end;
end end
else else
@ -901,7 +901,11 @@ unit pmodules;
end. end.
{ {
$Log$ $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 problem with libprefix at the wrong place
* fixed lib generation with smartlinking and no -CS used * fixed lib generation with smartlinking and no -CS used

View File

@ -500,12 +500,47 @@ const
hs:=current_scanner^.readcomment; hs:=current_scanner^.readcomment;
while (hs<>'') and (hs[length(hs)]=' ') do while (hs<>'') and (hs[length(hs)]=' ') do
dec(byte(hs[0])); 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); hs:=FixFileName(hs);
fsplit(hs,path,name,ext); fsplit(hs,path,name,ext);
{ first look in the path of _d then currentmodule } { first look in the path of _d then currentmodule }
path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found); path:=search(name+ext,path+';'+current_scanner^.inputfile^.path^+';'+includesearchpath,found);
{ shutdown current file } { shutdown current file }
current_scanner^.close; current_scanner^.tempclose;
{ load new file } { load new file }
hp:=new(pinputfile,init(path+name+ext)); hp:=new(pinputfile,init(path+name+ext));
current_scanner^.addfile(hp); current_scanner^.addfile(hp);
@ -517,6 +552,7 @@ const
current_module^.sourcefiles.register_file(hp); current_module^.sourcefiles.register_file(hp);
current_module^.current_index:=hp^.ref_index; current_module^.current_index:=hp^.ref_index;
end; end;
end;
procedure dir_description(t:tdirectivetoken); procedure dir_description(t:tdirectivetoken);
@ -732,7 +768,11 @@ const
{ {
$Log$ $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 * small fix for aktfilepos
Revision 1.20 1998/08/18 15:11:52 peter Revision 1.20 1998/08/18 15:11:52 peter

View File

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