C++11 source code generation

本秂侑毒 提交于 2019-12-10 11:03:13

问题


Is there some sort of library for C++ which contains classes which represents C++ source code? It should of course be able to output the source code to a stream. I'm looking for something which supports most C++11 features and is also capable of generating templated constructions.

When I google for this, I'm not getting the results I want. I'm sure though, that there is something available. Maybe I'm just using the wrong terms.


回答1:


Check out the Clang compiler which uses a library-based architecture to support implementing IDEs and other tools that need to process the AST. Clang fully supports all C++11 features (and some C++1y features)

More information can be found in the Clang documentation. Or in this blog which describes basic source to source transformations using clang::Rewriter.




回答2:


This is still in a very experimental phase, but in our lab we are developing a tool (Clava), which is based on Clang and uses a Javascript-like language to query and transform a given C/C++ code. It will be made open-source by the end of August 2017.

For instance, the current default example in the demo website reads all classes and structures in the C/C++ code and creates a C++/H pair with HDF5 wrappers for those classes (however, that code generation is a mix between AST and String literals).

(Clava - Online Demo)



来源:https://stackoverflow.com/questions/17339810/c11-source-code-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!