Detect variables implicitly declared

True, but you can rename the type instance. So If I have several modules with a variable “constants”
I can do

        use some_mode1 only :  k=>constants
        use some_mode2, only: x=>constants

and

      associate ( pi=> constants%pi) 
      write(*,*)pi
end associate 

works. Not perfect, but avoids some of the problems with public variables. instead of renaming if the value is a constant a redeclaration can be useful, as in

       real,parameter :: pi=constants%pi

allthough not particulary useful if you want to change the public value. Not perfect, but neither are the alternatives.

I am probably missing something. The variable c didn’t exist in the former version of the code (test1.f90?), so what do you mean by “the variable c gets defined automatically inside legrout because of the implicit typing”?

In the latter version (test2.f90?), c is available by use-association because of the unqualified use mod2. If you comment this line out, the compiler will give you errors for all variables not declared locally. You can then disposition them one-by-one to decide if they should be local variables, or brought in by use-association from the module by adding use mod2, only: b, c, etc.

Does this approach not satisfy the need?

The easy way to do this is to declare all of the implicitly typed variables. To do this in the example code we make an fsp file:

! legrout1.fsp 30-Mar-25 John Collins

% input directory ../src
test1.f90
mod1.f90
legrout1.f

% declare all symbols
! Suppress “Declaration inserted by fpt” message
% suppress diagnostic 4243

% keep output directories
% keep file name extensions
% keep layouts
% edit output file names: replace “src” by “fpt_output”
% overwrite changed files

! End of legrout1.fsp

We run fpt:
$ fpt legrout1.fsp

This makes ../fpt_output/legrout1.f with everything declared. It keeps all the comments, the layouts etc. but pretty-prints the code. The whole story is at
http://simconglobal.com/fortranimplicituse.tar.gz - the forum won’t let me upload it here.

Not really.
You should imagine that test2/1 and mod1/2 are placeholders for hundreds of thounsands of lines of code, not written by me.

I am going to try the three methods suggested and provide a feedback (fpt, spag, dump-fortran-original).

Here is a rudimentary script that performs the parsing.

1 Like