View Issue Details

IDProjectCategoryView StatusLast Update
0034767LazarusIDEpublic2020-01-21 05:31
ReportermangustAssigned ToMattias Gaertner 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionreopened 
Product VersionProduct Build 
Target VersionFixed in Version 
Summary0034767: Wrong calculation {$ifopt o-} state in TLinkScanner.IfOptDirective
DescriptionIn function `TLinkScanner.IfOptDirective` one condition to check is missing.

If `OPT` not define in `Values`

Values.Variables[CompilerSwitchesNames[Option]]


 
Steps To ReproduceTry use {$ifopt o-} when the `switch` is off or undefined.
For example: {$ifopt D-}.
Additional InformationMy version of the fix that is currently working for me.

function TLinkScanner.IfOptDirective: boolean;
// {$ifopt o+} or {$ifopt o-}
var Option, c: char;
var v:string;
begin
  inc(IfLevel);
  if StoreDirectives then
    FDirectives[FDirectivesCount-1].Kind:=lsdkIfOpt;
  if FSkippingDirectives<>lssdNone then exit(true);
  Result:=true;
  inc(SrcPos);
  Option:=UpChars[Src[SrcPos]];
  if (IsWordChar[Option]) and (CompilerSwitchesNames[Option]<>'')
  then begin
    inc(SrcPos);
    if (SrcPos<=SrcLen) then begin
      c:=Src[SrcPos];
      //--> in0k
      if c in ['+','-'] then begin
          v:=Values.Variables[CompilerSwitchesNames[Option]];
          if ( (c='+')AND(v='1') ) or
             ( (c='-')AND( (v='0')or(v='') ))
          then exit
          else begin
            SkipTillEndifElse(lssdTillElse);
            exit;
          end;
      end;
      //--< in0k
      (* wrong version
      if c in ['+','-'] then begin
        if (c='-')<>(Values.Variables[CompilerSwitchesNames[Option]]='0') then
        begin
          SkipTillEndifElse(lssdTillElse);
          exit;
        end;
      end; *)
    end;
  end;
end;
TagsNo tags attached.
Fixed in Revision59914.
LazTarget-
Widgetset
Attached Files

Relationships

related to 0036612 resolvedBart Broersma Codetool parses "{$IF ident > n}" wrong / Lazarus editor grayed out wrong section of const conditional compilation 

Activities

Juha Manninen

2018-12-27 13:58

developer   ~0112904

Provide a proper patch please.

Mattias Gaertner

2018-12-27 14:49

manager   ~0112908

Please close if ok

mangust

2018-12-28 05:26

reporter   ~0112935

Last edited: 2018-12-28 15:12

View 2 revisions

Yes, your fix works.

mangust

2018-12-28 15:11

reporter   ~0112949

However, it can further simplify the function.
Invert the condition, and then you get without using additional variables.
For example, as follows.

function TLinkScanner.IfOptDirective: boolean;
// {$ifopt o+} or {$ifopt o-}
var Option, c: char;
begin
  inc(IfLevel);
  if StoreDirectives then
    FDirectives[FDirectivesCount-1].Kind:=lsdkIfOpt;
  if FSkippingDirectives<>lssdNone then exit(true);
  Result:=true;
  inc(SrcPos);
  Option:=UpChars[Src[SrcPos]];
  if (IsWordChar[Option]) and (CompilerSwitchesNames[Option]<>'')
  then begin
    inc(SrcPos);
    if (SrcPos<=SrcLen) then begin
      c:=Src[SrcPos];
      if c in ['+','-'] then begin
        if (c='+')<>(Values.Variables[CompilerSwitchesNames[Option]]='1') then
        begin
          SkipTillEndifElse(lssdTillElse);
          exit;
        end;
      end;
    end;
  end;
end

Issue History

Date Modified Username Field Change
2018-12-27 13:00 mangust New Issue
2018-12-27 13:58 Juha Manninen Note Added: 0112904
2018-12-27 14:49 Mattias Gaertner Fixed in Revision => 59914.
2018-12-27 14:49 Mattias Gaertner LazTarget => -
2018-12-27 14:49 Mattias Gaertner Note Added: 0112908
2018-12-27 14:49 Mattias Gaertner Status new => resolved
2018-12-27 14:49 Mattias Gaertner Resolution open => fixed
2018-12-27 14:49 Mattias Gaertner Assigned To => Mattias Gaertner
2018-12-28 05:26 mangust Note Added: 0112935
2018-12-28 15:11 mangust Note Added: 0112949
2018-12-28 15:11 mangust Status resolved => assigned
2018-12-28 15:11 mangust Resolution fixed => reopened
2018-12-28 15:12 mangust Note Edited: 0112935 View Revisions
2020-01-21 05:31 Martin Friebe Relationship added related to 0036612