1

I know this question has been asked here, however it was from 2010 and I was wondering if anybody knows of some recent ones made.

I'm looking into using a style checker to help enforce coding conventions at my current workplace. I see the following few options:

  1. A nice flexible way to enforce difference style conventions exist. Vera++ looked interesting and extendable.
  2. Use/hack Google's cpplint style checker (seems daunting)
  3. get access to the parse tree (preferably the AST) of the current file and perform checks on that.

#3 seems the most flexible and wondering whether anyone knows of a program or way to hook into the AST?

Community
  • 1
  • 1
Setheron
  • 3,520
  • 3
  • 34
  • 52
  • 1
    At the AST level, a lot of information you may want to check for is already gone. This includes indentation/whitespace, comments, macros, placement of parentheses, brackets and braces. So if you want to enforce e.g. that macros are written in uppercase, the AST will not help you. – celtschk Dec 01 '11 at 21:44
  • astyle is fairly usable. – Tom Kerr Dec 01 '11 at 22:00
  • @celtschk: The first rule of style is *don't swell the details*. It is more important to identify dangerous vs. safe code patterns than checking whether the indentation is 4 or 8 spaces wide. – David Rodríguez - dribeas Dec 01 '11 at 23:34
  • I'd like to check that variable naming convention, boolean expressions in if statement, etc. – Setheron Dec 06 '11 at 15:16

2 Answers2

0

CppCheck build an AST. And it also allows you to write addons, where you can get access to AST. But as stated above it may wipe necessary information needed to check style. My choice is to customize cpplint.

Megamozg
  • 975
  • 9
  • 15
0

Try xCode with clang and all warning on.
You can also make clang dump the AST.

Daniel
  • 30,896
  • 18
  • 85
  • 139