From 93ae6261ccaef7c84096785c28d5f2569c1ec60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Wed, 31 Jan 2024 13:48:26 +0100 Subject: [PATCH] * Make current_scanner a function/procedure to better control lifetime --- compiler/scanner.pas | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/compiler/scanner.pas b/compiler/scanner.pas index 472215a489..0d7e70095e 100644 --- a/compiler/scanner.pas +++ b/compiler/scanner.pas @@ -256,6 +256,7 @@ interface function readpreprocint(var value:int64;const place:string):boolean; function readpreprocset(conform_to:tsetdef;var value:tnormalset;const place:string):boolean; function asmgetchar:char; + function DumpPointer : string; end; {$ifdef PREPROCWRITE} @@ -283,8 +284,6 @@ interface token, { current token being parsed } idtoken : ttoken; { holds the token if the pattern is a known word } - current_scanner : tscannerfile; { current scanner in use } - current_commentstyle : tcommentstyle; { needed to use read_comment from directives } {$ifdef PREPROCWRITE} preprocfile : tpreprocfile; { used with only preprocessing } @@ -299,6 +298,9 @@ interface procedure InitScanner; procedure DoneScanner; + function current_scanner : tscannerfile; { current scanner in use } + procedure set_current_scanner(avalue : tscannerfile; FreeOld : Boolean); { current scanner in use } + { To be called when the language mode is finally determined } Function SetCompileMode(const s:string; changeInit: boolean):boolean; Function SetCompileModeSwitch(s:string; changeInit: boolean):boolean; @@ -322,7 +324,16 @@ implementation { dictionaries with the supported directives } turbo_scannerdirectives : TFPHashObjectList; { for other modes } mac_scannerdirectives : TFPHashObjectList; { for mode mac } + _current_scanner : tscannerfile; { current scanner in use } + function current_scanner : tscannerfile; { current scanner in use } + + begin + if assigned(current_module) then + Result:=Tscannerfile(current_module.scanner) + else + Result:=Nil; + end; {***************************************************************************** Helper routines @@ -496,6 +507,14 @@ implementation end; + procedure set_current_scanner(avalue: tscannerfile; FreeOld: Boolean); + begin + if (avalue=nil) and FreeOld and (_current_scanner<>nil) then + _current_scanner.Free; + + _current_scanner:=avalue; + end; + Function SetCompileMode(const s:string; changeInit: boolean):boolean; var b : boolean; @@ -2953,7 +2972,7 @@ type TSCANNERFILE ****************************************************************************} - constructor tscannerfile.create(const fn:string; is_macro: boolean = false); + constructor tscannerfile.Create(const fn: string; is_macro: boolean); begin inputfile:=do_openinputfile(fn); if is_macro then @@ -2996,7 +3015,7 @@ type end; - destructor tscannerfile.destroy; + destructor tscannerfile.Destroy; begin if assigned(current_module) and (current_module.state=ms_compiled) and @@ -6197,6 +6216,20 @@ exit_label: until false; end; + function tscannerfile.DumpPointer: string; + var + i: Integer; + + begin + Result:=''; + if inputpointer=nil then exit; + i:=0; + While (inputpointer[I]<>#0) and (i<100) do + inc(i); + Setlength(result,I); + move(inputpointer^,Result[1],I); + end; + {***************************************************************************** Helpers