From d24065c529d29cb068680cabcadb2c86ce2ff578 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Fri, 15 Apr 2016 14:18:39 +0000 Subject: [PATCH] Fix compilation of the JEDI package. Old Delphi versions have {$WEAKPACKAGEUNIT} while newer ones also seem to allow {$WEAKPACKAGENUNIT ON}... :/ (analogous for DENYPACKAGEUNIT...) scanner.pas, tscannerfile: + new method readoptionalstate which reads a state like readstate, but if it encounters the closing } then it returns the provided fallback state scandir.pas: + do_moduleflagswitch: new parameter optional that triggers the use of readoptionalstate instead of readstate * dir_weakpackageunit & dir_denypackageunit: the ON/OFF is optional git-svn-id: trunk@33515 - --- compiler/scandir.pas | 13 +++++++++---- compiler/scanner.pas | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/compiler/scandir.pas b/compiler/scandir.pas index 03e5091e4f..32f193f74d 100644 --- a/compiler/scandir.pas +++ b/compiler/scandir.pas @@ -118,11 +118,14 @@ unit scandir; end; - procedure do_moduleflagswitch(flag:cardinal); + procedure do_moduleflagswitch(flag:cardinal;optional:boolean); var state : char; begin - state:=current_scanner.readstate; + if optional then + state:=current_scanner.readoptionalstate('+') + else + state:=current_scanner.readstate; if state='-' then current_module.flags:=current_module.flags and not flag else @@ -381,7 +384,7 @@ unit scandir; procedure dir_denypackageunit; begin - do_moduleflagswitch(uf_package_deny); + do_moduleflagswitch(uf_package_deny,true); end; procedure dir_description; @@ -1584,7 +1587,9 @@ unit scandir; procedure dir_weakpackageunit; begin - do_moduleflagswitch(uf_package_weak); + { old Delphi versions seem to use merely $WEAKPACKAGEUNIT while newer + Delphis have $WEAPACKAGEUNIT ON... :/ } + do_moduleflagswitch(uf_package_weak, true); end; procedure dir_writeableconst; diff --git a/compiler/scanner.pas b/compiler/scanner.pas index 08d2c4cd24..d70955f854 100644 --- a/compiler/scanner.pas +++ b/compiler/scanner.pas @@ -211,6 +211,7 @@ interface function readcomment:string; function readquotedstring:string; function readstate:char; + function readoptionalstate(fallback:char):char; function readstatedefault:char; procedure skipspace; procedure skipuntildirective; @@ -4222,6 +4223,37 @@ type end; + function tscannerfile.readoptionalstate(fallback:char):char; + var + state : char; + begin + state:=' '; + if c=' ' then + begin + current_scanner.skipspace; + if c='}' then + state:=fallback + else + begin + current_scanner.readid; + if pattern='ON' then + state:='+' + else + if pattern='OFF' then + state:='-'; + end; + end + else + if c='}' then + state:=fallback + else + state:=c; + if not (state in ['+','-']) then + Message(scan_e_wrong_switch_toggle); + readoptionalstate:=state; + end; + + function tscannerfile.readstatedefault:char; var state : char;