Browse Source

fcl-passrc: fixed modeswitch param and comment to be fpc compatible

git-svn-id: trunk@43285 -
Mattias Gaertner 5 years ago
parent
commit
ddcb2d80af

+ 0 - 1
packages/fcl-passrc/src/pasresolver.pp

@@ -338,7 +338,6 @@ const
     po_NoOverloadedProcs,
     po_NoOverloadedProcs,
     po_KeepClassForward,
     po_KeepClassForward,
     po_ArrayRangeExpr,
     po_ArrayRangeExpr,
-    po_CheckModeswitches,
     po_CheckCondFunction];
     po_CheckCondFunction];
 
 
 type
 type

+ 57 - 18
packages/fcl-passrc/src/pscanner.pp

@@ -80,6 +80,7 @@ const
   nMisplacedGlobalCompilerSwitch = 1029;
   nMisplacedGlobalCompilerSwitch = 1029;
   nLogMacroXSetToY = 1030;
   nLogMacroXSetToY = 1030;
   nInvalidDispatchFieldName = 1031;
   nInvalidDispatchFieldName = 1031;
+  nErrWrongSwitchToggle = 1032;
 
 
 // resourcestring patterns of messages
 // resourcestring patterns of messages
 resourcestring
 resourcestring
@@ -116,6 +117,7 @@ resourcestring
   SMisplacedGlobalCompilerSwitch = 'Misplaced global compiler switch, ignored';
   SMisplacedGlobalCompilerSwitch = 'Misplaced global compiler switch, ignored';
   SLogMacroXSetToY = 'Macro %s set to %s';
   SLogMacroXSetToY = 'Macro %s set to %s';
   SInvalidDispatchFieldName = 'Invalid Dispatch field name';
   SInvalidDispatchFieldName = 'Invalid Dispatch field name';
