asf wrote:
> Hi,
>         Could anybody please suggest me the static code analysis tool
> which can help to write C++ code that adheres to a coding standard.
> (like Checkstyle for JAVA). Any clues in this direction will be
> greatly appreciated.

I looked up the CheckStyle website. The tool seems to peform several 
different functions:

* Code formatting (whitespace & indentation)

Dehydra/treehydra don't analyze the source text, and so they are not the 
right tools to check code formatting

* Static coding conventions

Conventions such as "class member variables must start with m_" or "class 
names must use StudlyCaps" are easy to enforce using dehydra:

http://developer.mozilla.org/en/docs/Dehydra

Just write a process_type(t) function which checks

if (!/$[A-Z][a-z]/.test(t.name))
   error("Class " + t.name + " doesn't have a good name.");

or

for each (let member in t.members)
   let localName = member.name.split(/::/).slice(-1);
   if (localName.slice(-1).slice(0, 2) != "m_")
     error("Member variable " + member.name + " doesn't start with m_");

It is also possible to do much more complex analyses using treehydra, such 
as ensuring that certain functions are always called in pairs, see for instance

http://blog.mozilla.com/tglek/2008/05/27/treehydra-goes-push-and-pop/

where spidermonkey code has a convention that JS_LOCK and JS_UNLOCK must 
always be paired functions.

--BDS
_______________________________________________
Dev-static-analysis mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-static-analysis

Reply via email to