you may have come across a situation where you rename variables in large projects and it takes you a week to get it consistent such that the compiler doesn’t complain. For example, changing subroutine subroutine s(foo,bar) to subroutine s(fooo,bar) will require to change any call s(foo=a,bar=b) to call s(fooo=a,bar=b). The same holds for derived type member variables where the variable is accessed directly (so not through get/set).
I am wondering whether there is any automatic tool to do this job.
Isn’t there a compiler flag for unused variables?!
I just had a quick glance at the eclipse interface, and for somebody coming from the emacs/makefile league it looks all too much. However, I was wondering how I can attached an existing project to it which runs from an operational makefile, e.g. five hierachical libraries and several executables using those libraries. Any hint appreciated.
Yes, most compilers have flags that will tell you about unused variables and arguments, but if you’ve got lots of them, it’d be nice to have a tool that can automatically remove them all from your source code. Or at least make the process a lot easier.
I am interested in a tool that removes unused variables. They commonly arise in my code when I have refactored a chunk of code into a subroutine. Here is Python 3 code that splits declarations (after the real :: part) into individual variables. One can use it to rewrite declarations after omitting specified variables.
# https://stackoverflow.com/questions/40770990/split-string-by-comma-but-ignore-commas-in-brackets-or-in-quotes
import re
str = "x,y(n),z(n,n),a(m)"
words = re.split('(,(?=[^\\)]*(?:\\(|$)))',str)
var = [w for w in words if w != ","]
print(var)
gives output ['x', 'y(n)', 'z(n,n)', 'a(m)']. I know I am recreating the wheel.
Provides lexing, parsing, and basic analyses of Fortran code covering standards: FORTRAN 66, FORTRAN 77, Fortran 90, Fortran 95 and part of Fortran 2003. Includes data flow and basic block analysis, a renamer, and type analysis.