Any tools that scan code and provide a list of functions that invoke a given function

here is my problem, I remove the old code that I modified over the years and remove redundant functions,

I can do it in a slow way and comment on it, and see if the compiler generates an error. But I'm just wondering if there are any tools that can scan the code and give a list of functions that call this function.

I looked at ge-expert and icarus, but they only do this at the unit and class level, not at the functions.

any suggestions are welcome, thank you very much, Brian

+4
source share
5 answers

In recent versions of Delphi there is a "Link Search", available through the context menu or Ctrl-Shift-Enter. This has the advantage over a simple “file search” that it will only find links to the current function under the cursor, and not to any function or other identifier with the same name.

+6
source

Compile your project. Then, in the IDE, those lines that are accessed (rather than dead code) will have a blue dot in the left margin:

enter image description here

+6
source

No method is perfect, the limitations below are:

  • the .MAP file will include functions that the linker cannot resolve (for example, overriding methods in classes affected by your code).
  • it will only give you method names, but if the methods are overloaded, you can use several versions of these methods

The big pro with .MAP files is that they are easier to scan than the blue dots in the code editor.

This way it answers your question to provide a list of functions. But in fact, this may not be the case (:

Method using the .MAP file:

  • modify the project to include a detailed .MAP file
  • rebuild your project
  • the directory of your .EXE file will now contain the .MAP file
  • scan .MAP file for function names included in .EXE

This .MAP file will exclude functions eliminated by the compiler and linker.
This is a good sign that you have a dead code.

Similarly, you can use JDBG information. This contains more context, but also requires that you record some instruments yourself.

+4
source

For Pascal, this is trivial. First create a list of all the functions, then for each function find it in the text without following the word “function”, and then “(”. “Awk” will be a good tool for this.

0
source

If your version of Delphi is 2007 (or maybe before that?), I highly recommend that you consider using DGrok : Give this a try and you will see how capable it is (the demo application will say).

As pointed out by the author, you still need to implement symbol table support so that tools can refactor or Find links strong>: Roll your own ...

Don’t worry if you are stuck in Delphi, PasParse (the Delphi port of the DGrok parser, which was originally written in C #!) From Turbo87.

Note that Turbo87 forked the original Joe White Dgrok (latest version in 2008) (upgrade to VS2010 and add some documentation for LexScanner).

0
source

All Articles