* cleanup current module status

* new set_current_module function that sets the current_module and
    all related variables. Also closes scanner files if required, but
    that might still need some optimization to prevent closing/opening
    files too often

git-svn-id: trunk@7428 -
This commit is contained in:
peter 2007-05-23 13:33:53 +00:00
parent 085689af60
commit e2db0a3982
7 changed files with 48 additions and 68 deletions

View File

@ -98,8 +98,7 @@ type
use_redir, use_redir,
use_bugreport, use_bugreport,
use_gccoutput, use_gccoutput,
print_source_path, print_source_path : boolean;
compiling_current : boolean;
{ Redirection support } { Redirection support }
redirfile : text; redirfile : text;
{ Special file for bug report } { Special file for bug report }

View File

@ -178,7 +178,7 @@ begin
{ this is needed here for the IDE { this is needed here for the IDE
in case of compilation failure in case of compilation failure
at the previous compile } at the previous compile }
current_module:=nil; set_current_module(nil);
{ read the arguments } { read the arguments }
read_arguments(cmd); read_arguments(cmd);
{ inits which depend on arguments } { inits which depend on arguments }

View File

@ -195,6 +195,7 @@ interface
SmartLinkOFiles : TCmdStrList; { List of .o files which are generated, SmartLinkOFiles : TCmdStrList; { List of .o files which are generated,
used to delete them after linking } used to delete them after linking }
procedure set_current_module(p:tmodule);
function get_module(moduleindex : longint) : tmodule; function get_module(moduleindex : longint) : tmodule;
function get_source_file(moduleindex,fileindex : longint) : tinputfile; function get_source_file(moduleindex,fileindex : longint) : tinputfile;
procedure addloadedunit(hp:tmodule); procedure addloadedunit(hp:tmodule);
@ -218,6 +219,40 @@ implementation
Global Functions Global Functions
*****************************************************************************} *****************************************************************************}
procedure set_current_module(p:tmodule);
begin
{ save the state of the scanner }
if assigned(current_scanner) then
current_scanner.tempcloseinputfile;
{ set new module }
current_module:=p;
{ restore previous module settings }
Fillchar(current_filepos,0,sizeof(current_filepos));
if assigned(current_module) then
begin
current_asmdata:=tasmdata(current_module.asmdata);
{ restore scanner and file positions }
current_scanner:=tscannerfile(current_module.scanner);
if assigned(current_scanner) then
begin
current_scanner.tempopeninputfile;
current_scanner.gettokenpos;
parser_current_file:=current_scanner.inputfile.name^;
end
else
begin
current_filepos.moduleindex:=current_module.unit_index;
parser_current_file:='';
end;
end
else
begin
current_asmdata:=nil;
current_scanner:=nil;
end;
end;
function get_module(moduleindex : longint) : tmodule; function get_module(moduleindex : longint) : tmodule;
var var
hp : tmodule; hp : tmodule;

View File

@ -1318,9 +1318,7 @@ uses
{ reset } { reset }
do_load:=true; do_load:=true;
second_time:=false; second_time:=false;
current_module:=self; set_current_module(self);
SetCompileModule(current_module);
Fillchar(current_filepos,0,sizeof(current_filepos));
{ A force reload } { A force reload }
if do_reload then if do_reload then
@ -1353,12 +1351,6 @@ uses
if do_load then if do_load then
begin begin
{ we are loading a new module, save the state of the scanner
and reset scanner+module }
if assigned(current_scanner) then
current_scanner.tempcloseinputfile;
current_scanner:=nil;
{ loading the unit for a second time? } { loading the unit for a second time? }
if state=ms_registered then if state=ms_registered then
state:=ms_load state:=ms_load
@ -1470,21 +1462,10 @@ uses
assigned(tppumodule(old_current_module).ppufile) then assigned(tppumodule(old_current_module).ppufile) then
tppumodule(old_current_module).ppufile.tempopen; tppumodule(old_current_module).ppufile.tempopen;
{$endif SHORT_ON_FILE_HANDLES} {$endif SHORT_ON_FILE_HANDLES}
{ reload old scanner }
current_scanner:=tscannerfile(old_current_module.scanner);
if assigned(current_scanner) then
begin
current_scanner.tempopeninputfile;
current_scanner.gettokenpos
end
else
fillchar(current_filepos,sizeof(current_filepos),0);
end; end;
{ we are back, restore current_module } { we are back, restore current_module }
current_module:=old_current_module; set_current_module(old_current_module);
SetCompileModule(current_module);
end; end;

