Browse Source

* also (re)store the pending state when replaying a token stream

Sven/Sarah Barth 7 months ago
parent
commit
b1791af0a3
1 changed files with 9 additions and 7 deletions
  1. 9 7
      compiler/scanner.pas

+ 9 - 7
compiler/scanner.pas

@@ -90,10 +90,12 @@ interface
          tokenbuf : tdynamicarray;
          tokenbuf : tdynamicarray;
          tokenbuf_needs_swapping : boolean;
          tokenbuf_needs_swapping : boolean;
          next     : treplaystack;
          next     : treplaystack;
+         pending  : tpendingstate;
          constructor Create(atoken: ttoken;aidtoken:ttoken;
          constructor Create(atoken: ttoken;aidtoken:ttoken;
            const aorgpattern,apattern:string;const acstringpattern:ansistring;
            const aorgpattern,apattern:string;const acstringpattern:ansistring;
            apatternw:pcompilerwidestring;asettings:tsettings;
            apatternw:pcompilerwidestring;asettings:tsettings;
-           atokenbuf:tdynamicarray;change_endian:boolean;anext:treplaystack);
+           atokenbuf:tdynamicarray;change_endian:boolean;const apending:tpendingstate;
+           anext:treplaystack);
          destructor destroy;override;
          destructor destroy;override;
        end;
        end;
 
 
@@ -2972,7 +2974,7 @@ type
     constructor treplaystack.Create(atoken:ttoken;aidtoken:ttoken;
     constructor treplaystack.Create(atoken:ttoken;aidtoken:ttoken;
       const aorgpattern,apattern:string;const acstringpattern:ansistring;
       const aorgpattern,apattern:string;const acstringpattern:ansistring;
       apatternw:pcompilerwidestring;asettings:tsettings;
       apatternw:pcompilerwidestring;asettings:tsettings;
-      atokenbuf:tdynamicarray;change_endian:boolean;anext:treplaystack);
+      atokenbuf:tdynamicarray;change_endian:boolean;const apending:tpendingstate;anext:treplaystack);
       begin
       begin
         token:=atoken;
         token:=atoken;
         idtoken:=aidtoken;
         idtoken:=aidtoken;
@@ -2986,6 +2988,7 @@ type
             move(apatternw^.data^,patternw^.data^,apatternw^.len*sizeof(tcompilerwidechar));
             move(apatternw^.data^,patternw^.data^,apatternw^.len*sizeof(tcompilerwidechar));
           end;
           end;
         settings:=asettings;
         settings:=asettings;
+        pending:=apending;
         tokenbuf:=atokenbuf;
         tokenbuf:=atokenbuf;
         tokenbuf_needs_swapping:=change_endian;
         tokenbuf_needs_swapping:=change_endian;
         next:=anext;
         next:=anext;
@@ -3710,7 +3713,8 @@ type
 
 
         { save current scanner state }
         { save current scanner state }
         replaystack:=treplaystack.create(token,idtoken,orgpattern,pattern,
         replaystack:=treplaystack.create(token,idtoken,orgpattern,pattern,
-          cstringpattern,patternw,current_settings,replaytokenbuf,change_endian_for_replay,replaystack);
+          cstringpattern,patternw,current_settings,replaytokenbuf,change_endian_for_replay,
+          pendingstate,replaystack);
 {$ifdef check_inputpointer_limits}
 {$ifdef check_inputpointer_limits}
         if assigned(hidden_inputpointer) then
         if assigned(hidden_inputpointer) then
           dec_inputpointer;
           dec_inputpointer;
@@ -3723,10 +3727,7 @@ type
 
 
         { ensure that existing message state records won't be freed }
         { ensure that existing message state records won't be freed }
         current_settings.pmessage:=nil;
         current_settings.pmessage:=nil;
-
-        { flushpendingswitchesstate should have been called }
-        if assigned(pendingstate.nextmessagerecord) then
-          internalerror(2024122901);
+        pendingstate:=default(tpendingstate);
 
 
         { Initialize value of change_endian_for_replay variable }
         { Initialize value of change_endian_for_replay variable }
         change_endian_for_replay:=change_endian;
         change_endian_for_replay:=change_endian;
@@ -3777,6 +3778,7 @@ type
             change_endian_for_replay:=replaystack.tokenbuf_needs_swapping;
             change_endian_for_replay:=replaystack.tokenbuf_needs_swapping;
             { restore compiler settings }
             { restore compiler settings }
             current_settings:=replaystack.settings;
             current_settings:=replaystack.settings;
+            pendingstate:=replaystack.pending;
             if assigned(pendingstate.nextmessagerecord) then
             if assigned(pendingstate.nextmessagerecord) then
               FreeLocalVerbosity(pendingstate.nextmessagerecord);
               FreeLocalVerbosity(pendingstate.nextmessagerecord);
             pendingstate.nextmessagerecord:=current_settings.pmessage;
             pendingstate.nextmessagerecord:=current_settings.pmessage;