marshallward / flint Goto Github PK
View Code? Open in Web Editor NEWA framework for building Fortran code analysis tools in Python.
License: Apache License 2.0
A framework for building Fortran code analysis tools in Python.
License: Apache License 2.0
For possible inclusion into some future documentation:
From section 6.2 Luca Bonaventura, René Redler and Reinhard Budich. “Earth System Modelling - Volume 2.”, there is a section on "Software Coding Standards". It mentions the following Fortran static analyzers:
“FLINT Manual (1994) User’s manual, FORTRAN-lint source code analyzer. http://www.fnal.gov/docs/products/flint/manual.txt”
“FTNchek Tool (2004) ftnchek static analyzer for Fortran. http://www.dsm.fordham.edu/ftnchek/”
A quick Google search leads to a commercial product:
Cleanscape FortranLint
https://stellar.cleanscape.net/products/fortranlint/index.html
Hi @marshallward, I'm having difficulties updating the MOM5 diagnostics list following these instructions. I've cloned the latest MOM5 and Flint and made a script parse.py
from flint.project import Project
proj = Project(verbose=True)
proj.parse('../MOM5/src/mom5')
which I put in the flint
directory arranged like so
.
├── MOM5
│ ├── LICENSE
│ ├── README
│ ├── README.md
│ ├── bin
│ ├── data
│ ├── doc
│ ├── exp
│ ├── src
│ └── test
└── flint
├── README.rst
├── flint
├── out
├── parse.py
├── test
└── tools
but python3 parse.py > out
fails with
Traceback (most recent call last):
File "parse.py", line 4, in <module>
proj.parse('../MOM5/src/mom5')
File "/Users/andy/Documents/COSIMA/github/mom-ocean/flint/flint/project.py", line 37, in parse
f90file.parse(fpath)
File "/Users/andy/Documents/COSIMA/github/mom-ocean/flint/flint/source.py", line 70, in parse
unit.parse(flines)
File "/Users/andy/Documents/COSIMA/github/mom-ocean/flint/flint/units/unit.py", line 139, in parse
self.parse_header(lines.current_line)
File "/Users/andy/Documents/COSIMA/github/mom-ocean/flint/flint/units/unit.py", line 175, in parse_header
self.name = line[utype_idx + 1]
IndexError: list index out of range
If it's any help, tail -20 out
yields
X: return
X: end function rho_feistel
M: end module eqstate
../MOM5/src/mom5/ocean_param/gotm-4.0/util/ode_solvers.F90 (../MOM5/src/mom5/../MOM5/src/mom5/ocean_param/gotm-4.0/util/ode_solvers.F90)
flint: unsupported preprocess directive: include"cppdefs.h"
[]
S: subroutine ode_solver ( solver , numc , nlev , dt , cc , right_hand_side_rhs , right_hand_side_ppdd )
I: implicit none
D: integer , intent ( in ) :: solver , nlev , numc
E: realtype , intent ( in ) :: dt
E: realtype , intent ( inout ) :: cc ( 1 : numc , 0 : nlev )
E: interface
E: subroutine right_hand_side_ppdd ( first , numc , nlev , cc , pp , dd )
E: logical , intent ( in ) :: first
E: integer , intent ( in ) :: numc , nlev
E: realtype , intent ( in ) :: cc ( 1 : numc , 0 : nlev )
E: realtype , intent ( out ) :: pp ( 1 : numc , 1 : numc , 0 : nlev )
E: realtype , intent ( out ) :: dd ( 1 : numc , 1 : numc , 0 : nlev )
S: end
AFAIKR we only made that diagnostics list once, a couple of years ago.
In our MIRIAD project we have a flint tool, where perhaps there are ideas that might be useful for you to check. It's written in C, and we used it to check out Fortran77 based code for the most obvious mistakes that the compiles (at the time) didn't catch.
I noticed the most recent gfortran-10 compiler is getting ahead (in some areas) of what our flint can do.
So, not an issue, just a comment.
https://github.com/astroumd/miriad/blob/master/src/tools/flint.c
Could you provide installation instructions?
Here are some tough line continuation tests:
Here are three test files:
$ ls reserved_0*
reserved_01.f90 reserved_02.f90 reserved_03.f90
$ cat reserved_0*
program reserved_01
implicit none
if (end(1, 2) /= 2) error stop
if (end(2, 1) /= 2) error stop
contains
integer function end(return,&
integer)result(function);;;;&
integer integer,return;;;;;;&
;;function=return;if(return>&
integer)return;;;;;function=&
integer;;end function end;;;;
end program
program reserved_02
implicit none
if (integer() /= 1) error stop
contains
integer function integer()
integer function
function = function/function
integer = function
end function
end program
program reserved_03
implicit none
integer endsubroutine
call integer
if (endsubroutine /= 1) error stop
contains
subroutine integer
integer subroutine
endsubroutine &
= subroutine/subroutine
endsubroutine &
; end program
And here is the output of Flint:
./reserved_01.f90 (././reserved_01.f90)
P: program reserved_01
I: implicit none
E: if ( end ( 1 , 2 ) /= 2 ) error stop
E: if ( end ( 2 , 1 ) /= 2 ) error stop
P: contains
F: integer function end ( return , integer ) result ( function ) ; ; ; ; integer integer , return ; ; ; ; ; ; ; ; function = return ; if ( return > integer ) return ; ; ; ; ; function = integer ; ; end function end ; ; ; ;
E: end program
F: end program
F: end program
P: end program
./b.f90 (././b.f90)
M: module a
M: contains
S: subroutine b ( )
D: logical :: if
E: if = .false.
E: if ( if ) if = .true.
S: end subroutine
M: end module
./reserved_03.f90 (././reserved_03.f90)
P: program reserved_03
I: implicit none
D: integer endsubroutine
E: call integer
E: if ( endsubroutine /= 1 ) error stop
P: contains
S: subroutine integer
D: integer subroutine
E: endsubroutine = subroutine / subroutine
E: endsubroutine ; end program
S: endsubroutine ; end program
S: endsubroutine ; end program
P: endsubroutine ; end program
./reserved_02.f90 (././reserved_02.f90)
P: program reserved_02
I: implicit none
E: if ( integer ( ) /= 1 ) error stop
P: contains
F: integer function integer ( )
D: integer function
E: function = function / function
E: integer = function
F: end function
P: end program
The lines like E: endsubroutine ; end program
or E: end program
do not seem to be correct.
Hi Marshall
When I try parsing the MOM5 source I get
File "/Users/andy/Documents/COSIMA/github/mom-ocean/flint/flint/units/unit.py", line 191, in parse_header
self.name = line[utype_idx + 1]
IndexError: list index out of range
here
Line 191 in 7683da4
This occurs when line = ['end', 'interface']
with self.utype
='interface', so utype_idx
= 1
Should this be
self.name = line[utype_idx]
?
In order to integrate flint to handle docstrings, it would be helpful (maybe even necessary) to track the original unmodified and case-sensitive form of the tokens, such as variable or function names.
This was raised in NOAA-GFDL/MOM6#970. Thanks to @jr3cermak for raising this issue.
I suggest adding topics such as fortran
, static-analysis
, linter
in the About section at https://github.com/marshallward/flint.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.