[fpc-devel] Thoughts on being able to declare "pointer-to-type" parameters directly in method signatures?

Bernd Oppolzer bernd.oppolzer at t-online.de
Mon Jun 10 02:31:31 CEST 2019


Am 10.06.2019 um 00:28 schrieb Ben Grasset:
> On Sun, Jun 9, 2019 at 11:26 AM Florian Klämpfl 
> <florian at freepascal.org <mailto:florian at freepascal.org>> wrote:
>
>     Yes, but this has *nothing* to do with the output of -vp. Nothing.
>
>
> My point with that was more just getting at "clearly typed pointer 
> aliases are not actually that big of a deal internally for FPC", as in 
> it doesn't really matter if it *technically* declares a new type.
>
> Again, literally nobody in this entire message chain has stated any 
> actual reason why exactly they think it would be specifically *bad* to 
> have `^Type` in method parameters.


A compiler writer's point of view:

I did something similar recently, when I added types with parameters to my
New Stanford Pascal compiler (for example CHAR (15), STRING (25), 
DECIMAL (15, 2)).
I decided to allow this notation in procedure declarations, too.

This has the following impacts on the compiler:

- you have to parse "type with parameters" in procedure declarations, 
where you had only
type identifiers up to now

- you have to construct a new "artificial" type record with a name which 
is not a normal identifier
but which matches for identical notations used later and insert this 
record into the type list on
first occurence. In my case, the types CHAR (n) etc. are standard types, 
so they are inserted
into the type list of the top-level block, even if they occur at lower 
levels (there is one entry for
CHAR (n) for every different value of n, although the CHAR (n) types are 
compatible to each other
to a certain degree, same goes for STRING (n) - CHAR (n) is simply an 
abbreviation for
ARRAY [1..n] of CHAR; STRING (n) are varying length strings, involving a 
length field).

In the case of the pointer notation, things would be different:

- a pointer symbol should be accepted in front of the type identifier 
(or in my case, "type with parameters")

- the base type must have been declared already

- if there is no definition for this pointer type, also in this case a 
new "artificial" type record must be built,
but the type record should be inserted at the same level as the record 
of the base type. The generated
name should be unique, not a normal identifier, and dependent from the 
base type identifier.

But:

I am still not sure, if it is a good idea, because this would be an 
exception for pointer types;
other type constructors like arrays, records, enumerations etc. are 
still not supported ...
and it does not make sense IMO to support them.

Kind regards

Bernd

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190610/429abfe7/attachment.html>


More information about the fpc-devel mailing list