* Remove freeold from set_current_scanner

This commit is contained in:
Michaël Van Canneyt 2024-02-01 10:36:42 +01:00 committed by Michael Van Canneyt
parent 7cd044eae7
commit 6f7481fd24
5 changed files with 37 additions and 24 deletions

View File

@ -348,7 +348,7 @@ implementation
current_asmdata:=tasmdata(current_module.asmdata); current_asmdata:=tasmdata(current_module.asmdata);
current_debuginfo:=tdebuginfo(current_module.debuginfo); current_debuginfo:=tdebuginfo(current_module.debuginfo);
{ restore scanner and file positions } { restore scanner and file positions }
set_current_scanner(tscannerfile(current_module.scanner),false); set_current_scanner(tscannerfile(current_module.scanner));
if assigned(current_scanner) then if assigned(current_scanner) then
begin begin
current_scanner.tempopeninputfile; current_scanner.tempopeninputfile;
@ -364,7 +364,7 @@ implementation
else else
begin begin
current_asmdata:=nil; current_asmdata:=nil;
set_current_scanner(nil,false); set_current_scanner(nil);
current_debuginfo:=nil; current_debuginfo:=nil;
end; end;
end; end;
@ -683,7 +683,7 @@ implementation
{ also update current_scanner if it was pointing { also update current_scanner if it was pointing
to this module } to this module }
if current_scanner=tscannerfile(scanner) then if current_scanner=tscannerfile(scanner) then
set_current_scanner(nil,false); set_current_scanner(nil);
freeandnil(scanner); freeandnil(scanner);
end; end;
@ -786,7 +786,7 @@ implementation
{ also update current_scanner if it was pointing { also update current_scanner if it was pointing
to this module } to this module }
if current_scanner=tscannerfile(scanner) then if current_scanner=tscannerfile(scanner) then
set_current_scanner(nil,false); set_current_scanner(nil);
freeandnil(scanner); freeandnil(scanner);
end; end;
if assigned(procinfo) then if assigned(procinfo) then
@ -1153,7 +1153,7 @@ implementation
if assigned(scanner) then if assigned(scanner) then
begin begin
if current_scanner=tscannerfile(scanner) then if current_scanner=tscannerfile(scanner) then
set_current_scanner(nil,false); set_current_scanner(nil);
FreeAndNil(scanner); FreeAndNil(scanner);
scanner:=nil; scanner:=nil;
end; end;

View File

@ -151,7 +151,7 @@ uses
current_module:=old_current_module; {!} current_module:=old_current_module; {!}
current_asmdata:=old_asmdata; current_asmdata:=old_asmdata;
current_debuginfo:=old_debuginfo; current_debuginfo:=old_debuginfo;
set_current_scanner(old_scanner,False); set_current_scanner(old_scanner);
parser_current_file:=old_parser_file; parser_current_file:=old_parser_file;
end; end;
end; end;

View File

@ -85,7 +85,7 @@ implementation
pattern:=''; pattern:='';
orgpattern:=''; orgpattern:='';
cstringpattern:=''; cstringpattern:='';
set_current_scanner(nil,true); set_current_scanner(nil);
switchesstatestackpos:=0; switchesstatestackpos:=0;
{ register all nodes and tais } { register all nodes and tais }
@ -218,7 +218,7 @@ implementation
if assigned(current_scanner) then if assigned(current_scanner) then
begin begin
current_scanner.free; current_scanner.free;
set_current_scanner(nil,true); set_current_scanner(nil);
end; end;
@ -407,7 +407,7 @@ implementation
sc.firstfile; sc.firstfile;
module.scanner:=sc; module.scanner:=sc;
module.mainscanner:=sc; module.mainscanner:=sc;
set_current_scanner(sc,false); set_current_scanner(sc);
{ init macros before anything in the file is parsed.} { init macros before anything in the file is parsed.}
module.localmacrosymtable:= tmacrosymtable.create(false); module.localmacrosymtable:= tmacrosymtable.create(false);
@ -469,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
set_current_scanner(nil,false); set_current_scanner(nil);
end; end;
end; end;

View File

