tags:

views:

185

answers:

5

I am looking for options for an open source C++ compiler front-end (source parser/analyzer) that I could customize for my requirements. I do not need the back end implementation, just that it would help to find a fast and relatively bug free C++ front end that supports most standard features. Any suggestions?

[I did google, clang seems to be an option but i'd much prefer peer feedback before i begin with it.]

Arpan

A: 

Please list your actual requirements, might help people give more suggestions. The only two relatively mature open source C++ compiler front ends I know of are gcc and clang. C++ itself is quite complex, if you want something simpler I suggest C, perhaps the SDCC compiler which is fairly simplistic might help.

davr
+2  A: 

Clang and GCC are the two main options. GCC is very complicated (or so I've heard), and Clang is very promising but is immature.

GCC-XML uses GCC's frontend to spit out an XML description of the source. GCC-XML's output is not a full abstract source tree (it doesn't contain function bodies), but it would be a lot easier to work with than GCC itself. (The latest release on the GCC-XML page is horribly out of date; if you don't want to mess around with tracking its CVS yourself, you might try downloading a tarball from, e.g., Debian's gccxml page.)

Depending on your exact requirements, other options might work:

  • CINT is a C / C++ interpreter. I'm told that it's not very strict in its adherence to C++ standards.
  • ROSE can take C and C++ source and lets you do a variety of transformations on it. The C and C++ front-end of ROSE is licensed from EDG, so it's not open source, but it is freely redistributable.
  • Projects such as Doxygen and SWIG include their own limited C++ parsers. Although these are only intended for extracting documentation and generating interfaces, respectively, they may meet your needs.

Edit: For further reading, see "Parsing C++", by Andrew Birkett.

Josh Kelley
gcc-xml doesn't contain the function body.
KennyTM
Updated. Thanks.
Josh Kelley
A: 

Have you looked at LLVM clang?

Nikolai N Fetissov
+1  A: 

For one of the refactoring efforts I've done, we used Elsa:

http://scottmcpeak.com/elkhound/sources/elsa/

with mixed results. Some parts of our code were too complicated or nonstandard for Elsa to deal with, and had to be preprocessed out for the refactoring.

You can use this with Oink:

http://danielwilkerson.com/oink/

if source analysis is what you're in the mood for.

Hope this helps!

Owen S.
+1  A: 

The Digital Mars C++ compiler is not open source, but the source code is available for purchase (see http://www.digitalmars.com/shop.html) and you can customize it.

Walter Bright