开发者

Tool to find commented out VHDL code

开发者 https://www.devze.com 2023-02-15 09:02 出处:网络
This question asks the general question. I\'m asking about VHDL in particular, since the tools 开发者_运维知识库that question\'s answer mentions are for Java and PL/SQL. It doesn\'t need to be perfect

This question asks the general question. I'm asking about VHDL in particular, since the tools 开发者_运维知识库that question's answer mentions are for Java and PL/SQL. It doesn't need to be perfect, some manual interpretation would be fine. I'm doing this for an automated commit task.

EDIT 3/9/11: @phillipe pointed out automated commit task is inconsistent with manual interpretation. I'm trying to encourage other engineers to get rid of code and see that they did it. I guess a pessimistic tool would be better for commits; if it misses some code that isn't the end of the world. Or I could make it report the number of such lines and email me rather than stop the commit.


It seems to me that the ideal answer requires that you apply a parser that can recognize langauge substrings to the content of each comment. If the syntax error rate is small compared to the size of the comment, then you have commented-out code.

To do this, you need a parser that is willing to parse incomplete code fragments. Program transformation systems that offer source-to-source transformations (if you see this structure, replace it by that structure) have this machinery built-in; they must parse code patterns comprising the source-to-source transformations, which are generally language sentential forms.

Our DMS Software Reengineering Toolkit has exactly this property. As usual with DMS, it would have to be configured to parse VHDL (or Verilog) [this easy, DMS has full VHDL, Verilog and SystemVerilog front ends), scan the parse tree, find the attached comments (DMS captures comments as it parses), and then attempt to parse the comments using DMS's built-in "Pattern Parser". Some bookeeping to count syntax errors is needed. So this is possible.

I suspect it isn't worth the trouble. Your regexp hueristic is probably pretty good especially when backed up by a human being, if that human doesn't mind having to extra code reviews.


Here's what I am using so far

egrep  "^\s*--.*[;,]$" *.vhd

i.e., find lines that may have whitespace, then text, and end in a ; or ,. I found commas in comments were normal but those two characters were frequently comments out code since they frequently used at the end of VHDL lines.

Using what @Freddy Mallet suggested in the referenced about keywords, I came up with this. I tried to use VHDL keywords that aren't commonly used in English. This tended to work well for the same code, but had troubles on comments such as "process for ...". You might wish to use egrep -f and put the regexp in a file.

  egrep "^\s*--.*([;,]$|\s(architecture|array|assert|begin|block|case|component|downto|elsif|entity|generate|generic|inout|library|null|package|port|range|records|select|signal|type|until)\s)" src/*.vhd    
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号