[Pas2js] Compiler Options as Hints in Pas sources?

Mattias Gaertner nc-gaertnma at netcologne.de
Fri Dec 21 16:53:49 CET 2018


On Fri, 21 Dec 2018 11:38:03 +0100 (CET)
Michael Van Canneyt <michael at freepascal.org> wrote:

>[...]
> I had a quick look to see how this should be implemented, with the
> idea to take some of the load off you. It turns out to be a little
> more complicated than simply parsing the flag :)

Yes.

 
> Since this would be a local switch, this requires quite some changes,
> as the units or identifiers need to be tagged. Maybe a simple
> solution would be to keep a local flag in TPas2JSCompilerFile and
> mark all the identifiers simply as used while parsing when in
> RemoveNotUsedDeclarations. So
> 
> function TPas2jsCompilerFile.OnConverterIsElementUsed(Sender: TObject;
>    El: TPasElement): boolean;
> 
> begin
>    if Not LocalRemoveNotUsedDeclarationsFlag then
>       Result:=False
>    else
>      // The rest.
> end;
> 
> What do you think ?

Modeswitches, boolswitches (e.g. range checking), and these
custom switches can change at any place, but usually the number of
changes are far less than the number of identifiers/statements.
IMO it would be a waste of memory to add all flags to TPasElement.
At the moment pas2js stores the modeswitches and boolswitches in the
resolver scopes of units, classes and procedures. Of course this is
only a workaround.

One idea is to use a similar method as codetools:
Add a byte position to TPasElement and store a list of flag changes in
the scanner. Then add functions to query a flag at a specific byte
position.
This would allow to implement $push/$pop as well.

Mattias


More information about the Pas2js mailing list