[fpc-devel] Multiple type sections - Far forward type declarations [feasible feature request?]

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Oct 31 10:26:49 CET 2017


On Tue, 31 Oct 2017 09:46:52 +0100 (CET)
Michael Van Canneyt <michael at freepascal.org> wrote:

>[...]
> With your extended "forward type resolution" this would no longer be possible.
> Theoretically it probably can, but multiple passes would be needed. 
> This would aversely affect the compiler speed.

True for such an extended forward.
FPC allows only a simple forward. For example this is not allowed:

type
  TAnimal = class;
  TBird = class(TAnimal) end;
  TAnimal = class end;

The check at the end of a type section is done for usability, so that
missing declarations are spotted early and you cannot write spaghetti
code. There is no technical reason to check later, e.g. at the end of
the unit interface.

 
> Maybe some form of section folding (Type A ... Type B ->  Type A, B) can be done.
> 
> But maybe h2pas can be improved. multiple "type' sections following each
> other should not happen.

+1

Another solution is the h2paswizard in Lazarus, which uses h2pas and
various codetools. One of them sorts the declarations.


Mattias



More information about the fpc-devel mailing list