Recent

Author Topic: TPasSrcAnalysis enhancements?  (Read 901 times)

dsiders

  • Hero Member
  • *****
  • Posts: 1080
TPasSrcAnalysis enhancements?
« on: March 30, 2020, 07:10:05 pm »
I have been using TPasSrcAnalysis (passrcutil.pp) to examine source code, and it works well for most use cases. But it lacks some flexibility when used for source which doesn't follow certain conventions.

Specifically, it doesn't allow you to have code where include files (.inc) are in a directory other than the one where the source is located. The file resolver, scanner, and parser have the tools needed... you just can't access them because they're hidden away in private members with no API to configure them. To overcome this, you basically have to re-implement the class, and in some cases the storage container since its in the implementation section of the unit.

I think it would be useful to make it a little more configurable. For example, add properties for:

Code: [Select]
IncludePaths: TStrings;
Defines: TStrings;
ContainerClassType: TPasTreeContainerClass; // does not exist ATM

They can be accessed and maintained before Parse gets called.

CheckParser could be modified to use these values when creating/configuring the internal members:

Code: [Select]
FResolver // Call .AddIncludePath for each value in IncludePaths
FContainer // := FContainerClassType.Create;
FScanner // Call .AddDefine for each item in Defines

These measures eliminate the need to subclass for most use cases.

Just thinking out loud. Feedback appreciated.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: TPasSrcAnalysis enhancements?
« Reply #1 on: March 30, 2020, 10:44:30 pm »
If you don't want to make any changes to the unit file that fits your needs you can do a local class hack which then may allow you to override some features so you can implement some of your own...

For example in your working project

Type
 TParSrcAnalysis = Class(TheUnitFileItLivesIn.TParSrcAnalysis)

   Add your stuff here and override existing stuff..

 End;

Basically if this is seen first locally it will behave on your added features without modifying the original.

 Also, you have class helpers that can also give you some flex...
The only true wisdom is knowing you know nothing

dsiders

  • Hero Member
  • *****
  • Posts: 1080
Re: TPasSrcAnalysis enhancements?
« Reply #2 on: March 30, 2020, 11:43:29 pm »
If you don't want to make any changes to the unit file that fits your needs you can do a local class hack which then may allow you to override some features so you can implement some of your own...

For example in your working project

Type
 TParSrcAnalysis = Class(TheUnitFileItLivesIn.TParSrcAnalysis)
   Add your stuff here and override existing stuff..
 End;

Basically if this is seen first locally it will behave on your added features without modifying the original.

Also, you have class helpers that can also give you some flex...

Interceptor... got it. Good idea.

Not sure if class helpers would be useful, because I don't know much about them. I'll check the language reference. Thanks.

Obviously, the preferred option is getting the original modified accordingly.

Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018