Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2017-11

fpc procedure modifier []

13 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Maciej Izak
to Mattias Gaertner

2017-11-16 11:39 GMT+01:00 Mattias Gaertner :

What $modes support this? The reason I ask is I'm trying to distinguish them from Delphi Attributes in pparser.

for Delphi like attributes FPC will have new modeswitch "prefixedattributes" . The implicit usage for $prefixedattributes in DELPHI/DELPHIUNICODE mode is not decided yet (but IMO this is probable scenario).

Best regards, Maciej Izak

Reply by email

Mattias Gaertner
to Maciej Izak
Show quoted text 10 lines
2017-11-16 11:39 GMT+01:00 Mattias Gaertner : > What $modes support this? > The reason I ask is I'm trying to distinguish them from Delphi > Attributes in pparser. > for Delphi like attributes FPC will have new modeswitch "prefixedattributes" . The implicit usage for $prefixedattributes in DELPHI/DELPHIUNICODE mode is not decided yet (but IMO this is probable scenario).

Good to know. Thanks.

So, how will FPC distinguish the two []?

Mattias

Reply by email

Sven Barth
to Mattias Gaertner

Am 16.11.2017 14:01 schrieb "Mattias Gaertner" :

Show quoted text 8 lines
2017-11-16 11:39 GMT+01:00 Mattias Gaertner : > What $modes support this? > The reason I ask is I'm trying to distinguish them from Delphi > Attributes in pparser. > for Delphi like attributes FPC will have new modeswitch

"prefixedattributes" .

The implicit usage for $prefixedattributes in DELPHI/DELPHIUNICODE mode

is

not decided yet (but IMO this is probable scenario).

Good to know. Thanks.

So, how will FPC distinguish the two []?

The only idea I have is to check whether the first identifier is a attribute and if not handle it as a modifier (or if a comma is following the first identifier).

Regards,
Sven

Reply by email

Maciej Izak
to Mattias Gaertner: On Thu, 16 Nov 2017 11:49:59 +0100 Good to know. Thanks. So, how will FPC distinguish the…

2017-11-16 14:01 GMT+01:00 Mattias Gaertner :

Good to know. Thanks. So, how will FPC distinguish the two []?

for now the idea is very simple: for active prefixedattributes "procedure modifier []" will be inaccessible (which means breaking for backward compatibility). This is the reason why $prefixedattributes in DELPHI/DELPHIUNICODE may be not enabled by default. In Delphi mode "procedure modifier []" is used very rare (if ever?) so I see no real problem (even if the problem exist can be simple eliminated by switching off prefixedattributes).

anyway maybe is possible to use both "[]" at the same time, but that need to be checked.

Best regards, Maciej Izak

Reply by email

Mattias Gaertner
to Sven Barth: On Thu, 16 Nov 2017 11:49:59 +0100 "prefixedattributes" . is Good to know. Thanks. So,…
Show quoted text 7 lines
[...] So, how will FPC distinguish the two []? The only idea I have is to check whether the first identifier is a attribute and if not handle it as a modifier (or if a comma is following the first identifier).

pparser can't do that.

And I fear that this heuristic will lead to confusing error messages. I hope there is a better way.

Delphi does not support it. It thinks it is an undefined attribute. So IMO FPC's [] modifier should be disabled in mode delphi+delphiunicode. So the problem will only happen in mode objfpc or when the user enable the modeswitch prefixedattributes.

Maybe pparser can use a heuristic. What is the syntax and keywords of fpc's [] modifier?

If it is correct that FPC's modifier was never documented and is hardly used, perhaps a $modeswitch procmodifierbrackets can be added?

Mattias

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 20 lines
On Thu, 16 Nov 2017 14:12:18 +0100 Sven Barth via fpc-pascal wrote: > [...] > So, how will FPC distinguish the two []? > > > The only idea I have is to check whether the first identifier is a > attribute and if not handle it as a modifier (or if a comma is following > the first identifier). pparser can't do that. And I fear that this heuristic will lead to confusing error messages. I hope there is a better way. Delphi does not support it. It thinks it is an undefined attribute. So IMO FPC's [] modifier should be disabled in mode delphi+delphiunicode. So the problem will only happen in mode objfpc or when the user enable the modeswitch prefixedattributes.

I think that prefixedattributes should simply disable the use of proc modifier []. The probability of having code that needs both is almost zero, the [] syntax is very old and almost not used.

Mode Delphi(Unicode) enables prefixedattributes, all other modes need an explicit modeswitch to enable it.

Let's keep it clear, simple and unambiguous.

Michael.

Reply by email

Maciej Izak
to Michael Van Canneyt

2017-11-16 15:21 GMT+01:00 Michael Van Canneyt :

