Let us say that I have a Matlab function and I change its signature (i.e. add parameter). As Matlab does not ‘compile’ is there an easy way to determine which other functions do not use the right signature (i.e. submits the additional parameter). I do not want to determine this at runtime (i.e. get an error message) or have to do text searches. Hope this makes sense. Any feedback would be very much appreciated. Many thanks.
Share
This is more or less what the dependency report was invented for. Using that tool, you can find what functions/scripts call your altered function. Then it is just a question of manually inspecting every occurrence.
However, I’d advise to make your changes to the function signature such that backwards compatibility is maintained. You can do so by specifying default values for new parameters and/or issuing a
warningin those scenarios. That way, your code will run, and you will get run-time hints of deprecated code (which is more or less a necessary evil in interpreted/dynamic languages).For many dynamic languages (and MATLAB specifically) it is generally impossible to fully inspect the code without the interpreter executing the code. Just imagine the following piece of code:
In general, you’d say that the
magicfunction is called. However,magiccould map to a totally different function. This could be done in ways that are invisible to a static analysis tool (such as the dependency report): e.g.eval('magic = 1:100;');.The only way is to go through your whole code base, either inspecting every occurrence manually (which can be found easily with a text search) or by running a test that fully covers your code base.
edit:
There is however a way to access intermediate outputs of the MATLAB parser. This can be accessed using the undocumented and unsupported
mtreefunction (which can be called like this:t = mtree(file, '-file');for every file in your code base). Using the resulting structure you might be able to find calls with a certain amount of parameters.