Sign in Join

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

Mailing lists / fpc-pascal / 2023-12

method-definition

6 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Adriaan van Os

I am puzzled by the syntax rule <method-list> in Chapter 6. Classes of the FreePascal Language Reference (version 3.2.0)

Section 6.1 Class definitions has

method-definition = [ "CLASS" ] ( function-header | procedure-header | constructor-header | destructor-header ) ";" [ ( ( ( "virtual" | "dynamic" ) [ ";" "abstract" ] ) | "override" | "message" ( integer-constant | string-constant ) ) ";" ] [ call-modifiers ";" ] .

Section 6.6.1 Declaration has:

method-definition = ( function-header | procedure-header | constructor-header | destructor-header ) ";" method-directives .

method-directives = ( ( "virtual" | "dynamic" ) [ ";" "abstract" ] | "reintroduce" ";" | "override" ";" | "message" constant-expression ) [ call-modifiers ";" ] .

Is this supposed to be the same rule for <method-definition> ?

Some notes:

1. I don't see a rule <constant-expression> anywhere in the Language Reference

2. "reintroduce" is in just one of the two definitions.

3. the optional "CLASS" is in just one of the two definitions.

What complicates things, is that many conflicting rules have the same name in the Language Reference. For example, conceptually we have object-methods, record-methods, class-methods, interface-methods and objcclass-methods. But only the record method rules are prefixed as such.

Regards,

Adriaan van Os

Reply by email

Martin Frb
to Adriaan van Os
Adriaan van Os wrote 21 lines
I am puzzled by the syntax rule <method-list> in Chapter 6. Classes of the FreePascal Language Reference (version 3.2.0) Section 6.1 Class definitions has     method-definition = [ "CLASS" ] ( function-header | procedure-header | constructor-header | destructor-header ) ";" [ ( ( ( "virtual" | "dynamic" ) [ ";" "abstract" ] ) | "override" | "message" ( integer-constant | string-constant ) ) ";" ] [ call-modifiers ";" ] . Section 6.6.1 Declaration has:     method-definition = ( function-header | procedure-header | constructor-header | destructor-header ) ";" method-directives .     method-directives = ( ( "virtual" | "dynamic" ) [ ";" "abstract" ] | "reintroduce" ";" | "override" ";" | "message" constant-expression ) [ call-modifiers ";" ] . 2. "reintroduce" is in just one of the two definitions.
Another note: "reintroduce" is given as an alternative to "virtual;
[abstract;]".

However, a method can be reintroduced, and be virtual/abstract.

program Project1;{$Mode objfpc}
type
   TFoo = class
     procedure Bar; virtual; abstract;
   end;
   TFoo2 = class(TFoo)
     procedure Bar; reintroduce; virtual; abstract;
   end;
begin
end.

Reply by email

Mattias Gaertner
to Martin Frb
Martin Frb wrote 11 lines
[...] However, a method can be reintroduced, and be virtual/abstract. type   TFoo = class     procedure Bar; virtual; abstract;   end;   TFoo2 = class(TFoo)     procedure Bar; reintroduce; virtual; abstract;   end;

Can that make sense?

Mattias

Reply by email

Hairy Pixels
to Adriaan van Os: I am puzzled by the syntax rule <method-list> in Chapter 6. Classes of the FreePascal…
On Dec 15, 2023, at 8:56 PM, Adriaan van Os via fpc-pascal wrote: What complicates things, is that many conflicting rules have the same name in the Language Reference. For example, conceptually we have object-methods, record-methods, class-methods, interface-methods and objcclass-methods. But only the record method rules are prefixed as such.

You mean like why records require you to add "static" to class methods? Makes no sense to me either.

I don't understand why record constructors must have parameters while static functions do not.

Regards,
Ryan Joseph

Reply by email

Michael Van Canneyt
to Hairy Pixels
Hairy Pixels wrote 7 lines
> On Dec 15, 2023, at 8:56 PM, Adriaan van Os via fpc-pascal wrote: > > What complicates things, is that many conflicting rules have the same name in the Language Reference. For example, conceptually we have object-methods, record-methods, class-methods, interface-methods and objcclass-methods. But only the record method rules are prefixed as such. You mean like why records require you to add "static" to class methods? Makes no sense to me either.

Well, I guess the explanation is something like the following:

Because class methods normally get a TClass pointer (a class reference) as Self unless you specify self (in which case they become normal records).

Since records do not have a TClass concept, this 'Self' cannot be passed. To be consistent with classes and to make this explicit, the 'static' is required.

In my opinion this is superfluous, but embarcadero decided otherwise.

The requirement for parameters in record constructors I guess comes from C++ builder by Embarcadero. There are some limitations imposed by C++.

Whether they could be dropped in FPC is something Sven Barth should answer.

Michael.

Reply by email

Sven Barth
to Michael Van Canneyt

Michael Van Canneyt via fpc-pascal
schrieb am Sa., 16. Dez. 2023, 09:43:

Show quoted text 6 lines
The requirement for parameters in record constructors I guess comes from C++ builder by Embarcadero. There are some limitations imposed by C++. Whether they could be dropped in FPC is something Sven Barth should answer.

We only "inherited" that for Delphi compatibility. Technically the compiler could handle it without problems... 🤷‍♀️

Regards,
Sven

Reply by email