[fpc-pascal] fcl-passrc method/function invocations

Michael Van Canneyt michael at freepascal.org
Sun Oct 13 23:13:04 CEST 2019



On Sun, 13 Oct 2019, Ryan Joseph wrote:

> One of my tasks for the language server is determining “references” to a symbol, which means for functions I need to know all the times they were called.
>
> Given the syntax tree the parser creates how do I know when a function was
> called?  I see there is a TPasImplSimple that seems related but I’m not
> sure exactly.  It’s probably possible that it’s not always possible to
> know because there are unresolved types so: a := clss.DoThis; maybe be a
> function call or accessing a proeprty/member variable.

for this you need the resolver. The resolver resolves symbols.

That is a separate step in the process. You would need to traverse the
syntax tree, and let the resolver resolve every symbol encountered in
expressions or function call statements. (or just the symbol names 
you are interested in).

The resolver is implemented in pasresolver.pp and pasresolveeval.pas
(but I think you'll only need the former)

You can attach any amount of data to an element of the AST. 
For instance this could be the number of times the element is accessed.

Separate from the resolver, there is also the pasuseanalyser, 
which analyses if elements are used.

I don't think it keeps a count, though.

Michael.


More information about the fpc-pascal mailing list