+  SErrWrongSwitchToggle = 'Wrong switch toggle, use ON/OFF or +/-';
 
 
 type
 type
   TMessageType = (
   TMessageType = (
@@ -2502,7 +2504,6 @@ function TFileResolver.FindIncludeFileName(const AName: string): String;
   end;
   end;
 
 
 var
 var
-  i: Integer;
   FN : string;
   FN : string;
 
 
 begin
 begin
@@ -3496,36 +3497,74 @@ begin
 end;
 end;
 
 
 procedure TPascalScanner.HandleModeSwitch(const Param: String);
 procedure TPascalScanner.HandleModeSwitch(const Param: String);
-
+// $modeswitch param
+// name, name-, name+, name off, name on, name- comment, name on comment
 Var
 Var
   MS : TModeSwitch;
   MS : TModeSwitch;
   MSN,PM : String;
   MSN,PM : String;
-  P : Integer;
+  p : Integer;
+  Enable: Boolean;
 
 
 begin
 begin
-  MSN:=Uppercase(Param);
-  P:=Pos(' ',MSN);
-  if P<>0 then
-    begin
-    PM:=Trim(Copy(MSN,P+1,Length(MSN)-P));
-    MSN:=Copy(MSN,1,P-1);
-    end;
+  PM:=Param;
+  p:=1;
+  while (p<=length(PM)) and (PM[p] in ['a'..'z','A'..'Z','_','0'..'9']) do
+    inc(p);
+  MSN:=LeftStr(PM,p-1);
+  Delete(PM,1,p-1);
   MS:=StrToModeSwitch(MSN);
   MS:=StrToModeSwitch(MSN);
   if (MS=msNone) or not (MS in AllowedModeSwitches) then
   if (MS=msNone) or not (MS in AllowedModeSwitches) then
     begin
     begin
     if po_CheckModeSwitches in Options then
     if po_CheckModeSwitches in Options then
-      Error(nErrInvalidModeSwitch,SErrInvalidModeSwitch,[Param])
+      Error(nErrInvalidModeSwitch,SErrInvalidModeSwitch,[MSN])
     else
     else
-      exit; // ignore
+      DoLog(mtWarning,nErrInvalidModeSwitch,SErrInvalidModeSwitch,[MSN]);
+    exit; // ignore
     end;
     end;
-  if (PM='-') or (PM='OFF') then
+  if PM='' then
+    Enable:=true
+  else
+    case PM[1] of
+    '+','-':
+      begin
+      Enable:=PM[1]='+';
+      p:=2;
+      if (p<=length(PM)) and not (PM[p] in [' ',#9]) then
+        Error(nErrWrongSwitchToggle,SErrWrongSwitchToggle,[]);
+      end;
+    ' ',#9:
+      begin
+      PM:=TrimLeft(PM);
+      if PM<>'' then
+        begin
+        p:=1;
+        while (p<=length(PM)) and (PM[p] in ['A'..'Z']) do inc(p);
+        if (p<=length(PM)) and not (PM[p] in [' ',#9]) then
+          Error(nErrWrongSwitchToggle,SErrWrongSwitchToggle,[]);
+        PM:=LeftStr(PM,p-1);
+        if PM='ON' then
+          Enable:=true
+        else if PM='OFF' then
+          Enable:=false
+        else
+          Error(nErrWrongSwitchToggle,SErrWrongSwitchToggle,[]);
+        end;
+      end;
+    else
+      Error(nErrWrongSwitchToggle,SErrWrongSwitchToggle,[]);
+    end;
+
+  if MS in CurrentModeSwitches=Enable then
+    exit; // no change
+  if MS in ReadOnlyModeSwitches then
     begin
     begin
-    if MS in ReadOnlyModeSwitches then
-      Error(nErrInvalidModeSwitch,SErrInvalidModeSwitch,[Param]);
-    CurrentModeSwitches:=CurrentModeSwitches-[MS]
-    end
+    DoLog(mtWarning,nErrInvalidModeSwitch,SErrInvalidModeSwitch,[MSN]);
+    exit;
+    end;
+  if Enable then
+    CurrentModeSwitches:=CurrentModeSwitches+[MS]
   else
   else
-    CurrentModeSwitches:=CurrentModeSwitches+[MS];
+    CurrentModeSwitches:=CurrentModeSwitches-[MS];
 end;
 end;
 
 
 procedure TPascalScanner.PushSkipMode;
 procedure TPascalScanner.PushSkipMode;

+ 16 - 3
packages/fcl-passrc/tests/tcresolver.pas

@@ -131,8 +131,9 @@ type
     procedure OnCheckElementParent(El: TPasElement; arg: pointer);
     procedure OnCheckElementParent(El: TPasElement; arg: pointer);
     procedure FreeSrcMarkers;
     procedure FreeSrcMarkers;
     procedure OnPasResolverLog(Sender: TObject; const Msg: String);
     procedure OnPasResolverLog(Sender: TObject; const Msg: String);
-    procedure ScannerDirective(Sender: TObject; Directive, Param: String;
+    procedure OnScannerDirective(Sender: TObject; Directive, Param: String;
       var Handled: boolean);
       var Handled: boolean);
+    procedure OnScannerLog(Sender: TObject; const Msg: String);
   Protected
   Protected
     FirstSrcMarker, LastSrcMarker: PSrcMarker;
     FirstSrcMarker, LastSrcMarker: PSrcMarker;
     Procedure SetUp; override;
     Procedure SetUp; override;
@@ -1050,7 +1051,8 @@ begin
   FModules:=TObjectList.Create(true);
   FModules:=TObjectList.Create(true);
   inherited SetUp;
   inherited SetUp;
   Parser.Options:=Parser.Options+[po_ResolveStandardTypes];
   Parser.Options:=Parser.Options+[po_ResolveStandardTypes];
-  Scanner.OnDirective:=@ScannerDirective;
+  Scanner.OnDirective:=@OnScannerDirective;
+  Scanner.OnLog:=@OnScannerLog;
 end;
 end;
 
 
 procedure TCustomTestResolver.TearDown;
 procedure TCustomTestResolver.TearDown;
@@ -2548,7 +2550,7 @@ begin
   FResolverMsgs.Add(Item);
   FResolverMsgs.Add(Item);
 end;
 end;
 
 
-procedure TCustomTestResolver.ScannerDirective(Sender: TObject; Directive,
+procedure TCustomTestResolver.OnScannerDirective(Sender: TObject; Directive,
   Param: String; var Handled: boolean);
   Param: String; var Handled: boolean);
 var
 var
   aScanner: TPascalScanner;
   aScanner: TPascalScanner;
@@ -2563,6 +2565,17 @@ begin
   if Param='' then ;
   if Param='' then ;
 end;
 end;
 
 
+procedure TCustomTestResolver.OnScannerLog(Sender: TObject; const Msg: String);
+var
+  aScanner: TPascalScanner;
+begin
+  aScanner:=TPascalScanner(Sender);
+  if aScanner=nil then exit;
+  {$IFDEF VerbosePasResolver}
+  writeln('TCustomTestResolver.OnScannerLog ',GetObjName(Sender),' ',aScanner.LastMsgType,' ',aScanner.LastMsgNumber,' Msg="', Msg,'"');
+  {$ENDIF}
+end;
+
 function TCustomTestResolver.GetModules(Index: integer): TTestEnginePasResolver;
 function TCustomTestResolver.GetModules(Index: integer): TTestEnginePasResolver;
 begin
 begin
   Result:=TTestEnginePasResolver(FModules[Index]);
   Result:=TTestEnginePasResolver(FModules[Index]);

+ 1 - 1
packages/fcl-passrc/tests/tcscanner.pas

@@ -1730,7 +1730,7 @@ begin
       if SModeSwitchNames[M]<>'' then
       if SModeSwitchNames[M]<>'' then
         begin
         begin
         Scanner.CurrentModeSwitches:=[];
         Scanner.CurrentModeSwitches:=[];
-        NewSource('{$MODESWITCH '+SModeSwitchNames[M]+' '+C+'}');
+        NewSource('{$MODESWITCH '+SModeSwitchNames[M]+C+'}');
         While not (Scanner.FetchToken=tkEOF) do;
         While not (Scanner.FetchToken=tkEOF) do;
         if C in [' ','+'] then
         if C in [' ','+'] then
           AssertTrue(SModeSwitchNames[M]+C+' sets '+GetEnumName(TypeInfo(TModeSwitch),Ord(M)),M in Scanner.CurrentModeSwitches)
           AssertTrue(SModeSwitchNames[M]+C+' sets '+GetEnumName(TypeInfo(TModeSwitch),Ord(M)),M in Scanner.CurrentModeSwitches)