* Remove use of current_module

This commit is contained in:
Michaël Van Canneyt 2024-01-31 13:53:10 +01:00 committed by Michael Van Canneyt
parent a81715d6ea
commit d9317e5df5

View File

@ -59,7 +59,6 @@ implementation
begin begin
{ Current compiled module/proc } { Current compiled module/proc }
set_current_module(nil); set_current_module(nil);
current_module:=nil;
current_asmdata:=nil; current_asmdata:=nil;
current_procinfo:=nil; current_procinfo:=nil;
current_structdef:=nil; current_structdef:=nil;
@ -86,7 +85,7 @@ implementation
pattern:=''; pattern:='';
orgpattern:=''; orgpattern:='';
cstringpattern:=''; cstringpattern:='';
current_scanner:=nil; set_current_scanner(nil,true);
switchesstatestackpos:=0; switchesstatestackpos:=0;
{ register all nodes and tais } { register all nodes and tais }
@ -191,7 +190,6 @@ implementation
{ 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); set_current_module(nil);
current_module:=nil;
current_procinfo:=nil; current_procinfo:=nil;
current_asmdata:=nil; current_asmdata:=nil;
current_structdef:=nil; current_structdef:=nil;
@ -220,7 +218,8 @@ implementation
if assigned(current_scanner) then if assigned(current_scanner) then
begin begin
current_scanner.free; current_scanner.free;
current_scanner:=nil; set_current_scanner(nil,true);
end; end;
{ close scanner } { close scanner }
@ -340,6 +339,8 @@ implementation
olddata : pglobalstate; olddata : pglobalstate;
hp,hp2 : tmodule; hp,hp2 : tmodule;
finished : boolean; finished : boolean;
sc : tscannerfile;
begin begin
{ parsing a procedure or declaration should be finished } { parsing a procedure or declaration should be finished }
if assigned(current_procinfo) then if assigned(current_procinfo) then
@ -388,26 +389,30 @@ implementation
if assigned(current_module) then if assigned(current_module) then
internalerror(200501158); internalerror(200501158);
set_current_module(module); set_current_module(module);
addloadedunit(current_module); addloadedunit(module);
main_module:=current_module; main_module:=module;
current_module.state:=ms_compile; module.state:=ms_compile;
end; end
else
set_current_module(module);
if not(assigned(current_module) and if not(assigned(current_module) and
(current_module.state in [ms_compile,ms_second_compile])) then (current_module.state in [ms_compile,ms_second_compile])) then
internalerror(200212281); internalerror(200212281);
{ load current asmdata from current_module } { load current asmdata from current_module }
current_asmdata:=TAsmData(current_module.asmdata); current_asmdata:=TAsmData(module.asmdata);
{ startup scanner and load the first file } { startup scanner and load the first file }
current_scanner:=tscannerfile.Create(module.mainsource); sc:=tscannerfile.Create(module.mainsource);
current_scanner.firstfile; sc.firstfile;
current_module.scanner:=current_scanner; module.scanner:=sc;
module.mainscanner:=sc;
set_current_scanner(sc,false);
{ init macros before anything in the file is parsed.} { init macros before anything in the file is parsed.}
current_module.localmacrosymtable:= tmacrosymtable.create(false); module.localmacrosymtable:= tmacrosymtable.create(false);
macrosymtablestack.push(initialmacrosymtable); macrosymtablestack.push(initialmacrosymtable);
macrosymtablestack.push(current_module.localmacrosymtable); macrosymtablestack.push(module.localmacrosymtable);
{ read the first token } { read the first token }
current_scanner.readtoken(false); current_scanner.readtoken(false);
@ -421,16 +426,16 @@ implementation
try try
if (token=_UNIT) or (compile_level>1) then if (token=_UNIT) or (compile_level>1) then
begin begin
current_module.is_unit:=true; module.is_unit:=true;
finished:=proc_unit(current_module); finished:=proc_unit(module);
end end
else if (token=_ID) and (idtoken=_PACKAGE) then else if (token=_ID) and (idtoken=_PACKAGE) then
begin begin
current_module.IsPackage:=true; module.IsPackage:=true;
proc_package(current_module); proc_package(module);
end end
else else
proc_program(current_module,token=_LIBRARY); proc_program(module,token=_LIBRARY);
except except
on ECompilerAbort do on ECompilerAbort do
raise; raise;
@ -453,10 +458,10 @@ implementation
if (compile_level=1) and not finished then if (compile_level=1) and not finished then
internalerror(2012091901); internalerror(2012091901);
finally finally
if assigned(current_module) then if assigned(module) then
begin begin
if finished then if finished then
current_module.end_of_parsing module.end_of_parsing
else else
begin begin
{ these are saved in the unit's state and thus can be set to { these are saved in the unit's state and thus can be set to
@ -464,7 +469,7 @@ implementation
macrosymtablestack:=nil; macrosymtablestack:=nil;
symtablestack:=nil; symtablestack:=nil;
if current_scanner=current_module.scanner then if current_scanner=current_module.scanner then
current_scanner:=nil; set_current_scanner(nil,false);
end; end;
end; end;
@ -501,7 +506,7 @@ implementation
while assigned(hp) do while assigned(hp) do
begin begin
hp2:=tmodule(hp.next); hp2:=tmodule(hp.next);
if (hp<>current_module) then if (hp<>module) then
begin begin
loaded_units.remove(hp); loaded_units.remove(hp);
hp.free; hp.free;