@ -256,7 +256,9 @@ interface
function readpreprocint(var value:int64;const place:string):boolean; function readpreprocint(var value:int64;const place:string):boolean;
function readpreprocset(conform_to:tsetdef;var value:tnormalset;const place:string):boolean; function readpreprocset(conform_to:tsetdef;var value:tnormalset;const place:string):boolean;
function asmgetchar:char; function asmgetchar:char;
{$ifdef EXTDEBUG}
function DumpPointer : string; function DumpPointer : string;
{$endif EXTDEBUG}
end; end;
{$ifdef PREPROCWRITE} {$ifdef PREPROCWRITE}
@ -299,13 +301,16 @@ interface
procedure DoneScanner; procedure DoneScanner;
function current_scanner : tscannerfile; { current scanner in use } function current_scanner : tscannerfile; { current scanner in use }
procedure set_current_scanner(avalue : tscannerfile; FreeOld : Boolean); { current scanner in use } procedure set_current_scanner(avalue : tscannerfile); { current scanner in use }
{ To be called when the language mode is finally determined } { To be called when the language mode is finally determined }
Function SetCompileMode(const s:string; changeInit: boolean):boolean; Function SetCompileMode(const s:string; changeInit: boolean):boolean;
Function SetCompileModeSwitch(s:string; changeInit: boolean):boolean; Function SetCompileModeSwitch(s:string; changeInit: boolean):boolean;
procedure SetAppType(NewAppType:tapptype); procedure SetAppType(NewAppType:tapptype);
var
onfreescanner : procedure(s : tscannerfile) = nil;
implementation implementation
uses uses
@ -324,11 +329,19 @@ implementation
{ dictionaries with the supported directives } { dictionaries with the supported directives }
turbo_scannerdirectives : TFPHashObjectList; { for other modes } turbo_scannerdirectives : TFPHashObjectList; { for other modes }
mac_scannerdirectives : TFPHashObjectList; { for mode mac } mac_scannerdirectives : TFPHashObjectList; { for mode mac }
_current_scanner : tscannerfile; { current scanner in use } {
By default the current_scanner is current_module.scanner.
set_current_scanner sets the _temp_scanner variable.
If _temp_scanner is set, it is returned as the current scanner
}
_temp_scanner : tscannerfile;
function current_scanner : tscannerfile; { current scanner in use } function current_scanner : tscannerfile; { current scanner in use }
begin begin
Result:=_temp_scanner;
if result<>nil then
exit;
if assigned(current_module) then if assigned(current_module) then
Result:=Tscannerfile(current_module.scanner) Result:=Tscannerfile(current_module.scanner)
else else
@ -506,13 +519,9 @@ implementation
{$endif i8086} {$endif i8086}
end; end;
procedure set_current_scanner(avalue: tscannerfile);
procedure set_current_scanner(avalue: tscannerfile; FreeOld: Boolean);
begin begin
if (avalue=nil) and FreeOld and (_current_scanner<>nil) then _temp_scanner:=avalue;
_current_scanner.Free;
_current_scanner:=avalue;
end; end;
Function SetCompileMode(const s:string; changeInit: boolean):boolean; Function SetCompileMode(const s:string; changeInit: boolean):boolean;
@ -2972,7 +2981,7 @@ type
TSCANNERFILE TSCANNERFILE
****************************************************************************} ****************************************************************************}
constructor tscannerfile.Create(const fn: string; is_macro: boolean); constructor tscannerfile.Create(const fn: string; is_macro: boolean);
begin begin
inputfile:=do_openinputfile(fn); inputfile:=do_openinputfile(fn);
if is_macro then if is_macro then
@ -3015,8 +3024,10 @@ type
end; end;
destructor tscannerfile.Destroy; destructor tscannerfile.Destroy;
begin begin
if assigned(onfreescanner) then
onfreescanner(self);
if assigned(current_module) and if assigned(current_module) and
(current_module.state=ms_compiled) and (current_module.state=ms_compiled) and
(status.errorcount=0) then (status.errorcount=0) then
@ -6216,6 +6227,7 @@ exit_label:
until false; until false;
end; end;
{$ifdef EXTDEBUG}
function tscannerfile.DumpPointer: string; function tscannerfile.DumpPointer: string;
var var
i: Integer; i: Integer;
@ -6224,12 +6236,13 @@ exit_label:
Result:=''; Result:='';
if inputpointer=nil then exit; if inputpointer=nil then exit;
i:=0; i:=0;
While (inputpointer[I]<>#0) and (i<100) do While (inputpointer[I]<>#0) and (i<200) do
inc(i); inc(i);
Setlength(result,I); Setlength(result,I);
move(inputpointer^,Result[1],I); move(inputpointer^,Result[1],I);
result:='<'+inttostr(inputstart)+'>'+result;
end; end;
{$endif EXTDEBUG}
{***************************************************************************** {*****************************************************************************
Helpers Helpers

View File

@ -168,7 +168,7 @@ implementation
in the current one } in the current one }
old_block_type:=block_type; old_block_type:=block_type;
sstate.new_scanner:=tscannerfile.Create('_Macro_.'+tempname,true); sstate.new_scanner:=tscannerfile.Create('_Macro_.'+tempname,true);
set_current_scanner(sstate.new_scanner,False); set_current_scanner(sstate.new_scanner);
block_type:=old_block_type; block_type:=old_block_type;
{ required for e.g. FpcDeepCopy record method (uses "out" parameter; field { required for e.g. FpcDeepCopy record method (uses "out" parameter; field
names are escaped via &, so should not cause conflicts } names are escaped via &, so should not cause conflicts }
@ -181,7 +181,7 @@ implementation
if sstate.valid then if sstate.valid then
begin begin
sstate.new_scanner.free; sstate.new_scanner.free;
set_current_scanner(sstate.old_scanner,false); set_current_scanner(sstate.old_scanner);
current_filepos:=sstate.old_filepos; current_filepos:=sstate.old_filepos;
token:=sstate.old_token; token:=sstate.old_token;
current_settings.modeswitches:=sstate.old_modeswitches; current_settings.modeswitches:=sstate.old_modeswitches;