View Issue Details

IDProjectCategoryView StatusLast Update
0038125LazarusIDEpublic2020-11-25 07:02
ReporterOkobaPatino Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version2.1 (SVN) 
Summary0038125: JCF fails formatting using defines in uses
DescriptionThis will fail:
uses classes, {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};
But not this one:
uses classes {$ifdef WINDOWS}, windows {$ELSE}, linux {$ENDIF};
TagsNo tags attached.
Fixed in Revision
LazTarget
Widgetset
Attached Files

Relationships

related to 0019754 acknowledged Jedi Code Format (JCF) parser needs to be replaced with codetools parser 

Activities

Domingo Galmés

2020-11-24 14:20

reporter   ~0127158

I have tested and fails if the option 'Enable preprocessor parsing' is disabled.
If you enable this option in the format settings, works well.

PS:
About your comment merging JCF and codetools i think i don't have the time nor the skills for do that task.


Sample code used for testing.

unit unit4;

{$mode objfpc}{$H+}

interface

uses Classes {$ifdef WINDOWS}, windows {$ELSE}, linux {$ENDIF};

implementation

uses Classes, {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};

type
  generic TFakeClass<_GT> = class
    class function gmax(a, b: _GT): _GT;
  end;
end.

OkobaPatino

2020-11-24 14:31

reporter   ~0127159

Yes, it does not fail nor format the code; it will also insert a space every time you format! After hitting it several times, it will be like:
program Project1;

uses
  Classes,
 {$ifdef WINDOWS} windows {$ELSE} linux {$ENDIF};

begin
end.


Did you add any custom option for preprocessing?
P.S: I understand, and thank you for keeping JCF uptodate; that makes coding more joyful.

Domingo Galmés

2020-11-24 21:53

reporter   ~0127162

I have been testing the problem a bit, and I see that with the current implementation if the use of the preprocessor is not enabled, jcf treats the directives {$ IFDEF} {$ELSE},... as comments and therefore gives the error when it does not find a comma between windows and linux in the following statement.

uses Classes, {$ ifdef WINDOWS} windows {$ ELSE} linux {$ ENDIF};
It transforms in
uses Classes, windows linux;

On the other hand, if we allow the use of the jcf preprocessor, it only formats the part that meets the {$ IF} condition

In short, I don't see an easy way to change jcf's behavior to format the two parts of {$ IF} {$ ELSE} {$ END} so I won't be able to send any patches to fix the "problem". I'm sorry.

I have not added any custom options for preprocessing.

With the following code the behavior of jcf is better seen.

unit unit4;
interface

uses Classes {$ ifndef WINDOWS}, Windows {$ ELSE}, linux {$ ENDIF};

implementation

uses Classes, {$ ifdef WINDOWS} windows {$ ELSE} linux {$ ENDIF};

type
{$ ifdef WINDOWS}
generic TFakeClass <_GT> = class
class function gmax (a, b: _GT): _GT;
end;
{$ ELSE}
generic TFakeClass <_GT> = class
class function gmax (a, b: _GT): _GT;
end;
{$ ENDIF}
end.

Juha Manninen

2020-11-25 01:46

developer   ~0127169

> About your comment merging JCF and codetools i think i don't have the time nor the skills for do that task.

I didn't see the actual comment but Codetools solves a different problem than JCF. Codetools parses also code that is broken temporarily while you edit. It parses all used units to get you available identifiers based on context of your code. In a big project like Lazarus itself it goes through huge amounts of code in the background. It is optimized for speed and data structure efficiency.
JCF does not need to care about external units or libraries. It is enough to understand Pascal syntax.
Long time ago I opened the related issue about using Codetools for a formatting tool but I am not sure any more if it was a good idea.

OkobaPatino

2020-11-25 07:02

reporter   ~0127171

Thank you Domingo.

Issue History

Date Modified Username Field Change
2020-11-24 13:56 OkobaPatino New Issue
2020-11-24 14:20 Domingo Galmés Note Added: 0127158
2020-11-24 14:31 OkobaPatino Note Added: 0127159
2020-11-24 21:53 Domingo Galmés Note Added: 0127162
2020-11-25 01:28 Juha Manninen Relationship added related to 0019754
2020-11-25 01:46 Juha Manninen Note Added: 0127169
2020-11-25 07:02 OkobaPatino Note Added: 0127171