Thread: [GD-General] C++ analyzers?
Brought to you by:
vexxed72
From: Brian H. <bri...@py...> - 2002-07-17 18:34:39
|
One of my bitches about software development are that the tools suck. Many things that can and should be automated simply aren't. Tools like Emacs and make provide a lot of helpers when you have to do this manual stuff, but they don't actually solve problems that are language specific (since those tools aren't language specific). When working on a large codebase, invariably it acquires several layers of cruft and detritus. Several Java IDEs provide high level tools to do things like refactor, automatically name types and objects, etc. This can be immensely useful. Now that I'm parked on about 120K of source code that I've written, there are times when I want to issue a "query" about some type or variable. Of course, that query ends up being "grep", which completely and utterly sucks when you have lots of name collisions. There are certain variable and function names that are so ubiquitous that grepping for them returns a thousand hits. init/create/alloc and shutdown/destroy/free; flags, type, name, next, prev, id; etc. One way I've gotten around this is defensive coding, whereby I prefix members with their parent type name: struct HSprite { int iSpriteWidth; //instead of iWidth }; Anyone that has used an old K&R style compiler that didn't consider the type and global namespaces differently will probably have done something similar out of necessity. It should be entirely possible for a code analyzer to go through and build a dependency and call graph, with knowledge of the framework's inheritance, friendship and polymorphism, and answer queries or generate warnings. When doing spring cleaning on my code base, some of the examples of things that I know the compiler/linker could do but simply don't (and which requires lots of searching for me) are: - warn when including header files that aren't needed. A typical example is when you're doing some debugging and you need sprintf() or FILE so you #include <stdio.h>, but forget to remove it when you're done. - warn when forward declarations aren't used or aren't relevant, e.g. you do "class Foo" which you've later renamed to "class FooBar", but you still have forward declarations to a non-existent class (which don't cause problems) - warn when friendships aren't necessary. This happens when you establish a friendship from A to B because you don't want B::privateThing accessible by the world, just by A. But then later on you change some stuff, and now A doesn't need B::privateThing, but it's still a friend of the class. - warn about types, classes, variables, and functions that are never referenced. This is pretty open ended, and can mean everything from abstract base classes that are never derived from to concrete classes that are never instantiated, but it helps to find vestigial cruft. This has a lot of problems if all you're doing is building a library because you can't tell what the client program is calling, but if you're building test programs, it's a good way of making sure you have reasonable coverage analysis without actually running a coverage analysis program. And, I'm sure, there are a million other things it could check for that currently require manual intervention. Anyone know if such a tool exists? -Hook |
From: Thatcher U. <tu...@tu...> - 2002-07-17 18:50:16
|
On Jul 17, 2002 at 11:34 -0700, Brian Hook wrote: > [snip] > > And, I'm sure, there are a million other things it could check for that > currently require manual intervention. Anyone know if such a tool > exists? PC-Lint exists; claims to do lots of the stuff you mentioned, and more: http://www.gimpel.com/html/lintinfo.htm I've never used it. Also I think people sometimes use Doxygen to do some of what you mentioned. -- Thatcher Ulrich http://tulrich.com |
From: Parveen K. <pk...@sf...> - 2002-07-18 05:26:38
|
Brian Hook wrote: > One of my bitches about software development are that the tools suck. > Many things that can and should be automated simply aren't. Tools like > Emacs and make provide a lot of helpers when you have to do this manual > stuff, but they don't actually solve problems that are language specific > (since those tools aren't language specific). > [snip] If your using emacs, etags might be a little more helpful than grep in certain cases. http://www.gnu.org/manual/emacs-21.2/html_chapter/emacs_26.html#SEC334 Or ebrowse, which is specifically for C++, but I haven't ever used it. http://www-es.fernuni-hagen.de/cgi-bin/info2html?(ebrowse)Top If your using emacs, seems you might be using gcc as well. It's always a good idea to turn on all warnings (and most people do) with -Wall. There are a bunch of compilation switches that aren't covered by -Wall that I like to use: -Weffc++ -Wold-style-cast -pedantic -Wunreachable-code -ansi -Weffc++ catches a few of items (but not nearly enough) from Scott Meyer's Effective C++, which is a pretty cool concept. I've never used gcov. http://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Gcov.html#Gcov Does anyone have any experience with it? Seems like it might be able to find some of that "vestigial cruft". I guess gprof, or any other good profiler, can be used to get the same effect. Don't know how useful these primarily *nix tools will be since a lot of developers are probably sitting in Win32 land. Parveen |
From: Peter L. <pe...@to...> - 2002-07-18 18:21:54
|
coincidentally enough, today I was searching for (and not finding..) a file differencing program that understood C++. Most differencing programs can be configured to ignore whitespace; it would be nice to ignore comments, too. Even more powerful would be one that compared the parse-tree, ignoring symbol name changes. This may sound frivolous, but it's not. Typically, when I'm merging some code into an existing project, I'll add a ton of comments, rename things to match a common set of naming conventions, maybe add or remove a few parentheses or curly braces, and maybe move a few variable declarations or definitions. If the code breaks after that, I've totally lost the ability to (in an automated way) compare it to the original source. But none of the above operations -should- have changed the way the parsed code should look. (OK, maybe moving variable definitions could..) I've hunted around the net a bit, and haven't found a code repository of helpful little utilities like that. I suspect it's out there somewhere, though. Peter -----Original Message----- From: gam...@li... [mailto:gam...@li...]On Behalf Of Brian Hook Sent: Wednesday, July 17, 2002 11:35 AM To: gam...@li... Subject: [GD-General] C++ analyzers? One of my bitches about software development are that the tools suck. Many things that can and should be automated simply aren't. Tools like Emacs and make provide a lot of helpers when you have to do this manual stuff, but they don't actually solve problems that are language specific (since those tools aren't language specific). When working on a large codebase, invariably it acquires several layers of cruft and detritus. Several Java IDEs provide high level tools to do things like refactor, automatically name types and objects, etc. This can be immensely useful. Now that I'm parked on about 120K of source code that I've written, there are times when I want to issue a "query" about some type or variable. Of course, that query ends up being "grep", which completely and utterly sucks when you have lots of name collisions. There are certain variable and function names that are so ubiquitous that grepping for them returns a thousand hits. init/create/alloc and shutdown/destroy/free; flags, type, name, next, prev, id; etc. One way I've gotten around this is defensive coding, whereby I prefix members with their parent type name: struct HSprite { int iSpriteWidth; //instead of iWidth }; Anyone that has used an old K&R style compiler that didn't consider the type and global namespaces differently will probably have done something similar out of necessity. It should be entirely possible for a code analyzer to go through and build a dependency and call graph, with knowledge of the framework's inheritance, friendship and polymorphism, and answer queries or generate warnings. When doing spring cleaning on my code base, some of the examples of things that I know the compiler/linker could do but simply don't (and which requires lots of searching for me) are: - warn when including header files that aren't needed. A typical example is when you're doing some debugging and you need sprintf() or FILE so you #include <stdio.h>, but forget to remove it when you're done. - warn when forward declarations aren't used or aren't relevant, e.g. you do "class Foo" which you've later renamed to "class FooBar", but you still have forward declarations to a non-existent class (which don't cause problems) - warn when friendships aren't necessary. This happens when you establish a friendship from A to B because you don't want B::privateThing accessible by the world, just by A. But then later on you change some stuff, and now A doesn't need B::privateThing, but it's still a friend of the class. - warn about types, classes, variables, and functions that are never referenced. This is pretty open ended, and can mean everything from abstract base classes that are never derived from to concrete classes that are never instantiated, but it helps to find vestigial cruft. This has a lot of problems if all you're doing is building a library because you can't tell what the client program is calling, but if you're building test programs, it's a good way of making sure you have reasonable coverage analysis without actually running a coverage analysis program. And, I'm sure, there are a million other things it could check for that currently require manual intervention. Anyone know if such a tool exists? -Hook ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Kerim B. <wa...@st...> - 2002-07-18 18:54:07
|
Hello Peter, Thursday, July 18, 2002, 10:19:42 PM, you wrote: PL> coincidentally enough, today I was searching for (and not finding..) a file PL> differencing program that understood C++. Most differencing programs can be PL> configured to ignore whitespace; it would be nice to ignore comments, too. PL> Even more powerful would be one that compared the parse-tree, ignoring PL> symbol name changes. This may sound frivolous, but it's not. Typically, when PL> I'm merging some code into an existing project, I'll add a ton of comments, PL> rename things to match a common set of naming conventions, maybe add or PL> remove a few parentheses or curly braces, and maybe move a few variable PL> declarations or definitions. PL> If the code breaks after that, I've totally lost the ability to (in an PL> automated way) compare it to the original source. But none of the above PL> operations -should- have changed the way the parsed code should look. (OK, PL> maybe moving variable definitions could..) PL> I've hunted around the net a bit, and haven't found a code repository of PL> helpful little utilities like that. I suspect it's out there somewhere, PL> though. It's not precisely what you're asking for but using unit tests and integrating your code often helps with this kind of problems alot. (In case someone missed it read excellent Martin Fowler's "Continuous Integration" where he explays why and when it is good for a man to check-in often: http://www.martinfowler.com/articles/continuousIntegration.html ) Best regards, Kerim mailto:wa...@st... PL> Peter PL> -----Original Message----- PL> From: gam...@li... PL> [mailto:gam...@li...]On Behalf Of PL> Brian Hook PL> Sent: Wednesday, July 17, 2002 11:35 AM PL> To: gam...@li... PL> Subject: [GD-General] C++ analyzers? PL> One of my bitches about software development are that the tools suck. PL> Many things that can and should be automated simply aren't. Tools like PL> Emacs and make provide a lot of helpers when you have to do this manual PL> stuff, but they don't actually solve problems that are language specific PL> (since those tools aren't language specific). PL> When working on a large codebase, invariably it acquires several layers PL> of cruft and detritus. Several Java IDEs provide high level tools to do PL> things like refactor, automatically name types and objects, etc. This PL> can be immensely useful. PL> Now that I'm parked on about 120K of source code that I've written, PL> there are times when I want to issue a "query" about some type or PL> variable. PL> Of course, that query ends up being "grep", which completely and utterly PL> sucks when you have lots of name collisions. There are certain variable PL> and function names that are so ubiquitous that grepping for them returns PL> a thousand hits. init/create/alloc and shutdown/destroy/free; flags, PL> type, name, next, prev, id; etc. PL> One way I've gotten around this is defensive coding, whereby I prefix PL> members with their parent type name: PL> struct HSprite PL> { PL> int iSpriteWidth; //instead of iWidth PL> }; PL> Anyone that has used an old K&R style compiler that didn't consider the PL> type and global namespaces differently will probably have done something PL> similar out of necessity. PL> It should be entirely possible for a code analyzer to go through and PL> build a dependency and call graph, with knowledge of the framework's PL> inheritance, friendship and polymorphism, and answer queries or generate PL> warnings. PL> When doing spring cleaning on my code base, some of the examples of PL> things that I know the compiler/linker could do but simply don't (and PL> which requires lots of searching for me) are: PL> - warn when including header files that aren't needed. A typical PL> example is when you're doing some debugging and you need sprintf() or PL> FILE so you #include <stdio.h>, but forget to remove it when you're PL> done. PL> - warn when forward declarations aren't used or aren't relevant, e.g. PL> you do "class Foo" which you've later renamed to "class FooBar", but you PL> still have forward declarations to a non-existent class (which don't PL> cause problems) PL> - warn when friendships aren't necessary. This happens when you PL> establish a friendship from A to B because you don't want PL> B::privateThing accessible by the world, just by A. But then later on PL> you change some stuff, and now A doesn't need B::privateThing, but it's PL> still a friend of the class. PL> - warn about types, classes, variables, and functions that are never PL> referenced. This is pretty open ended, and can mean everything from PL> abstract base classes that are never derived from to concrete classes PL> that are never instantiated, but it helps to find vestigial cruft. This PL> has a lot of problems if all you're doing is building a library because PL> you can't tell what the client program is calling, but if you're PL> building test programs, it's a good way of making sure you have PL> reasonable coverage analysis without actually running a coverage PL> analysis program. PL> And, I'm sure, there are a million other things it could check for that PL> currently require manual intervention. Anyone know if such a tool PL> exists? PL> -Hook PL> ------------------------------------------------------- PL> This sf.net email is sponsored by:ThinkGeek PL> Welcome to geek heaven. PL> http://thinkgeek.com/sf PL> _______________________________________________ PL> Gamedevlists-general mailing list PL> Gam...@li... PL> https://lists.sourceforge.net/lists/listinfo/gamedevlists-general PL> Archives: PL> http://sourceforge.net/mailarchive/forum.php?forum_id=557 PL> ------------------------------------------------------- PL> This sf.net email is sponsored by:ThinkGeek PL> Welcome to geek heaven. PL> http://thinkgeek.com/sf PL> _______________________________________________ PL> Gamedevlists-general mailing list PL> Gam...@li... PL> https://lists.sourceforge.net/lists/listinfo/gamedevlists-general PL> Archives: PL> http://sourceforge.net/mailarchive/forum.php?forum_id=557 |
From: Mick W. <mi...@ne...> - 2002-07-18 19:08:05
|
Araxis Merge (www.araxis.com) can be configured to ignore lines based on regular expressions. It comes with default expressions for (optionally) ignoring C++ // style comments, and VSS auto-inserted data. It's also a brilliant merge program. Mick. -----Original Message----- From: gam...@li... [mailto:gam...@li...]On Behalf Of Peter Lipson Sent: Thursday, July 18, 2002 11:20 AM To: gam...@li... Subject: RE: [GD-General] C++ analyzers? coincidentally enough, today I was searching for (and not finding..) a file differencing program that understood C++. Most differencing programs can be configured to ignore whitespace; it would be nice to ignore comments, too. |
From: Jeff L. <je...@SP...> - 2002-07-21 22:46:27
|
> Message: 9 > From: "Dirk Ringe" <ri...@ph...> > To: <gam...@li...> > Subject: RE: [GD-General] C++ analyzers? > Date: Fri, 19 Jul 2002 09:46:16 +0200 > > We just wrote an include file to pull the relevant level 4 > warnings up to > level 3. It is force included throughout the project: Ye gods, why bother with level 4 at all? Our projects use /W4 with this: #if defined(_WIN32) /* * warnings we turn off are: * 4054 type cast from function pointer to data pointer void * * 4055 type cast from data pointer void * to function pointer * 4097 typedef-name used as synonym for class-name * 4115 named type definition in parentheses (in MS header rpcasynch.h) * 4127 conditional expression is constant * 4204 non-constant aggregate initialiser * 4511 copy constructor could not be generated (a few) * 4512 assignment operator could not be generated (a few) * 4514 unreferenced inline function has been removed (hundreds in C++ headers) * 4615 unknown user warning number (bogus warnings) */ #pragma warning( disable : 4054 4055 4097 4115 4127 4511 4512 4514 4615 4204 ) #endif and we find that that traps any unsavoury practices that we need. Allowing 4127 is perhaps a bit generous but we have an debug mechanism that hits it a lot, and everyone likes to code 'while(1)...' instead of 'for(;;)...' for some reason. There are a could of Windows header files which need you to disable extra warnings, and there are one or two that actually turn warnings DOWN without ever turning them back up, but thats pretty easy to locate and nail. |