diff --git a/compiler/parser.pas b/compiler/parser.pas index 94cf92748d..c9b3e05adb 100644 --- a/compiler/parser.pas +++ b/compiler/parser.pas @@ -86,6 +86,7 @@ implementation pattern:=''; orgpattern:=''; current_scanner:=nil; + switchesstatestackpos:=0; { register all nodes and tais } registernodes; @@ -280,6 +281,8 @@ implementation oldcurrent_procinfo : tprocinfo; old_settings : tsettings; oldsourcecodepage : tcodepagestring; + old_switchesstatestack : tswitchesstatestack; + old_switchesstatestackpos : Integer; end; var @@ -300,11 +303,13 @@ implementation with olddata^ do begin old_current_module:=current_module; - { save symtable state } + + { save symtable state } oldsymtablestack:=symtablestack; oldmacrosymtablestack:=macrosymtablestack; oldcurrent_procinfo:=current_procinfo; - { save scanner state } + + { save scanner state } oldc:=c; oldpattern:=pattern; oldorgpattern:=orgpattern; @@ -312,14 +317,19 @@ implementation oldidtoken:=idtoken; old_block_type:=block_type; oldtokenpos:=current_tokenpos; - { save cg } + old_switchesstatestack:=switchesstatestack; + old_switchesstatestackpos:=switchesstatestackpos; + + { save cg } oldparse_only:=parse_only; - { save akt... state } - { handle the postponed case first } + + { save akt... state } + { handle the postponed case first } flushpendingswitchesstate; oldcurrent_filepos:=current_filepos; old_settings:=current_settings; end; + { reset parser, a previous fatal error could have left these variables in an unreliable state, this is important for the IDE } afterassignment:=false; @@ -457,8 +467,12 @@ implementation idtoken:=oldidtoken; current_tokenpos:=oldtokenpos; block_type:=old_block_type; + switchesstatestack:=old_switchesstatestack; + switchesstatestackpos:=old_switchesstatestackpos; + { restore cg } parse_only:=oldparse_only; + { restore symtable state } symtablestack:=oldsymtablestack; macrosymtablestack:=oldmacrosymtablestack; diff --git a/compiler/scandir.pas b/compiler/scandir.pas index c7779a142f..8415ea5cad 100644 --- a/compiler/scandir.pas +++ b/compiler/scandir.pas @@ -23,22 +23,10 @@ unit scandir; {$i fpcdefs.inc} -interface - - - procedure InitScannerDirectives; - -implementation + interface uses - SysUtils, - cutils,cfileutl, - globtype,globals,systems,widestr,cpuinfo, - verbose,comphook,ppu, - scanner,switches, - fmodule, - symconst,symtable, - rabase; + globtype; const switchesstatestackmax = 20; @@ -49,10 +37,27 @@ implementation verbosity: longint; end; + type + tswitchesstatestack = array[0..switchesstatestackmax] of tsavedswitchesstate; + var - switchesstatestack: array[0..switchesstatestackmax] of tsavedswitchesstate; + switchesstatestack:tswitchesstatestack; switchesstatestackpos: Integer; + procedure InitScannerDirectives; + + implementation + + uses + SysUtils, + cutils,cfileutl, + globals,systems,widestr,cpuinfo, + verbose,comphook,ppu, + scanner,switches, + fmodule, + symconst,symtable, + rabase; + {***************************************************************************** Helpers *****************************************************************************} @@ -1405,6 +1410,4 @@ implementation AddDirective('Z4',directive_all, @dir_z4); end; -begin - switchesstatestackpos:= 0; end.