Show quoted text 8 lines
I think that prefixedattributes should simply disable the use of proc modifier []. The probability of having code that needs both is almost zero, the [] syntax is very old and almost not used. Mode Delphi(Unicode) enables prefixedattributes, all other modes need an explicit modeswitch to enable it. Let's keep it clear, simple and unambiguous.

+1 . so I think that we have clear situation.

Best regards, Maciej Izak

Reply by email

Sven Barth
to Mattias Gaertner: On Thu, 16 Nov 2017 14:12:18 +0100 pparser can't do that. And I fear that this heuristic…
Mattias Gaertner wrote 23 lines
On Thu, 16 Nov 2017 14:12:18 +0100 Sven Barth via fpc-pascal wrote: > [...] > So, how will FPC distinguish the two []? > > > The only idea I have is to check whether the first identifier is a > attribute and if not handle it as a modifier (or if a comma is following > the first identifier). pparser can't do that. And I fear that this heuristic will lead to confusing error messages. I hope there is a better way. Delphi does not support it. It thinks it is an undefined attribute. So IMO FPC's [] modifier should be disabled in mode delphi+delphiunicode. So the problem will only happen in mode objfpc or when the user enable the modeswitch prefixedattributes. Maybe pparser can use a heuristic. What is the syntax and keywords of fpc's [] modifier?

Keywords are all supported modifiers.

"[" <MODIFIER> [,<MODIFIER>[,...]] "]"

And this can be mixed and matched with non-bracketed modifiers, so the following is valid:

=== code begin ===

procedure Bla; cdecl; [public, overload]; iocheck;
begin
end;

=== code end ===

If it is correct that FPC's modifier was never documented and is hardly used, perhaps a $modeswitch procmodifierbrackets can be added?

It is at least not totally undocumented:
https://www.freepascal.org/docs-html/current/ref/refsu81.html#x199-22100014.10.12

It's a feature that FPC supports and thus there are probably users out there that use it no matter whether it's in Delphi mode or not.

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth: On Thu, 16 Nov 2017 11:49:59 +0100 "prefixedattributes" . is Good to know. Thanks. So,…
Sven Barth wrote 28 lines
Am 16.11.2017 14:01 schrieb "Mattias Gaertner" < >: On Thu, 16 Nov 2017 11:49:59 +0100 Maciej Izak < > wrote: > 2017-11-16 11:39 GMT+01:00 Mattias Gaertner < >: > > > What $modes support this? > > The reason I ask is I'm trying to distinguish them from Delphi > > Attributes in pparser. > > > > for Delphi like attributes FPC will have new modeswitch "prefixedattributes" . > The implicit usage for $prefixedattributes  in DELPHI/DELPHIUNICODE mode is > not decided yet (but IMO this is probable scenario). Good to know. Thanks. So, how will FPC distinguish the two []? The only idea I have is to check whether the first identifier is a attribute and if not handle it as a modifier (or if a comma is following the first identifier). 

One other point to differentiate them: the modifier one always ends with a semicolon after the closing bracket, Delphi's attributes never do that.

Regards,
Sven

Reply by email

Sven Barth
to Maciej Izak
Maciej Izak wrote 17 lines
2017-11-16 20:17 GMT+01:00 Sven Barth via fpc-pascal < >: One other point to differentiate them: the modifier one always ends with a semicolon after the closing bracket, Delphi's attributes never do that. sadly this is not true at all :( see: https://svn.freepascal.org/cgi-bin/viewvc.cgi?view=revision&revision=35000 in above example it works without semicolon without any problems 

Okay, that might be true in the middle of the modifier list, but not if it's the last one:

=== code begin ===

unit tprocmod;
interface
procedure Bla; cdecl; [public, overload]
var
  test: LongInt;
implementation
procedure Bla;
begin
end;
end.

=== code end ===

This results in "Syntax error, ";" expected but "VAR" found".

In how far that can be used to handle the modifiers and attributes together in parallel needs to be seen...

Regards,
Sven

Reply by email

Mattias Gaertner
to Maciej Izak: 2017-11-16 15:21 GMT+01:00 Michael Van Canneyt : +1 . so I think that we have clear…
Show quoted text 10 lines
2017-11-16 15:21 GMT+01:00 Michael Van Canneyt : > I think that prefixedattributes should simply disable the use of proc > modifier []. The probability of having code that needs both is almost zero, > the [] syntax is very old and almost not used. > > Mode Delphi(Unicode) enables prefixedattributes, all other modes need an > explicit modeswitch to enable it. > > Let's keep it clear, simple and unambiguous.

I like clear, simple and unambiguous.

+1 . so I think that we have clear situation.

Mattias

Reply by email