开发者

Options for open source front end for C++

开发者 https://www.devze.com 2023-01-02 23:49 出处:网络
I am looking for options for an open source C++ compiler front-end (source parser/analyzer) that 开发者_如何学GoI could customize for my requirements. I do not need the back end implementation, just t

I am looking for options for an open source C++ compiler front-end (source parser/analyzer) that 开发者_如何学GoI 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


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.


Have you looked at LLVM clang?


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!


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.


CLang is probably the way to go these days for a comprehensive solution, but if you're looking for something standalone that you can understand then check out this project on github:

https://github.com/robertoraggi/cplusplus

Out of the box it comes with a little command line utility to dump the AST, symbols, and IR code.

This is the C++ front end used in QTCreator. It does a decent job parsing most modern C++ code and even though the cplusplus front end hasn't been updated for a while, QTCreator is very actively used and developed. This code has quite a bit of mileage on it.

0

精彩评论

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