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.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to