View File

@ -60,11 +60,10 @@ implementation
testcurobject:=0; testcurobject:=0;
{ Current compiled module/proc } { Current compiled module/proc }
set_current_module(nil);
current_module:=nil; current_module:=nil;
compiled_module:=nil;
current_asmdata:=nil; current_asmdata:=nil;
current_procinfo:=nil; current_procinfo:=nil;
SetCompileModule(nil);
loaded_units:=TLinkedList.Create; loaded_units:=TLinkedList.Create;
@ -134,11 +133,10 @@ implementation
begin begin
{ Reset current compiling info, so destroy routines can't { Reset current compiling info, so destroy routines can't
reference the data that might already be destroyed } reference the data that might already be destroyed }
set_current_module(nil);
current_module:=nil; current_module:=nil;
compiled_module:=nil;
current_procinfo:=nil; current_procinfo:=nil;
current_asmdata:=nil; current_asmdata:=nil;
SetCompileModule(nil);
{ unload units } { unload units }
if assigned(loaded_units) then if assigned(loaded_units) then
@ -183,7 +181,7 @@ implementation
begin begin
new(preprocfile,init('pre')); new(preprocfile,init('pre'));
{ initialize a module } { initialize a module }
current_module:=new(pmodule,init(filename,false)); set_current_module(new(pmodule,init(filename,false)));
macrosymtablestack:= initialmacrosymtable; macrosymtablestack:= initialmacrosymtable;
current_module.localmacrosymtable:= tmacrosymtable.create(false); current_module.localmacrosymtable:= tmacrosymtable.create(false);
@ -275,7 +273,7 @@ implementation
oldparse_only : boolean; oldparse_only : boolean;
{ akt.. things } { akt.. things }
oldcurrent_filepos : tfileposinfo; oldcurrent_filepos : tfileposinfo;
old_compiled_module : tmodule; old_current_module : tmodule;
oldcurrent_procinfo : tprocinfo; oldcurrent_procinfo : tprocinfo;
old_settings : tsettings; old_settings : tsettings;
oldsourcecodepage : tcodepagestring; oldsourcecodepage : tcodepagestring;
@ -293,7 +291,7 @@ implementation
new(olddata); new(olddata);
with olddata^ do with olddata^ do
begin begin
old_compiled_module:=compiled_module; old_current_module:=current_module;
{ save symtable state } { save symtable state }
oldsymtablestack:=symtablestack; oldsymtablestack:=symtablestack;
oldmacrosymtablestack:=macrosymtablestack; oldmacrosymtablestack:=macrosymtablestack;
@ -343,7 +341,7 @@ implementation
begin begin
if assigned(current_module) then if assigned(current_module) then
internalerror(200501158); internalerror(200501158);
current_module:=tppumodule.create(nil,filename,'',false); set_current_module(tppumodule.create(nil,filename,'',false));
addloadedunit(current_module); addloadedunit(current_module);
main_module:=current_module; main_module:=current_module;
current_module.state:=ms_compile; current_module.state:=ms_compile;
@ -352,11 +350,6 @@ implementation
(current_module.state in [ms_compile,ms_second_compile])) then (current_module.state in [ms_compile,ms_second_compile])) then
internalerror(200212281); internalerror(200212281);
{ Set the module to use for verbose }
compiled_module:=current_module;
SetCompileModule(current_module);
Fillchar(current_filepos,0,sizeof(current_filepos));
{ Load current state from the init values } { Load current state from the init values }
current_settings:=init_settings; current_settings:=init_settings;
@ -457,18 +450,6 @@ implementation
block_type:=old_block_type; block_type:=old_block_type;
{ restore cg } { restore cg }
parse_only:=oldparse_only; parse_only:=oldparse_only;
{ asm data }
if assigned(old_compiled_module) then
current_asmdata:=tasmdata(old_compiled_module.asmdata)
else
current_asmdata:=nil;
{ restore previous scanner }
if assigned(old_compiled_module) then
current_scanner:=tscannerfile(old_compiled_module.scanner)
else
current_scanner:=nil;
if assigned(current_scanner) then
parser_current_file:=current_scanner.inputfile.name^;
{ restore symtable state } { restore symtable state }
symtablestack:=oldsymtablestack; symtablestack:=oldsymtablestack;
macrosymtablestack:=oldmacrosymtablestack; macrosymtablestack:=oldmacrosymtablestack;
@ -508,8 +489,7 @@ implementation
end; end;
end; end;
dec(compile_level); dec(compile_level);
compiled_module:=olddata^.old_compiled_module; set_current_module(olddata^.old_current_module);
SetCompileModule(compiled_module);
dispose(olddata); dispose(olddata);
end; end;

