开发者

Are there any tools that can "find references" to built in ops?

开发者 https://www.devze.com 2022-12-19 18:30 出处:网络
I was reading the explanation under this item in the Google C++ style guide and it got me thinking; are there any tools that work like VS\'s \"Find all references\" tool but for built in ops and the l

I was reading the explanation under this item in the Google C++ style guide and it got me thinking; are there any tools that work like VS's "Find all references" tool but for built in ops and the like? For example s开发者_StackOverflow社区ay I want to find all places where the native "+" operator is used on a pointer (or maybe just a pointer to an object) and an integer, or where signed and unsigned types are added.


To determine which ops are "built-in", you have to be able to parse C++, and determine for each subexpression, what the types of the operands are. The built-in ops are then the ones selected when the operands are scalars of type char, int, long, float, double, pointer, etc. (The non-built-in ones are function names and operator punctuation that has been used to override such operators in various class definitions).

Parsing C++ is pretty hard by most people standards. "Just" a parser/lexer won't get you there soon or easily. What is really hard is resolving the meaning of the names, determining the types of names, and then determining what the various subexpressions means, because you have to encode the several-hundred pages of the C++ standard which decribes how all that works. What you really want is a pre-built C++ front end that will bend to your will.

While GNU and MSVC have full C++ front ends, they really want to be a compiler, and pretty much can't be coerced into helping you easily.

The DMS Software Reengineering Toolkit would be ideal for this task. It is designed to support the construction of custom analysis tools, and has full language front ends for many standard languages, including C, Java, C#, COBOL ... and finally, C++.

DMS parses source text just like the compiler, builds compiler data structures (trees, symbol tables, etc.) and makes those available mostly by a procedural API to let you write queries against those data structures.

One of those queries is, "for this tree, which is the type?". Using that, it is pretty straightforward to determine if you have a "standard" operator such as integer-add.

EDIT: (Oddly enough, several days after writing this answer, I just got a small contract to identify all the non-built in operators in a C++ program!).


I am not aware of such tools, but if you have access to parser/lexer, then in principle you can create such tool. I do not know much about Visual Studio and how much access you have to write your own plug-ins. It should be possible with eclipse or netbeans. If you are emacs user, take a look at cedet. I am currently messing around with it, and it seems not too difficult to implement such tool using semantic database.

0

精彩评论

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