integrated-application-development / integrated-application-development/pasfmt

Expand conditional code inlining capabilities

Open
#207 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
105
Forks
20
PR merge metrics
No merged PRs in 30d

Description

I was not sure if I should add this to the already closed issue so I decided to create a new issue.

The existing behavior still creates an unreadable mess - the following code:

```
Nullable = {$IFDEF NULLABLE_PACKED}packed {$ENDIF}record
private
fValue: T;
fHasValue: {$IFNDEF NULLABLE_CMR}string{$ELSE}Boolean{$ENDIF};

```

gets turned into

```
Nullable =
{$IFDEF NULLABLE_PACKED}
packed
{$ENDIF}
record
private
fValue: T;
fHasValue:
{$IFNDEF NULLABLE_CMR}
string
{$ELSE}
Boolean
{$ENDIF}
;
```

And another one:

```
class operator Implicit(const {$IFDEF SUPPORTS_CONSTREF}[ref]{$ENDIF}value: Lazy): ILazy;
```

turns into:

```
class operator Implicit(
const
{$IFDEF SUPPORTS_CONSTREF}
[ref]
{$ENDIF}
value: Lazy
): ILazy;
```

and I also found this which goes completely bonkers:

```
function IsNullable(typeInfo: PTypeInfo): Boolean;
const
PrefixString = 'Nullable<'; // DO NOT LOCALIZE
begin
Result := Assigned(typeInfo) and (typeInfo.Kind in [tkRecord{$IF Declared(tkMRecord)}, tkMRecord{$IFEND}])
and StartsText(PrefixString, typeInfo.TypeName);
end;
```

turns into:

```
function IsNullable(typeInfo: PTypeInfo): Boolean;
const
PrefixString = 'Nullable<'; // DO NOT LOCALIZE
begin
Result :=
Assigned(typeInfo)
and (typeInfo.Kind
in [
tkRecord
{$IF Declared(tkMRecord)}
,
tkMRecord
{$IFEND}
])
and StartsText(PrefixString, typeInfo.TypeName);
end;
```

This last one is probably also related to what I reported in #205. Even though the overzealous line breaking is bad enough IMO it makes it look worse because it keeps indenting. While I admit that the original does not have the best formatting for readability the formatted one does no better IMHO.

This would already improve it a bit I guess:

```
function IsNullable(typeInfo: PTypeInfo): Boolean;
const
PrefixString = 'Nullable<'; // DO NOT LOCALIZE
begin
Result := Assigned(typeInfo)
and (typeInfo.Kind in [tkRecord{$IF Declared(tkMRecord)}, tkMRecord{$IFEND}])
and StartsText(PrefixString, typeInfo.TypeName);
end;
```

The interesting thing here is that it does not only wrap around the conditionals but also more lines than necessary. If you remove the conditionals around the `tkMRecord` it turns this into a 2 liner.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.