View File

@ -348,7 +348,7 @@ implementation
pbestrealtype:=@s64floattype; pbestrealtype:=@s64floattype;
oldcurrentmodule:=current_module; oldcurrentmodule:=current_module;
current_module:=nil; set_current_module(nil);
loadtype('byte',u8inttype); loadtype('byte',u8inttype);
loadtype('shortint',s8inttype); loadtype('shortint',s8inttype);
loadtype('word',u16inttype); loadtype('word',u16inttype);
@ -399,7 +399,7 @@ implementation
ptruinttype:=u32inttype; ptruinttype:=u32inttype;
ptrsinttype:=s32inttype; ptrsinttype:=s32inttype;
{$endif cpu64bit} {$endif cpu64bit}
current_module:=oldcurrentmodule; set_current_module(oldcurrentmodule);
end; end;

View File

@ -79,7 +79,6 @@ interface
procedure PrepareReport; procedure PrepareReport;
function CheckVerbosity(v:longint):boolean; function CheckVerbosity(v:longint):boolean;
procedure SetCompileModule(p:tmodulebase);
procedure ShowStatus; procedure ShowStatus;
function ErrorCount:longint; function ErrorCount:longint;
procedure SetErrorFlags(const s:string); procedure SetErrorFlags(const s:string);
@ -120,9 +119,6 @@ implementation
uses uses
comphook,fmodule; comphook,fmodule;
var
compiling_module : tmodulebase;
{**************************************************************************** {****************************************************************************
Extra Handlers for default compiler Extra Handlers for default compiler
@ -367,12 +363,6 @@ var
end; end;
procedure SetCompileModule(p:tmodulebase);
begin
compiling_module:=p;
end;
var var
lastfileidx, lastfileidx,
lastmoduleidx : longint; lastmoduleidx : longint;
@ -403,9 +393,6 @@ var
lastfileidx:=0; lastfileidx:=0;
lastmoduleidx:=module.unit_index; lastmoduleidx:=module.unit_index;
end; end;
status.compiling_current:=assigned(compiling_module) and
(module=compiling_module) and
(compiling_module.state in [ms_compile,ms_second_compile]);
end; end;
@ -871,8 +858,6 @@ end;
status.currentmodule:=''; status.currentmodule:='';
status.currentsource:=''; status.currentsource:='';
status.currentsourcepath:=''; status.currentsourcepath:='';
status.compiling_current:=false;
compiling_module:=nil;
{ Register internalerrorproc for cutils/cclasses } { Register internalerrorproc for cutils/cclasses }
internalerrorproc:=@internalerror; internalerrorproc:=@internalerror;
end; end;