[fpc-devel] Templates / Generics
Florian Klaempfl
florian at freepascal.org
Fri Nov 4 20:28:15 CET 2005
I read the disussion above and I'll post my thoughts so far below:
- we'll use a syntax as close as possible to Chrome, e.g.
type
TList<T> = class
...
end;
- instantiation will be only possible in declaration blocks, not in code
blocks:
possible:
var
mylist : TList<integer>;
const
mylist : TList<integer> = nil;
type
mylist = TList<integer>;
forbidden:
procedure p(mylist : TList<integer>);
begin
...
mylist:=TList<integer>.create;
...
end;
Maybe we need an exception to this when supporting sub routine templates:
procedure<T> p(mylist : TList<T>);
begin
...
end;
but this doesn't lead to an ambigious syntax.
- instantiation steps which require code generation are done after main
program compilation based on information saved in the unit files, this
has some advantages:
- several equal instantiations require only one specialisation
- it's possible to setup an symbol environment as it has been used in
the template definition, so the cyclic unit use problem is void it
requires though that a lot symbols of the implementation part of a unit
must be written to the unit file if the unit contains a template definition
This approach will require some compiler clean ups but that isn't that
bad ;)
Any comments :)?
More information about the fpc-devel
mailing list