Tools for refactoring legacy codes

The thread on implicit typing and backwards compatability got me thinking about what tools existed for automatic refactoring of old codes. The two I’m familiar with but have never used are camFort and the Polyhedron software plusFort SPAG program. Some IDE’s also have some limited refactoring capability. I’m curious if anyone has experience with camFort and SPAG. camFort is free but SPAG cost major $$$$. Also are there other codes available that have the capabiility to refactor old codes. When I first looked at camFort several years ago, I decided the effort to install was more than I was willing to expend at the time. To build from scratch, you have to install a Haskell compiler and various libraries etc. I see now they have prebuilt binaries so I might give it another look.

For camFort, go to

https://camfort.github.io/

Under the publications link you will find a paper that describes how camFort works. Basically, it acts as a front end compiiler that compiles code to an AST. @certik , could some of the functionality of camFort be embedded in LFortran. The camFort paper link is

For SPAG go to the Polyhedron web site.

https://polyhedron.com/?product=plusfort

4 Likes

Yes, we plan to eventually implement such refactorings. The way LFortran works is that once it can compile the code from fixed-form (in this case) with all the old features into ASR (the LFortran’s internal representation), which is 1:1 with the original code (every feature is represented), we apply ASR->ASR refactorings such as getting rid of equivalence or gotos and other such features, by rewriting it using an equivalent modern feature. Then we have ASR->Fortran printer, that prints ASR in a modern way (free-form, etc.).

5 Likes

fpt will refactor legacy codes in many respects. It converts to free format, and converts many legacy constructs to standard Fortran - for example, DECODE and ENCODE, DEFINE FILE and implicit SAVE. For most applications it is free. See http://simconglobal.com .

1 Like

My list of Fortran tools has sections on Refactoring and Static Analysis. A new refactoring tool is

but I am unable to install it on WSL2
git clone https://github.com/NLESC-JCER/roquefort.git
Cloning into 'roquefort'...
remote: Enumerating objects: 717, done.        
remote: Counting objects: 100% (227/227), done.        
remote: Compressing objects: 100% (153/153), done.        
remote: Total 717 (delta 125), reused 127 (delta 71), pack-reused 490        
Receiving objects: 100% (717/717), 160.58 KiB | 464.00 KiB/s, done.
Resolving deltas: 100% (477/477), done.

(base) /mnt/c/fortran/public_domain$ cd roquefort

(base) /mnt/c/fortran/public_domain/roquefort$ pip install .
Traceback (most recent call last):
  File "/home/bingy/miniconda3/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 23, in <module>
    from pip._internal.cli.progress_bars import BAR_TYPES
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/cli/progress_bars.py", line 12, in <module>
    from pip._internal.utils.logging import get_indentation
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/utils/logging.py", line 18, in <module>
    from pip._internal.utils.misc import ensure_dir
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 33, in <module>
    from pip._internal.locations import (
  File "/home/bingy/miniconda3/lib/python3.8/site-packages/pip/_internal/locations.py", line 64, in <module>
    site_packages = sysconfig.get_path("purelib")  # type: Optional[str]
  File "/home/bingy/miniconda3/lib/python3.8/sysconfig.py", line 521, in get_path
    return get_paths(scheme, vars, expand)[name]
  File "/home/bingy/miniconda3/lib/python3.8/sysconfig.py", line 511, in get_paths
    return _expand_vars(scheme, vars)
  File "/home/bingy/miniconda3/lib/python3.8/sysconfig.py", line 172, in _expand_vars
    _extend_dict(vars, get_config_vars())
  File "/home/bingy/miniconda3/lib/python3.8/sysconfig.py", line 559, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/home/bingy/miniconda3/lib/python3.8/sysconfig.py", line 430, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_x86_64_conda_linux_gnu'

Can someone else try it?

Installs cleanly with Python 3.10 on Arch Linux.

1 Like

I have also used yapakit, sadly not now maintained, see Yapakit

I think findent download | SourceForge.net (easier installations: findent · PyPI, Findent :: Anaconda.org) has some refactoring capabilities although I have never personally tested them. It claims it can convert fixed to free form and vice versa, relabel statements and complete end statements. Not sure I would go as far as call that refactoring, but it might be enough for some.