用于删除 Fortran 代码中未使用的局部变量的工具
有没有一些好的工具可以从自由形式的 Fortran 代码中删除未使用的局部变量?
背景是我们有一个非常大的代码库,并且在过去 20 年里一直禁用未使用的警告,因此警告数量相当多,太多而无法手动修复。
我知道 Photran 有这种重构功能,但我尝试了一下却遇到了问题。由于某种原因,它要求可以解析整个源代码(它无法对我们的代码库进行解析)来进行重构,尽管对于这种重构,在我看来应该足以仅检查单个文件。
Is there some good tool for removing unused local variables from free form Fortran code?
The background is that we have a codebase which is very large, and unused warnings has been disabled for the last 20 years, so there are quite a lot of them, too many to fix manually.
I know Photran has that kind of refactoring, but I tried it and ran into problems. For some reason it requires that the entire source code can be parsed (which it does not manage to do with our codebase) to do the refactoring, although for this refactoring it should IMO be enough to just check single files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我是根据编译器消息手动完成此操作的。一种可能的自动工具:SPAG / plusFORT 的文章说:
我使用过免费的、精简功能的版本,但不记得该版本是否删除了未使用的变量。
I've done this by hand, based on the compiler messages. One possible automatic tool: the writeup for SPAG / plusFORT says:
I've used the free, reduced functionality version but don't remember whether that version removed unused variables.
这将作为一个答案,因为它无法放入评论框中 - 但不要将其视为答案,更多的是作为评论
除此之外,抱歉,但我不知道不认为存在这样的工具。 TZXH 问你正在使用什么编译器 - 不是因为它有那么大的区别,而是(我认为)因为他可能正在考虑解析编译器警告以获取变量列表,然后浏览 Fortran 文件,然后半-手动删除这些变量。
我从来没有做过这样的事情,但这是一个可行的过程。有一些潜在的缺点,但它可以工作。
除此之外,为了分析(并编写新的,因为它确实是一个非常好的 IDE)Fortran 源代码,我找到了 SciTools了解一个非常有用的工具。不确定它是否具有满足您要求的功能,但它可能会有所帮助。
this is going as an answer, cause it can't fit in a comment box - don't think of it as an answer though, more of as a comment
Apart from that, sorry, but I don't think such a tool exists. TZXH asked what compiler you're using - not because it makes that much of a difference, but (I think) because maybe he was thinking of maybe parsing compiler warnings to get a list of variables, then going through Fortran files, and semi-manually removing those variables.
I've never done anything like that, but it's a process that could work. Has some potential drawbacks but it could work.
Apart from that, for analysis (and writing new one, for it is really a very nice IDE) of Fortran source code I found SciTools Understand a very helpful tool. Not sure whether it has a feature to do what you're asking, but it could help.
有一个“美化”Python 脚本作为 GPL CP2K 工具链的一部分。您可以在 CP2K 项目源存储库中找到它。您将需要 prettify.py 和 normalizeFortranFile.py 脚本。由于它还尝试“美化”文件,因此如果您确实只想删除局部变量,则必须编辑脚本。
There is a "prettify" Python script as part of the GPL CP2K toolchain. You can find it in in the CP2K project source repository. You will need the prettify.py and normalizeFortranFile.py scripts. Since it also tries to "prettify" the file, you will have to edit the script if you really only want to remove local variables.
对于 gfortran,你可以使用这个 perl 脚本,参数“build_log”应该是 gfortran -Wunused 的输出(或者任何让你未使用的变量警告):
显然你应该查看源代码并检查它是否做了你想要它做的事情。但粗略地说,它读取编译器输出并删除编译器在其抱怨的行上抱怨的变量。
For gfortran you can use this perl script, the argument "build_log" should be the output of gfortran -Wunused (or whatever gets you unused variable warnings):
Obviously you should look at the source and check that it does what you want it to do. But roughly speaking it reads the compiler output and removes the variable that the compiler complains about on the line which it is complaining.
PlusFORT 是您唯一的选择,而且价格并不便宜。但它已经在数百万行旧的 Fortran (77) 代码上使用,并且相当成熟。如需意见,请尝试 comp.lang.fortran
PlusFORT is your only option and its not cheap. But it has been used on millions of lines of old Fortran (77) code and is fairly mature. For opinions try comp.lang.fortran